From 10b62eecd94be53eca4ac2555af860f864966d76 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 14 Sep 2017 15:37:05 -0700 Subject: IR: handle control flow constructs (#186) * IR: handle control flow constructs This change includes a bunch of fixes and additions to the IR path: - `slang-ir-assembly` is now a valid output target (so we can use it for testing) - This uses what used to be the IR "dumping" logic, revamped to support much prettier output. - A future change will need to add back support for less prettified output to use when actually debugging - IR generation for `for` loops and `if` statements is supported - HLSL output from the above control flow constructs is implemented - Revamped the handling of l-values, and in particular work on compound ops like `+=` - Add basic IR support for `groupshared` variables - Add basic IR support for storing compute thread-group size - Output semantics on entry point parameters - This uses the AST structures to find semantics, so its still needs work - Pass through loop unroll flags - This is required to match `fxc` output, at least until we implement unrolling ourselves. * Fixup: 64-bit build issues. * fixup for merge --- source/slang/compiler.cpp | 52 +++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'source/slang/compiler.cpp') diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index 9ca1d247f..25ae460c7 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -499,25 +499,14 @@ namespace Slang } #endif -#if 0 - String emitSPIRVAssembly( - ExtraContext& context) + List emitSlangIRForEntryPoint( + EntryPointRequest* entryPoint) { - if(context.getTranslationUnitOptions().entryPoints.Count() == 0) - { - // TODO(tfoley): need to write diagnostics into this whole thing... - fprintf(stderr, "no entry point specified\n"); - return ""; - } - - StringBuilder sb; - for (auto entryPoint : context.getTranslationUnitOptions().entryPoints) - { - sb << emitSPIRVAssemblyForEntryPoint(context, entryPoint); - } - return sb.ProduceString(); + SLANG_UNIMPLEMENTED_X("Slang IR Binary Generation"); } -#endif + + String emitSlangIRAssemblyForEntryPoint( + EntryPointRequest* entryPoint); // Do emit logic for a single entry point CompileResult emitEntryPoint( @@ -578,6 +567,22 @@ namespace Slang } break; + case CodeGenTarget::SlangIR: + { + List code = emitSlangIRForEntryPoint(entryPoint); + maybeDumpIntermediate(compileRequest, code.Buffer(), code.Count(), target); + result = CompileResult(code); + } + break; + + case CodeGenTarget::SlangIRAssembly: + { + String code = emitSlangIRAssemblyForEntryPoint(entryPoint); + maybeDumpIntermediate(compileRequest, code.Buffer(), target); + result = CompileResult(code); + } + break; + case CodeGenTarget::None: // The user requested no output break; @@ -957,6 +962,10 @@ namespace Slang dumpIntermediateText(compileRequest, data, size, ".dxbc.asm"); break; + case CodeGenTarget::SlangIRAssembly: + dumpIntermediateText(compileRequest, data, size, ".slang-ir.asm"); + break; + case CodeGenTarget::SPIRV: dumpIntermediateBinary(compileRequest, data, size, ".spv"); { @@ -972,6 +981,15 @@ namespace Slang dumpIntermediateText(compileRequest, dxbcAssembly.begin(), dxbcAssembly.Length(), ".dxbc.asm"); } break; + + case CodeGenTarget::SlangIR: + dumpIntermediateBinary(compileRequest, data, size, ".slang-ir"); + { + // TODO: need to support dissassembly from Slang IR binary +// String slangIRAssembly = dissassembleSlangIR(compileRequest, data, size); +// dumpIntermediateText(compileRequest, slangIRAssembly.begin(), slangIRAssembly.Length(), ".slang-ir.asm"); + } + break; } } -- cgit v1.2.3