Skip to content
Snippets Groups Projects
Commit a081f003 authored by Russel Arbore's avatar Russel Arbore
Browse files

Some starter code for IR def

parent 523df6ac
No related branches found
No related tags found
No related merge requests found
...@@ -5,3 +5,28 @@ version = 3 ...@@ -5,3 +5,28 @@ version = 3
[[package]] [[package]]
name = "hercules_ir" name = "hercules_ir"
version = "0.1.0" version = "0.1.0"
dependencies = [
"nom",
]
[[package]]
name = "memchr"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
...@@ -2,3 +2,6 @@ ...@@ -2,3 +2,6 @@
name = "hercules_ir" name = "hercules_ir"
version = "0.1.0" version = "0.1.0"
authors = ["Russel Arbore <rarbore2@illinois.edu>"] authors = ["Russel Arbore <rarbore2@illinois.edu>"]
[dependencies]
nom = "*"
\ No newline at end of file
pub struct FunctionID(u32);
pub struct NodeID(u32);
const NULL_NODE: NodeID = NodeID(0xFFFFFFFF);
pub struct ConstantID(u32);
pub struct TypeID(u32);
pub struct Module {
functions: Vec<Function>,
typed: Vec<Type>,
constants: Vec<Constant>,
}
pub struct Function {
name: String,
nodes: Vec<Node>,
}
pub enum Type {
Control,
Integer8,
Integer16,
Integer32,
Integer64,
Float32,
Float64,
}
pub enum Constant {
Integer8(u8),
Integer16(u16),
Integer32(u32),
Integer64(u64),
Float32(f32),
Float64(f64),
}
pub enum Node {
Start,
Region {
preds: Box<[NodeID]>,
},
If {
control: NodeID,
cond: NodeID,
},
Phi {
control: NodeID,
data: Box<[NodeID]>,
},
Return {
control: NodeID,
value: NodeID,
},
Constant {
id: ConstantID,
},
Add {
control: NodeID,
left: NodeID,
right: NodeID,
},
Sub {
control: NodeID,
left: NodeID,
right: NodeID,
},
Mul {
control: NodeID,
left: NodeID,
right: NodeID,
},
Div {
control: NodeID,
left: NodeID,
right: NodeID,
},
Call {
args: Box<[NodeID]>,
},
}
impl From<u32> for FunctionID {
fn from(v: u32) -> Self {
FunctionID(v)
}
}
impl From<u64> for FunctionID {
fn from(v: u64) -> Self {
FunctionID(v as u32)
}
}
impl From<usize> for FunctionID {
fn from(v: usize) -> Self {
FunctionID(v as u32)
}
}
impl From<u32> for NodeID {
fn from(v: u32) -> Self {
NodeID(v)
}
}
impl From<u64> for NodeID {
fn from(v: u64) -> Self {
NodeID(v as u32)
}
}
impl From<usize> for NodeID {
fn from(v: usize) -> Self {
NodeID(v as u32)
}
}
impl From<u32> for ConstantID {
fn from(v: u32) -> Self {
ConstantID(v)
}
}
impl From<u64> for ConstantID {
fn from(v: u64) -> Self {
ConstantID(v as u32)
}
}
impl From<usize> for ConstantID {
fn from(v: usize) -> Self {
ConstantID(v as u32)
}
}
pub mod ir;
pub use crate::ir::*;
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