LEFT | RIGHT |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. | 3 # Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import json | 7 import json |
8 | 8 |
9 # This file contains the definitions for all the builtin in JSON format. | 9 # This file contains the definitions for all the builtin in JSON format. |
10 json_data = open('builtin_symbols.json') | 10 json_data = open('builtin_symbols.json') |
11 builtin = json.load(json_data) | 11 builtin = json.load(json_data) |
12 | 12 |
13 # This maps the shader language's types and how to create the TTypes in the symb
ol table. | 13 # This maps the shader language's types and how to create the TTypes in the symb
ol table. |
14 ttypeMap = builtin["ttypemap"] | 14 ttypeMap = builtin["ttypemap"] |
15 | 15 |
16 # This is the output that we are going to generate. | 16 # This is the output that we are going to generate. |
17 output = open('builtin_symbol_table.cpp', 'w'); | 17 output = open('builtin_symbol_table.cpp', 'w'); |
18 | 18 |
19 # The header part of the file. | 19 # The header part of the file. |
20 header = """// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights res
erved. | 20 header = """// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights res
erved. |
21 // Use of this source code is governed by a BSD-style license that can be | 21 // Use of this source code is governed by a BSD-style license that can be |
22 // found in the LICENSE file. | 22 // found in the LICENSE file. |
23 | 23 |
24 // ************************************************************* | 24 // ************************************************************* |
25 // This file is generated by generate_builtin_symbol_table.py. | 25 // This file is generated by generate_builtin_symbol_table.py. |
26 // * DO NOT HAND MODIFY * | 26 // * DO NOT HAND MODIFY * |
27 // ************************************************************* | 27 // ************************************************************* |
28 #include "compiler/builtin_symbol_table.h" | 28 #include "compiler/builtin_symbol_table.h" |
| 29 #include "compiler/SymbolTable.h" |
29 """ | 30 """ |
30 output.write(header) | 31 output.write(header) |
| 32 |
| 33 registerfunc = """ |
| 34 static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
ype1, const char* pname1) |
| 35 { |
| 36 TFunction* f = new TFunction(new TString(name), *rvalue); |
| 37 TParameter param = {new TString(pname1), ptype1}; |
| 38 f->addParameter(param); |
| 39 t->insert(*f); |
| 40 } |
| 41 static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
ype1, const char* pname1, TType* ptype2, const char* pname2) |
| 42 { |
| 43 TFunction* f = new TFunction(new TString(name), *rvalue); |
| 44 TParameter param1 = {new TString(pname1), ptype1}; |
| 45 f->addParameter(param1); |
| 46 TParameter param2 = {new TString(pname2), ptype2}; |
| 47 f->addParameter(param2); |
| 48 t->insert(*f); |
| 49 } |
| 50 |
| 51 static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* pt
ype1, const char* pname1, TType* ptype2, const char* pname2, TType* ptype3, cons
t char* pname3) |
| 52 { |
| 53 TFunction* f = new TFunction(new TString(name), *rvalue); |
| 54 TParameter param1 = {new TString(pname1), ptype1}; |
| 55 f->addParameter(param1); |
| 56 TParameter param2 = {new TString(pname2), ptype2}; |
| 57 f->addParameter(param2); |
| 58 TParameter param3 = {new TString(pname3), ptype3}; |
| 59 f->addParameter(param3); |
| 60 t->insert(*f); |
| 61 } |
| 62 """ |
| 63 output.write(registerfunc) |
31 | 64 |
32 commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& reso
urces, TSymbolTable * t) {\n" | 65 commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& reso
urces, TSymbolTable * t) {\n" |
33 output.write(commonHeader) | 66 output.write(commonHeader) |
34 | 67 |
35 for func in builtin["common"]: | 68 for func in builtin["common"]: |
36 out = "" | 69 out = "" |
37 indent = " "; | 70 indent = " "; |
38 size = len(func['parameter']) | 71 size = len(func['parameter']) |
39 if 'condition' in func: | 72 if 'condition' in func: |
40 out += indent + "if (" + func['condition'] + ") {\n" | 73 out += indent + "if (" + func['condition'] + ") {\n" |
41 indent += indent; | 74 indent += indent; |
42 » out += indent + "BUILTIN" + str(size) + "(t, " | 75 » out += indent + "builtin" + str(size) + "(t, " |
43 out += ttypeMap[func['return_type']] | 76 out += ttypeMap[func['return_type']] |
44 out += ", \"" + func['name'] + "\"" | 77 out += ", \"" + func['name'] + "\"" |
45 paramlist = func['parameter'] | 78 paramlist = func['parameter'] |
46 paramdef = ""; | 79 paramdef = ""; |
47 for param in paramlist: | 80 for param in paramlist: |
48 paramdef += ", " | 81 paramdef += ", " |
49 paramdef += ttypeMap[param['type']]· | 82 paramdef += ttypeMap[param['type']]· |
50 paramdef += ", \"" + param['name'] + "\"" | 83 paramdef += ", \"" + param['name'] + "\"" |
51 » out += paramdef + ")\n" | 84 » out += paramdef + ");\n" |
52 if 'condition' in func: | 85 if 'condition' in func: |
53 out += " }\n" | 86 out += " }\n" |
54 output.write(out) | 87 output.write(out) |
55 output.write("}\n") | 88 output.write("}\n") |
56 | 89 |
57 json_data.close() | 90 json_data.close() |
58 output.close() | 91 output.close() |
LEFT | RIGHT |