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 support for SHIFT_LEFT (<<) operator and other assignment operato… #205

Merged
merged 4 commits into from
Oct 27, 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 @@ -34,6 +34,7 @@
("COMMA", r","),
("COLON", r":"),
("QUESTION", r"\?"),
("SHIFT_LEFT", r"<<"),
("LESS_EQUAL", r"<="),
("GREATER_EQUAL", r">="),
("LESS_THAN", 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 @@ -238,6 +238,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -255,6 +256,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
]:
# Handle assignment operators (e.g., =, +=, -=, ^=, etc.)
op = self.current_token[1]
Expand All @@ -275,6 +277,7 @@ def parse_variable_declaration_or_assignment(self):
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -403,6 +406,7 @@ def parse_assignment(self):
"ASSIGN_XOR",
"ASSIGN_OR",
"ASSIGN_AND",
"SHIFT_LEFT",
]:
op = self.current_token[1]
self.eat(self.current_token[0])
Expand Down Expand Up @@ -441,6 +445,7 @@ def parse_relational(self):
left = self.parse_additive()
while self.current_token[0] in [
"LESS_THAN",
"SHIFT_LEFT",
"GREATER_THAN",
"LESS_EQUAL",
"GREATER_EQUAL",
Expand Down
6 changes: 4 additions & 2 deletions tests/test_backend/test_directx/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,19 @@ def test_assignment_ops_parsing():
out_color /= 2.0;
}

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

output.redValue |= 0x2;

// Applying shift left operation
output.redValue << 1; // Shift left by 1
output.redValue &= 0x3;

}


return output;
}
"""
Expand Down
7 changes: 6 additions & 1 deletion tests/test_backend/test_directx/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,21 @@ def test_assignment_ops_tokenization():
output.out_color /= 2.0;
}

// Testing SHIFT_LEFT (<<) operator on some condition
if (input.in_position.r == 0.5) {
uint redValue = asuint(output.out_color.r);
redValue ^= 0x1;
output.redValue ^= 0x1;
output.out_color.r = asfloat(redValue);
output.redValue |= 0x2;

// Applying shift left operation
output.redValue << 1; // Shift left by 1
redValue |= 0x2;

redValue &= 0x3;
}


return output;
}
"""
Expand Down
5 changes: 4 additions & 1 deletion tests/test_backend/test_directx/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,19 @@ def test_assignment_ops_parsing():
out_color /= 2.0;
}

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

output.redValue |= 0x2;

// Applying shift left operation
output.redValue << 1; // Shift left by 1
output.redValue &= 0x3;
}


return output;
}
"""
Expand Down
Loading