summaryrefslogtreecommitdiffstats
path: root/source/slang/parser.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-08-31 12:47:39 -0700
committerTim Foley <tfoley@nvidia.com>2017-09-06 13:52:04 -0700
commit5900f32fff9970b4221ce7fb7e94133e387ff9de (patch)
treefd83b7e861dbc6a0d442d5a913a1bcd9df547408 /source/slang/parser.cpp
parente59a1b39317c10815baaed3b70c4a6580dbe1e63 (diff)
Continue work on IR-based codegen
This gets us far enough that we can convert a single test case to use the IR, under the new `-use-ir` flag. Getting this merged into mainline will at least ensure that we keep the IR path working in a minimal fashion, even when we have to add functionality the existing AST-based path There is definitely some clutter here from keeping both IR-based and AST-based translation around, but I don't want to have a long-lived branch for the IR that gets further and further away from the `master` branch that is actually getting used and tested. Summary of changes: - Add pointer types and basic `load` operation to be able to handle variable declarations - Add basic `call` instruction type - Add simple address math for field reference in l-value - Always add IR for referenced decls to global scope - Add notion of "intrinsic" type modifier, which maps a type declaration directly to an IR opcode (plus optional literal operands to handle things like texture/sampler flavor) - Improve printing of IR instructions, types, operands - Add constant-buffer type to IR - Allow any instruction to be detected as "should be folded into use sites" and use this to tag things of constant-buffer type - Also add logic for implicit base on member expressions, to handle references to `cbuffer` members - Add connection back to original decl to IR variables (including global shader parameters...) - Use reflection name instead of true name when emitting HLSL from IR (so that we can match HLSL output) - Make IR include decorations for type layout - Re-use existing emit logic for HLSL semantics to output `register` semantics for IR-based code - Make IR-based codegen be an option we can enable from the command line - It still isn't on by default (it can barely manage a trivial shader), but it seems better to enable it always instead of putting it under an `#ifdef` - Fix up how we check for intrinsic operations suring AST-based cross compilation so that adding new intrinsic ops for the IR won't break codegen.
Diffstat (limited to 'source/slang/parser.cpp')
-rw-r--r--source/slang/parser.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 7da309d29..9c0d692e6 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -3916,6 +3916,20 @@ namespace Slang
return modifier;
}
+ static RefPtr<RefObject> parseIntrinsicTypeModifier(Parser* parser, void* /*userData*/)
+ {
+ RefPtr<IntrinsicTypeModifier> modifier = new IntrinsicTypeModifier();
+ parser->ReadToken(TokenType::LParent);
+ modifier->irOp = uint32_t(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).Content));
+ while( AdvanceIf(parser, TokenType::Comma) )
+ {
+ auto operand = uint32_t(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).Content));
+ modifier->irOperands.Add(operand);
+ }
+ parser->ReadToken(TokenType::RParent);
+
+ return modifier;
+ }
static RefPtr<RefObject> parseImplicitConversionModifier(Parser* parser, void* /*userData*/)
{
RefPtr<ImplicitConversionModifier> modifier = new ImplicitConversionModifier();
@@ -4020,6 +4034,7 @@ namespace Slang
MODIFIER(__builtin_type, parseBuiltinTypeModifier);
MODIFIER(__magic_type, parseMagicTypeModifier);
+ MODIFIER(__intrinsic_type, parseIntrinsicTypeModifier);
MODIFIER(__implicit_conversion, parseImplicitConversionModifier);
#undef MODIFIER