This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 656
feat(rome_control_flow): add the control flow crate #2781
Merged
Merged
Conversation
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
Deploying with Cloudflare Pages
|
ematipico
approved these changes
Jun 25, 2022
leops
force-pushed
the
refactor/analyze-visitor
branch
from
June 28, 2022 08:16
efa4a07
to
5bb829a
Compare
ematipico
reviewed
Jun 28, 2022
Comment on lines
+66
to
+69
pub struct Instruction<L: Language> { | ||
pub kind: InstructionKind, | ||
pub node: Option<SyntaxNode<L>>, | ||
} |
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.
Maybe we should create some utility functions to quickly create instructions.
I was looking at how they are created inside the visitors, and there's a lot of code we could save:
impl Instruction {
pub fn new_statement() -> Self;
pub fn new_return() -> Self;
pub fn new_jump(conditional: boo, block: BlockId) -> Self;
pub fn with_node(self, node: SyntaxNode<L>) -> Self;
}
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 ended up implementing these methods on the FunctionBuilder
itself, this avoids having to call append_instruction
once the instruction has been built and instead directly constructs it in place
leops
force-pushed
the
refactor/analyze-visitor
branch
2 times, most recently
from
June 29, 2022 09:24
5f66f71
to
fc4f882
Compare
leops
force-pushed
the
feature/control-flow-graph
branch
from
June 29, 2022 09:36
e69284b
to
9e9196f
Compare
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
leops
force-pushed
the
feature/control-flow-graph
branch
from
June 29, 2022 13:16
9e9196f
to
9c81afb
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
This PR adds a new
rome_control_flow
containing the data structures needed to represent a control flow graph, as well as associated helpers for building such a graph.The control flow graph is an auxiliary data structure to the syntax tree representing the execution order of statements and expressions in the function as a graph of "basic blocks" comprised of a flattened list of instruction. There are currently 3 kind of instructions:
Statement
denotes the execution of a certain syntax node that may have some side effects but does not explicitly impact the control flow,Jump
signals an edge from the current block to another block in the function (the edge may be conditional in which case it will generally be associated with an expression), and finallyReturn
represents an exit point for the function (these includes return statements but also throw statements).As an example, considering the following JavaScript function:
The following control flow graph would be generated:
(Note that the generated graph contains extraneous jumps and edges, these could be avoided in the generation pass but ultimately it does not influence the end result as everything following an unconditional jump is treated as unreachable)
Test Plan
The crate doesn't really have any tests at the moment since it's mostly comprised of definitions for plain data structures, while the code generating these is intended to live in the language-specific analyzer implementations. I could however try to add a few tests for the
FunctionBuilder
helper using theRawLanguage
fromrome_rowan