summaryrefslogtreecommitdiffstats
path: root/source/slang/check.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-28 13:34:38 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-06 09:17:04 -0700
commitf145e09a6dcbcf326f782b3e6a76dbf291c792cf (patch)
tree88a04619ceaaa37b87199dd82334cc9d102c156d /source/slang/check.cpp
parentc0d2c17bc73bc2a8863e086af3ea395ad09465ee (diff)
Start to support cross-compilation via "lowering" pass
- The big change here is the introduction of a "lowering" pass that takes an input AST from the semantic checker, and produces an output AST suitable for emitting. The intention is that he lowering pass is responsible for: - Stripping out unused code (when we have enough information to do so), by only outputting declarations that are transitively references from an entry point - When cross-compiling to GLSL, generating a suitable `void main()` entry point to wrap the user-written entry-point function - (Eventually) legalizing types in the program, by scalarizing aggregate types that mix uniform and resource types - (Eventually) instantiating generic declarations so that the resulting code only deals with fully specialized declarations - (Eventually) de-sugaring OOP constructs into basic "structs and functions" form - (Eventually) instantiating code that depends on interface types at the concrete types chosen - It is clear that there is still a lot of work to be done there, to this change is really about getting infrastructure in place without breaking the existing test cases. - One cleanup here is that we get rid of the idea of whole-translation-unit output, since that was specific to HLSL output, and there is really no strong reason for keeping it. Users should now just ask for the output for each entry point that they wanted to generate. - The biggest source of complexity for the lowering process is that it needs to produce the same AST structure as the input, to deal with the complexity of the rewriter case. That is, we need the output to be able to reproduce the input exactly in the case where we are rewriting and nothing needs to change, so the output format needs at least the degrees of freedom of the input. - As a result, we end up having to distinguish "rewriter" and "full" modes in both lowering and code-emit steps, so that we can react appropriately. - Generating a GLSL `main()` also adds a lot of complexity. Right now I'm using the simplest approach, where we always output the Slang/HLSL entry point as an ordinary function (as written) and then emit a simple GLSL `main()` to call it. I generate globals for all the shader inputs/outputs (these need to be scalarized and have explicit `location`s attached), and then collect these into the `struct` types of the original parameters as needed. - This approach will start to have some major down-sides once we have to deal with "arrayed" input/output - A long-term question here is how to replace entry-point parameter types with scalarized and/or "transposed" versions, while still letting the original code work as written (including copying those inputs to temporary arrays) - Split `BlockStatementSyntaxNode` into: - `BlockStmt` which just provides a scope around a `body` statement - `SeqStmt` which just allows multiple statements to be treated as one - Change how we emit `for` loops, to deal with the case where the initialization part might expand into multiple statements - Basically `for(A;B;C) {D}` becomes `{A; for(;B;C) {D}}`, so we can handle arbitrary statements for `A` - As an additional wrinkle, when we are rewriting HLSL, we just generate `A; for(;B;C) {D}` to deal with the broken scoping there - This change is needed because the lowering pass was sometimes expanding the original initialization statement `A` into a block `{A}`. Certainly if it declared multiple variables we'd need to handle it, and this seemed the easiest way - A more significant challenge for lowering would come if/when we ever wanted to support true short-circuiting behavior for `&&` and `||` - For right now I'm not changing the behavior of the "rewriter" mode, so we still have `UnparsedStmt` instances being generated, but it is clear that eventually we need to parse *all* input, even if we can't type-check 100% of it. This is required so that we can rewrite user code that might refer to a shader input with interface type.
Diffstat (limited to 'source/slang/check.cpp')
-rw-r--r--source/slang/check.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index a3e061a3b..a79af3f37 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -1581,11 +1581,16 @@ namespace Slang
DeclVisitor::dispatch(stmt->decl);
}
- void visit(BlockStatementSyntaxNode *stmt)
+ void visit(BlockStmt* stmt)
{
- for (auto & node : stmt->Statements)
+ checkStmt(stmt->body);
+ }
+
+ void visit(SeqStmt* stmt)
+ {
+ for(auto ss : stmt->stmts)
{
- checkStmt(node);
+ checkStmt(ss);
}
}
@@ -2414,6 +2419,24 @@ namespace Slang
return appExpr;
}
+ //
+
+ RefPtr<ExpressionSyntaxNode> visit(AssignExpr* expr)
+ {
+ expr->left = CheckExpr(expr->left);
+
+ auto type = expr->left->Type;
+
+ expr->right = Coerce(type, CheckTerm(expr->right));
+
+ if (!type.IsLeftValue)
+ {
+ getSink()->diagnose(expr, Diagnostics::assignNonLValue);
+ }
+ expr->Type = type;
+ return expr;
+ }
+
//