4 #ifndef ILANG_ILANG_CPP_H__
5 #define ILANG_ILANG_CPP_H__
14 #ifdef SMTSWITCH_INTERFACE
15 #include <smt-switch/smt.h>
16 #endif // SMTSWITCH_INTERFACE
40 void LogPath(
const std::string& path);
66 typedef std::shared_ptr<Sort> SortPtr;
69 SortPtr ptr_ =
nullptr;
84 static SortRef MEM(
const int& addr_w,
const int& data_w);
88 inline SortPtr
get()
const {
return ptr_; }
94 typedef std::shared_ptr<Expr> ExprPtr;
97 ExprPtr ptr_ =
nullptr;
108 inline ExprPtr
get()
const {
return ptr_; }
116 std::string
name()
const;
174 ExprRef
operator&(
const ExprRef& a,
const ExprRef& b);
176 ExprRef
operator|(
const ExprRef& a,
const ExprRef& b);
178 ExprRef
operator^(
const ExprRef& a,
const ExprRef& b);
180 ExprRef
operator<<(
const ExprRef& a,
const ExprRef& b);
182 ExprRef
operator>>(
const ExprRef& a,
const ExprRef& b);
184 ExprRef
Lshr(
const ExprRef& a,
const ExprRef& b);
186 ExprRef
operator+(
const ExprRef& a,
const ExprRef& b);
188 ExprRef
operator-(
const ExprRef& a,
const ExprRef& b);
190 ExprRef
operator*(
const ExprRef& a,
const ExprRef& b);
192 ExprRef
operator/(
const ExprRef& a,
const ExprRef& b);
195 ExprRef
operator&(
const ExprRef& a,
const bool& b);
197 ExprRef
operator|(
const ExprRef& a,
const bool& b);
199 ExprRef
operator^(
const ExprRef& a,
const bool& b);
201 ExprRef
operator<<(
const ExprRef& a,
const int& b);
203 ExprRef
operator>>(
const ExprRef& a,
const int& b);
205 ExprRef
Lshr(
const ExprRef& a,
const int& b);
213 ExprRef
SRem(
const ExprRef& a,
const ExprRef& b);
215 ExprRef
URem(
const ExprRef& a,
const ExprRef& b);
217 ExprRef
SMod(
const ExprRef& a,
const ExprRef& b);
226 ExprRef
operator==(
const ExprRef& a,
const ExprRef& b);
228 ExprRef
operator!=(
const ExprRef& a,
const ExprRef& b);
230 ExprRef
operator<(
const ExprRef& a,
const ExprRef& b);
232 ExprRef
operator>(
const ExprRef& a,
const ExprRef& b);
234 ExprRef
operator<=(
const ExprRef& a,
const ExprRef& b);
236 ExprRef
operator>=(
const ExprRef& a,
const ExprRef& b);
238 ExprRef
Ult(
const ExprRef& a,
const ExprRef& b);
240 ExprRef
Ugt(
const ExprRef& a,
const ExprRef& b);
242 ExprRef
Ule(
const ExprRef& a,
const ExprRef& b);
244 ExprRef
Uge(
const ExprRef& a,
const ExprRef& b);
246 ExprRef
Slt(
const ExprRef& a,
const ExprRef& b);
248 ExprRef
Sgt(
const ExprRef& a,
const ExprRef& b);
250 ExprRef
Sle(
const ExprRef& a,
const ExprRef& b);
252 ExprRef
Sge(
const ExprRef& a,
const ExprRef& b);
256 ExprRef
operator==(
const ExprRef& a,
const bool& b);
292 ExprRef
Load(
const ExprRef& mem,
const ExprRef& addr);
294 ExprRef
Store(
const ExprRef& mem,
const ExprRef& addr,
const ExprRef& data);
307 ExprRef
Concat(
const ExprRef& msbv,
const ExprRef& lsbv);
312 ExprRef
Extract(
const ExprRef& bv,
const int& hi,
const int& lo);
316 ExprRef
SelectBit(
const ExprRef& bv,
const int& idx);
320 ExprRef
ZExt(
const ExprRef& bv,
const int& length);
324 ExprRef
SExt(
const ExprRef& bv,
const int& length);
328 ExprRef
LRotate(
const ExprRef& bv,
const int& immediate);
332 ExprRef
RRotate(
const ExprRef& bv,
const int& immediate);
340 ExprRef
Imply(
const ExprRef& ante,
const ExprRef& cons);
346 ExprRef
Ite(
const ExprRef& cond,
const ExprRef& t,
const ExprRef& f);
366 const std::map<NumericType, NumericType>& vals,
367 const int& addr_width,
const int& data_width);
373 bool TopEqual(
const ExprRef& a,
const ExprRef& b);
378 typedef std::shared_ptr<Func> FuncPtr;
381 FuncPtr ptr_ =
nullptr;
394 const std::vector<SortRef>& dvec);
400 std::string
name()
const;
402 inline FuncPtr
get()
const {
return ptr_; }
419 typedef std::shared_ptr<Instr> InstrPtr;
422 InstrPtr ptr_ =
nullptr;
465 inline InstrPtr
get()
const {
return ptr_; }
468 std::string
name()
const;
475 typedef std::shared_ptr<InstrLvlAbs> IlaPtr;
478 IlaPtr ptr_ =
nullptr;
502 const int& data_width);
545 std::string
name()
const;
569 Ila child(
const std::string& name)
const;
572 inline IlaPtr
get()
const {
return ptr_; }
585 SANITY_CHECK_AND_FIX = 0,
588 REWRITE_CONDITIONAL_STORE,
589 REWRITE_LOAD_FROM_STORE
594 bool ExecutePass(
const std::vector<PassID>& passes)
const;
602 std::ostream&
operator<<(std::ostream& out,
const ExprRef& expr);
604 std::ostream&
operator<<(std::ostream& out,
const InstrRef& instr);
606 std::ostream&
operator<<(std::ostream& out,
const Ila& ila);
620 #ifdef SYNTH_INTERFACE
621 Ila ImportSynthAbstraction(
const std::string& file_name,
625 const std::string& ila_name);
632 void ImportChildSynthAbstraction(
const std::string& file_name, Ila& parent,
633 const std::string& ila_name);
634 #endif // SYNTH_INTERFACE
640 void ExportSysCSim(
const Ila& ila,
const std::string& dir_path,
641 bool optimize =
false);
651 IlaZ3Unroller(z3::context& ctx,
const std::string& suff =
"");
662 step_pred_.push_back({k, p});
687 const int& init = 0);
693 const int& init = 0);
699 const int& init = 0);
720 std::vector<ExprRef> glob_pred_;
722 std::vector<ExprRef> init_pred_;
724 std::vector<std::pair<int, ExprRef>> step_pred_;
726 std::string extra_suff_;
729 std::shared_ptr<Unroller> univ_ =
nullptr;
733 template <
class T>
void InitializeUnroller(T unroller) {
734 for (
auto it = glob_pred_.begin(); it != glob_pred_.end(); it++) {
735 unroller->AddGlobPred(it->get());
737 for (
auto it = init_pred_.begin(); it != init_pred_.end(); it++) {
738 unroller->AddInitPred(it->get());
740 for (
auto it = step_pred_.begin(); it != step_pred_.end(); it++) {
741 unroller->AddStepPred(it->second.get(), it->first);
748 #ifdef SMTSWITCH_INTERFACE
754 smt::Term ResetAndGetSmtTerm(smt::SmtSolver& solver,
const ExprRef& expr,
755 const std::string& suffix =
"");
757 #endif // SMTSWITCH_INTERFACE
761 #endif // ILANG_ILANG_CPP_H__
ExprRef operator<<(const ExprRef &a, const ExprRef &b)
Left shift for bit-vectors.
ExprRef BvConst(const NumericType &bv_val, const int &bit_width)
Return a bit-vector constant.
ExprRef init(const size_t &i) const
Access the i-th initial condition.
z3::expr UnrollMonoFree(const Ila &top, const int &k, const int &init=0)
Unroll the ILA monolithically with each step freely defined.
bool TopEqual(const ExprRef &a, const ExprRef &b)
Topologically equivalent.
z3::expr UnrollPathFree(const std::vector< InstrRef > &path, const int &init=0)
Unroll a path with each step freely defined.
Base class for unrolling ILA execution in different settings.
Definition: u_unroller.h:19
ExprRef NewBvInput(const std::string &name, const int &bit_width)
Declare an input of bit-vector type.
static SortRef BV(const int &bit_w)
Return a bit-vector Sort of the given bit-width.
The wrapper of Func (uninterpreted function).
Definition: ilang++.h:376
ExprRef operator&(const ExprRef &a, const ExprRef &b)
Logical AND (bit-wise for bit-vectors).
FuncRef(const std::string &name, const SortRef &range)
Constructor with zero input argument (domain).
ExprRef SRem(const ExprRef &a, const ExprRef &b)
Arithmetic signed remainder.
SortRef(SortPtr ptr)
Constructor with the pointer of the actual data.
int data_width() const
Return the data bit-width if is memory; return -1 otherwise.
bool ExportIlaPortable(const Ila &ila, const std::string &file_name)
Export the ILA portable to file.
ExprRef LRotate(const ExprRef &bv, const int &immediate)
Left-rotate the bit-vector with immediate number of times.
void ExportSysCSim(const Ila &ila, const std::string &dir_path, bool optimize=false)
Generate the SystemC simulator.
ExprRef NewBoolState(const std::string &name)
Declare a state variable of Boolean type.
The wrapper of Sort (type for different AST nodes).
Definition: ilang++.h:64
void LogPath(const std::string &path)
Set the path for log file. If specified, logfiles are written into this directory instead of the defa...
void ExportToVerilog(std::ostream &fout) const
Export instruction without child-program as Verilog.
~InstrRef()
Default destructor.
void EnableDebug(const std::string &tag)
Add a debug tag.
ExprRef Ule(const ExprRef &a, const ExprRef &b)
Unsigned less than or equal to (bit-vectors only).
The class for expression, which is the basic type for variables, constraints, state update expression...
Definition: expr.h:25
void AddInit(const ExprRef &init)
Add one initial constraint.
void SetProgram(const Ila &prog)
Set the child-program of the instruction.
ExprRef operator<=(const ExprRef &a, const ExprRef &b)
Signed/Unsigned less than or equal to (bit-vectors only).
ExprRef Slt(const ExprRef &a, const ExprRef &b)
Signed less than (bit-vectors only).
void AddStepPred(const int &k, const ExprRef &p)
Add a predicate that should be asserted at the k-th step.
Definition: ilang++.h:661
ExprRef URem(const ExprRef &a, const ExprRef &b)
Arithmetic unsigned remainder.
void ClearStepPred()
Clear the step-specific predicates.
Definition: ilang++.h:669
IlaZ3Unroller(z3::context &ctx, const std::string &suff="")
Default constructor.
The class for the Instruction. An Instr object contains:
Definition: instr.h:24
int addr_width() const
Return the address bit-width if is memory; return -1 otherwise.
ExprRef Store(const ExprRef &addr, const ExprRef &data) const
Store to memory.
size_t init_num() const
Return the number of initial condition.
ExprRef Lshr(const ExprRef &a, const ExprRef &b)
Logical right shift for bit-vectors.
ExprRef operator^(const ExprRef &a, const ExprRef &b)
Logical XOR (bit-wise for bit-vectors).
ExprRef operator/(const ExprRef &a, const ExprRef &b)
Unsigned division for bit-vectors.
ExprRef Uge(const ExprRef &a, const ExprRef &b)
Unsigned greater than or equal to (bit-vectors only).
ExprRef Store(const ExprRef &mem, const ExprRef &addr, const ExprRef &data)
Store to memory.
ExprRef operator>(const ExprRef &a, const ExprRef &b)
Signed/Unsigned greater than (bit-vectors only).
void SetFetch(const ExprRef &fetch)
Set the fetch function of the ILA.
ExprRef ZExt(const ExprRef &bv, const int &length)
Zero-extend the bit-vector to the specified length.
ExprRef operator|(const ExprRef &a, const ExprRef &b)
Logical OR (bit-wise for bit-vectors).
ExprRef SMod(const ExprRef &a, const ExprRef &b)
Arithmetic signed modular.
void SetDecode(const ExprRef &decode)
Set the decode function of the instruction.
ExprRef Sle(const ExprRef &a, const ExprRef &b)
Signed less than or equal to (bit-vectors only).
ExprRef valid() const
Return the valid function.
ExprRef Sge(const ExprRef &a, const ExprRef &b)
Signed greater than or equal to (bit-vectors only).
z3::expr UnrollMonoConn(const Ila &top, const int &k, const int &init=0)
Unroll the ILA monolithically with each step connected.
The wrapper of generating z3::expr for verification.
Definition: ilang++.h:647
z3::expr UnrollPathConn(const std::vector< InstrRef > &path, const int &init=0)
Unroll a path with each step connected.
~FuncRef()
Default destructor.
InstrRef NewInstr(const std::string &name)
Declare an instruction.
ExprRef Ugt(const ExprRef &a, const ExprRef &b)
Unsigned greater than (bit-vectors only).
void SetValid(const ExprRef &valid)
Set the valid function of the ILA.
ExprRef operator==(const ExprRef &a, const ExprRef &b)
Equal.
ExprRef operator*(const ExprRef &a, const ExprRef &b)
Unsigned multiply for bit-vectors.
size_t child_num() const
Return the number of child-ILAs.
Ila ImportIlaPortable(const std::string &file_name)
Import the ILA portable from file.
ExprRef operator()(const int &hi, const int &lo) const
Extract bit-field in the bit-vector.
void LogLevel(const int &lvl)
Set the minimun log level. Log messages at or above this level will be logged. (Default: 0) ...
void LogToErr(bool to_err)
Pipe log to stderr. Log messages to stderr instead of logfiles, if set to 1.
The wrapper of InstrLvlAbs (ILA).
Definition: ilang++.h:473
ExprRef Load(const ExprRef &addr) const
Load from memory.
~ExprRef()
Default destructor.
InstrRef(InstrPtr ptr)
Constructor with the pointer of the actual data.
ExprRef operator-(const ExprRef &a)
Arithmetic negate for bit-vectors.
PassID
Supported pass ID.
Definition: ilang++.h:584
std::string name() const
Return the function name as std::string.
std::string name() const
Return the instruction name as std::string.
size_t state_num() const
Return the number of state variables.
bool SetEntryNum(const int &num)
Set the entry number of the memory (size regardless of bit-width).
ExprRef Load(const ExprRef &mem, const ExprRef &addr)
Load from memory.
void ClearInitPred()
Clear the initial predicates.
Definition: ilang++.h:667
The class of Instruction-Level Abstraction (ILA). An ILA contains:
Definition: instr_lvl_abs.h:35
int bit_width() const
Return the bit-width if is bit-vector; return -1 otherwise.
ExprRef operator()() const
Apply the function with no argument.
ExprRef Imply(const ExprRef &ante, const ExprRef &cons)
Logical imply for Booleans.
ExprRef Extract(const ExprRef &bv, const int &hi, const int &lo)
Extract bit-field in the bit-vector.
void DisableDebug(const std::string &tag)
Remove a debug tag.
ExprRef(ExprPtr ptr)
Constructor with the pointer of the actual data.
static SortRef MEM(const int &addr_w, const int &data_w)
Return a memory (array) Sort of the given address/data bit-width.
void AddInitPred(const ExprRef &p)
Add a predicate that should be asserted in the initial condition.
Definition: ilang++.h:659
The wrapper of Expr (e.g. state var, var relation, constant, etc).
Definition: ilang++.h:92
uint64_t NumericType
Data type for numerics. NOTE: SHOULD BE SYNCED WITH BvValType!!
Definition: ilang++.h:25
std::string name() const
Return the Ila name.
The wrapper of Instr (instruction).
Definition: ilang++.h:417
void ExportToVerilog(std::ostream &fout) const
Export an ILA as Verilog.
size_t instr_num() const
Return the number of instructions.
int GetEntryNum()
GEt the entry number of the memory (size regardless of bit-width).
z3::expr NextState(const ExprRef &v, const int &t)
Return the z3::expr representing the next state at the time.
ExprRef GetDecode() const
Get the decode function of the instruction.
z3::expr Equal(const ExprRef &va, const int &ta, const ExprRef &vb, const int &tb)
Return the z3::expr representing a and b are equal at their time.
ExprRef NewMemState(const std::string &name, const int &addr_width, const int &data_width)
Declare a state variable of memory (array) type.
ExprRef operator!(const ExprRef &a)
Logical not for Booleans.
size_t input_num() const
Return the number of input variables.
ExprRef BoolConst(bool bool_val)
Return a Boolean constant.
ExprRef Ite(const ExprRef &cond, const ExprRef &t, const ExprRef &f)
If-then-else on the Boolean condition.
ExprRef MemConst(const NumericType &def_val, const std::map< NumericType, NumericType > &vals, const int &addr_width, const int &data_width)
Return a memory constant.
~IlaZ3Unroller()
Default virtual destructor.
~Ila()
Default destructor.
ExprRef Append(const ExprRef &lsbv) const
Append another bit-vector to the less significant side.
void FlattenHierarchy()
Flatten the hierarchy by lifting child-instructions as the top-level parent instructions.
ExprRef Concat(const ExprRef &msbv, const ExprRef &lsbv)
Concatenate two bit-vectors.
ExprRef SelectBit(const ExprRef &bv, const int &idx)
Extract single bit in the bit-vector.
Ila child(const size_t &i) const
Access the i-th child-ILA.
ExprRef operator!=(const ExprRef &a, const ExprRef &b)
Not equal.
ExprRef fetch() const
Return the fetch function.
The class for sort (type for expr, and the range/domain of functions).
Definition: sort.h:22
bool ExecutePass(const std::vector< PassID > &passes) const
Execute the specified passes in order.
z3::expr UnrollPathSubs(const std::vector< InstrRef > &path, const int &init=0)
Unroll a path with each step connected with rewriting.
ExprRef input(const size_t &i) const
Access the i-th input variable.
ExprRef RRotate(const ExprRef &bv, const int &immediate)
Right-rotate the bit-vector with immediate number of times.
ExprRef SExt(const ExprRef &bv, const int &length)
Sign-extend the bit-vector to the specified length.
ExprRef state(const size_t &i) const
Access the i-th state variable.
void SetUnsignedComparison(bool sign)
ExprRef NewBoolInput(const std::string &name)
Declare an input of Boolean type.
void ClearGlobPred()
Clear the global predicates.
Definition: ilang++.h:665
ExprRef SExt(const int &length) const
Sign-extend the bit-vector to the specified length.
std::string name() const
Return the expression name as std::string.
InstrRef instr(const size_t &i) const
Access the i-th instruction.
z3::expr GetZ3Expr(const ExprRef &v, const int &t=0)
Return the z3::expr representing the current-based Expr at the time.
~SortRef()
Default destructor.
void ExportToVerilogWithChild(std::ostream &fout) const
Export instruction with the child-program as Verilog.
z3::func_decl GetZ3FuncDecl(const FuncRef &f) const
Return the z3::func_decl representing f.
ExprRef operator~(const ExprRef &a)
Bit-wise complement for bit-vectors.
static SortRef BOOL()
Return a Boolean Sort.
ExprRef ZExt(const int &length) const
Zero-extend the bit-vector to the specified length.
ExprRef operator>=(const ExprRef &a, const ExprRef &b)
Signed/Unsigned greater than or equal to (bit-vectors only).
ExprRef operator+(const ExprRef &a, const ExprRef &b)
Unsigned addition for bit-vectors.
ExprRef GetUpdate(const ExprRef &state) const
Set the update function of the given state variable.
void AddGlobPred(const ExprRef &p)
Add a predicate that should be asserted globally when unrolled.
Definition: ilang++.h:657
ExprRef Ult(const ExprRef &a, const ExprRef &b)
Unsigned less than (bit-vectors only).
Ila(const std::string &name)
Constructor with the specified name.
ExprRef Sgt(const ExprRef &a, const ExprRef &b)
Signed greater than (bit-vectors only).
z3::expr CurrState(const ExprRef &v, const int &t)
Return the z3::expr representing the current state at the time.
void ReplaceArg(const int &i, const ExprRef &new_arg)
Replace the i-th argument with the new node.
ExprRef NewBvState(const std::string &name, const int &bit_width)
Declare a state variable of bit-vector type.
void SetUpdate(const ExprRef &state, const ExprRef &update)
Set the update function of the given state variable.
ExprRef operator<(const ExprRef &a, const ExprRef &b)
Signed/Unsigned less than (bit-vectors only).
The class for uninterpreted function.
Definition: func.h:23
Ila NewChild(const std::string &name)
Declare a child-ILA.
ExprRef operator>>(const ExprRef &a, const ExprRef &b)
Arithmetic right shift for bit-vectors.