From ec8175c1f0afe3f7758f70da240aba03a791c3a9 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 17 Aug 2017 14:51:09 -0700 Subject: [ir] Add support for "decorations" on instructions The terminology here is similar to SPIR-V. For right now the only decoration exposed is a fairly brute-force one that just points back to a high-level declaration so that we can look up info on it that might affect how we print output. --- source/slang/emit.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 1f0436d8a..6440c63a3 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3827,6 +3827,11 @@ emitDeclImpl(decl, nullptr); String getName(IRInst* inst) { + if(auto decoration = inst->findDecoration()) + { + return getText(decoration->decl->getName()); + } + StringBuilder sb; sb << "_S"; sb << inst->id; @@ -4038,6 +4043,17 @@ emitDeclImpl(decl, nullptr); } } + void emitIRSemantics( + EmitContext* context, + IRInst* inst) + { + auto decoration = inst->findDecoration(); + if( decoration ) + { + EmitSemantics(decoration->decl); + } + } + void emitIRFunc( EmitContext* context, IRFunc* func) @@ -4061,6 +4077,9 @@ emitDeclImpl(decl, nullptr); } emit(")"); + + emitIRSemantics(context, func); + // TODO: encode declaration vs. definition bool isDefinition = true; if(isDefinition) @@ -4097,6 +4116,9 @@ emitDeclImpl(decl, nullptr); { auto fieldType = ff->getFieldType(); emitIRType(context, fieldType, getName(ff)); + + emitIRSemantics(context, ff); + emit(";\n"); } emit("};\n"); @@ -4250,7 +4272,7 @@ String emitEntryPoint( // // We'll try to detect the cases here: // -#if 1 +#if 0 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