Compiler::Compiler()
: fErrorCount(0) {
- auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this));
- auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this));
+ auto types = std::shared_ptr<SymbolTable>(new SymbolTable(this));
+ auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, this));
fIRGenerator = new IRGenerator(&fContext, symbols, *this);
fTypes = types;
#define ADD_TYPE(t) types->addWithoutOwnership(fContext.f ## t ## _Type->fName, \
, fErrors(errorReporter) {}
void IRGenerator::pushSymbolTable() {
- fSymbolTable.reset(new SymbolTable(std::move(fSymbolTable), fErrors));
+ fSymbolTable.reset(new SymbolTable(std::move(fSymbolTable), &fErrors));
}
void IRGenerator::popSymbolTable() {
(int) i)));
}
}
- return std::unique_ptr<InterfaceBlock>(new InterfaceBlock(intf.fPosition, *var,
+ return std::unique_ptr<InterfaceBlock>(new InterfaceBlock(intf.fPosition,
+ var,
intf.fTypeName,
intf.fInstanceName,
std::move(sizes),
// need to remap to a top-left coordinate system
if (fRTHeightStructId == (SpvId) -1) {
// height variable hasn't been written yet
- std::shared_ptr<SymbolTable> st(new SymbolTable(fErrors));
+ std::shared_ptr<SymbolTable> st(new SymbolTable(&fErrors));
ASSERT(fRTHeightFieldIndex == (SpvId) -1);
std::vector<Type::Field> fields;
fields.emplace_back(Modifiers(), SkString(SKSL_RTHEIGHT_NAME),
Type intfStruct(Position(), name, fields);
Layout layout(-1, -1, 1, -1, -1, -1, -1, false, false, false, Layout::Format::kUnspecified,
false, Layout::kUnspecified_Primitive, -1, -1);
- Variable intfVar(Position(), Modifiers(layout, Modifiers::kUniform_Flag), name,
- intfStruct, Variable::kGlobal_Storage);
+ Variable* intfVar = new Variable(Position(),
+ Modifiers(layout, Modifiers::kUniform_Flag),
+ name,
+ intfStruct,
+ Variable::kGlobal_Storage);
+ fSynthetics.takeOwnership(intfVar);
InterfaceBlock intf(Position(), intfVar, name, SkString(""),
std::vector<std::unique_ptr<Expression>>(), st);
fRTHeightStructId = this->writeInterfaceBlock(intf);
, fBoolTrue(0)
, fBoolFalse(0)
, fSetupFragPosition(false)
- , fCurrentBlock(0) {
+ , fCurrentBlock(0)
+ , fSynthetics(nullptr, errors) {
this->setupIntrinsics();
}
std::stack<SpvId> fContinueTarget;
SpvId fRTHeightStructId = (SpvId) -1;
SpvId fRTHeightFieldIndex = (SpvId) -1;
+ // holds variables synthesized during output, for lifetime purposes
+ SymbolTable fSynthetics;
friend class PointerLValue;
friend class SwizzleLValue;
* At the IR level, this is represented by a single variable of struct type.
*/
struct InterfaceBlock : public ProgramElement {
- InterfaceBlock(Position position, const Variable& var, SkString typeName, SkString instanceName,
+ InterfaceBlock(Position position, const Variable* var, SkString typeName, SkString instanceName,
std::vector<std::unique_ptr<Expression>> sizes,
std::shared_ptr<SymbolTable> typeOwner)
: INHERITED(position, kInterfaceBlock_Kind)
- , fVariable(std::move(var))
+ , fVariable(*var)
, fTypeName(std::move(typeName))
, fInstanceName(std::move(instanceName))
, fSizes(std::move(sizes))
*/
class SymbolTable {
public:
- SymbolTable(ErrorReporter& errorReporter)
- : fErrorReporter(errorReporter) {}
+ SymbolTable(ErrorReporter* errorReporter)
+ : fErrorReporter(*errorReporter) {}
- SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporter)
+ SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter* errorReporter)
: fParent(parent)
- , fErrorReporter(errorReporter) {}
+ , fErrorReporter(*errorReporter) {}
const Symbol* operator[](const SkString& name);