Skip to content

Commit

Permalink
refactor interpreter compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Dec 1, 2023
1 parent 15b78a1 commit 6b6e1db
Show file tree
Hide file tree
Showing 3 changed files with 290 additions and 162 deletions.
19 changes: 18 additions & 1 deletion src/ir/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::ir::{Context, Expr, ExprRef, GetNode, SignalInfo, SignalKind, State, TransitionSystem};
use std::collections::HashMap;
use std::ops::Index;

pub fn find_expr_with_multiple_uses(ctx: &Context, sys: &TransitionSystem) -> Vec<ExprRef> {
let counts = count_expr_uses(ctx, sys);
Expand Down Expand Up @@ -81,7 +82,7 @@ pub fn is_usage_root_signal(info: &SignalInfo) -> bool {

/// A dense hash map to store meta-data related to each expression
#[derive(Debug, Default)]
struct ExprMetaData<T: Default + Clone> {
pub struct ExprMetaData<T: Default + Clone> {
inner: Vec<T>,
default: T,
}
Expand All @@ -104,6 +105,22 @@ impl<T: Default + Clone> ExprMetaData<T> {
}
}

impl<T: Default + Clone> Index<ExprRef> for ExprMetaData<T> {
type Output = T;

fn index(&self, index: ExprRef) -> &Self::Output {
self.get(index)
}
}

impl<T: Default + Clone> Index<&ExprRef> for ExprMetaData<T> {
type Output = T;

fn index(&self, index: &ExprRef) -> &Self::Output {
self.get(*index)
}
}

pub trait ForEachChild<T> {
fn for_each_child(&self, visitor: impl FnMut(&T));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod type_check;

pub use analysis::{
count_expr_uses, count_expr_uses_without_init, find_expr_with_multiple_uses,
is_usage_root_signal, ForEachChild,
is_usage_root_signal, ExprMetaData, ForEachChild,
};
pub use expr::{
bv_value_fits_width, AddNode, ArrayType, BVLiteralInt, Context, Expr, ExprNodeConstruction,
Expand Down
Loading

0 comments on commit 6b6e1db

Please sign in to comment.