summaryrefslogtreecommitdiff
path: root/source/slang/compiler.h
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-10-16 13:12:11 -0700
committerGitHub <noreply@github.com>2017-10-16 13:12:11 -0700
commitf12c2552b3f494cbc8245edb90b32b93ca8a1539 (patch)
tree4cd08ad6037067dc70844a4a847fb3228e0176ee /source/slang/compiler.h
parent3e3e2473bf85365593629bd1f6f070d11f0b8ab2 (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/compiler.h')
-rw-r--r--source/slang/compiler.h69
1 files changed, 53 insertions, 16 deletions
diff --git a/source/slang/compiler.h b/source/slang/compiler.h
index 9de74e2cd..b7ab980fc 100644
--- a/source/slang/compiler.h
+++ b/source/slang/compiler.h
@@ -47,7 +47,12 @@ namespace Slang
SPIRVAssembly = SLANG_SPIRV_ASM,
DXBytecode = SLANG_DXBC,
DXBytecodeAssembly = SLANG_DXBC_ASM,
- SlangIR = SLANG_IR,
+ };
+
+ enum class ContainerFormat
+ {
+ None = SLANG_CONTAINER_FORMAT_NONE,
+ SlangModule = SLANG_CONTAINER_FORMAT_SLANG_MODULE,
};
enum class LineDirectiveMode : SlangLineDirectiveMode
@@ -108,13 +113,14 @@ namespace Slang
// (only used when compiling from the command line)
String outputPath;
- // The resulting output for the enry point
- //
- // TODO: low-level code generation should be a distinct step
- CompileResult result;
-
// The translation unit that this entry point came from
TranslationUnitRequest* getTranslationUnit();
+
+ // The declaration of the entry-point function itself.
+ // This will be filled in as part of semantic analysis;
+ // it should not be assumed to be available in cases
+ // where any errors were diagnosed.
+ RefPtr<FuncDecl> decl;
};
enum class PassThroughMode : SlangPassThrough
@@ -156,10 +162,27 @@ namespace Slang
// The parsed syntax for the translation unit
RefPtr<ModuleDecl> SyntaxNode;
- // The resulting output for the translation unit
- //
- // TODO: low-level code generation should be a distinct step
- CompileResult result;
+ // The IR-level code for this translation unit.
+ // This will only be valid/non-null after semantic
+ // checking and IR generation are complete, so it
+ // is not safe to use this field without testing for NULL.
+ IRModule* irModule;
+ };
+
+ // A request to generate output in some target format
+ class TargetRequest : public RefObject
+ {
+ public:
+ CompileRequest* compileRequest;
+ CodeGenTarget target;
+
+ // The resulting reflection layout information
+ RefPtr<ProgramLayout> layout;
+
+ // Generated compile results for each entry point
+ // in the parent compile request (indexing matches
+ // the order they are given in the compile request)
+ List<CompileResult> entryPointResults;
};
// A directory to be searched when looking for files (e.g., `#include`)
@@ -182,8 +205,15 @@ namespace Slang
// Pointer to parent session
Session* mSession;
- // What target language are we compiling to?
- CodeGenTarget Target = CodeGenTarget::Unknown;
+ // Information on the targets we are being asked to
+ // generate code for.
+ List<RefPtr<TargetRequest>> targets;
+
+ // What container format are we being asked to generate?
+ ContainerFormat containerFormat = ContainerFormat::None;
+
+ // Path to output container to
+ String containerOutputPath;
// Directories to search for `#include` files or `import`ed modules
List<SearchDirectory> searchDirectories;
@@ -235,18 +265,18 @@ namespace Slang
// Files that compilation depended on
List<String> mDependencyFilePaths;
- // The resulting reflection layout information
- RefPtr<ProgramLayout> layout;
+ // Generated bytecode representation of all the code
+ List<uint8_t> generatedBytecode;
// Modules that have been dynamically loaded via `import`
//
// This is a list of unique modules loaded, in the order they were encountered.
List<RefPtr<ModuleDecl> > loadedModulesList;
- // Map from the logical name of a module to its definition
+ // Map from the path of a module file to its definition
Dictionary<String, RefPtr<ModuleDecl>> mapPathToLoadedModule;
- // Map from the path of a module file to its definition
+ // Map from the logical name of a module to its definition
Dictionary<Name*, RefPtr<ModuleDecl>> mapNameToLoadedModules;
@@ -257,8 +287,12 @@ namespace Slang
void parseTranslationUnit(
TranslationUnitRequest* translationUnit);
+ // Perform primary semantic checking on all
+ // of the translation units in the program
void checkAllTranslationUnits();
+ void generateIR();
+
int executeActionsInner();
int executeActions();
@@ -282,6 +316,9 @@ namespace Slang
String const& name,
Profile profile);
+ UInt addTarget(
+ CodeGenTarget target);
+
RefPtr<ModuleDecl> loadModule(
Name* name,
String const& path,