summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-11-27 16:33:28 -0800
committerGitHub <noreply@github.com>2017-11-27 16:33:28 -0800
commit31993854b164fb6e19e449b7be550b1e48297ef5 (patch)
tree42e8f1542e2773288fec546a2e0dac20cbc0e83f /source
parent109ee8aae399042fba6ea71e43e5ee2d441288dd (diff)
Cleanups (#298)
* Rename `lower.{h,cpp}` to `ast-legalize.{h,cpp}` This pass isn't really performing lowering akin to `lower-to-ir.{h,cpp}` so the file name is misleading. By renaming this pass we emphasize its role as an AST-related pass. Also update the comment at the top of `ast-legalize.h` to reflect the intended purpose of this pass in a world where we have the IR up and running. * Allow `import` as an alias for `__import` The use of double underscores to mark our new syntax has so far had two purposes: 1. It helps identify syntax that isn't meant to be exposed to users in its current form (e.g., `__generic` gets a double underscore because we want users to have a more pleasant surface syntax for generics that they write). This rationale doesn't apply to `__import`, which is a major language feature that users need to interact with. 2. It helps avoid the problem where the compiler treats something as a keyword that isn't supposed to be reserved in HLSL/GLSL and so causes existing user code to fail to parse (e.g., when the user tries to write a function called `import`). This no longer matters because we look up almost all of our keywords using the existing lexical scoping in the language (so the user can shadow almost any keyword with a local declaration). So, neither of the original two reasons applies to `__import`, and it makes sense to expose it as `import`. Doing so is a one-line change.
Diffstat (limited to 'source')
-rw-r--r--source/slang/ast-legalize.cpp (renamed from source/slang/lower.cpp)4
-rw-r--r--source/slang/ast-legalize.h65
-rw-r--r--source/slang/emit.cpp2
-rw-r--r--source/slang/lower.h41
-rw-r--r--source/slang/parser.cpp1
-rw-r--r--source/slang/slang.vcxproj4
-rw-r--r--source/slang/slang.vcxproj.filters4
7 files changed, 73 insertions, 48 deletions
diff --git a/source/slang/lower.cpp b/source/slang/ast-legalize.cpp
index 5a6603add..5b6c5ae38 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/ast-legalize.cpp
@@ -1,5 +1,5 @@
-// lower.cpp
-#include "lower.h"
+// ast-legalize.cpp
+#include "ast-legalize.h"
#include "emit.h"
#include "type-layout.h"
diff --git a/source/slang/ast-legalize.h b/source/slang/ast-legalize.h
new file mode 100644
index 000000000..071ff6c51
--- /dev/null
+++ b/source/slang/ast-legalize.h
@@ -0,0 +1,65 @@
+// ast-legalize.h
+#ifndef SLANG_AST_LEGALIZE_H_INCLUDED
+#define SLANG_AST_LEGALIZE_H_INCLUDED
+
+// The AST legalization pass takes an AST and tries to transform
+// it to make sure that it is legal for a chosen compilation target.
+//
+// This can include many different kinds of work:
+//
+// - If the input was written in HLSL/Slang, but we want GLSL output, then
+// this pass is responsible for converting certain HLSL idioms into
+// their GLSL equivalents. This is not a really good cross-compilation
+// solution (in particular, it does *not* support Slang code that uses
+// and of our more advanced features), and it will eventually be deprecated
+// in favor of the IR-based code generation approach.
+//
+// - For input written in GLSL, we support a few extensions to the specified
+// language rules (e.g., we support `struct` types that mix resource and
+// uniform types, and we also support `struct` types for vertex inputs).
+// These need to be lowered to vanilla GLSL. This also applies to HLSL if
+// the `-split-mixed-types` flag is set.
+//
+// - When using the IR to provide portable library code, with entry points
+// written in unchecked (`-no-checking`) HLSL or GLSL, this pass will
+// be applied to the unchecked code, and used to determine what subset of
+// the Slang code must be compiled via the IR.
+//
+// Note: in the case where input is pure Slang code (or the subset of
+// HLSL that we can fully check) this pass is not needed or used at all;
+// instead we perform all lowering, legalization, etc. entirely via the IR.
+//
+
+#include "../core/basic.h"
+
+#include "compiler.h"
+#include "syntax.h"
+
+namespace Slang
+{
+ class EntryPointRequest;
+ class ProgramLayout;
+ class TranslationUnitRequest;
+
+ struct ExtensionUsageTracker;
+
+ struct LoweredEntryPoint
+ {
+ // The actual lowered entry point
+ RefPtr<FuncDecl> entryPoint;
+
+ // The generated program AST that
+ // contains the entry point and any
+ // other declarations it uses
+ RefPtr<ModuleDecl> program;
+ };
+
+ // Emit code for a single entry point, based on
+ // the input translation unit.
+ LoweredEntryPoint lowerEntryPoint(
+ EntryPointRequest* entryPoint,
+ ProgramLayout* programLayout,
+ CodeGenTarget target,
+ ExtensionUsageTracker* extensionUsageTracker);
+}
+#endif
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index 22dcf4333..d6f1f8e1a 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -1,8 +1,8 @@
// emit.cpp
#include "emit.h"
+#include "ast-legalize.h"
#include "ir-insts.h"
-#include "lower.h"
#include "lower-to-ir.h"
#include "mangle.h"
#include "name.h"
diff --git a/source/slang/lower.h b/source/slang/lower.h
deleted file mode 100644
index 919260af3..000000000
--- a/source/slang/lower.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// lower.h
-#ifndef SLANG_LOWER_H_INCLUDED
-#define SLANG_LOWER_H_INCLUDED
-
-// The "lowering" step takes an input AST written in the complete Slang
-// language and turns it into a more minimal format (still using the
-// same AST) suitable for emission into lower-level languages.
-
-#include "../core/basic.h"
-
-#include "compiler.h"
-#include "syntax.h"
-
-namespace Slang
-{
- class EntryPointRequest;
- class ProgramLayout;
- class TranslationUnitRequest;
-
- struct ExtensionUsageTracker;
-
- struct LoweredEntryPoint
- {
- // The actual lowered entry point
- RefPtr<FuncDecl> entryPoint;
-
- // The generated program AST that
- // contains the entry point and any
- // other declarations it uses
- RefPtr<ModuleDecl> program;
- };
-
- // Emit code for a single entry point, based on
- // the input translation unit.
- LoweredEntryPoint lowerEntryPoint(
- EntryPointRequest* entryPoint,
- ProgramLayout* programLayout,
- CodeGenTarget target,
- ExtensionUsageTracker* extensionUsageTracker);
-}
-#endif
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 0a4360e3f..54d098343 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -4154,6 +4154,7 @@ namespace Slang
DECL(interface, parseInterfaceDecl);
DECL(syntax, parseSyntaxDecl);
DECL(__import, parseImportDecl);
+ DECL(import, parseImportDecl);
#undef DECL
diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj
index 984ec7011..d0e4e840e 100644
--- a/source/slang/slang.vcxproj
+++ b/source/slang/slang.vcxproj
@@ -187,7 +187,7 @@
<ClInclude Include="name.h" />
<ClInclude Include="object-meta-begin.h" />
<ClInclude Include="object-meta-end.h" />
- <ClInclude Include="lower.h" />
+ <ClInclude Include="ast-legalize.h" />
<ClInclude Include="parameter-binding.h" />
<ClInclude Include="parser.h" />
<ClInclude Include="preprocessor.h" />
@@ -220,7 +220,7 @@
<ClCompile Include="lexer.cpp" />
<ClCompile Include="lookup.cpp" />
<ClCompile Include="lower-to-ir.cpp" />
- <ClCompile Include="lower.cpp" />
+ <ClCompile Include="ast-legalize.cpp" />
<ClCompile Include="mangle.cpp" />
<ClCompile Include="name.cpp" />
<ClCompile Include="options.cpp" />
diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters
index ce933db6e..c93934fff 100644
--- a/source/slang/slang.vcxproj.filters
+++ b/source/slang/slang.vcxproj.filters
@@ -34,7 +34,6 @@
<ClInclude Include="type-defs.h" />
<ClInclude Include="val-defs.h" />
<ClInclude Include="visitor.h" />
- <ClInclude Include="lower.h" />
<ClInclude Include="name.h" />
<ClInclude Include="ir.h" />
<ClInclude Include="lower-to-ir.h" />
@@ -43,6 +42,7 @@
<ClInclude Include="bytecode.h" />
<ClInclude Include="vm.h" />
<ClInclude Include="mangle.h" />
+ <ClInclude Include="ast-legalize.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="check.cpp" />
@@ -62,7 +62,6 @@
<ClCompile Include="token.cpp" />
<ClCompile Include="type-layout.cpp" />
<ClCompile Include="options.cpp" />
- <ClCompile Include="lower.cpp" />
<ClCompile Include="source-loc.cpp" />
<ClCompile Include="name.cpp" />
<ClCompile Include="ir.cpp" />
@@ -72,6 +71,7 @@
<ClCompile Include="mangle.cpp" />
<ClCompile Include="dxc-support.cpp" />
<ClCompile Include="ir-legalize-types.cpp" />
+ <ClCompile Include="ast-legalize.cpp" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="core.meta.slang" />