Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BITWISE_XOR operator support in lexer and parser #208

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crosstl/src/backend/DirectX/DirectxLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
("ASSIGN_XOR", r"\^="),
("ASSIGN_OR", r"\|="),
("ASSIGN_AND", r"\&="),
("BITWISE_XOR", r"\^"),
("AND", r"&&"),
("OR", r"\|\|"),
("DOT", r"\."),
Expand Down
5 changes: 5 additions & 0 deletions crosstl/src/backend/DirectX/DirectxParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
"BITWISE_XOR",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -257,6 +258,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
"BITWISE_XOR",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -278,6 +280,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
"BITWISE_XOR",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -407,6 +410,7 @@ def parse_assignment(self):
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
"BITWISE_XOR",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -449,6 +453,7 @@ def parse_relational(self):
"GREATER_THAN",
"LESS_EQUAL",
"GREATER_EQUAL",
"BITWISE_XOR",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down
9 changes: 9 additions & 0 deletions tests/test_backend/test_directx/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ def test_assignment_ops_parsing():
output.redValue &= 0x3;
}

// Testing BITWISE_XOR (^) operator on some condition
if (input.in_position.r == 0.5) {
uint redValue = asuint(output.out_color.r);
output.redValue ^ 0x1;
// BITWISE_XOR operation
output.out_color.r = asfloat(redValue);
}



return output;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_backend/test_directx/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ def test_assignment_ops_parsing():
output.redValue &= 0x3;
}

// Testing BITWISE_XOR (^) operator on some condition
if (input.in_position.r == 0.5) {
uint redValue = asuint(output.out_color.r);
output.redValue ^ 0x1; // BITWISE_XOR operation
output.out_color.r = asfloat(redValue);
}



return output;
}
Expand Down
Loading