-
Notifications
You must be signed in to change notification settings - Fork 237
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
Fixes https://github.com/sampsyo/bril/issues/342 #343
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f506b7e
Fixes https://github.com/sampsyo/bril/issues/342
Pat-Lafon 292a127
A possible fix for brilift too
Pat-Lafon 61c119e
cargo fmt
Pat-Lafon ad2b6e9
Warning for https://github.com/sampsyo/bril/issues/341
Pat-Lafon f3ccd1d
cargo fmt
Pat-Lafon 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 |
---|---|---|
|
@@ -1294,28 +1294,29 @@ pub fn create_module_from_program<'a>( | |
} | ||
}); | ||
|
||
(llvm_func, instrs, block, heap) | ||
(llvm_func, instrs, block, heap, return_type) | ||
}, | ||
) | ||
.collect(); // Important to collect, can't be done lazily because we need all functions to be loaded in before a call instruction of a function is processed. | ||
|
||
// Now actually build each function | ||
funcs | ||
.into_iter() | ||
.for_each(|(llvm_func, instrs, mut block, heap)| { | ||
.for_each(|(llvm_func, instrs, mut block, heap, return_type)| { | ||
let mut last_instr = None; | ||
|
||
// Maps labels to llvm blocks for jumps | ||
let mut block_map = HashMap::new(); | ||
|
||
// If their are actually instructions, proceed | ||
if !instrs.is_empty() { | ||
builder.position_at_end(block); | ||
|
||
// Maps labels to llvm blocks for jumps | ||
let mut block_map = HashMap::new(); | ||
instrs.iter().for_each(|i| match i { | ||
bril_rs::Code::Label { label, .. } => { | ||
let new_block = block_map_get(context, llvm_func, &mut block_map, label); | ||
|
||
// Check if wee need to insert a jump since all llvm blocks must be terminated | ||
// Check if we need to insert a jump since all llvm blocks must be terminated | ||
if !is_terminating_instr(&last_instr) { | ||
builder | ||
.build_unconditional_branch(block_map_get( | ||
|
@@ -1354,7 +1355,19 @@ pub fn create_module_from_program<'a>( | |
|
||
// Make sure every function is terminated with a return if not already | ||
if !is_terminating_instr(&last_instr) { | ||
builder.build_return(None).unwrap(); | ||
if return_type.is_none() { | ||
builder.build_return(None).unwrap(); | ||
} else { | ||
// This block did not have a terminating instruction | ||
// Returning void is ill-typed for this function | ||
// This code should be unreachable in well-formed Bril | ||
// Let's just arbitrarily jump to avoid needing to | ||
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. 🤣 |
||
// instantiate a valid return value. | ||
assert!(!block_map.is_empty()); | ||
builder | ||
.build_unconditional_branch(*block_map.values().next().unwrap()) | ||
.unwrap(); | ||
} | ||
} | ||
}); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@abs(x: int): int { | ||
ret x; | ||
.label435: | ||
} | ||
|
||
@main() { | ||
x : int = const 42; | ||
y : int = call @abs x; | ||
print y; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
42 |
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.
could preserve original function here instead of instrs and return_type
That, or do a zip later with the original functions and the llvm ones