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

Metadata #2022

Merged
merged 10 commits into from
May 16, 2024
Merged

Metadata #2022

merged 10 commits into from
May 16, 2024

Conversation

eliascxstro
Copy link
Contributor

new_metadata.pest:

  • created new .pest file to parse metadata which follows the format:

metadata #{
group1: /path/to/file LINE_NUMBER
group2: /path/to/file LINE_NUMBER
}#

  • As long as a .futil file has this appropriately filled out, the debugger can step through it.

new_parser.rs

  • new file to parse the rules in new_metadata.pest

Miscellaneous:

  • Edited debugger and interpreter constructor to enable the debugger to step through any .futil file with the format above.

@@ -120,13 +118,15 @@ impl MyAdapter {
let map = status.get_status().clone();
// Declare line number beforehand
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clone shouldn't be necessary

@@ -96,6 +101,10 @@ impl Debugger {
let mut ctx = ir::from_ast::ast_to_ir(ws)?;
let pm = PassManager::default_passes()?;

// Metadata stuff
let metadata = ctx.metadata.clone().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clone isn't necessary

@@ -96,6 +101,10 @@ impl Debugger {
let mut ctx = ir::from_ast::ast_to_ir(ws)?;
let pm = PassManager::default_passes()?;

// Metadata stuff
let metadata = ctx.metadata.clone().unwrap();
let mapping = parse_metadata(&metadata).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to use the map method of Option so that we don't explode in the case
where the metadata isn't present, rather than using unwrap

Comment on lines 142 to 143
metadata: Option<NewSourceMap>,
) -> InterpreterResult<(Self, NewSourceMap)> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave this constructor only returning a debugger for the time
being, and have the from_file one be used when there is a need to return the
metadata table. There's also not much point in passing in the metadata map only
to return it as a non-option since this will break the code in places where the
metadata map isn't present

Comment on lines 25 to 31
}
fn group_name(input: Node) -> ParseResult<String> {
input
.as_str()
.parse::<String>()
.map_err(|_| input.error("Expected character"))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&str means it's a string slice, which can be easily turned into a String
with the to_string method which is infallible. You can then wrap the whole
thing in an Ok(_) to get the desired result

Suggested change
}
fn group_name(input: Node) -> ParseResult<String> {
input
.as_str()
.parse::<String>()
.map_err(|_| input.error("Expected character"))
}
.to_string()

fn path(input: Node) -> ParseResult<String> {
input
.as_str()
.parse::<String>()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note about strings as the prior one!

Comment on lines +21 to +24
input
.as_str()
.parse::<u64>()
.map_err(|_| input.error("Expected number"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use match_nodes! here to avoid needing to invoke parse. If we've
reached this point it should already be parseable anyway so no need for this
failure path.

See

fn pc_ufx(input: Node) -> ParseResult<usize> {

for an example


fn entry(input: Node) -> ParseResult<(String, GroupContents)> {
Ok(match_nodes!(input.into_children();
[group_name(g), path(p),num(n)] => (g,GroupContents {path:p, line: n})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing

Comment on lines 201 to 202
let (cidb, _) =
Debugger::new(&components, main_component, map, env, None)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the other note about the constructor

Copy link
Collaborator

@EclecticGriffin EclecticGriffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whole looks great! Really good work with this, there are a few minor issues to correct with the constructor and a few ways the parser code could be simplified but otherwise this is looking good

@EclecticGriffin EclecticGriffin linked an issue May 6, 2024 that may be closed by this pull request
@eliascxstro eliascxstro merged commit 1a4050d into main May 16, 2024
18 checks passed
@eliascxstro eliascxstro deleted the metadata branch May 16, 2024 18:59
jiahanxie353 pushed a commit to jiahanxie353/calyx that referenced this pull request May 29, 2024
* Basic scaffolding for metadeta

* Implemented new_metadata.pset and new_parser.rs

* Added new_parser and test cases

* Enabled debugger to debug any .futil file

* Clippy complaints

* Adjusted code to PR suggestions and added some comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New metadata format
2 participants