OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
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 | 7 |
8 #include "SkSLCompiler.h" | 8 #include "SkSLCompiler.h" |
9 | 9 |
10 #include <fstream> | 10 #include <fstream> |
(...skipping 25 matching lines...) Expand all Loading... |
36 ; | 36 ; |
37 | 37 |
38 namespace SkSL { | 38 namespace SkSL { |
39 | 39 |
40 Compiler::Compiler() | 40 Compiler::Compiler() |
41 : fErrorCount(0) { | 41 : fErrorCount(0) { |
42 auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this)); | 42 auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this)); |
43 auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this)); | 43 auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this)); |
44 fIRGenerator = new IRGenerator(symbols, *this); | 44 fIRGenerator = new IRGenerator(symbols, *this); |
45 fTypes = types; | 45 fTypes = types; |
46 #define ADD_TYPE(t) types->add(k ## t ## _Type->fName, k ## t ## _Type) | 46 #define ADD_TYPE(t) types->addWithoutOwnership(k ## t ## _Type.fName, &k ##
t ## _Type) |
47 ADD_TYPE(Void); | 47 ADD_TYPE(Void); |
48 ADD_TYPE(Float); | 48 ADD_TYPE(Float); |
49 ADD_TYPE(Vec2); | 49 ADD_TYPE(Vec2); |
50 ADD_TYPE(Vec3); | 50 ADD_TYPE(Vec3); |
51 ADD_TYPE(Vec4); | 51 ADD_TYPE(Vec4); |
52 ADD_TYPE(Double); | 52 ADD_TYPE(Double); |
53 ADD_TYPE(DVec2); | 53 ADD_TYPE(DVec2); |
54 ADD_TYPE(DVec3); | 54 ADD_TYPE(DVec3); |
55 ADD_TYPE(DVec4); | 55 ADD_TYPE(DVec4); |
56 ADD_TYPE(Int); | 56 ADD_TYPE(Int); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 default: | 178 default: |
179 ABORT("unsupported declaration: %s\n", decl.description().c_str(
)); | 179 ABORT("unsupported declaration: %s\n", decl.description().c_str(
)); |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin
g text) { | 184 std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin
g text) { |
185 fErrorText = ""; | 185 fErrorText = ""; |
186 fErrorCount = 0; | 186 fErrorCount = 0; |
187 fIRGenerator->pushSymbolTable(); | 187 fIRGenerator->pushSymbolTable(true); |
188 std::vector<std::unique_ptr<ProgramElement>> result; | 188 std::vector<std::unique_ptr<ProgramElement>> elements; |
189 switch (kind) { | 189 switch (kind) { |
190 case Program::kVertex_Kind: | 190 case Program::kVertex_Kind: |
191 this->internalConvertProgram(SKSL_VERT_INCLUDE, &result); | 191 this->internalConvertProgram(SKSL_VERT_INCLUDE, &elements); |
192 break; | 192 break; |
193 case Program::kFragment_Kind: | 193 case Program::kFragment_Kind: |
194 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &result); | 194 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &elements); |
195 break; | 195 break; |
196 } | 196 } |
197 this->internalConvertProgram(text, &result); | 197 this->internalConvertProgram(text, &elements); |
| 198 auto result = std::unique_ptr<Program>(new Program(kind, std::move(elements)
, |
| 199 fIRGenerator->fSymbolTabl
e));; |
198 fIRGenerator->popSymbolTable(); | 200 fIRGenerator->popSymbolTable(); |
199 this->writeErrorCount(); | 201 this->writeErrorCount(); |
200 return std::unique_ptr<Program>(new Program(kind, std::move(result)));; | 202 return result; |
201 } | 203 } |
202 | 204 |
203 void Compiler::error(Position position, std::string msg) { | 205 void Compiler::error(Position position, std::string msg) { |
204 fErrorCount++; | 206 fErrorCount++; |
205 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n"
; | 207 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n"
; |
206 } | 208 } |
207 | 209 |
208 std::string Compiler::errorText() { | 210 std::string Compiler::errorText() { |
209 std::string result = fErrorText; | 211 std::string result = fErrorText; |
210 return result; | 212 return result; |
(...skipping 23 matching lines...) Expand all Loading... |
234 bool Compiler::toSPIRV(Program::Kind kind, std::string text, std::string* out) { | 236 bool Compiler::toSPIRV(Program::Kind kind, std::string text, std::string* out) { |
235 std::stringstream buffer; | 237 std::stringstream buffer; |
236 bool result = this->toSPIRV(kind, text, buffer); | 238 bool result = this->toSPIRV(kind, text, buffer); |
237 if (result) { | 239 if (result) { |
238 *out = buffer.str(); | 240 *out = buffer.str(); |
239 } | 241 } |
240 return fErrorCount == 0; | 242 return fErrorCount == 0; |
241 } | 243 } |
242 | 244 |
243 } // namespace | 245 } // namespace |
OLD | NEW |