Skip to content

Commit

Permalink
btor2: correctly parse inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Nov 13, 2023
1 parent 1462ffa commit 75f4802
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/btor2/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ struct Parser<'a> {
state_map: HashMap<LineId, StateRef>,
/// maps file id to signal in the Transition System
signal_map: HashMap<LineId, SignalRef>,
/// maps file id to input in the Transition System
input_map: HashMap<LineId, ExprRef>,
}

type LineId = u32;
Expand All @@ -65,7 +63,6 @@ impl<'a> Parser<'a> {
type_map: HashMap::new(),
state_map: HashMap::new(),
signal_map: HashMap::new(),
input_map: HashMap::new(),
}
}

Expand Down Expand Up @@ -141,7 +138,7 @@ impl<'a> Parser<'a> {
}
"ones" => Some(self.parse_ones(line, tokens)?),
"state" => Some(self.parse_state(line, &cont, line_id)?),
"input" => Some(self.parse_input(line, &cont, line_id)?),
"input" => Some(self.parse_input(line, &cont)?),
"init" | "next" => {
self.parse_state_init_or_next(line, &cont, op == "init")?;
None
Expand Down Expand Up @@ -348,16 +345,11 @@ impl<'a> Parser<'a> {
Ok(sym)
}

fn parse_input(
&mut self,
line: &str,
cont: &LineTokens,
line_id: LineId,
) -> ParseLineResult<ExprRef> {
fn parse_input(&mut self, line: &str, cont: &LineTokens) -> ParseLineResult<ExprRef> {
let tpe = self.get_tpe_from_id(line, cont.tokens[2])?;
let name = self.get_label_name(cont, "input");
let sym = self.ctx.symbol(name, tpe);
self.input_map.insert(line_id, sym);
self.sys.add_input(self.ctx, sym);
Ok(sym)
}

Expand Down
10 changes: 10 additions & 0 deletions src/ir/transition_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub struct State {
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct StateRef(usize);

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct InputRef(usize);

#[derive(Debug, PartialEq, Eq)]
pub struct TransitionSystem {
pub name: String,
Expand Down Expand Up @@ -85,6 +88,13 @@ impl TransitionSystem {
StateRef(id)
}

pub fn add_input(&mut self, ctx: &impl GetNode<Expr, ExprRef>, symbol: ExprRef) -> InputRef {
assert!(symbol.is_symbol(ctx));
let id = self.inputs.len();
self.inputs.push(symbol);
InputRef(id)
}

pub fn modify_state<F>(&mut self, reference: StateRef, modify: F)
where
F: FnOnce(&mut State),
Expand Down

0 comments on commit 75f4802

Please sign in to comment.