Skip to content

Commit 7b67c1d

Browse files
Lesson 5: Global Analysis & SSA
Completed SSA construction routines
1 parent d337c9f commit 7b67c1d

File tree

4 files changed

+436
-4
lines changed

4 files changed

+436
-4
lines changed

common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ indoc = "2.0.5"
88
serde_json = "1.0"
99
smallstr = "0.3.0"
1010
smallvec = "1.13.2"
11+
brilirs = { version = "0.1.0", path = "../bril/brilirs" }
1112

1213
[dependencies.bril-rs]
1314
version = "0.1.0"

common/src/cfg.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub mod ssa;
2+
13
use bril_rs::Function;
24
use std::{
35
collections::{HashMap, HashSet},
@@ -23,10 +25,12 @@ struct Node<Data: NodeEntry> {
2325
predecessor_indices: SmallVec<[usize; 2]>,
2426
}
2527

28+
#[derive(Debug, Clone)]
2629
pub struct DirectedGraph<Data: NodeEntry> {
2730
nodes: Vec<Node<Data>>,
2831
}
2932

33+
#[derive(Debug, Clone)]
3034
pub struct Cfg {
3135
pub dag: DirectedGraph<BasicBlock>,
3236
pub function_name: String,
@@ -223,6 +227,9 @@ impl Cfg {
223227
pub fn get_basic_block(&self, index: NodeIndex) -> &BasicBlock {
224228
&self.dag.nodes[index].data
225229
}
230+
pub fn get_basic_block_mut(&mut self, index: NodeIndex) -> &mut BasicBlock {
231+
&mut self.dag.nodes.get_mut(index).unwrap().data
232+
}
226233
}
227234

228235
impl<'a> Dominators<'a> {
@@ -344,11 +351,9 @@ impl<'a> Dominators<'a> {
344351

345352
#[cfg(test)]
346353
mod tests {
354+
use super::*;
347355
use bril_rs::Program;
348356
use indoc::indoc;
349-
350-
use super::*;
351-
352357
use std::sync::LazyLock;
353358

354359
static PROGRAM: LazyLock<Program> = LazyLock::new(|| {

0 commit comments

Comments
 (0)