-
Notifications
You must be signed in to change notification settings - Fork 60
[fud2] Serialize Plans into Assignment Lists #2555
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
Closed
+1,594
−9
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4d6832d
Add Recursive decent parser for serialized plans.
jku20 76acfc8
Refactor parser looking ahead to nicer errors.
jku20 b76b25b
Implement parsing with bad errors.
jku20 6aadf43
Remove unused file.
jku20 f81ed16
Remove mod referring to deleted file.
jku20 685502e
Add serialization.
jku20 cbf087a
Cargo fmt.
jku20 275b614
Implement to and from ASTs.
jku20 01bc270
Add new mode to emit plans in new syntax.
jku20 438239e
Add planner which reads new format.
jku20 38695f6
Support quoted paths as ids.
jku20 de9df59
Add json support.
jku20 c4d79a5
Add json parsing modulo file path problem.
jku20 62580a3
Rename planners to have better names.
jku20 311b152
Better document the ast.
jku20 e4a4fcf
Remove custom error trait.
jku20 43a4c0d
Change from_parts to the nicer from_session.
jku20 e2ee1da
Add better specification of language synatx.
jku20 e6e092e
More documentation.
jku20 7640eed
Document ASTToStepList.
jku20 f3d0206
Hide exposed visitors.
jku20 70a50e3
Add weird id test.
jku20 efae500
Fix error in docs and remove duplication.
jku20 71a7a62
Rename module to flang.
jku20 2f6d6b4
More module renaming.
jku20 3da37f4
Remove old snapshots.
jku20 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,135 @@ | ||
| use std::{collections::HashMap, ops}; | ||
|
|
||
| use camino::Utf8PathBuf; | ||
| use cranelift_entity::PrimaryMap; | ||
|
|
||
| use crate::{ | ||
| exec::{IO, OpRef, Operation}, | ||
| flang::ast::{ | ||
| Assignment, AssignmentList, Op, Visitable, Visitor, VisitorResult, | ||
| }, | ||
| }; | ||
|
|
||
| pub fn steps_to_ast( | ||
| plan: &Vec<(OpRef, Vec<IO>, Vec<IO>)>, | ||
| ops: &PrimaryMap<OpRef, Operation>, | ||
| ) -> AssignmentList { | ||
| let mut ast = AssignmentList { assigns: vec![] }; | ||
| for step in plan { | ||
| let vars = step | ||
| .1 | ||
| .iter() | ||
| .map(|v| match v { | ||
| IO::StdIO(utf8_path_buf) => utf8_path_buf, | ||
| IO::File(utf8_path_buf) => utf8_path_buf, | ||
| }) | ||
| .cloned() | ||
| .collect(); | ||
| let args = step | ||
| .2 | ||
| .iter() | ||
| .map(|v| match v { | ||
| IO::StdIO(utf8_path_buf) => utf8_path_buf, | ||
| IO::File(utf8_path_buf) => utf8_path_buf, | ||
| }) | ||
| .cloned() | ||
| .collect(); | ||
|
|
||
| let fun = Op { | ||
| name: ops[step.0].name.clone(), | ||
| args, | ||
| }; | ||
|
|
||
| let assignment = Assignment { vars, value: fun }; | ||
| ast.assigns.push(assignment); | ||
| } | ||
|
|
||
| ast | ||
| } | ||
|
|
||
| /// A struct to convert a flang AST into the steps of a `Plan`. | ||
| struct ASTToStepList { | ||
| step_list: Vec<(OpRef, Vec<IO>, Vec<IO>)>, | ||
| name_to_op_ref: HashMap<String, OpRef>, | ||
| } | ||
|
|
||
| impl ASTToStepList { | ||
| fn from_ops(ops: &PrimaryMap<OpRef, Operation>) -> Self { | ||
| let name_to_op_ref = | ||
| ops.iter().map(|(k, v)| (v.name.clone(), k)).collect(); | ||
| ASTToStepList { | ||
| step_list: vec![], | ||
| name_to_op_ref, | ||
| } | ||
| } | ||
|
|
||
| fn step_list_from_ast( | ||
| &mut self, | ||
| ast: &AssignmentList, | ||
| ) -> Vec<(OpRef, Vec<IO>, Vec<IO>)> { | ||
| self.step_list = vec![]; | ||
| let _ = ast.visit(self); | ||
| self.step_list.clone() | ||
| } | ||
| } | ||
|
|
||
| impl Visitor for ASTToStepList { | ||
| type Result = ops::ControlFlow<()>; | ||
|
|
||
| fn visit_assignment(&mut self, a: &Assignment) -> Self::Result { | ||
| let vars = a.vars.iter().map(|s| IO::File(s.clone())).collect(); | ||
| let args = a.value.args.iter().map(|s| IO::File(s.clone())).collect(); | ||
| let op_ref = self.name_to_op_ref[&a.value.name]; | ||
|
|
||
| self.step_list.push((op_ref, vars, args)); | ||
| Self::Result::output() | ||
| } | ||
| } | ||
|
|
||
| /// Given a flang AST and a set of ops, returns the steps of a `Plan` which the flang AST | ||
| /// represents. | ||
| pub fn ast_to_steps( | ||
| ast: &AssignmentList, | ||
| ops: &PrimaryMap<OpRef, Operation>, | ||
| ) -> Vec<(OpRef, Vec<IO>, Vec<IO>)> { | ||
| ASTToStepList::from_ops(ops).step_list_from_ast(ast) | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| struct ASTToString { | ||
| assigns: Vec<String>, | ||
| } | ||
|
|
||
| impl ASTToString { | ||
| fn new() -> Self { | ||
| ASTToString { assigns: vec![] } | ||
| } | ||
|
|
||
| fn string_from_ast(&mut self, ast: &AssignmentList) -> String { | ||
| self.assigns = vec![]; | ||
| let _ = ast.visit(self); | ||
| self.assigns.join("\n") | ||
| } | ||
| } | ||
|
|
||
| impl Visitor for ASTToString { | ||
| type Result = ops::ControlFlow<()>; | ||
|
|
||
| fn visit_assignment(&mut self, a: &Assignment) -> Self::Result { | ||
| let var_vec: Vec<String> = | ||
| a.vars.iter().map(Utf8PathBuf::to_string).collect(); | ||
| let vars = var_vec.join(", "); | ||
| let arg_vec: Vec<String> = | ||
| a.value.args.iter().map(Utf8PathBuf::to_string).collect(); | ||
| let args = arg_vec.join(", "); | ||
| let assign_string = format!("{} = {}({});", vars, a.value.name, args); | ||
| self.assigns.push(assign_string); | ||
| Self::Result::output() | ||
| } | ||
| } | ||
|
|
||
| /// Returns a pretty printed string from a flang AST. The returned string will be valid flang | ||
| /// syntax. | ||
| pub fn ast_to_string(ast: &AssignmentList) -> String { | ||
| ASTToString::new().string_from_ast(ast) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.