Commit 18f50f78 by acleung@chromium.org

Less memory intensive initializing of builtins.

R=alokp@chromium.org Review URL: https://codereview.appspot.com/9436044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2425 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b07ec5bf
......@@ -64,6 +64,8 @@
'COMPILER_IMPLEMENTATION',
],
'sources': [
'compiler/builtin_symbol_table.h',
'compiler/builtin_symbol_table.cpp',
'compiler/BaseTypes.h',
'compiler/BuiltInFunctionEmulator.cpp',
'compiler/BuiltInFunctionEmulator.h',
......
......@@ -4,6 +4,7 @@
// found in the LICENSE file.
//
#include "compiler/builtin_symbol_table.h"
#include "compiler/BuiltInFunctionEmulator.h"
#include "compiler/DetectCallDepth.h"
#include "compiler/ForLoopUnroll.h"
......@@ -68,6 +69,7 @@ bool InitializeSymbolTable(
}
}
InsertBuiltInFunctionsCommon(resources, &symbolTable);
IdentifyBuiltIns(type, spec, resources, symbolTable);
return true;
......@@ -132,6 +134,7 @@ bool TCompiler::Init(const ShBuiltInResources& resources)
// Generate built-in symbol table.
if (!InitBuiltInSymbolTable(resources))
return false;
InitExtensionBehavior(resources, extensionBehavior);
fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
......
//
// Copyright (c) 2002-2013 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 _BUILTIN_SYMBOL_TABLE_INCLUDED_
#define _BUILTIN_SYMBOL_TABLE_INCLUDED_
#include "GLSLANG/ShaderLang.h"
class TSymbolTable;
extern void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable * t);
#endif // _BUILTIN_SYMBOL_TABLE_INCLUDED_
#!/usr/bin/python
# Copyright (c) 2013 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.
import json
# This file contains the definitions for all the builtin in JSON format.
json_data = open('builtin_symbols.json')
builtin = json.load(json_data)
# This maps the shader language's types and how to create the TTypes in the symbol table.
ttypeMap = builtin["ttypemap"]
# This is the output that we are going to generate.
output = open('builtin_symbol_table.cpp', 'w');
# The header part of the file.
header = """// Copyright (c) 2002-2013 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.
// *************************************************************
// This file is generated by generate_builtin_symbol_table.py.
// * DO NOT HAND MODIFY *
// *************************************************************
#include "compiler/builtin_symbol_table.h"
#include "compiler/SymbolTable.h"
"""
output.write(header)
registerfunc = """
static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param = {new TString(pname1), ptype1};
f->addParameter(param);
t->insert(*f);
}
static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param1 = {new TString(pname1), ptype1};
f->addParameter(param1);
TParameter param2 = {new TString(pname2), ptype2};
f->addParameter(param2);
t->insert(*f);
}
static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2, TType* ptype3, const char* pname3)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param1 = {new TString(pname1), ptype1};
f->addParameter(param1);
TParameter param2 = {new TString(pname2), ptype2};
f->addParameter(param2);
TParameter param3 = {new TString(pname3), ptype3};
f->addParameter(param3);
t->insert(*f);
}
"""
output.write(registerfunc)
commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable * t) {\n"
output.write(commonHeader)
for func in builtin["common"]:
out = ""
indent = " ";
size = len(func['parameter'])
if 'condition' in func:
out += indent + "if (" + func['condition'] + ") {\n"
indent += indent;
out += indent + "builtin" + str(size) + "(t, "
out += ttypeMap[func['return_type']]
out += ", \"" + func['name'] + "\""
paramlist = func['parameter']
paramdef = "";
for param in paramlist:
paramdef += ", "
paramdef += ttypeMap[param['type']]
paramdef += ", \"" + param['name'] + "\""
out += paramdef + ");\n"
if 'condition' in func:
out += " }\n"
output.write(out)
output.write("}\n")
json_data.close()
output.close()
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