Commit 76b82085 by alokp@chromium.org

Added GLSL backend for ESSL translator.

Review URL: http://codereview.appspot.com/698041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@69 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 32e58cde
...@@ -58,10 +58,30 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "..\src\libEGL\lib ...@@ -58,10 +58,30 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "..\src\libEGL\lib
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLESv2", "..\src\libGLESv2\libGLESv2.vcproj", "{B5871A7A-968C-42E3-A33B-981E6F448E78}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLESv2", "..\src\libGLESv2\libGLESv2.vcproj", "{B5871A7A-968C-42E3-A33B-981E6F448E78}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7} = {5620F0E4-6C43-49BC-A178-B804E1A0C3A7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_glsl", "..\src\compiler\translator_glsl.vcproj", "{65DB6E65-00E6-4533-8446-5F623BD94909}"
ProjectSection(ProjectDependencies) = postProject
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_hlsl", "..\src\compiler\translator_hlsl.vcproj", "{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}"
ProjectSection(ProjectDependencies) = postProject
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compiler", "..\src\compiler\compiler.vcproj", "{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "essl_to_glsl", "translator\essl_to_glsl.vcproj", "{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}"
ProjectSection(ProjectDependencies) = postProject
{65DB6E65-00E6-4533-8446-5F623BD94909} = {65DB6E65-00E6-4533-8446-5F623BD94909}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "essl_to_hlsl", "translator\essl_to_hlsl.vcproj", "{E12EA115-EBC7-47C2-B651-30A0CE986025}"
ProjectSection(ProjectDependencies) = postProject
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7} = {5620F0E4-6C43-49BC-A178-B804E1A0C3A7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_common", "..\src\compiler\translator_common.vcproj", "{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -117,6 +137,22 @@ Global ...@@ -117,6 +137,22 @@ Global
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Debug|Win32.Build.0 = Debug|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Debug|Win32.Build.0 = Debug|Win32
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.ActiveCfg = Release|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.ActiveCfg = Release|Win32
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.Build.0 = Release|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.Build.0 = Release|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Debug|Win32.ActiveCfg = Debug|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Debug|Win32.Build.0 = Debug|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Release|Win32.ActiveCfg = Release|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Release|Win32.Build.0 = Release|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Debug|Win32.ActiveCfg = Debug|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Debug|Win32.Build.0 = Debug|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Release|Win32.ActiveCfg = Release|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Release|Win32.Build.0 = Release|Win32
{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}.Debug|Win32.ActiveCfg = Debug|Win32
{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}.Debug|Win32.Build.0 = Debug|Win32
{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}.Release|Win32.ActiveCfg = Release|Win32
{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}.Release|Win32.Build.0 = Release|Win32
{E12EA115-EBC7-47C2-B651-30A0CE986025}.Debug|Win32.ActiveCfg = Debug|Win32
{E12EA115-EBC7-47C2-B651-30A0CE986025}.Debug|Win32.Build.0 = Debug|Win32
{E12EA115-EBC7-47C2-B651-30A0CE986025}.Release|Win32.ActiveCfg = Release|Win32
{E12EA115-EBC7-47C2-B651-30A0CE986025}.Release|Win32.Build.0 = Release|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.ActiveCfg = Debug|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.ActiveCfg = Debug|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.Build.0 = Debug|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.Build.0 = Debug|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Release|Win32.ActiveCfg = Release|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Release|Win32.ActiveCfg = Release|Win32
......
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="essl_to_glsl"
ProjectGUID="{EADEBCCD-65ED-45D1-9E06-949A21EBAB9E}"
RootNamespace="essl_to_glsl"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\src\common\debug.cpp"
>
</File>
<File
RelativePath=".\translator.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="essl_to_hlsl"
ProjectGUID="{E12EA115-EBC7-47C2-B651-30A0CE986025}"
RootNamespace="essl_to_hlsl"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\..\src\common\debug.cpp"
>
</File>
<File
RelativePath=".\translator.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "GLSLANG/ShaderLang.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
// Return codes from main.
//
enum TFailCode {
ESuccess = 0,
EFailUsage,
EFailCompile,
EFailLink,
EFailCompilerCreate,
EFailLinkerCreate
};
static EShLanguage FindLanguage(char *lang);
bool CompileFile(char *fileName, ShHandle, int, const TBuiltInResource*);
void usage();
void FreeFileData(char **data);
char** ReadFileData(char *fileName);
void LogMsg(char* msg, const char* name, const int num, const char* logName);
int ShOutputMultipleStrings(char ** );
//Added to accomodate the multiple strings.
int OutputMultipleStrings = 1;
//
// Set up the per compile resources
//
void GenerateResources(TBuiltInResource& resources)
{
resources.maxVertexAttribs = 8;
resources.maxVertexUniformVectors = 128;
resources.maxVaryingVectors = 8;
resources.maxVertexTextureImageUnits = 0;
resources.maxCombinedTextureImageUnits = 8;
resources.maxTextureImageUnits = 8;
resources.maxFragmentUniformVectors = 16;
resources.maxDrawBuffers = 1;
}
int C_DECL main(int argc, char* argv[])
{
int numCompilers = 0;
bool compileFailed = false;
int debugOptions = 0;
int i;
ShHandle linker = 0;
ShHandle uniformMap = 0;
ShHandle compilers[EShLangCount];
ShInitialize();
argc--;
argv++;
for (; argc >= 1; argc--, argv++) {
if (argv[0][0] == '-' || argv[0][0] == '/') {
switch (argv[0][1]) {
case 'i': debugOptions |= EDebugOpIntermediate; break;
case 'o': debugOptions |= EDebugOpObjectCode; break;
default: usage(); return EFailUsage;
}
} else {
compilers[numCompilers] = ShConstructCompiler(FindLanguage(argv[0]), debugOptions);
if (compilers[numCompilers] == 0)
return EFailCompilerCreate;
++numCompilers;
TBuiltInResource resources;
GenerateResources(resources);
if (!CompileFile(argv[0], compilers[numCompilers-1], debugOptions, &resources))
compileFailed = true;
}
}
if (!numCompilers) {
usage();
return EFailUsage;
}
for (i = 0; i < numCompilers; ++i) {
LogMsg("BEGIN", "COMPILER", i, "INFO LOG");
puts(ShGetInfoLog(compilers[i]));
LogMsg("END", "COMPILER", i, "INFO LOG");
}
if ((debugOptions & EDebugOpObjectCode) != 0) {
for (i = 0; i < numCompilers; ++i) {
LogMsg("BEGIN", "COMPILER", i, "OBJ CODE");
puts(ShGetObjectCode(compilers[i]));
LogMsg("END", "COMPILER", i, "OBJ CODE");
}
}
for (i = 0; i < numCompilers; ++i)
ShDestruct(compilers[i]);
return compileFailed ? EFailCompile : ESuccess;
}
//
// Deduce the language from the filename. Files must end in one of the
// following extensions:
//
// .frag* = fragment programs
// .vert* = vertex programs
//
static EShLanguage FindLanguage(char *name)
{
if (!name)
return EShLangFragment;
char *ext = strrchr(name, '.');
if (ext && strcmp(ext, ".sl") == 0)
for (; ext > name && ext[0] != '.'; ext--);
if (ext = strrchr(name, '.')) {
if (strncmp(ext, ".frag", 4) == 0) return EShLangFragment;
if (strncmp(ext, ".vert", 4) == 0) return EShLangVertex;
}
return EShLangFragment;
}
//
// Read a file's data into a string, and compile it using ShCompile
//
bool CompileFile(char *fileName, ShHandle compiler, int debugOptions, const TBuiltInResource *resources)
{
int ret;
char **data = ReadFileData(fileName);
if (!data)
return false;
ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, resources, debugOptions);
FreeFileData(data);
return ret ? true : false;
}
//
// print usage to stdout
//
void usage()
{
printf("Usage: translate [-i -o] file1 file2 ...\n"
"Where: filename = filename ending in .frag or .vert\n"
" -i = print intermediate tree\n"
" -o = print translated code\n");
}
//
// Malloc a string of sufficient size and read a string into it.
//
# define MAX_SOURCE_STRINGS 5
char** ReadFileData(char *fileName)
{
FILE* in = fopen(fileName, "r");
char* fdata = 0;
int count = 0;
char** return_data = (char**)malloc(MAX_SOURCE_STRINGS+1);
if (!in) {
printf("Error: unable to open input file: %s\n", fileName);
return 0;
}
while (fgetc(in) != EOF)
count++;
fseek(in, 0, SEEK_SET);
if (!(fdata = (char*)malloc(count+2))) {
printf("Error allocating memory\n");
return 0;
}
if (fread(fdata, 1, count, in) != count) {
printf("Error reading input file: %s\n", fileName);
return 0;
}
fdata[count] = '\0';
fclose(in);
if (count == 0){
return_data[0] = (char*)malloc(count+2);
return_data[0][0] = '\0';
OutputMultipleStrings = 0;
return return_data;
}
int len = (int)(ceil)((float)count / (float)OutputMultipleStrings);
int ptr_len = 0, i = 0;
while (count > 0) {
return_data[i] = (char*)malloc(len+2);
memcpy(return_data[i], fdata+ptr_len, len);
return_data[i][len] = '\0';
count -= (len);
ptr_len += (len);
if (count < len){
if(count == 0){
OutputMultipleStrings = (i+1);
break;
}
len = count;
}
++i;
}
return return_data;
}
void FreeFileData(char** data)
{
for(int i=0;i<OutputMultipleStrings;i++)
free(data[i]);
}
void LogMsg(char* msg, const char* name, const int num, const char* logName)
{
printf(num >= 0 ? "#### %s %s %d %s ####\n" :
"#### %s %s INFO LOG ####\n", msg, name, num, logName);
}
int ShOutputMultipleStrings(char** argv)
{
if(!(abs(OutputMultipleStrings = atoi(*argv)))||((OutputMultipleStrings >5 || OutputMultipleStrings < 1)? 1:0)){
printf("Invalid Command Line Argument after -c option.\n"
"Usage: -c <integer> where integer =[1,5]\n"
"This option must be specified before the input file path\n");
return 0;
}
return 1;
}
 
Microsoft Visual Studio Solution File, Format Version 10.00 Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008 # Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "libEGL\libEGL.vcproj", "{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "libEGL\libEGL.vcproj", "{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{B5871A7A-968C-42E3-A33B-981E6F448E78} = {B5871A7A-968C-42E3-A33B-981E6F448E78} {B5871A7A-968C-42E3-A33B-981E6F448E78} = {B5871A7A-968C-42E3-A33B-981E6F448E78}
...@@ -8,10 +8,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "libEGL\libEGL.vcp ...@@ -8,10 +8,20 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libEGL", "libEGL\libEGL.vcp
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLESv2", "libGLESv2\libGLESv2.vcproj", "{B5871A7A-968C-42E3-A33B-981E6F448E78}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLESv2", "libGLESv2\libGLESv2.vcproj", "{B5871A7A-968C-42E3-A33B-981E6F448E78}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7} = {5620F0E4-6C43-49BC-A178-B804E1A0C3A7}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_glsl", "compiler\translator_glsl.vcproj", "{65DB6E65-00E6-4533-8446-5F623BD94909}"
ProjectSection(ProjectDependencies) = postProject
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_hlsl", "compiler\translator_hlsl.vcproj", "{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}"
ProjectSection(ProjectDependencies) = postProject
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compiler", "compiler\compiler.vcproj", "{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "translator_common", "compiler\translator_common.vcproj", "{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -27,6 +37,14 @@ Global ...@@ -27,6 +37,14 @@ Global
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Debug|Win32.Build.0 = Debug|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Debug|Win32.Build.0 = Debug|Win32
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.ActiveCfg = Release|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.ActiveCfg = Release|Win32
{B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.Build.0 = Release|Win32 {B5871A7A-968C-42E3-A33B-981E6F448E78}.Release|Win32.Build.0 = Release|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Debug|Win32.ActiveCfg = Debug|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Debug|Win32.Build.0 = Debug|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Release|Win32.ActiveCfg = Release|Win32
{65DB6E65-00E6-4533-8446-5F623BD94909}.Release|Win32.Build.0 = Release|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Debug|Win32.ActiveCfg = Debug|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Debug|Win32.Build.0 = Debug|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Release|Win32.ActiveCfg = Release|Win32
{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}.Release|Win32.Build.0 = Release|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.ActiveCfg = Debug|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.ActiveCfg = Debug|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.Build.0 = Debug|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Debug|Win32.Build.0 = Debug|Win32
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Release|Win32.ActiveCfg = Release|Win32 {5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}.Release|Win32.ActiveCfg = Release|Win32
......
...@@ -4,19 +4,7 @@ ...@@ -4,19 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "Common.h" #include "TranslatorGLSL.h"
#include "ShHandle.h"
//
// Here is where real machine specific high-level data would be defined.
//
class TGenericCompiler : public TCompiler {
public:
TGenericCompiler(EShLanguage l, int dOptions) : TCompiler(l, infoSink), debugOptions(dOptions) { }
virtual bool compile(TIntermNode* root);
TInfoSink infoSink;
int debugOptions;
};
// //
// This function must be provided to create the actual // This function must be provided to create the actual
...@@ -25,7 +13,7 @@ public: ...@@ -25,7 +13,7 @@ public:
// //
TCompiler* ConstructCompiler(EShLanguage language, int debugOptions) TCompiler* ConstructCompiler(EShLanguage language, int debugOptions)
{ {
return new TGenericCompiler(language, debugOptions); return new TranslatorGLSL(language, debugOptions);
} }
// //
...@@ -35,13 +23,3 @@ void DeleteCompiler(TCompiler* compiler) ...@@ -35,13 +23,3 @@ void DeleteCompiler(TCompiler* compiler)
{ {
delete compiler; delete compiler;
} }
//
// Generate code from the given parse tree
//
bool TGenericCompiler::compile(TIntermNode *root)
{
haveValidObjectCode = true;
return haveValidObjectCode;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "TranslatorHLSL.h"
//
// This function must be provided to create the actual
// compile object used by higher level code. It returns
// a subclass of TCompiler.
//
TCompiler* ConstructCompiler(EShLanguage language, int debugOptions)
{
return new TranslatorHLSL(language, debugOptions);
}
//
// Delete the compiler made by ConstructCompiler
//
void DeleteCompiler(TCompiler* compiler)
{
delete compiler;
}
...@@ -272,7 +272,7 @@ public: ...@@ -272,7 +272,7 @@ public:
return returnValue; return returnValue;
} }
TBasicType getType() { return type; } TBasicType getType() const { return type; }
private: private:
union { union {
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
// //
class TGenericLinker : public TLinker { class TGenericLinker : public TLinker {
public: public:
TGenericLinker(EShExecutable e, int dOptions) : TLinker(e, infoSink), debugOptions(dOptions) { } TGenericLinker(EShExecutable e, int dOptions) : TLinker(e), debugOptions(dOptions) { }
bool link(TCompilerList&, TUniformMap*) { return true; } bool link(TCompilerList&, TUniformMap*) { return true; }
void getAttributeBindings(ShBindingTable const **t) const { } void getAttributeBindings(ShBindingTable const **t) const { }
TInfoSink infoSink;
int debugOptions; int debugOptions;
}; };
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "OutputGLSL.h"
#include "common/debug.h"
namespace
{
TString getTypeName(const TType& type)
{
TInfoSinkBase out;
if (type.isMatrix())
{
out << "mat";
out << type.getNominalSize();
}
else if (type.isArray())
{
UNIMPLEMENTED();
}
else if (type.isVector())
{
switch (type.getBasicType())
{
case EbtFloat: out << "vec"; break;
case EbtInt: out << "ivec"; break;
case EbtBool: out << "bvec"; break;
default: UNREACHABLE(); break;
}
out << type.getNominalSize();
}
else
{
if (type.getBasicType() == EbtStruct)
out << type.getTypeName();
else
out << type.getBasicString();
}
return TString(out.c_str());
}
TString getUnmangledFunctionName(const TString& mangledName)
{
return TString(mangledName.c_str(), mangledName.find_first_of('('));
}
TString getIndentationString(int depth)
{
TString indentation(depth, ' ');
return indentation;
}
} // namespace
TOutputGLSL::TOutputGLSL(TParseContext &context)
: TIntermTraverser(true, true, true),
writeFullSymbol(false),
parseContext(context)
{
}
void TOutputGLSL::header()
{
TInfoSinkBase& out = objSink();
TSymbolTableLevel* symbols = parseContext.symbolTable.getGlobalLevel();
for (TSymbolTableLevel::const_iterator symbolIter = symbols->begin(); symbolIter != symbols->end(); ++symbolIter)
{
const TSymbol* symbol = symbolIter->second;
if (!symbol->isVariable())
continue;
const TVariable* variable = static_cast<const TVariable*>(symbol);
const TString& name = variable->getName();
const TType& type = variable->getType();
TQualifier qualifier = type.getQualifier();
//symbol->dump(parseContext.infoSink);
}
}
void TOutputGLSL::writeTriplet(Visit visit, const char* preStr, const char* inStr, const char* postStr)
{
TInfoSinkBase& out = objSink();
if (visit == PreVisit && preStr)
{
out << preStr;
}
else if (visit == InVisit && inStr)
{
out << inStr;
}
else if (visit == PostVisit && postStr)
{
out << postStr;
}
}
void TOutputGLSL::visitSymbol(TIntermSymbol* node)
{
TInfoSinkBase& out = objSink();
if (writeFullSymbol)
{
TQualifier qualifier = node->getQualifier();
if ((qualifier != EvqTemporary) && (qualifier != EvqGlobal))
out << node->getQualifierString() << " ";
out << getTypeName(node->getType()) << " ";
}
out << node->getSymbol();
}
void TOutputGLSL::visitConstantUnion(TIntermConstantUnion* node)
{
TInfoSinkBase& out = objSink();
TType type = node->getType();
int size = type.getObjectSize();
if (size > 1)
out << getTypeName(type) << "(";
for (int i = 0; i < size; ++i) {
const constUnion& data = node->getUnionArrayPointer()[i];
switch (data.getType())
{
case EbtFloat: out << data.getFConst(); break;
case EbtInt: out << data.getIConst(); break;
case EbtBool: out << data.getBConst(); break;
default: UNREACHABLE(); break;
}
if (i != size - 1)
out << ", ";
}
if (size > 1)
out << ")";
}
bool TOutputGLSL::visitBinary(Visit visit, TIntermBinary* node)
{
bool visitChildren = true;
TInfoSinkBase& out = objSink();
switch (node->getOp())
{
case EOpAssign: writeTriplet(visit, NULL, " = ", NULL); break;
case EOpInitialize:
if (visit == InVisit) {
out << " = ";
writeFullSymbol= false;
}
break;
case EOpAddAssign: writeTriplet(visit, NULL, " += ", NULL); break;
case EOpSubAssign: UNIMPLEMENTED(); break;
case EOpMulAssign: UNIMPLEMENTED(); break;
case EOpVectorTimesMatrixAssign: UNIMPLEMENTED(); break;
case EOpVectorTimesScalarAssign: UNIMPLEMENTED(); break;
case EOpMatrixTimesScalarAssign: UNIMPLEMENTED(); break;
case EOpMatrixTimesMatrixAssign: UNIMPLEMENTED(); break;
case EOpDivAssign: UNIMPLEMENTED(); break;
case EOpIndexDirect: writeTriplet(visit, NULL, "[", "]"); break;
case EOpIndexIndirect: UNIMPLEMENTED(); break;
case EOpIndexDirectStruct:
if (visit == InVisit)
{
out << ".";
// TODO(alokp): ASSERT
out << node->getType().getFieldName();
visitChildren = false;
}
break;
case EOpVectorSwizzle:
if (visit == InVisit)
{
out << ".";
TIntermAggregate* rightChild = node->getRight()->getAsAggregate();
TIntermSequence& sequence = rightChild->getSequence();
for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); ++sit)
{
TIntermConstantUnion* element = (*sit)->getAsConstantUnion();
ASSERT(element->getBasicType() == EbtInt);
ASSERT(element->getNominalSize() == 1);
const constUnion& data = element->getUnionArrayPointer()[0];
ASSERT(data.getType() == EbtInt);
switch (data.getIConst())
{
case 0: out << "x"; break;
case 1: out << "y"; break;
case 2: out << "z"; break;
case 3: out << "w"; break;
default: UNREACHABLE(); break;
}
}
visitChildren = false;
}
break;
case EOpAdd: writeTriplet(visit, "(", " + ", ")"); break;
case EOpSub: writeTriplet(visit, "(", " - ", ")"); break;
case EOpMul: writeTriplet(visit, "(", " * ", ")"); break;
case EOpDiv: writeTriplet(visit, "(", " / ", ")"); break;
case EOpMod: UNIMPLEMENTED(); break;
case EOpEqual: UNIMPLEMENTED(); break;
case EOpNotEqual: UNIMPLEMENTED(); break;
case EOpLessThan: writeTriplet(visit, "(", " < ", ")"); break;
case EOpGreaterThan: writeTriplet(visit, NULL, " > ", NULL); break;
case EOpLessThanEqual: UNIMPLEMENTED(); break;
case EOpGreaterThanEqual: UNIMPLEMENTED(); break;
// Notice the fall-through.
case EOpVectorTimesScalar:
case EOpVectorTimesMatrix:
case EOpMatrixTimesVector:
case EOpMatrixTimesScalar:
case EOpMatrixTimesMatrix:
writeTriplet(visit, "(", " * ", ")");
break;
case EOpLogicalOr: writeTriplet(visit, "(", " || ", ")"); break;
case EOpLogicalXor: UNIMPLEMENTED(); break;
case EOpLogicalAnd: UNIMPLEMENTED(); break;
default: UNREACHABLE(); break;
}
return visitChildren;
}
bool TOutputGLSL::visitUnary(Visit visit, TIntermUnary* node)
{
TInfoSinkBase& out = objSink();
switch (node->getOp())
{
case EOpNegative: writeTriplet(visit, "(-", NULL, ")"); break;
case EOpVectorLogicalNot: UNIMPLEMENTED(); break;
case EOpLogicalNot: UNIMPLEMENTED(); break;
case EOpPostIncrement: UNIMPLEMENTED(); break;
case EOpPostDecrement: UNIMPLEMENTED(); break;
case EOpPreIncrement: UNIMPLEMENTED(); break;
case EOpPreDecrement: UNIMPLEMENTED(); break;
case EOpConvIntToBool: UNIMPLEMENTED(); break;
case EOpConvFloatToBool: UNIMPLEMENTED(); break;
case EOpConvBoolToFloat: UNIMPLEMENTED(); break;
case EOpConvIntToFloat: writeTriplet(visit, "float(", NULL, ")"); break;
case EOpConvFloatToInt: UNIMPLEMENTED(); break;
case EOpConvBoolToInt: UNIMPLEMENTED(); break;
case EOpRadians: UNIMPLEMENTED(); break;
case EOpDegrees: UNIMPLEMENTED(); break;
case EOpSin: writeTriplet(visit, "sin(", NULL, ")"); break;
case EOpCos: writeTriplet(visit, "cos(", NULL, ")"); break;
case EOpTan: UNIMPLEMENTED(); break;
case EOpAsin: UNIMPLEMENTED(); break;
case EOpAcos: UNIMPLEMENTED(); break;
case EOpAtan: UNIMPLEMENTED(); break;
case EOpExp: UNIMPLEMENTED(); break;
case EOpLog: UNIMPLEMENTED(); break;
case EOpExp2: UNIMPLEMENTED(); break;
case EOpLog2: UNIMPLEMENTED(); break;
case EOpSqrt: UNIMPLEMENTED(); break;
case EOpInverseSqrt: UNIMPLEMENTED(); break;
case EOpAbs: UNIMPLEMENTED(); break;
case EOpSign: UNIMPLEMENTED(); break;
case EOpFloor: writeTriplet(visit, "floor(", NULL, ")"); break;
case EOpCeil: UNIMPLEMENTED(); break;
case EOpFract: UNIMPLEMENTED(); break;
case EOpLength: UNIMPLEMENTED(); break;
case EOpNormalize: writeTriplet(visit, "normalize(", NULL, ")"); break;
case EOpAny: UNIMPLEMENTED(); break;
case EOpAll: UNIMPLEMENTED(); break;
default: UNREACHABLE(); break;
}
return true;
}
bool TOutputGLSL::visitSelection(Visit visit, TIntermSelection* node)
{
TInfoSinkBase& out = objSink();
out << "if (";
node->getCondition()->traverse(this);
out << ") {\n";
incrementDepth();
node->getTrueBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
if (node->getFalseBlock())
{
out << " else {\n";
node->getFalseBlock()->traverse(this);
out << getIndentationString(depth - 2) << "}";
}
decrementDepth();
out << "\n";
return false;
}
bool TOutputGLSL::visitAggregate(Visit visit, TIntermAggregate* node)
{
TInfoSinkBase& out = objSink();
switch (node->getOp())
{
case EOpSequence:
if (visit == PreVisit)
{
out << getIndentationString(depth);
}
else if (visit == InVisit)
{
out << ";\n";
out << getIndentationString(depth - 1);
}
else
{
out << ";\n";
}
break;
case EOpComma:
UNIMPLEMENTED();
return true;
case EOpFunction:
if (visit == PreVisit)
{
TString returnType = node->getBasicString();
TString functionName = getUnmangledFunctionName(node->getName());
out << returnType << " " << functionName;
}
else if (visit == InVisit)
{
// Called after traversing function arguments (EOpParameters)
// but before traversing function body (EOpSequence).
out << "{\n";
}
else if (visit == PostVisit)
{
// Called after traversing function body (EOpSequence).
out << "}\n";
}
break;
case EOpFunctionCall:
if (visit == PreVisit)
{
TString functionName = getUnmangledFunctionName(node->getName());
out << functionName << "(";
}
else if (visit == InVisit)
{
out << ", ";
}
else
{
out << ")";
}
break;
case EOpParameters:
if (visit == PreVisit)
{
out << "(";
writeFullSymbol = true;
}
else if (visit == InVisit)
{
out << ", ";
}
else
{
out << ")";
writeFullSymbol = false;
}
break;
case EOpDeclaration:
if (visit == PreVisit)
{
writeFullSymbol = true;
}
else if (visit == InVisit)
{
out << ", ";
writeFullSymbol = false;
}
else
{
writeFullSymbol = false;
}
break;
case EOpConstructFloat: UNIMPLEMENTED(); break;
case EOpConstructVec2: writeTriplet(visit, "vec2(", ", ", ")"); break;
case EOpConstructVec3: writeTriplet(visit, "vec3(", ", ", ")"); break;
case EOpConstructVec4: writeTriplet(visit, "vec4(", ", ", ")"); break;
case EOpConstructBool: UNIMPLEMENTED(); break;
case EOpConstructBVec2: UNIMPLEMENTED(); break;
case EOpConstructBVec3: UNIMPLEMENTED(); break;
case EOpConstructBVec4: UNIMPLEMENTED(); break;
case EOpConstructInt: UNIMPLEMENTED(); break;
case EOpConstructIVec2: UNIMPLEMENTED(); break;
case EOpConstructIVec3: UNIMPLEMENTED(); break;
case EOpConstructIVec4: UNIMPLEMENTED(); break;
case EOpConstructMat2: UNIMPLEMENTED(); break;
case EOpConstructMat3: UNIMPLEMENTED(); break;
case EOpConstructMat4: writeTriplet(visit, "mat4(", ", ", ")"); break;
case EOpConstructStruct: UNIMPLEMENTED(); break;
case EOpLessThan: UNIMPLEMENTED(); break;
case EOpGreaterThan: UNIMPLEMENTED(); break;
case EOpLessThanEqual: UNIMPLEMENTED(); break;
case EOpGreaterThanEqual: UNIMPLEMENTED(); break;
case EOpVectorEqual: UNIMPLEMENTED(); break;
case EOpVectorNotEqual: UNIMPLEMENTED(); break;
case EOpMod: writeTriplet(visit, "mod(", ", ", ")"); break;
case EOpPow: writeTriplet(visit, "pow(", ", ", ")"); break;
case EOpAtan: UNIMPLEMENTED(); break;
case EOpMin: writeTriplet(visit, "min(", ", ", ")"); break;
case EOpMax: writeTriplet(visit, "max(", ", ", ")"); break;
case EOpClamp: writeTriplet(visit, "clamp(", ", ", ")"); break;
case EOpMix: writeTriplet(visit, "mix(", ", ", ")"); break;
case EOpStep: UNIMPLEMENTED(); break;
case EOpSmoothStep: UNIMPLEMENTED(); break;
case EOpDistance: UNIMPLEMENTED(); break;
case EOpDot: writeTriplet(visit, "dot(", ", ", ")"); break;
case EOpCross: UNIMPLEMENTED(); break;
case EOpFaceForward: UNIMPLEMENTED(); break;
case EOpReflect: writeTriplet(visit, "reflect(", ", ", ")"); break;
case EOpRefract: UNIMPLEMENTED(); break;
case EOpMul: UNIMPLEMENTED(); break;
default: UNREACHABLE(); break;
}
return true;
}
bool TOutputGLSL::visitLoop(Visit visit, TIntermLoop* node)
{
UNIMPLEMENTED();
return true;
}
bool TOutputGLSL::visitBranch(Visit visit, TIntermBranch* node)
{
TInfoSinkBase &out = objSink();
switch (node->getFlowOp())
{
case EOpKill: UNIMPLEMENTED(); break;
case EOpBreak: UNIMPLEMENTED(); break;
case EOpContinue: UNIMPLEMENTED(); break;
case EOpReturn:
if (visit == PreVisit)
out << "return ";
break;
default: UNREACHABLE(); break;
}
return true;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef CROSSCOMPILERGLSL_OUTPUTGLSL_H_
#define CROSSCOMPILERGLSL_OUTPUTGLSL_H_
#include "intermediate.h"
#include "ParseHelper.h"
class TOutputGLSL : public TIntermTraverser
{
public:
TOutputGLSL(TParseContext &context);
void header();
protected:
TInfoSinkBase& objSink() { return parseContext.infoSink.obj; }
void writeTriplet(Visit visit, const char* preStr, const char* inStr, const char* postStr);
virtual void visitSymbol(TIntermSymbol* node);
virtual void visitConstantUnion(TIntermConstantUnion* node);
virtual bool visitBinary(Visit visit, TIntermBinary* node);
virtual bool visitUnary(Visit visit, TIntermUnary* node);
virtual bool visitSelection(Visit visit, TIntermSelection* node);
virtual bool visitAggregate(Visit visit, TIntermAggregate* node);
virtual bool visitLoop(Visit visit, TIntermLoop* node);
virtual bool visitBranch(Visit visit, TIntermBranch* node);
private:
bool writeFullSymbol;
TParseContext &parseContext;
};
#endif // CROSSCOMPILERGLSL_OUTPUTGLSL_H_
...@@ -56,7 +56,7 @@ class TIntermNode; ...@@ -56,7 +56,7 @@ class TIntermNode;
// //
class TCompiler : public TShHandleBase { class TCompiler : public TShHandleBase {
public: public:
TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { } TCompiler(EShLanguage l) : language(l), haveValidObjectCode(false) { }
virtual ~TCompiler() { } virtual ~TCompiler() { }
EShLanguage getLanguage() { return language; } EShLanguage getLanguage() { return language; }
virtual TInfoSink& getInfoSink() { return infoSink; } virtual TInfoSink& getInfoSink() { return infoSink; }
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
virtual TCompiler* getAsCompiler() { return this; } virtual TCompiler* getAsCompiler() { return this; }
virtual bool linkable() { return haveValidObjectCode; } virtual bool linkable() { return haveValidObjectCode; }
TInfoSink& infoSink; TInfoSink infoSink;
protected: protected:
EShLanguage language; EShLanguage language;
bool haveValidObjectCode; bool haveValidObjectCode;
...@@ -85,8 +85,7 @@ typedef TVector<TShHandleBase*> THandleList; ...@@ -85,8 +85,7 @@ typedef TVector<TShHandleBase*> THandleList;
class TLinker : public TShHandleBase { class TLinker : public TShHandleBase {
public: public:
TLinker(EShExecutable e, TInfoSink& iSink) : TLinker(EShExecutable e) :
infoSink(iSink),
executable(e), executable(e),
haveReturnableObjectCode(false), haveReturnableObjectCode(false),
appAttributeBindings(0), appAttributeBindings(0),
...@@ -105,7 +104,7 @@ public: ...@@ -105,7 +104,7 @@ public:
virtual ShBindingTable* getUniformBindings() const { return uniformBindings; } virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
virtual TInfoSink& getInfoSink() { return infoSink; } virtual TInfoSink& getInfoSink() { return infoSink; }
TInfoSink& infoSink; TInfoSink infoSink;
protected: protected:
EShExecutable executable; EShExecutable executable;
bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "Initialize.h" #include "Initialize.h"
#include "InitializeDll.h" #include "InitializeDll.h"
#include "OutputHLSL.h"
#include "ParseHelper.h" #include "ParseHelper.h"
#include "ShHandle.h" #include "ShHandle.h"
#include "SymbolTable.h" #include "SymbolTable.h"
...@@ -244,19 +243,20 @@ int ShCompile( ...@@ -244,19 +243,20 @@ int ShCompile(
return 0; return 0;
GlobalPoolAllocator.push(); GlobalPoolAllocator.push();
compiler->infoSink.info.erase(); TInfoSink& infoSink = compiler->infoSink;
compiler->infoSink.debug.erase(); infoSink.info.erase();
compiler->infoSink.obj.erase(); infoSink.debug.erase();
infoSink.obj.erase();
if (numStrings == 0) if (numStrings == 0)
return 1; return 1;
TIntermediate intermediate(compiler->infoSink); TIntermediate intermediate(infoSink);
TSymbolTable symbolTable(SymbolTables[compiler->getLanguage()]); TSymbolTable symbolTable(SymbolTables[compiler->getLanguage()]);
GenerateBuiltInSymbolTable(resources, compiler->infoSink, &symbolTable, compiler->getLanguage()); GenerateBuiltInSymbolTable(resources, infoSink, &symbolTable, compiler->getLanguage());
TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), compiler->infoSink); TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), infoSink);
parseContext.initializeExtensionBehavior(); parseContext.initializeExtensionBehavior();
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
...@@ -290,18 +290,10 @@ int ShCompile( ...@@ -290,18 +290,10 @@ int ShCompile(
if (debugOptions & EDebugOpIntermediate) if (debugOptions & EDebugOpIntermediate)
intermediate.outputTree(parseContext.treeRoot); intermediate.outputTree(parseContext.treeRoot);
if(debugOptions & EDebugOpObjectCode)
{
sh::OutputHLSL outputHLSL(parseContext);
outputHLSL.header();
parseContext.treeRoot->traverse(&outputHLSL);
}
// //
// Call the machine dependent compiler // Call the machine dependent compiler
// //
if (! compiler->compile(parseContext.treeRoot)) if (!compiler->compile(parseContext.treeRoot))
success = false; success = false;
} }
} }
......
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "TranslatorGLSL.h"
#include "OutputGLSL.h"
TranslatorGLSL::TranslatorGLSL(EShLanguage l, int dOptions)
: TCompiler(l),
debugOptions(dOptions) {
}
bool TranslatorGLSL::compile(TIntermNode* root) {
TParseContext& parseContext = *GetGlobalParseContext();
TOutputGLSL outputGLSL(parseContext);
outputGLSL.header();
parseContext.treeRoot->traverse(&outputGLSL);
return true;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATORGLSL_H_
#define COMPILER_TRANSLATORGLSL_H_
#include "ShHandle.h"
class TranslatorGLSL : public TCompiler {
public:
TranslatorGLSL(EShLanguage l, int dOptions);
virtual bool compile(TIntermNode* root);
int debugOptions;
};
#endif // COMPILER_TRANSLATORGLSL_H_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "TranslatorHLSL.h"
#include "OutputHLSL.h"
TranslatorHLSL::TranslatorHLSL(EShLanguage l, int dOptions)
: TCompiler(l),
debugOptions(dOptions) {
}
bool TranslatorHLSL::compile(TIntermNode* root) {
TParseContext& parseContext = *GetGlobalParseContext();
sh::OutputHLSL outputHLSL(parseContext);
outputHLSL.header();
parseContext.treeRoot->traverse(&outputHLSL);
return true;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATORHLSL_H_
#define COMPILER_TRANSLATORHLSL_H_
#include "ShHandle.h"
class TranslatorHLSL : public TCompiler {
public:
TranslatorHLSL(EShLanguage l, int dOptions);
virtual bool compile(TIntermNode* root);
int debugOptions;
};
#endif // COMPILER_TRANSLATORHLSL_H_
...@@ -97,6 +97,7 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary* node) ...@@ -97,6 +97,7 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary* node)
switch (node->getOp()) { switch (node->getOp()) {
case EOpAssign: out.debug << "move second child to first child"; break; case EOpAssign: out.debug << "move second child to first child"; break;
case EOpInitialize: out.debug << "initialize first child with second child"; break;
case EOpAddAssign: out.debug << "add second child into first child"; break; case EOpAddAssign: out.debug << "add second child into first child"; break;
case EOpSubAssign: out.debug << "subtract second child into first child"; break; case EOpSubAssign: out.debug << "subtract second child into first child"; break;
case EOpMulAssign: out.debug << "multiply second child into first child"; break; case EOpMulAssign: out.debug << "multiply second child into first child"; break;
...@@ -187,9 +188,9 @@ bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node) ...@@ -187,9 +188,9 @@ bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node)
case EOpLength: out.debug << "length"; break; case EOpLength: out.debug << "length"; break;
case EOpNormalize: out.debug << "normalize"; break; case EOpNormalize: out.debug << "normalize"; break;
// case EOpDPdx: out.debug << "dPdx"; break; // case EOpDPdx: out.debug << "dPdx"; break;
// case EOpDPdy: out.debug << "dPdy"; break; // case EOpDPdy: out.debug << "dPdy"; break;
// case EOpFwidth: out.debug << "fwidth"; break; // case EOpFwidth: out.debug << "fwidth"; break;
case EOpAny: out.debug << "any"; break; case EOpAny: out.debug << "any"; break;
case EOpAll: out.debug << "all"; break; case EOpAll: out.debug << "all"; break;
...@@ -316,6 +317,7 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -316,6 +317,7 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
int size = node->getType().getObjectSize(); int size = node->getType().getObjectSize();
char buf[300];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
OutputTreeText(out, node, depth); OutputTreeText(out, node, depth);
switch (node->getUnionArrayPointer()[i].getType()) { switch (node->getUnionArrayPointer()[i].getType()) {
...@@ -326,25 +328,16 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node) ...@@ -326,25 +328,16 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
out.debug << "false"; out.debug << "false";
out.debug << " (" << "const bool" << ")"; out.debug << " (" << "const bool" << ")";
out.debug << "\n"; out.debug << "\n";
break; break;
case EbtFloat: case EbtFloat:
{
char buf[300];
sprintf(buf, "%f (%s)", node->getUnionArrayPointer()[i].getFConst(), "const float"); sprintf(buf, "%f (%s)", node->getUnionArrayPointer()[i].getFConst(), "const float");
out.debug << buf << "\n"; out.debug << buf << "\n";
}
break; break;
case EbtInt: case EbtInt:
{
char buf[300];
sprintf(buf, "%d (%s)", node->getUnionArrayPointer()[i].getIConst(), "const int"); sprintf(buf, "%d (%s)", node->getUnionArrayPointer()[i].getIConst(), "const int");
out.debug << buf << "\n"; out.debug << buf << "\n";
break; break;
}
default: default:
out.info.message(EPrefixInternalError, "Unknown constant", node->getLine()); out.info.message(EPrefixInternalError, "Unknown constant", node->getLine());
break; break;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9.00"
Name="compiler" Name="translator_common"
ProjectGUID="{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}" ProjectGUID="{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD}"
RootNamespace="compiler" RootNamespace="compiler"
Keyword="Win32Proj" Keyword="Win32Proj"
...@@ -150,10 +150,6 @@ ...@@ -150,10 +150,6 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> >
<File <File
RelativePath=".\CodeGen.cpp"
>
</File>
<File
RelativePath=".\glslang.l" RelativePath=".\glslang.l"
> >
<FileConfiguration <FileConfiguration
...@@ -236,10 +232,6 @@ ...@@ -236,10 +232,6 @@
> >
</File> </File>
<File <File
RelativePath=".\OutputHLSL.cpp"
>
</File>
<File
RelativePath=".\parseConst.cpp" RelativePath=".\parseConst.cpp"
> >
</File> </File>
...@@ -366,10 +358,6 @@ ...@@ -366,10 +358,6 @@
> >
</File> </File>
<File <File
RelativePath=".\OutputHLSL.h"
>
</File>
<File
RelativePath=".\ParseHelper.h" RelativePath=".\ParseHelper.h"
> >
</File> </File>
......
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="translator_glsl"
ProjectGUID="{65DB6E65-00E6-4533-8446-5F623BD94909}"
RootNamespace="CrossCompilerGLSL"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="./;../;../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\CodeGenGLSL.cpp"
>
</File>
<File
RelativePath=".\OutputGLSL.cpp"
>
</File>
<File
RelativePath=".\TranslatorGLSL.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\OutputGLSL.h"
>
</File>
<File
RelativePath=".\TranslatorGLSL.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="translator_hlsl"
ProjectGUID="{5620F0E4-6C43-49BC-A178-B804E1A0C3A7}"
RootNamespace="CrossCompilerHLSL"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../../include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="./;../;../../include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\CodeGenHLSL.cpp"
>
</File>
<File
RelativePath=".\OutputHLSL.cpp"
>
</File>
<File
RelativePath=".\TranslatorHLSL.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\OutputHLSL.h"
>
</File>
<File
RelativePath=".\TranslatorHLSL.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment