moved SkSL InterfaceBlock data into IRNode
Change-Id: If85369d978e395502b2169d605c2513a9086b57e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326916 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
41fc174d79
commit
eaf4788a75
@ -509,7 +509,7 @@ bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visitProgramElement(ELEM pe) {
|
|||||||
return this->visitStatement(*pe.template as<FunctionDefinition>().body());
|
return this->visitStatement(*pe.template as<FunctionDefinition>().body());
|
||||||
|
|
||||||
case ProgramElement::Kind::kInterfaceBlock:
|
case ProgramElement::Kind::kInterfaceBlock:
|
||||||
for (auto& e : pe.template as<InterfaceBlock>().fSizes) {
|
for (auto& e : pe.template as<InterfaceBlock>().sizes()) {
|
||||||
if (e && this->visitExpression(*e)) {
|
if (e && this->visitExpression(*e)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -378,9 +378,9 @@ ParsedModule Compiler::parseModule(Program::Kind kind, ModuleData data, const Pa
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ProgramElement::Kind::kInterfaceBlock: {
|
case ProgramElement::Kind::kInterfaceBlock: {
|
||||||
const Variable* var = element->as<InterfaceBlock>().fVariable;
|
const Variable& var = element->as<InterfaceBlock>().variable();
|
||||||
SkASSERT(var->isBuiltin());
|
SkASSERT(var.isBuiltin());
|
||||||
intrinsics->insertOrDie(var->name(), std::move(element));
|
intrinsics->insertOrDie(var.name(), std::move(element));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -544,11 +544,11 @@ void Dehydrator::write(const ProgramElement& e) {
|
|||||||
case ProgramElement::Kind::kInterfaceBlock: {
|
case ProgramElement::Kind::kInterfaceBlock: {
|
||||||
const InterfaceBlock& i = e.as<InterfaceBlock>();
|
const InterfaceBlock& i = e.as<InterfaceBlock>();
|
||||||
this->writeCommand(Rehydrator::kInterfaceBlock_Command);
|
this->writeCommand(Rehydrator::kInterfaceBlock_Command);
|
||||||
this->write(*i.fVariable);
|
this->write(i.variable());
|
||||||
this->write(i.fTypeName);
|
this->write(i.typeName());
|
||||||
this->write(i.fInstanceName);
|
this->write(i.instanceName());
|
||||||
this->writeU8(i.fSizes.size());
|
this->writeU8(i.sizes().count());
|
||||||
for (const auto& s : i.fSizes) {
|
for (const auto& s : i.sizes()) {
|
||||||
this->write(s.get());
|
this->write(s.get());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1175,13 +1175,13 @@ void GLSLCodeGenerator::writeModifiers(const Modifiers& modifiers,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GLSLCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
void GLSLCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
||||||
if (intf.fTypeName == "sk_PerVertex") {
|
if (intf.typeName() == "sk_PerVertex") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->writeModifiers(intf.fVariable->modifiers(), true);
|
this->writeModifiers(intf.variable().modifiers(), true);
|
||||||
this->writeLine(intf.fTypeName + " {");
|
this->writeLine(intf.typeName() + " {");
|
||||||
fIndentation++;
|
fIndentation++;
|
||||||
const Type* structType = &intf.fVariable->type();
|
const Type* structType = &intf.variable().type();
|
||||||
while (structType->typeKind() == Type::TypeKind::kArray) {
|
while (structType->typeKind() == Type::TypeKind::kArray) {
|
||||||
structType = &structType->componentType();
|
structType = &structType->componentType();
|
||||||
}
|
}
|
||||||
@ -1193,10 +1193,10 @@ void GLSLCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
|||||||
}
|
}
|
||||||
fIndentation--;
|
fIndentation--;
|
||||||
this->write("}");
|
this->write("}");
|
||||||
if (intf.fInstanceName.size()) {
|
if (intf.instanceName().size()) {
|
||||||
this->write(" ");
|
this->write(" ");
|
||||||
this->write(intf.fInstanceName);
|
this->write(intf.instanceName());
|
||||||
for (const auto& size : intf.fSizes) {
|
for (const auto& size : intf.sizes()) {
|
||||||
this->write("[");
|
this->write("[");
|
||||||
if (size) {
|
if (size) {
|
||||||
this->writeExpression(*size, kTopLevel_Precedence);
|
this->writeExpression(*size, kTopLevel_Precedence);
|
||||||
|
@ -774,7 +774,7 @@ std::unique_ptr<Statement> IRGenerator::getNormalizeSkPositionCode() {
|
|||||||
const Variable* skPerVertex = nullptr;
|
const Variable* skPerVertex = nullptr;
|
||||||
if (const ProgramElement* perVertexDecl = fIntrinsics->find(Compiler::PERVERTEX_NAME)) {
|
if (const ProgramElement* perVertexDecl = fIntrinsics->find(Compiler::PERVERTEX_NAME)) {
|
||||||
SkASSERT(perVertexDecl->is<InterfaceBlock>());
|
SkASSERT(perVertexDecl->is<InterfaceBlock>());
|
||||||
skPerVertex = perVertexDecl->as<InterfaceBlock>().fVariable;
|
skPerVertex = &perVertexDecl->as<InterfaceBlock>().variable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// sk_Position = float4(sk_Position.xy * rtAdjust.xz + sk_Position.ww * rtAdjust.yw,
|
// sk_Position = float4(sk_Position.xy * rtAdjust.xz + sk_Position.ww * rtAdjust.yw,
|
||||||
@ -2835,7 +2835,7 @@ void IRGenerator::cloneBuiltinVariables() {
|
|||||||
initialValue = decl.value().get();
|
initialValue = decl.value().get();
|
||||||
} else {
|
} else {
|
||||||
SkASSERT(clonedDecl->is<InterfaceBlock>());
|
SkASSERT(clonedDecl->is<InterfaceBlock>());
|
||||||
sharedVar = clonedDecl->as<InterfaceBlock>().fVariable;
|
sharedVar = &clonedDecl->as<InterfaceBlock>().variable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now clone the Variable, and add the clone to the Program's symbol table.
|
// Now clone the Variable, and add the clone to the Program's symbol table.
|
||||||
@ -2852,7 +2852,7 @@ void IRGenerator::cloneBuiltinVariables() {
|
|||||||
GlobalVarDeclaration& global = clonedDecl->as<GlobalVarDeclaration>();
|
GlobalVarDeclaration& global = clonedDecl->as<GlobalVarDeclaration>();
|
||||||
global.declaration()->as<VarDeclaration>().setVar(clonedVar);
|
global.declaration()->as<VarDeclaration>().setVar(clonedVar);
|
||||||
} else {
|
} else {
|
||||||
clonedDecl->as<InterfaceBlock>().fVariable = clonedVar;
|
clonedDecl->as<InterfaceBlock>().setVariable(clonedVar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember this new re-mapping...
|
// Remember this new re-mapping...
|
||||||
|
@ -982,15 +982,15 @@ void MetalCodeGenerator::writeFunction(const FunctionDefinition& f) {
|
|||||||
}
|
}
|
||||||
} else if (e->is<InterfaceBlock>()) {
|
} else if (e->is<InterfaceBlock>()) {
|
||||||
const InterfaceBlock& intf = e->as<InterfaceBlock>();
|
const InterfaceBlock& intf = e->as<InterfaceBlock>();
|
||||||
if ("sk_PerVertex" == intf.fTypeName) {
|
if (intf.typeName() == "sk_PerVertex") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this->write(", constant ");
|
this->write(", constant ");
|
||||||
this->writeType(intf.fVariable->type());
|
this->writeType(intf.variable().type());
|
||||||
this->write("& " );
|
this->write("& " );
|
||||||
this->write(fInterfaceBlockNameMap[&intf]);
|
this->write(fInterfaceBlockNameMap[&intf]);
|
||||||
this->write(" [[buffer(");
|
this->write(" [[buffer(");
|
||||||
this->write(to_string(intf.fVariable->modifiers().fLayout.fBinding));
|
this->write(to_string(intf.variable().modifiers().fLayout.fBinding));
|
||||||
this->write(")]]");
|
this->write(")]]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1113,13 +1113,13 @@ void MetalCodeGenerator::writeModifiers(const Modifiers& modifiers,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MetalCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
void MetalCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
||||||
if ("sk_PerVertex" == intf.fTypeName) {
|
if ("sk_PerVertex" == intf.typeName()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->writeModifiers(intf.fVariable->modifiers(), true);
|
this->writeModifiers(intf.variable().modifiers(), true);
|
||||||
this->write("struct ");
|
this->write("struct ");
|
||||||
this->writeLine(intf.fTypeName + " {");
|
this->writeLine(intf.typeName() + " {");
|
||||||
const Type* structType = &intf.fVariable->type();
|
const Type* structType = &intf.variable().type();
|
||||||
fWrittenStructs.push_back(structType);
|
fWrittenStructs.push_back(structType);
|
||||||
while (structType->typeKind() == Type::TypeKind::kArray) {
|
while (structType->typeKind() == Type::TypeKind::kArray) {
|
||||||
structType = &structType->componentType();
|
structType = &structType->componentType();
|
||||||
@ -1131,17 +1131,17 @@ void MetalCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf) {
|
|||||||
}
|
}
|
||||||
fIndentation--;
|
fIndentation--;
|
||||||
this->write("}");
|
this->write("}");
|
||||||
if (intf.fInstanceName.size()) {
|
if (intf.instanceName().size()) {
|
||||||
this->write(" ");
|
this->write(" ");
|
||||||
this->write(intf.fInstanceName);
|
this->write(intf.instanceName());
|
||||||
for (const auto& size : intf.fSizes) {
|
for (const auto& size : intf.sizes()) {
|
||||||
this->write("[");
|
this->write("[");
|
||||||
if (size) {
|
if (size) {
|
||||||
this->writeExpression(*size, kTopLevel_Precedence);
|
this->writeExpression(*size, kTopLevel_Precedence);
|
||||||
}
|
}
|
||||||
this->write("]");
|
this->write("]");
|
||||||
}
|
}
|
||||||
fInterfaceBlockNameMap[&intf] = intf.fInstanceName;
|
fInterfaceBlockNameMap[&intf] = intf.instanceName();
|
||||||
} else {
|
} else {
|
||||||
fInterfaceBlockNameMap[&intf] = "_anonInterface" + to_string(fAnonInterfaceCount++);
|
fInterfaceBlockNameMap[&intf] = "_anonInterface" + to_string(fAnonInterfaceCount++);
|
||||||
}
|
}
|
||||||
@ -1537,7 +1537,7 @@ void MetalCodeGenerator::writeGlobalStruct() {
|
|||||||
void VisitInterfaceBlock(const InterfaceBlock& block, const String& blockName) override {
|
void VisitInterfaceBlock(const InterfaceBlock& block, const String& blockName) override {
|
||||||
this->AddElement();
|
this->AddElement();
|
||||||
fCodeGen->write(" constant ");
|
fCodeGen->write(" constant ");
|
||||||
fCodeGen->write(block.fTypeName);
|
fCodeGen->write(block.typeName());
|
||||||
fCodeGen->write("* ");
|
fCodeGen->write("* ");
|
||||||
fCodeGen->writeName(blockName);
|
fCodeGen->writeName(blockName);
|
||||||
fCodeGen->write(";\n");
|
fCodeGen->write(";\n");
|
||||||
|
@ -2697,14 +2697,14 @@ static void update_sk_in_count(const Modifiers& m, int* outSkInCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool appendRTHeight) {
|
SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool appendRTHeight) {
|
||||||
bool isBuffer = (0 != (intf.fVariable->modifiers().fFlags & Modifiers::kBuffer_Flag));
|
bool isBuffer = ((intf.variable().modifiers().fFlags & Modifiers::kBuffer_Flag) != 0);
|
||||||
bool pushConstant = (0 != (intf.fVariable->modifiers().fLayout.fFlags &
|
bool pushConstant = ((intf.variable().modifiers().fLayout.fFlags &
|
||||||
Layout::kPushConstant_Flag));
|
Layout::kPushConstant_Flag) != 0);
|
||||||
MemoryLayout memoryLayout = (pushConstant || isBuffer) ?
|
MemoryLayout memoryLayout = (pushConstant || isBuffer) ?
|
||||||
MemoryLayout(MemoryLayout::k430_Standard) :
|
MemoryLayout(MemoryLayout::k430_Standard) :
|
||||||
fDefaultLayout;
|
fDefaultLayout;
|
||||||
SpvId result = this->nextId();
|
SpvId result = this->nextId();
|
||||||
const Type* type = &intf.fVariable->type();
|
const Type* type = &intf.variable().type();
|
||||||
if (fProgram.fInputs.fRTHeight && appendRTHeight) {
|
if (fProgram.fInputs.fRTHeight && appendRTHeight) {
|
||||||
SkASSERT(fRTHeightStructId == (SpvId) -1);
|
SkASSERT(fRTHeightStructId == (SpvId) -1);
|
||||||
SkASSERT(fRTHeightFieldIndex == (SpvId) -1);
|
SkASSERT(fRTHeightFieldIndex == (SpvId) -1);
|
||||||
@ -2715,7 +2715,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
|
|||||||
type = new Type(type->fOffset, type->name(), fields);
|
type = new Type(type->fOffset, type->name(), fields);
|
||||||
}
|
}
|
||||||
SpvId typeId;
|
SpvId typeId;
|
||||||
Modifiers intfModifiers = intf.fVariable->modifiers();
|
Modifiers intfModifiers = intf.variable().modifiers();
|
||||||
if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) {
|
if (intfModifiers.fLayout.fBuiltin == SK_IN_BUILTIN) {
|
||||||
for (const auto& e : fProgram.elements()) {
|
for (const auto& e : fProgram.elements()) {
|
||||||
if (e->is<ModifiersDeclaration>()) {
|
if (e->is<ModifiersDeclaration>()) {
|
||||||
@ -2724,7 +2724,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
typeId = this->getType(Type("sk_in", Type::TypeKind::kArray,
|
typeId = this->getType(Type("sk_in", Type::TypeKind::kArray,
|
||||||
intf.fVariable->type().componentType(),
|
intf.variable().type().componentType(),
|
||||||
fSkInCount),
|
fSkInCount),
|
||||||
memoryLayout);
|
memoryLayout);
|
||||||
} else {
|
} else {
|
||||||
@ -2744,7 +2744,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
|
|||||||
layout.fSet = 0;
|
layout.fSet = 0;
|
||||||
}
|
}
|
||||||
this->writeLayout(layout, result);
|
this->writeLayout(layout, result);
|
||||||
fVariableMap[intf.fVariable] = result;
|
fVariableMap[&intf.variable()] = result;
|
||||||
if (fProgram.fInputs.fRTHeight && appendRTHeight) {
|
if (fProgram.fInputs.fRTHeight && appendRTHeight) {
|
||||||
delete type;
|
delete type;
|
||||||
}
|
}
|
||||||
@ -3198,16 +3198,16 @@ void SPIRVCodeGenerator::writeInstructions(const Program& program, OutputStream&
|
|||||||
for (const auto& e : program.elements()) {
|
for (const auto& e : program.elements()) {
|
||||||
if (e->is<InterfaceBlock>()) {
|
if (e->is<InterfaceBlock>()) {
|
||||||
InterfaceBlock& intf = e->as<InterfaceBlock>();
|
InterfaceBlock& intf = e->as<InterfaceBlock>();
|
||||||
const Modifiers& modifiers = intf.fVariable->modifiers();
|
const Modifiers& modifiers = intf.variable().modifiers();
|
||||||
if (SK_IN_BUILTIN == modifiers.fLayout.fBuiltin) {
|
if (SK_IN_BUILTIN == modifiers.fLayout.fBuiltin) {
|
||||||
SkASSERT(skInSize != -1);
|
SkASSERT(skInSize != -1);
|
||||||
intf.fSizes.emplace_back(new IntLiteral(fContext, -1, skInSize));
|
intf.sizes().emplace_back(new IntLiteral(fContext, -1, skInSize));
|
||||||
}
|
}
|
||||||
SpvId id = this->writeInterfaceBlock(intf);
|
SpvId id = this->writeInterfaceBlock(intf);
|
||||||
if (((modifiers.fFlags & Modifiers::kIn_Flag) ||
|
if (((modifiers.fFlags & Modifiers::kIn_Flag) ||
|
||||||
(modifiers.fFlags & Modifiers::kOut_Flag)) &&
|
(modifiers.fFlags & Modifiers::kOut_Flag)) &&
|
||||||
modifiers.fLayout.fBuiltin == -1 &&
|
modifiers.fLayout.fBuiltin == -1 &&
|
||||||
!is_dead(*intf.fVariable)) {
|
!is_dead(intf.variable())) {
|
||||||
interfaceVars.insert(id);
|
interfaceVars.insert(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,11 @@ IRNode::IRNode(int offset, int kind, const InlineMarkerData& data)
|
|||||||
, fKind(kind)
|
, fKind(kind)
|
||||||
, fData(data) {}
|
, fData(data) {}
|
||||||
|
|
||||||
|
IRNode::IRNode(int offset, int kind, const InterfaceBlockData& data)
|
||||||
|
: fOffset(offset)
|
||||||
|
, fKind(kind)
|
||||||
|
, fData(data) {}
|
||||||
|
|
||||||
IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
|
IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
|
||||||
: fOffset(offset)
|
: fOffset(offset)
|
||||||
, fKind(kind)
|
, fKind(kind)
|
||||||
|
@ -160,6 +160,13 @@ protected:
|
|||||||
bool fIsStatic;
|
bool fIsStatic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct InterfaceBlockData {
|
||||||
|
const Variable* fVariable;
|
||||||
|
String fTypeName;
|
||||||
|
String fInstanceName;
|
||||||
|
std::shared_ptr<SymbolTable> fTypeOwner;
|
||||||
|
};
|
||||||
|
|
||||||
struct IntLiteralData {
|
struct IntLiteralData {
|
||||||
const Type* fType;
|
const Type* fType;
|
||||||
int64_t fValue;
|
int64_t fValue;
|
||||||
@ -256,6 +263,7 @@ protected:
|
|||||||
kFunctionReference,
|
kFunctionReference,
|
||||||
kIfStatement,
|
kIfStatement,
|
||||||
kInlineMarker,
|
kInlineMarker,
|
||||||
|
kInterfaceBlock,
|
||||||
kIntLiteral,
|
kIntLiteral,
|
||||||
kModifiersDeclaration,
|
kModifiersDeclaration,
|
||||||
kSection,
|
kSection,
|
||||||
@ -289,6 +297,7 @@ protected:
|
|||||||
FunctionReferenceData fFunctionReference;
|
FunctionReferenceData fFunctionReference;
|
||||||
IfStatementData fIfStatement;
|
IfStatementData fIfStatement;
|
||||||
InlineMarkerData fInlineMarker;
|
InlineMarkerData fInlineMarker;
|
||||||
|
InterfaceBlockData fInterfaceBlock;
|
||||||
IntLiteralData fIntLiteral;
|
IntLiteralData fIntLiteral;
|
||||||
ModifiersDeclarationData fModifiersDeclaration;
|
ModifiersDeclarationData fModifiersDeclaration;
|
||||||
SectionData fSection;
|
SectionData fSection;
|
||||||
@ -380,6 +389,11 @@ protected:
|
|||||||
*(new(&fContents) InlineMarkerData) = data;
|
*(new(&fContents) InlineMarkerData) = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NodeData(InterfaceBlockData data)
|
||||||
|
: fKind(Kind::kInterfaceBlock) {
|
||||||
|
*(new(&fContents) InterfaceBlockData) = data;
|
||||||
|
}
|
||||||
|
|
||||||
NodeData(IntLiteralData data)
|
NodeData(IntLiteralData data)
|
||||||
: fKind(Kind::kIntLiteral) {
|
: fKind(Kind::kIntLiteral) {
|
||||||
*(new(&fContents) IntLiteralData) = data;
|
*(new(&fContents) IntLiteralData) = data;
|
||||||
@ -506,6 +520,9 @@ protected:
|
|||||||
case Kind::kInlineMarker:
|
case Kind::kInlineMarker:
|
||||||
*(new(&fContents) InlineMarkerData) = other.fContents.fInlineMarker;
|
*(new(&fContents) InlineMarkerData) = other.fContents.fInlineMarker;
|
||||||
break;
|
break;
|
||||||
|
case Kind::kInterfaceBlock:
|
||||||
|
*(new(&fContents) InterfaceBlockData) = other.fContents.fInterfaceBlock;
|
||||||
|
break;
|
||||||
case Kind::kIntLiteral:
|
case Kind::kIntLiteral:
|
||||||
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
||||||
break;
|
break;
|
||||||
@ -605,6 +622,9 @@ protected:
|
|||||||
case Kind::kInlineMarker:
|
case Kind::kInlineMarker:
|
||||||
fContents.fInlineMarker.~InlineMarkerData();
|
fContents.fInlineMarker.~InlineMarkerData();
|
||||||
break;
|
break;
|
||||||
|
case Kind::kInterfaceBlock:
|
||||||
|
fContents.fInterfaceBlock.~InterfaceBlockData();
|
||||||
|
break;
|
||||||
case Kind::kIntLiteral:
|
case Kind::kIntLiteral:
|
||||||
fContents.fIntLiteral.~IntLiteralData();
|
fContents.fIntLiteral.~IntLiteralData();
|
||||||
break;
|
break;
|
||||||
@ -681,6 +701,8 @@ protected:
|
|||||||
|
|
||||||
IRNode(int offset, int kind, const InlineMarkerData& data);
|
IRNode(int offset, int kind, const InlineMarkerData& data);
|
||||||
|
|
||||||
|
IRNode(int offset, int kind, const InterfaceBlockData& data);
|
||||||
|
|
||||||
IRNode(int offset, int kind, const IntLiteralData& data);
|
IRNode(int offset, int kind, const IntLiteralData& data);
|
||||||
|
|
||||||
IRNode(int offset, int kind, const ModifiersDeclarationData& data);
|
IRNode(int offset, int kind, const ModifiersDeclarationData& data);
|
||||||
@ -835,6 +857,16 @@ protected:
|
|||||||
return fData.fContents.fInlineMarker;
|
return fData.fContents.fInlineMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InterfaceBlockData& interfaceBlockData() {
|
||||||
|
SkASSERT(fData.fKind == NodeData::Kind::kInterfaceBlock);
|
||||||
|
return fData.fContents.fInterfaceBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
const InterfaceBlockData& interfaceBlockData() const {
|
||||||
|
SkASSERT(fData.fKind == NodeData::Kind::kInterfaceBlock);
|
||||||
|
return fData.fContents.fInterfaceBlock;
|
||||||
|
}
|
||||||
|
|
||||||
const IntLiteralData& intLiteralData() const {
|
const IntLiteralData& intLiteralData() const {
|
||||||
SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral);
|
SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral);
|
||||||
return fData.fContents.fIntLiteral;
|
return fData.fContents.fIntLiteral;
|
||||||
|
@ -29,26 +29,53 @@ struct InterfaceBlock : public ProgramElement {
|
|||||||
|
|
||||||
InterfaceBlock(int offset, const Variable* var, String typeName, String instanceName,
|
InterfaceBlock(int offset, const Variable* var, String typeName, String instanceName,
|
||||||
ExpressionArray sizes, std::shared_ptr<SymbolTable> typeOwner)
|
ExpressionArray sizes, std::shared_ptr<SymbolTable> typeOwner)
|
||||||
: INHERITED(offset, kProgramElementKind)
|
: INHERITED(offset, InterfaceBlockData{var, std::move(typeName), std::move(instanceName),
|
||||||
, fVariable(var)
|
std::move(typeOwner)}) {
|
||||||
, fTypeName(std::move(typeName))
|
fExpressionChildren.move_back_n(sizes.size(), sizes.data());
|
||||||
, fInstanceName(std::move(instanceName))
|
}
|
||||||
, fSizes(std::move(sizes))
|
|
||||||
, fTypeOwner(typeOwner) {}
|
const Variable& variable() const {
|
||||||
|
return *this->interfaceBlockData().fVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVariable(const Variable* var) {
|
||||||
|
this->interfaceBlockData().fVariable = var;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String& typeName() const {
|
||||||
|
return this->interfaceBlockData().fTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String& instanceName() const {
|
||||||
|
return this->interfaceBlockData().fInstanceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::shared_ptr<SymbolTable>& typeOwner() const {
|
||||||
|
return this->interfaceBlockData().fTypeOwner;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressionArray& sizes() {
|
||||||
|
return fExpressionChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ExpressionArray& sizes() const {
|
||||||
|
return fExpressionChildren;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<ProgramElement> clone() const override {
|
std::unique_ptr<ProgramElement> clone() const override {
|
||||||
ExpressionArray sizesClone;
|
ExpressionArray sizesClone;
|
||||||
sizesClone.reserve_back(fSizes.size());
|
sizesClone.reserve_back(this->sizes().size());
|
||||||
for (const auto& s : fSizes) {
|
for (const auto& size : this->sizes()) {
|
||||||
sizesClone.push_back(s ? s->clone() : nullptr);
|
sizesClone.push_back(size ? size->clone() : nullptr);
|
||||||
}
|
}
|
||||||
return std::make_unique<InterfaceBlock>(fOffset, fVariable, fTypeName, fInstanceName,
|
return std::make_unique<InterfaceBlock>(fOffset, &this->variable(), this->typeName(),
|
||||||
std::move(sizesClone), fTypeOwner);
|
this->instanceName(), std::move(sizesClone),
|
||||||
|
this->typeOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
String description() const override {
|
String description() const override {
|
||||||
String result = fVariable->modifiers().description() + fTypeName + " {\n";
|
String result = this->variable().modifiers().description() + this->typeName() + " {\n";
|
||||||
const Type* structType = &fVariable->type();
|
const Type* structType = &this->variable().type();
|
||||||
while (structType->typeKind() == Type::TypeKind::kArray) {
|
while (structType->typeKind() == Type::TypeKind::kArray) {
|
||||||
structType = &structType->componentType();
|
structType = &structType->componentType();
|
||||||
}
|
}
|
||||||
@ -56,9 +83,9 @@ struct InterfaceBlock : public ProgramElement {
|
|||||||
result += f.description() + "\n";
|
result += f.description() + "\n";
|
||||||
}
|
}
|
||||||
result += "}";
|
result += "}";
|
||||||
if (fInstanceName.size()) {
|
if (this->instanceName().size()) {
|
||||||
result += " " + fInstanceName;
|
result += " " + this->instanceName();
|
||||||
for (const auto& size : fSizes) {
|
for (const auto& size : this->sizes()) {
|
||||||
result += "[";
|
result += "[";
|
||||||
if (size) {
|
if (size) {
|
||||||
result += size->description();
|
result += size->description();
|
||||||
@ -69,12 +96,6 @@ struct InterfaceBlock : public ProgramElement {
|
|||||||
return result + ";";
|
return result + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
const Variable* fVariable;
|
|
||||||
const String fTypeName;
|
|
||||||
const String fInstanceName;
|
|
||||||
ExpressionArray fSizes;
|
|
||||||
const std::shared_ptr<SymbolTable> fTypeOwner;
|
|
||||||
|
|
||||||
using INHERITED = ProgramElement;
|
using INHERITED = ProgramElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@ public:
|
|||||||
ProgramElement(int offset, const FunctionDefinitionData& data)
|
ProgramElement(int offset, const FunctionDefinitionData& data)
|
||||||
: INHERITED(offset, (int) Kind::kFunction, data) {}
|
: INHERITED(offset, (int) Kind::kFunction, data) {}
|
||||||
|
|
||||||
|
ProgramElement(int offset, const InterfaceBlockData& data)
|
||||||
|
: INHERITED(offset, (int) Kind::kInterfaceBlock, data) {}
|
||||||
|
|
||||||
ProgramElement(int offset, const ModifiersDeclarationData& data)
|
ProgramElement(int offset, const ModifiersDeclarationData& data)
|
||||||
: INHERITED(offset, (int) Kind::kModifiers, data) {}
|
: INHERITED(offset, (int) Kind::kModifiers, data) {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user