summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-11-01 22:49:30 -0700
committerGitHub <noreply@github.com>2023-11-01 22:49:30 -0700
commite712ebd93aa9a2845bde3ea541aaa7cd415548b7 (patch)
tree14d2bf34cb35e7433a80abc8feb612184f6a52ec /source/slang
parent6aca3813c4ccc496c0f9b2db293acb546aa11d2d (diff)
Add mnemonic parsing for `intrinsic_type` modifier. (#3306)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-ast-modifier.h2
-rw-r--r--source/slang/slang-parser.cpp48
2 files changed, 29 insertions, 21 deletions
diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h
index bf79028d7..f430c5f7a 100644
--- a/source/slang/slang-ast-modifier.h
+++ b/source/slang/slang-ast-modifier.h
@@ -433,6 +433,8 @@ class IntrinsicTypeModifier : public Modifier
// The IR opcode to use when constructing a type
uint32_t irOp;
+ Token opToken;
+
// Additional literal opreands to provide when creating instances.
// (e.g., for a texture type this passes in shape/mutability info)
List<uint32_t> irOperands;
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 59aff4dc0..e701a1c2b 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -6773,6 +6773,31 @@ namespace Slang
addBuiltinSyntaxImpl(session, scope, name, &parseSimpleSyntax, (void*) syntaxClass.classInfo, getClass<T>());
}
+ static IROp parseIROp(Parser* parser, Token& outToken)
+ {
+ if (AdvanceIf(parser, TokenType::OpSub))
+ {
+ outToken = parser->ReadToken();
+ return IROp(-stringToInt(outToken.getContent()));
+ }
+ else if (parser->LookAheadToken(TokenType::IntegerLiteral))
+ {
+ outToken = parser->ReadToken();
+ return IROp(stringToInt(outToken.getContent()));
+ }
+ else
+ {
+ outToken = parser->ReadToken(TokenType::Identifier);;
+ auto op = findIROp(outToken.getContent());
+
+ if (op == kIROp_Invalid)
+ {
+ parser->sink->diagnose(outToken, Diagnostics::unimplemented, "unknown intrinsic op");
+ }
+ return op;
+ }
+ }
+
static NodeBase* parseIntrinsicOpModifier(Parser* parser, void* /*userData*/)
{
IntrinsicOpModifier* modifier = parser->astBuilder->create<IntrinsicOpModifier>();
@@ -6794,26 +6819,7 @@ namespace Slang
//
if (AdvanceIf(parser, TokenType::LParent))
{
- if (AdvanceIf(parser, TokenType::OpSub))
- {
- modifier->op = IROp(-stringToInt(parser->ReadToken().getContent()));
- }
- else if (parser->LookAheadToken(TokenType::IntegerLiteral))
- {
- modifier->op = IROp(stringToInt(parser->ReadToken().getContent()));
- }
- else
- {
- modifier->opToken = parser->ReadToken(TokenType::Identifier);
-
- modifier->op = findIROp(modifier->opToken.getContent());
-
- if (modifier->op == kIROp_Invalid)
- {
- parser->sink->diagnose(modifier->opToken, Diagnostics::unimplemented, "unknown intrinsic op");
- }
- }
-
+ modifier->op = parseIROp(parser, modifier->opToken);
parser->ReadToken(TokenType::RParent);
}
@@ -7124,7 +7130,7 @@ namespace Slang
{
IntrinsicTypeModifier* modifier = parser->astBuilder->create<IntrinsicTypeModifier>();
parser->ReadToken(TokenType::LParent);
- modifier->irOp = uint32_t(stringToInt(parser->ReadToken(TokenType::IntegerLiteral).getContent()));
+ modifier->irOp = parseIROp(parser, modifier->opToken);
while( AdvanceIf(parser, TokenType::Comma) )
{
auto operand = uint32_t(stringToInt(parser->ReadToken(TokenType::IntegerLiteral).getContent()));