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

Parse type, use ordered_float

parent 42347bb6
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,18 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "hercules_ir"
version = "0.1.0"
dependencies = [
"nom",
"ordered-float",
]
[[package]]
......@@ -30,3 +37,21 @@ dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num-traits"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
dependencies = [
"autocfg",
]
[[package]]
name = "ordered-float"
version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06"
dependencies = [
"num-traits",
]
......@@ -4,4 +4,5 @@ version = "0.1.0"
authors = ["Russel Arbore <rarbore2@illinois.edu>"]
[dependencies]
nom = "*"
\ No newline at end of file
nom = "*"
ordered-float = "*"
\ No newline at end of file
extern crate ordered_float;
#[derive(Clone)]
pub struct Module {
pub functions: Vec<Function>,
......@@ -13,7 +15,7 @@ pub struct Function {
pub nodes: Vec<Node>,
}
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Type {
Control(u64),
Integer8,
......@@ -24,14 +26,14 @@ pub enum Type {
Float64,
}
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Constant {
Integer8(u8),
Integer16(u16),
Integer32(u32),
Integer64(u64),
Float32(f32),
Float64(f64),
Float32(ordered_float::OrderedFloat<f32>),
Float64(ordered_float::OrderedFloat<f64>),
}
#[derive(Clone)]
......@@ -91,7 +93,7 @@ pub enum Node {
},
}
#[derive(Clone)]
#[derive(Clone, Copy)]
pub struct FunctionID(u32);
impl FunctionID {
......@@ -104,7 +106,7 @@ impl FunctionID {
}
}
#[derive(Clone)]
#[derive(Clone, Copy)]
pub struct NodeID(u32);
impl NodeID {
......@@ -117,7 +119,7 @@ impl NodeID {
}
}
#[derive(Clone)]
#[derive(Clone, Copy)]
pub struct ConstantID(u32);
impl ConstantID {
......@@ -130,7 +132,7 @@ impl ConstantID {
}
}
#[derive(Clone)]
#[derive(Clone, Copy)]
pub struct TypeID(u32);
impl TypeID {
......
......@@ -76,7 +76,7 @@ fn parse_function<'a>(
for (_, id) in context.node_ids.iter() {
fixed_nodes[id.idx()] = Node::Parameter { index: id.idx() }
}
return Ok((
Ok((
ir_text,
Function {
name: String::from(function_name),
......@@ -84,7 +84,7 @@ fn parse_function<'a>(
return_type,
nodes: fixed_nodes,
},
));
))
}
fn parse_node<'a>(
......@@ -95,7 +95,16 @@ fn parse_node<'a>(
}
fn parse_type<'a>(ir_text: &'a str, context: &mut Context<'a>) -> nom::IResult<&'a str, TypeID> {
todo!()
let (ir_text, ty) =
nom::combinator::map(nom::bytes::complete::tag("i32"), |_| Type::Integer32)(ir_text)?;
let id = if let Some(id) = context.interned_types.get(&ty) {
*id
} else {
let id = TypeID::new(context.interned_types.len());
context.interned_types.insert(ty, id);
id
};
Ok((ir_text, id))
}
fn parse_constant<'a>(
......@@ -111,6 +120,6 @@ mod tests {
#[test]
fn parse_ir1() {
parse("fn add(x: i32, y: i32) -> i32 return(z) z = add(start, x, y)");
parse("fn add(x: i32, y: i32) -> i32 r = return(z) z = add(start, x, y)");
}
}
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