From 6ee42fbcfb139865c0ff59e4b35c55c8434ff8b1 Mon Sep 17 00:00:00 2001 From: Maharshi Basu <84385565+MashyBasker@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:50:43 +0530 Subject: [PATCH] enh(directx): add directx backend support for ASSIGN_AND (#207) 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 --- crosstl/src/backend/DirectX/DirectxLexer.py | 1 + crosstl/src/backend/DirectX/DirectxParser.py | 4 ++++ tests/test_backend/test_directx/test_codegen.py | 5 ++++- tests/test_backend/test_directx/test_lexer.py | 4 ++++ tests/test_backend/test_directx/test_parser.py | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crosstl/src/backend/DirectX/DirectxLexer.py b/crosstl/src/backend/DirectX/DirectxLexer.py index c5a1574..d6632a3 100644 --- a/crosstl/src/backend/DirectX/DirectxLexer.py +++ b/crosstl/src/backend/DirectX/DirectxLexer.py @@ -45,6 +45,7 @@ ("DIVIDE_EQUALS", r"/="), ("ASSIGN_XOR", r"\^="), ("ASSIGN_OR", r"\|="), + ("ASSIGN_AND", r"\&="), ("AND", r"&&"), ("OR", r"\|\|"), ("DOT", r"\."), diff --git a/crosstl/src/backend/DirectX/DirectxParser.py b/crosstl/src/backend/DirectX/DirectxParser.py index 3dd6014..2764649 100644 --- a/crosstl/src/backend/DirectX/DirectxParser.py +++ b/crosstl/src/backend/DirectX/DirectxParser.py @@ -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] @@ -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] @@ -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]) @@ -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]) diff --git a/tests/test_backend/test_directx/test_codegen.py b/tests/test_backend/test_directx/test_codegen.py index ed7112b..55ed1be 100644 --- a/tests/test_backend/test_directx/test_codegen.py +++ b/tests/test_backend/test_directx/test_codegen.py @@ -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; diff --git a/tests/test_backend/test_directx/test_lexer.py b/tests/test_backend/test_directx/test_lexer.py index 4cb364d..76ba0bc 100644 --- a/tests/test_backend/test_directx/test_lexer.py +++ b/tests/test_backend/test_directx/test_lexer.py @@ -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; diff --git a/tests/test_backend/test_directx/test_parser.py b/tests/test_backend/test_directx/test_parser.py index 7d3cc2d..5b1b702 100644 --- a/tests/test_backend/test_directx/test_parser.py +++ b/tests/test_backend/test_directx/test_parser.py @@ -177,6 +177,8 @@ def test_assignment_ops_parsing(): output.out_color.r = asfloat(redValue); output.redValue |= 0x2; + + output.redValue &= 0x3; } return output;