From 95348fdb623509eb22c04d4c7c19af8228c5a533 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 17 Aug 2017 14:17:29 -0700 Subject: [ir] Represent fields more direclty Previously, a `StructType` was an ordinary instruction that took a variable number of types are operands, representing the types of fields. This ends up being inconvenient for a few reasons: - To add decorations to the fields, you'd end up having to decorate the struct type instead (SPIR-V has this problem) - You need to compute field indices during lowering, when you might prefer to defer that until later - The get/set field operations now need an index, which needs to be an explicit operand, which means a magic numeric literal floating around to represent the index The new approach fixes for the first two of these, and at least makes the last one a bit nicer. A `StructDecl` is now a parent instruction, and its sub-instructions represent the fields of the type - each field is an explicit instruction of type `StructField`. The operation to extract a field takes a direct reference the struct field, so everything is quite explicit. --- source/slang/emit.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 35020249b..1f0436d8a 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4016,8 +4016,8 @@ emitDeclImpl(decl, nullptr); emitIRInstResultDecl(context, inst); emitIROperand(context, fieldExtract->getBase()); - emit(".field"); - emit(fieldExtract->fieldIndex); + emit("."); + emit(getName(fieldExtract->getField())); emit(";\n"); } break; @@ -4087,20 +4087,16 @@ emitDeclImpl(decl, nullptr); void emitIRStruct( EmitContext* context, - IRStructType* structType) + IRStructDecl* structType) { emit("struct "); emit(getName(structType)); emit("\n{\n"); - auto fieldCount = structType->getFieldCount(); - for( UInt ff = 0; ff < fieldCount; ++ff ) - { - auto fieldType = structType->getFieldType(ff); - - String fieldName = "field"; - fieldName.append(ff); - emitIRType(context, fieldType, fieldName); + for(auto ff = structType->getFirstField(); ff; ff = ff->getNextField()) + { + auto fieldType = ff->getFieldType(); + emitIRType(context, fieldType, getName(ff)); emit(";\n"); } emit("};\n"); @@ -4119,7 +4115,7 @@ emitDeclImpl(decl, nullptr); break; case kIROp_StructType: - emitIRStruct(context, (IRStructType*) inst); + emitIRStruct(context, (IRStructDecl*) inst); break; default: @@ -4254,7 +4250,7 @@ String emitEntryPoint( // // We'll try to detect the cases here: // -#if 0 +#if 1 if(!(translationUnit->compileFlags & SLANG_COMPILE_FLAG_NO_CHECKING )) { // This seems to be case (3), because the user is asking for full -- cgit v1.2.3