diff options
Diffstat (limited to 'source/slang/compiler.h')
| -rw-r--r-- | source/slang/compiler.h | 172 |
1 files changed, 127 insertions, 45 deletions
diff --git a/source/slang/compiler.h b/source/slang/compiler.h index 39c91e21b..36fc5f42f 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -14,7 +14,7 @@ namespace Slang { struct IncludeHandler; - struct CompileRequest; + class CompileRequest; enum class CompilerMode { @@ -48,11 +48,42 @@ namespace Slang ReflectionJSON = SLANG_REFLECTION_JSON, }; + class CompileRequest; + class TranslationUnitRequest; + + // Result of compiling an entry point + struct EntryPointResult + { + String outputSource; + }; + // Describes an entry point that we've been requested to compile - struct EntryPointOption + class EntryPointRequest : public RefObject { + public: + // The parent compile request + CompileRequest* compileRequest = nullptr; + + // The name of the entry point function (e.g., `main`) String name; + + // The profile that the entry point will be compiled for + // (this is a combination of the target state, and also + // a feature level that sets capabilities) Profile profile; + + // The index of the translation unit (within the parent + // compile request) that the entry point function is + // supposed to be defined in. + int translationUnitIndex; + + // The resulting output for the enry point + // + // TODO: low-level code generation should be a distinct step + EntryPointResult result; + + // The translation unit that this entry point came from + TranslationUnitRequest* getTranslationUnit(); }; enum class PassThroughMode : SlangPassThrough @@ -74,27 +105,49 @@ namespace Slang String content; }; - // Options for a single translation unit being requested by the user - class TranslationUnitOptions + // Result of compiling a translation unit + struct TranslationUnitResult + { + String outputSource; + }; + + // A single translation unit requested to be compiled. + // + class TranslationUnitRequest : public RefObject { public: - SourceLanguage sourceLanguage = SourceLanguage::Unknown; + // The parent compile request + CompileRequest* compileRequest = nullptr; - // All entry points we've been asked to compile for this translation unit - List<EntryPointOption> entryPoints; + // The language in which the source file(s) + // are assumed to be written + SourceLanguage sourceLanguage = SourceLanguage::Unknown; // The source file(s) that will be compiled to form this translation unit + // + // Usually, for HLSL or GLSL there will be only one file. List<RefPtr<SourceFile> > sourceFiles; + // The entry points associated with this translation unit + List<RefPtr<EntryPointRequest> > entryPoints; + // Preprocessor definitions to use for this translation unit only // (whereas the ones on `CompileOptions` will be shared) Dictionary<String, String> preprocessorDefinitions; // Compile flags for this translation unit SlangCompileFlags compileFlags = 0; - }; + // The parsed syntax for the translation unit + RefPtr<ProgramSyntaxNode> SyntaxNode; + // The resulting output for the translation unit + // + // TODO: low-level code generation should be a distinct step + TranslationUnitResult result; + }; + + // A directory to be searched when looking for files (e.g., `#include`) struct SearchDirectory { enum Kind @@ -114,9 +167,14 @@ namespace Slang Kind kind; }; - class CompileOptions + class Session; + + class CompileRequest : public RefObject { public: + // Pointer to parent session + Session* mSession; + // What target language are we compiling to? CodeGenTarget Target = CodeGenTarget::Unknown; @@ -127,7 +185,11 @@ namespace Slang Dictionary<String, String> preprocessorDefinitions; // Translation units we are being asked to compile - List<TranslationUnitOptions> translationUnits; + List<RefPtr<TranslationUnitRequest> > translationUnits; + + // Entry points we've been asked to compile (each + // assocaited with a translation unit). + List<RefPtr<EntryPointRequest> > entryPoints; // The code generation profile we've been asked to use. Profile profile; @@ -137,53 +199,73 @@ namespace Slang // Compile flags to be shared by all translation units SlangCompileFlags compileFlags = 0; - }; - // This is the representation of a given translation unit - class CompileUnit - { - public: - TranslationUnitOptions options; - RefPtr<ProgramSyntaxNode> SyntaxNode; - }; + // Output stuff + DiagnosticSink mSink; + String mDiagnosticOutput; - // TODO: pick an appropriate name for this... - class CollectionOfTranslationUnits : public RefObject - { - public: - List<CompileUnit> translationUnits; + // Files that compilation depended on + List<String> mDependencyFilePaths; - // TODO: this is more output-oriented, but maybe okay to have here... + // The resulting reflection layout information RefPtr<ProgramLayout> layout; - }; - // Context information for code generation - struct ExtraContext - { - CompileOptions const* options = nullptr; - TranslationUnitOptions const* translationUnitOptions = nullptr; + // Modules that have been dynamically loaded via `import` + Dictionary<String, RefPtr<ProgramSyntaxNode>> loadedModules; + + + CompileRequest(Session* session) + : mSession(session) + {} - CompileResult* compileResult = nullptr; + ~CompileRequest() + {} - RefPtr<ProgramSyntaxNode> programSyntax; - ProgramLayout* programLayout; + void parseTranslationUnit( + TranslationUnitRequest* translationUnit); - String sourceText; - String sourcePath; + void CompileRequest::checkTranslationUnit( + TranslationUnitRequest* translationUnit); - CompileOptions const& getOptions() { return *options; } - TranslationUnitOptions const& getTranslationUnitOptions() { return *translationUnitOptions; } - }; + void checkAllTranslationUnits(); + + int executeActionsInner(); + int executeActions(); + + int addTranslationUnit(SourceLanguage language, String const& name); + + void addTranslationUnitSourceString( + int translationUnitIndex, + String const& path, + String const& source); - TranslationUnitResult passThrough( - String const& sourceText, - String const& sourcePath, - const CompileOptions & options, - TranslationUnitOptions const& translationUnitOptions); + void addTranslationUnitSourceFile( + int translationUnitIndex, + String const& path); + + int addEntryPoint( + int translationUnitIndex, + String const& name, + Profile profile); + + RefPtr<ProgramSyntaxNode> loadModule( + String const& name, + String const& path, + String const& source, + CodePosition const& loc); + + String autoImportModule( + String const& path, + String const& source, + CodePosition const& loc); + + RefPtr<ProgramSyntaxNode> findOrImportModule( + String const& name, + CodePosition const& loc); + }; void generateOutput( - ExtraContext& context, - CollectionOfTranslationUnits* collectionOfTranslationUnits); + CompileRequest* compileRequest); } #endif
\ No newline at end of file |
