-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cider DAP Metadata Table Generation (#2197)
Addresses issue #2183 This branch implements a new compiler pass to generate the metadata table for calyx-to-calyx debugging. --------- Co-authored-by: Serena <[email protected]>
- Loading branch information
Showing
6 changed files
with
141 additions
and
2 deletions.
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
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,91 @@ | ||
use crate::traversal::{Action, Named, VisResult, Visitor}; | ||
use calyx_ir::Id; | ||
use calyx_utils::WithPos; | ||
use linked_hash_map::LinkedHashMap; | ||
use std::fmt; | ||
use std::path::PathBuf; | ||
|
||
/// Metadata stores a Map between each group name and data used in the metadata table (specified in PR #2022) | ||
#[derive(Default)] | ||
pub struct Metadata { | ||
groups: LinkedHashMap<Id, (usize, PathBuf)>, | ||
} | ||
|
||
impl Metadata { | ||
/// Create an empty metadata table | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
/// Add a new entry to the metadata table | ||
fn add_entry(&mut self, name: Id, line: usize, path: PathBuf) { | ||
let ins = self.groups.insert(name, (line, path)); | ||
if let Some(_v) = ins { | ||
panic!("Two of same group name found") | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Metadata { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let grps = &self.groups; | ||
|
||
for (name, (line_num, file)) in grps { | ||
let file = file.to_str().unwrap(); | ||
writeln!(f, " {name}: {file} {line_num}")?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Named for Metadata { | ||
fn name() -> &'static str { | ||
"metadata-table-generation" | ||
} | ||
fn description() -> &'static str { | ||
"generates metadata table for a file not containing one" | ||
} | ||
} | ||
|
||
impl Visitor for Metadata { | ||
//iterate over all groups in all components and collect metadata | ||
fn start_context(&mut self, ctx: &mut calyx_ir::Context) -> VisResult { | ||
if ctx.metadata.is_none() { | ||
let mut table = Metadata::new(); | ||
for component in &ctx.components { | ||
let cmpt_iter = component.groups.into_iter(); | ||
for rcc_grp in cmpt_iter { | ||
let grp = rcc_grp.borrow_mut(); | ||
let pos_data = grp.attributes.copy_span(); | ||
let (file, line_num) = pos_data.get_line_num(); | ||
table.add_entry(grp.name(), line_num, PathBuf::from(file)); | ||
} | ||
|
||
ctx.metadata = Some(table.to_string()); | ||
} | ||
} | ||
Ok(Action::Stop) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::PathBuf; | ||
|
||
use calyx_ir::Id; | ||
|
||
use crate::passes::metadata_table_gen::Metadata; | ||
#[test] | ||
fn test_metadata() { | ||
let mut data = Metadata::new(); | ||
let empt_string = data.to_string(); | ||
assert_eq!(empt_string, ""); | ||
|
||
let path = PathBuf::from("/temp/path/for/testing.futil"); | ||
data.add_entry(Id::from("group_1"), 12, path.clone()); | ||
data.add_entry(Id::from("group_2"), 23, path); | ||
let test_string = data.to_string(); | ||
assert_eq!(test_string, " group_1: /temp/path/for/testing.futil 12\n group_2: /temp/path/for/testing.futil 23\n") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import "primitives/core.futil"; | ||
component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { | ||
cells {} | ||
wires { | ||
group g1 { | ||
} | ||
group g2 { | ||
} | ||
group g3 { | ||
} | ||
} | ||
control {} | ||
} | ||
metadata #{ | ||
g1: tests/passes/metadata-table-gen.futil 8 | ||
g2: tests/passes/metadata-table-gen.futil 9 | ||
g3: tests/passes/metadata-table-gen.futil 10 | ||
|
||
}# |
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,13 @@ | ||
// -p metadata-table-generation | ||
|
||
import "primitives/core.futil"; | ||
|
||
component main() -> () { | ||
cells {} | ||
wires { | ||
group g1 {} | ||
group g2 {} | ||
group g3 {} | ||
} | ||
control {} | ||
} |