diff options
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 4f135d144..710cc0b45 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1964,6 +1964,9 @@ void FrontEndCompileRequest::parseTranslationUnit( break; } + // TODO(JS): + // Note! that a adding a define twice will cause an exception in debug builds + // that may be desirable or not... Dictionary<String, String> combinedPreprocessorDefinitions; for(auto& def : getLinkage()->preprocessorDefinitions) combinedPreprocessorDefinitions.Add(def.Key, def.Value); @@ -1972,12 +1975,45 @@ void FrontEndCompileRequest::parseTranslationUnit( for(auto& def : translationUnit->preprocessorDefinitions) combinedPreprocessorDefinitions.Add(def.Key, def.Value); + // Define standard macros, if not already defined. This style assumes using `#if __SOME_VAR` style, as in + // + // ``` + // #if __SLANG_COMPILER__ + // ``` + // + // This choice is made because slang outputs a warning on using a variable in an #if if not defined + // + // Of course this means using #ifndef/#ifdef/defined() is probably not appropraite with thes variables. + { + // Used to identify level of HLSL language compatibility + combinedPreprocessorDefinitions.AddIfNotExists("__HLSL_VERSION", "2020"); + + // Indicates this is being compiled by the slang *compiler* + combinedPreprocessorDefinitions.AddIfNotExists("__SLANG_COMPILER__", "1"); + + // Set macro depending on source type + switch (translationUnit->sourceLanguage) + { + case SourceLanguage::HLSL: + // Used to indicate compiled as HLSL language + combinedPreprocessorDefinitions.AddIfNotExists("__HLSL__", "1"); + break; + case SourceLanguage::Slang: + // Used to indicate compiled as Slang language + combinedPreprocessorDefinitions.AddIfNotExists("__SLANG__", "1"); + break; + default: break; + } + + // If not set, define as 0. + combinedPreprocessorDefinitions.AddIfNotExists("__HLSL__", "0"); + combinedPreprocessorDefinitions.AddIfNotExists("__SLANG__", "0"); + } + auto module = translationUnit->getModule(); ASTBuilder* astBuilder = module->getASTBuilder(); - //ASTBuilder* astBuilder = linkage->getASTBuilder(); - ModuleDecl* translationUnitSyntax = astBuilder->create<ModuleDecl>(); translationUnitSyntax->nameAndLoc.name = translationUnit->moduleName; @@ -2060,8 +2096,6 @@ void FrontEndCompileRequest::parseTranslationUnit( } } - - #if 0 // Test serialization { |
