Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an IR for BTOR2 to reduce the dependencies on the C parser #2003

Closed
wants to merge 36 commits into from

Conversation

obhalerao
Copy link
Contributor

Modify the BTOR2 interpreter to use a new IR that does not depend on the BTOR2 parser written in C. I also added a suite of test BTOR2 programs to ensure that the interpreter remained correct with the new IR.

Copy link
Collaborator

@EclecticGriffin EclecticGriffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a bunch of nits here and there. It has been a while since I used turnt but it doesn't seem like there are .out files for the tests. Were those omitted by mistake? Are we not at that stage yet? Or am I just missing something?

In any case, good work! Very exciting

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gitignore file shouldn't be committed. If there's anything not being ignored that should be, please add it to the main gitignore

Comment on lines 4 to 10
use crate::ir::BinOpType;
use crate::ir::Btor2Instr;
use crate::ir::Btor2InstrContents;
use crate::ir::ConstantType;
use crate::ir::LiteralType;
use crate::ir::SortType;
use crate::ir::UnOpType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: All these imports can be merged together

arg2: _,
kind,
} => match kind {
BinOpType::Add => eval_binary_op(env, line, SharedEnvironment::add),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: if the args are not needed in the match they can be elided like so

Suggested change
BinOpType::Add => eval_binary_op(env, line, SharedEnvironment::add),
Btor2InstrContents::BinOp { kind, .. } => match kind {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh it applied on the wrong line, but you get the point

arg2: _,
kind,
} => match kind {
BinOpType::Add => eval_binary_op(env, line, SharedEnvironment::add),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure of these matches could be further simplified into a single arm
which just calls eval_binary_op and selects the appropriate function with a
helper function that takes kind as an argument. The helper function can match
on kind and this function will no longer need to which should make things easier
to follow.

// binary - boolean
btor2tools::Btor2Tag::Iff => {
eval_binary_op(env, line, SharedEnvironment::iff)
prog_iterator.try_for_each(|line| match &line.contents {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a strong reason to use try_for_each here since it would do the
same thing as a for loop with use of the ? operator and the latter is, in my
subjective opinion, easier to read

Comment on lines 195 to 227
Constant {
constant: Option<String>,
kind: ConstantType,
},
Literal {
kind: LiteralType,
},
UnOp {
arg1: i64,
kind: UnOpType,
},
BinOp {
arg1: i64,
arg2: i64,
kind: BinOpType,
},
Conditional {
arg1: i64,
arg2: i64,
arg3: i64,
},
Slice {
arg1: i64,
u: i64,
l: i64,
},
Input {
name: String,
},
Output {
name: String,
arg1: i64,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would double-check if i64 is the correct choice for all these arguments. Is
it the case that negative values are possible?


pub enum Btor2InstrContents {
Constant {
constant: Option<String>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future it might be better if this String is parsed into something, but
for now this is fine

Comment on lines 265 to 271
btor2tools::Btor2Tag::Not => convert_unary_op(line),
btor2tools::Btor2Tag::Inc => convert_unary_op(line),
btor2tools::Btor2Tag::Dec => convert_unary_op(line),
btor2tools::Btor2Tag::Neg => convert_unary_op(line),
btor2tools::Btor2Tag::Redand => convert_unary_op(line),
btor2tools::Btor2Tag::Redor => convert_unary_op(line),
btor2tools::Btor2Tag::Redxor => convert_unary_op(line),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These arms can all be collapsed into a single pattern match, i.e. the or | of
the possible patterns. This is true of several other sections. It's not critical
but I think it is slightly cleaner

line.symbol().unwrap().to_string_lossy().into_owned();
let src_node_idx = line.args()[0] as usize;
let output_val = s_env.get(src_node_idx);
ir_lines.iter().for_each(|line| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a strong reason to use for_each here over a normal for loop

Comment on lines 1 to 29
use crate::bvec::BitVector;

impl From<list<bool>> for BitVector {

}

impl From<u8> for BitVector {

}

impl From<u16> for BitVector {

}

impl From<u32> for BitVector {

}

impl From<u64> for BitVector {

}

impl From<u128> for BitVector {

}

impl From<usize> for BitVector {

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file isn't in the module tree and so can be deleted for the moment

Copy link
Contributor

This pull request has been marked as stale due to inactivity.

@EclecticGriffin
Copy link
Collaborator

Going to close this for now since there's no one to push this forward at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants