-
Notifications
You must be signed in to change notification settings - Fork 195
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
[hlsl-out] Fix fallthrough in switch statements (for FXC) #1920
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1651,7 +1651,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { | |||||||||||||||||
let indent_level_1 = level.next(); | ||||||||||||||||||
let indent_level_2 = indent_level_1.next(); | ||||||||||||||||||
|
||||||||||||||||||
for case in cases { | ||||||||||||||||||
for (i, case) in cases.iter().enumerate() { | ||||||||||||||||||
match case.value { | ||||||||||||||||||
crate::SwitchValue::Integer(value) => writeln!( | ||||||||||||||||||
self.out, | ||||||||||||||||||
|
@@ -1663,25 +1663,35 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// FXC doesn't support fallthrough so we duplicate the body of the following case blocks | ||||||||||||||||||
if case.fall_through { | ||||||||||||||||||
// Generate each fallthrough case statement in a new block. This is done to | ||||||||||||||||||
// prevent symbol collision of variables declared in these cases statements. | ||||||||||||||||||
writeln!(self.out, "{}/* fallthrough */", indent_level_2)?; | ||||||||||||||||||
writeln!(self.out, "{}{{", indent_level_2)?; | ||||||||||||||||||
} | ||||||||||||||||||
for sta in case.body.iter() { | ||||||||||||||||||
self.write_stmt( | ||||||||||||||||||
module, | ||||||||||||||||||
sta, | ||||||||||||||||||
func_ctx, | ||||||||||||||||||
back::Level(indent_level_2.0 + usize::from(case.fall_through)), | ||||||||||||||||||
)?; | ||||||||||||||||||
} | ||||||||||||||||||
let curr_len = i + 1; | ||||||||||||||||||
let end_case_idx = curr_len | ||||||||||||||||||
+ cases | ||||||||||||||||||
.iter() | ||||||||||||||||||
.skip(curr_len) | ||||||||||||||||||
.position(|case| !case.fall_through) | ||||||||||||||||||
.unwrap(); | ||||||||||||||||||
let indent_level_3 = indent_level_2.next(); | ||||||||||||||||||
for case in &cases[i..=end_case_idx] { | ||||||||||||||||||
writeln!(self.out, "{}{{", indent_level_2)?; | ||||||||||||||||||
for sta in case.body.iter() { | ||||||||||||||||||
self.write_stmt(module, sta, func_ctx, indent_level_3)?; | ||||||||||||||||||
} | ||||||||||||||||||
writeln!(self.out, "{}}}", indent_level_2)?; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
if case.fall_through { | ||||||||||||||||||
writeln!(self.out, "{}}}", indent_level_2)?; | ||||||||||||||||||
} else if case.body.last().map_or(true, |s| !s.is_terminator()) { | ||||||||||||||||||
writeln!(self.out, "{}break;", indent_level_2)?; | ||||||||||||||||||
let last_case = &cases[end_case_idx]; | ||||||||||||||||||
if last_case.body.last().map_or(true, |s| !s.is_terminator()) { | ||||||||||||||||||
writeln!(self.out, "{}break;", indent_level_2)?; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+1684
to
+1687
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pair with the above suggestion:
Suggested change
|
||||||||||||||||||
} else { | ||||||||||||||||||
for sta in case.body.iter() { | ||||||||||||||||||
self.write_stmt(module, sta, func_ctx, indent_level_2)?; | ||||||||||||||||||
} | ||||||||||||||||||
if case.body.last().map_or(true, |s| !s.is_terminator()) { | ||||||||||||||||||
writeln!(self.out, "{}break;", indent_level_2)?; | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
writeln!(self.out, "{}}}", indent_level_1)?; | ||||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified a bit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the naming to be slightly more confusing here since
rest
andfallthrough
contain the first case as well. Gettingfallthrough_count
should also skip the first element (since it's the first case) and add one at the end.I tried to make it more clear as well without much luck...