Skip to content
Snippets Groups Projects
Commit cab91750 authored by rarbore2's avatar rarbore2
Browse files

Parse labels from .hir files.

parent 254bea95
No related branches found
No related tags found
1 merge request!124Parse labels from .hir files.
......@@ -37,6 +37,7 @@ struct Context<'a> {
interned_constants: HashMap<Constant, ConstantID>,
interned_dynamic_constants: HashMap<DynamicConstant, DynamicConstantID>,
reverse_dynamic_constant_map: HashMap<DynamicConstantID, DynamicConstant>,
interned_labels: HashMap<String, LabelID>,
}
/*
......@@ -97,6 +98,16 @@ impl<'a> Context<'a> {
id
}
}
fn get_label_id(&mut self, label: String) -> LabelID {
if let Some(id) = self.interned_labels.get(&label) {
*id
} else {
let id = LabelID::new(self.interned_labels.len());
self.interned_labels.insert(label, id);
id
}
}
}
/*
......@@ -153,12 +164,16 @@ fn parse_module<'a>(ir_text: &'a str, context: Context<'a>) -> nom::IResult<&'a
for (dynamic_constant, id) in context.interned_dynamic_constants {
dynamic_constants[id.idx()] = dynamic_constant;
}
let mut labels = vec!["".to_string(); context.interned_labels.len()];
for (label, id) in context.interned_labels {
labels[id.idx()] = label;
}
let module = Module {
functions: fixed_functions,
types,
constants,
dynamic_constants,
labels: vec![],
labels,
};
Ok((rest, module))
}
......@@ -227,10 +242,13 @@ fn parse_function<'a>(
// `nodes`, as returned by parsing, is in parse order, which may differ from
// the order dictated by NodeIDs in the node name intern map.
let mut fixed_nodes = vec![Node::Start; context.borrow().node_ids.len()];
let mut labels = vec![HashSet::new(); fixed_nodes.len()];
for (name, node) in nodes {
// We can remove items from the node name intern map now, as the map
// will be cleared during the next iteration of parse_function.
fixed_nodes[context.borrow_mut().node_ids.remove(name).unwrap().idx()] = node;
let id = context.borrow_mut().node_ids.remove(name).unwrap();
fixed_nodes[id.idx()] = node;
labels[id.idx()].insert(context.borrow_mut().get_label_id(name.to_string()));
}
// The nodes removed from node_ids in the previous step are nodes that are
......@@ -264,7 +282,7 @@ fn parse_function<'a>(
entry: true,
nodes: fixed_nodes,
schedules: vec![vec![]; num_nodes],
labels: vec![HashSet::new(); num_nodes],
labels,
device: None,
},
))
......@@ -1232,7 +1250,7 @@ mod tests {
#[test]
fn parse_ir1() {
parse(
let module = parse(
"
fn myfunc(x: i32) -> i32
y = call<0>(add, x, x)
......@@ -1246,5 +1264,14 @@ fn add<1>(x: i32, y: i32) -> i32
",
)
.unwrap();
assert_eq!(module.labels.len(), 5);
assert_eq!(
module.functions[0].labels.len(),
module.functions[0].nodes.len()
);
assert_eq!(
module.functions[1].labels.len(),
module.functions[1].nodes.len()
);
}
}
......@@ -532,7 +532,13 @@ impl<'a, 'b> FunctionEdit<'a, 'b> {
if let Some(schedules) = self.added_and_updated_schedules.get_mut(&id) {
schedules.push(schedule);
} else {
let mut schedules = self.editor.function.schedules[id.idx()].clone();
let mut schedules = self
.editor
.function
.schedules
.get(id.idx())
.unwrap_or(&vec![])
.clone();
if !schedules.contains(&schedule) {
schedules.push(schedule);
}
......@@ -569,7 +575,13 @@ impl<'a, 'b> FunctionEdit<'a, 'b> {
if let Some(labels) = self.added_and_updated_labels.get_mut(&id) {
labels.insert(label);
} else {
let mut labels = self.editor.function.labels[id.idx()].clone();
let mut labels = self
.editor
.function
.labels
.get(id.idx())
.unwrap_or(&HashSet::new())
.clone();
labels.insert(label);
self.added_and_updated_labels.insert(id, labels);
}
......
......@@ -1576,6 +1576,7 @@ fn run_pass(
pm.bbs = bbs;
}
}
println!("Ran Pass: {:?}", pass);
Ok((result, changed))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment