diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-10-16 13:12:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-16 13:12:11 -0700 |
| commit | f12c2552b3f494cbc8245edb90b32b93ca8a1539 (patch) | |
| tree | 4cd08ad6037067dc70844a4a847fb3228e0176ee /source/slang/bytecode.cpp | |
| parent | 3e3e2473bf85365593629bd1f6f070d11f0b8ab2 (diff) | |
Implement notion of a "container format" (#213)
The big addition here is that the Slang "bytecode" is no longer treated as just a "code generation target" (`CodeGenTarget`) akin to DX bytecode (DXBC) or SPIR-V, but instead is a `ContainerFormat` that can be used to emit all the results of a compile request (well, currently just the IR-as-BC, but the intention is there).
Getting to this goal involved some prior checkins that eliminated bogus "targets" that weren't really akin to SPIR-V or DXBC: `-target slang-ir-asm` and `-target reflection-json`. Those targets were really in place to support testing, and so they've been made more explicit testing/debug options.
This change eliminates `-target slang-ir` and instead tries to allow the user to specify `-o foo.slang-module` as an output file name, that indicates the intention to output a "container" file that will wrap up all the generated code.
I've also gone ahead and generalized the existing `-target` option so that we are actually building up a *list* of code generation targets. This is largely just a cleanup, since it forces code to be more aware of when it is doing something target-specific vs. target independent. For example, reflection layout information lives on a requested target, and not on the compile request as a whole, and similarly output code is per-target, per-entry-point.
As a cleanup, I eliminated support for per-translation-unit output. This was vestigial code from back when I used to try and do HLSL generation for a whole translation unit instead of per-entry-point (which turned out to be a lot of complexity for little gain), and it was only being used in the `hello` example and the `render-test` test fixture - in both cases fixing it up was easy enough. I've stubbed out the old `spGetTranslationUnitSource` API, but haven't removed it yet.
Diffstat (limited to 'source/slang/bytecode.cpp')
| -rw-r--r-- | source/slang/bytecode.cpp | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp index 8d8d609b9..085b7303d 100644 --- a/source/slang/bytecode.cpp +++ b/source/slang/bytecode.cpp @@ -936,6 +936,12 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( BytecodeGenerationContext* context, IRModule* irModule) { + if (!irModule) + { + // Not IR module? Then return a null pointer. + return BytecodeGenerationPtr<BCModule>(); + } + // A module in the bytecode is mostly just a list of the // global symbols in the module. // @@ -1032,9 +1038,9 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( return bcModule; } -void generateBytecodeStream( +void generateBytecodeContainer( BytecodeGenerationContext* context, - IRModule* irModule) + CompileRequest* compileReq) { // Header must be the very first thing in the bytecode stream BytecodeGenerationPtr<BCHeader> header = allocate<BCHeader>(context); @@ -1042,9 +1048,49 @@ void generateBytecodeStream( memcpy(header->magic, "slang\0bc", sizeof(header->magic)); header->version = 0; - header->module = generateBytecodeForModule(context, irModule); + // TODO: Need to generate BC representation of all the public/exported + // declrations in the translation units, so that they can be used to + // resolve depenencies downstream. + + // TODO: Need to dump BC representation of compiled kernel codes + // for each specified code-generation target. + + UInt translationUnitCount = compileReq->translationUnits.Count(); + + List<BytecodeGenerationPtr<BCModule>> bcModulesList; + for (auto translationUnitReq : compileReq->translationUnits) + { + auto bcModule = generateBytecodeForModule(context, translationUnitReq->irModule); + bcModulesList.Add(bcModule); + } + + UInt bcModuleCount = bcModulesList.Count(); + header->moduleCount = bcModuleCount; + + auto bcModules = allocateArray<BCPtr<BCModule>>(context, bcModuleCount); + header->modules = bcModules; + for(UInt ii = 0; ii < bcModuleCount; ++ii) + { + bcModules[ii] = bcModulesList[ii]; + } +} + +void generateBytecodeForCompileRequest( + CompileRequest* compileReq) +{ + SharedBytecodeGenerationContext sharedContext; + + BytecodeGenerationContext context; + context.shared = &sharedContext; + + generateBytecodeContainer(&context, compileReq); + + compileReq->generatedBytecode = sharedContext.bytecode; } +// TODO: Need to support IR emit at the whole-module/compile-request +// level, and not just for individual entry points. +#if 0 List<uint8_t> emitSlangIRForEntryPoint( EntryPointRequest* entryPoint) { @@ -1072,5 +1118,6 @@ List<uint8_t> emitSlangIRForEntryPoint( return sharedContext.bytecode; } +#endif } // namespace Slang |
