Skip to content

Commit

Permalink
enh(directx): add directx backend support for ASSIGN_AND (#207)
Browse files Browse the repository at this point in the history
Implementation details:

- Add ASSIGN_AND token to lexer
- Implement ASSIGN_AND parsing in directx parser

Test details:

- Add parser and codegen tests for ASSIGN_AND
- Add lexer tests for ASSIGN_AND and ASSIGN_OR

Signed-off-by: Maharshi Basu <[email protected]>
  • Loading branch information
MashyBasker authored Oct 21, 2024
1 parent e2f2c24 commit 6ee42fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions crosstl/src/backend/DirectX/DirectxLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
("DIVIDE_EQUALS", r"/="),
("ASSIGN_XOR", r"\^="),
("ASSIGN_OR", r"\|="),
("ASSIGN_AND", r"\&="),
("AND", r"&&"),
("OR", r"\|\|"),
("DOT", r"\."),
Expand Down
4 changes: 4 additions & 0 deletions crosstl/src/backend/DirectX/DirectxParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def parse_variable_declaration_or_assignment(self):
"DIVIDE_EQUALS",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -250,6 +251,7 @@ def parse_variable_declaration_or_assignment(self):
"DIVIDE_EQUALS",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -269,6 +271,7 @@ def parse_variable_declaration_or_assignment(self):
"DIVIDE_EQUALS",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -380,6 +383,7 @@ def parse_assignment(self):
"DIVIDE_EQUALS",
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down
5 changes: 4 additions & 1 deletion tests/test_backend/test_directx/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ def test_assignment_ops_parsing():
output.redValue ^= 0x1;
output.out_color.r = asfloat(redValue);
outpu.redValue |= 0x2;
output.redValue |= 0x2;
output.redValue &= 0x3;
}
return output;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_backend/test_directx/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def test_assignment_ops_tokenization():
uint redValue = asuint(output.out_color.r);
redValue ^= 0x1;
output.out_color.r = asfloat(redValue);
redValue |= 0x2;
redValue &= 0x3;
}
return output;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_backend/test_directx/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def test_assignment_ops_parsing():
output.out_color.r = asfloat(redValue);
output.redValue |= 0x2;
output.redValue &= 0x3;
}
return output;
Expand Down

0 comments on commit 6ee42fb

Please sign in to comment.