Skip to content

Commit

Permalink
ascent driven IR gen WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
StuartHarris committed Nov 25, 2024
1 parent 84c5805 commit 9ce3eec
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 46 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crux_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ guppy = "0.17.4"
ignore = "0.4.23"
lazy-regex = "3.3.0"
libc = "0.2.161"
petgraph = "0.6.5"
ramhorns = "1.0.1"
rustdoc-json = "0.9.2"
rustdoc-types = "0.32.2"
Expand Down
16 changes: 11 additions & 5 deletions crux_cli/src/codegen/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
rc::Rc,
};

#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ContainerFormat {
/// An empty struct, e.g. `struct A`.
UnitStruct,
Expand All @@ -21,7 +21,7 @@ pub enum ContainerFormat {
Enum(BTreeMap<u32, Named<VariantFormat>>),
}

#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Format {
/// A format whose value is initially unknown. Used internally for tracing. Not (de)serializable.
Variable(Variable<Format>),
Expand Down Expand Up @@ -69,18 +69,18 @@ pub enum Format {

/// A named value.
/// Used for named parameters or variants.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Named<T> {
pub name: String,
pub value: T,
}

/// A mutable holder for an initially unknown value.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Variable<T>(Rc<RefCell<Option<T>>>);

/// Description of a variant in an enum.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum VariantFormat {
/// A variant whose format is initially unknown. Used internally for tracing. Not (de)serializable.
Variable(Variable<VariantFormat>),
Expand Down Expand Up @@ -145,3 +145,9 @@ where
}
}
}

impl<T: std::hash::Hash> std::hash::Hash for Variable<T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.borrow().hash(state);
}
}
8 changes: 3 additions & 5 deletions crux_cli/src/codegen/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub(crate) fn generate(edges: &[(Node, Node)], data: &Data) {
}
ContainerFormat::UnitStruct => (),
ContainerFormat::NewTypeStruct(_format) => (),
ContainerFormat::TupleStruct(ref mut v) => {
println!("{:?}", v);
ContainerFormat::TupleStruct(ref mut _v) => {
// v.push(Format::Tuple((data, t).into()));
}
ContainerFormat::Enum(_btree_map) => (),
Expand All @@ -86,15 +85,14 @@ pub(crate) fn generate(edges: &[(Node, Node)], data: &Data) {
}
ContainerFormat::UnitStruct => todo!(),
ContainerFormat::NewTypeStruct(_format) => todo!(),
ContainerFormat::TupleStruct(ref mut v) => {
println!("{:?}", v);
ContainerFormat::TupleStruct(ref mut _v) => {
// v.push(Format::Tuple((data, t).into()));
}
ContainerFormat::Struct(_vec) => todo!(),
},
_ => continue,
}
println!("{:?} \n-> {:?}\n", from, to);
// println!("{:?} \n-> {:?}\n", from, to);
}
// println!();
println!("{:#?}", containers);
Expand Down
Loading

0 comments on commit 9ce3eec

Please sign in to comment.