From 6ade47fab12ea15da63546e069f673d181ea6f05 Mon Sep 17 00:00:00 2001 From: Bo-Yuan Huang Date: Mon, 20 Jul 2020 14:19:32 -0400 Subject: [PATCH] Remove legacy header and bug fix --- include/ilang/ila/ast/expr_op.h | 10 +- include/ilang/ila/expr_fuse.h | 227 -------------------- src/ila-mngr/p_rewrite_conditional_store.cc | 14 +- src/ila/instr_lvl_abs.cc | 18 +- 4 files changed, 18 insertions(+), 251 deletions(-) delete mode 100644 include/ilang/ila/expr_fuse.h diff --git a/include/ilang/ila/ast/expr_op.h b/include/ilang/ila/ast/expr_op.h index ad3485e95..7de15549a 100644 --- a/include/ilang/ila/ast/expr_op.h +++ b/include/ilang/ila/ast/expr_op.h @@ -286,7 +286,7 @@ class ExprOpEq : public ExprOp { const std::string& suffix) const; }; // class ExprOpEq -// Not equal is implemented in ExprFuse with Eq and Not. +// Not equal is implemented in asthub with Eq and Not. /// \brief The class wrapper for binary comparison signed less than "<". class ExprOpLt : public ExprOp { @@ -308,9 +308,9 @@ class ExprOpGt : public ExprOp { const std::string& suffix) const; }; // class ExprOpGt -// Signed less than or equal to is implemented in ExprFuse with Eq and Lt. +// Signed less than or equal to is implemented in asthub with Eq and Lt. -// Signed greater than or equal to is implemented in ExprFuse with Eq and Gt. +// Signed greater than or equal to is implemented in asthub with Eq and Gt. /// \brief The class wrapper for binary comparison unsigned less than. class ExprOpUlt : public ExprOp { @@ -332,9 +332,9 @@ class ExprOpUgt : public ExprOp { const std::string& suffix) const; }; // class ExprOpUgt -// Unsigned less than or equal to is implemented in ExprFuse with Eq and ULt. +// Unsigned less than or equal to is implemented in asthub with Eq and ULt. -// Unsigned greater than or equal to is implemented in ExprFuse with Eq and UGt. +// Unsigned greater than or equal to is implemented in asthub with Eq and UGt. /******************************************************************************/ // Memory diff --git a/include/ilang/ila/expr_fuse.h b/include/ilang/ila/expr_fuse.h deleted file mode 100644 index 0b5569167..000000000 --- a/include/ilang/ila/expr_fuse.h +++ /dev/null @@ -1,227 +0,0 @@ -/// \file -/// Header of the wrapping Expr usage - -#ifndef ILANG_ILA_EXPR_FUSE_H__ -#define ILANG_ILA_EXPR_FUSE_H__ - -#include - -#include -#include -#include -#include -#include - -/// \namespace ilang -namespace ilang { - -/// \namespace ExprFuse -/// Defines the wrapper for hiding imeplementation dependent type details. -namespace ExprFuse { -/******************************************************************************/ -// Variable -/******************************************************************************/ -/// Create new Boolean variable. -ExprPtr NewBoolVar(const std::string& name); -/// Create new bitvector variable. -ExprPtr NewBvVar(const std::string& name, const int& bit_width); -/// Create new memory variable. -ExprPtr NewMemVar(const std::string& name, const int& addr_width, - const int& data_width); - -/******************************************************************************/ -// Constant -/******************************************************************************/ -/// Create a Boolean constant. -ExprPtr BoolConst(const bool& val); -/// Create a Boolean constant from BoolVal. -ExprPtr BoolConst(const BoolVal& val); -/// Create a bitvector constant. -ExprPtr BvConst(const BvValType& val, const int& bit_width); -/// Create a bitvector constant from BvVal. -ExprPtr BvConst(const BvVal& val, const int& bit_width); -/// Create a memory constant with only the defauly value. -ExprPtr MemConst(const BvValType& def_val, const int& addr_width, - const int& data_width); -/// Create a memory constant from MemVal. -ExprPtr MemConst(const MemVal& val, const int& addr_width, - const int& data_width); - -/******************************************************************************/ -// Unary operation -/******************************************************************************/ -/// Arithematic negate (bv only) -ExprPtr Negate(const ExprPtr& obj); -/// Boolean not (bool only) -ExprPtr Not(const ExprPtr& obj); -/// Bit-wise Complement (bv only) -ExprPtr Complement(const ExprPtr& obj); - -/******************************************************************************/ -// Binary operation -/******************************************************************************/ -/// Logical AND -ExprPtr And(const ExprPtr& l, const ExprPtr& r); -/// Logical OR -ExprPtr Or(const ExprPtr& l, const ExprPtr& r); -/// Logical XOR -ExprPtr Xor(const ExprPtr& l, const ExprPtr& r); -/// Left shift (bv only) (l << r) -ExprPtr Shl(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic right shift (bv only) (l >> r) -ExprPtr Ashr(const ExprPtr& l, const ExprPtr& r); -/// Logical right shift (bv only) (l >> r) -ExprPtr Lshr(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic addition (bv only) -ExprPtr Add(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic subtraction (bv only) -ExprPtr Sub(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic unsigned division (bv only) -ExprPtr Div(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic signed remainder (bv only) -ExprPtr SRem(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic unsigned remainder (bv only) -ExprPtr URem(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic signed modular (bv only) -ExprPtr SMod(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic unsigned modular (bv only) -ExprPtr Mod(const ExprPtr& l, const ExprPtr& r); -/// Arithmetic unsigned multiply (bv only) -ExprPtr Mul(const ExprPtr& l, const ExprPtr& r); - -// helper functions for constant arguments -/// Logical AND with Boolean constant. -ExprPtr And(const ExprPtr& l, const bool& r); -/// Logical OR with Boolean constant. -ExprPtr Or(const ExprPtr& l, const bool& r); -/// Logical XOR with Boolean constant. -ExprPtr Xor(const ExprPtr& l, const bool& r); -/// Left shift with int. -ExprPtr Shl(const ExprPtr& l, const int& r); -/// Arithmetic right shift with int. -ExprPtr Ashr(const ExprPtr& l, const int& r); -/// Logical right shift with int. -ExprPtr Lshr(const ExprPtr& l, const int& r); -/// Arithmetic addition with constant. -ExprPtr Add(const ExprPtr& l, const BvValType& r); -/// Arithmetic subtraction with constant. -ExprPtr Sub(const ExprPtr& l, const BvValType& r); -/// Arithmetic unsigned multiply with constant (bv only). -ExprPtr Mul(const ExprPtr& l, const BvValType& r); - -/******************************************************************************/ -// Comparison -/******************************************************************************/ -/// Comparison: equal -ExprPtr Eq(const ExprPtr& l, const ExprPtr& r); -/// Comparison: not equal -ExprPtr Ne(const ExprPtr& l, const ExprPtr& r); -/// Comparison: signed less than (bv only) -ExprPtr Lt(const ExprPtr& l, const ExprPtr& r); -/// Comparison: signed greater than (bv only) -ExprPtr Gt(const ExprPtr& l, const ExprPtr& r); -/// Comparison: signed less than or equal to (bv only) -ExprPtr Le(const ExprPtr& l, const ExprPtr& r); -/// Comparison: signed greater than or equal to (bv only) -ExprPtr Ge(const ExprPtr& l, const ExprPtr& r); -/// Comparison: unsigned less than (bv only) -ExprPtr Ult(const ExprPtr& l, const ExprPtr& r); -/// Comparison: unsigned greater than (bv only) -ExprPtr Ugt(const ExprPtr& l, const ExprPtr& r); -/// Comparison: unsigned less than or equal to (bv only) -ExprPtr Ule(const ExprPtr& l, const ExprPtr& r); -/// Comparison: unsigned greater than or equal to (bv only) -ExprPtr Uge(const ExprPtr& l, const ExprPtr& r); - -// helper functions for constant arguments -#if 0 -/// Equal to Boolean. -ExprPtr Eq(const ExprPtr& l, const bool& r); -#endif -/// Equal to constant. -ExprPtr Eq(const ExprPtr& l, const BvValType& r); -/// Not equal to constant. -ExprPtr Ne(const ExprPtr& l, const BvValType& r); -/// Signed less than constant. -ExprPtr Lt(const ExprPtr& l, const BvValType& r); -/// Signed greater than constant. -ExprPtr Gt(const ExprPtr& l, const BvValType& r); -/// Signed less than or equal to constant. -ExprPtr Le(const ExprPtr& l, const BvValType& r); -/// Signed greater than or equal to constant. -ExprPtr Ge(const ExprPtr& l, const BvValType& r); -/// Unsgned less than constant. -ExprPtr Ult(const ExprPtr& l, const BvValType& r); -/// Unsigned greater than constant. -ExprPtr Ugt(const ExprPtr& l, const BvValType& r); -/// Unsigned less than or equal to constant. -ExprPtr Ule(const ExprPtr& l, const BvValType& r); -/// Unsigned greater than or equal to constant. -ExprPtr Uge(const ExprPtr& l, const BvValType& r); - -/******************************************************************************/ -// Memory -/******************************************************************************/ -/// Memory load -ExprPtr Load(const ExprPtr& mem, const ExprPtr& addr); -/// Memory store -ExprPtr Store(const ExprPtr& mem, const ExprPtr& addr, const ExprPtr& data); - -/// Memory load from constant address -ExprPtr Load(const ExprPtr& mem, const BvValType& addr); -/// Memory store to constant address and data -ExprPtr Store(const ExprPtr& mem, const BvValType& addr, const BvValType& data); - -/// Set memory size. -bool SetMemSize(const ExprPtr& mem, const int& size = 0); -/// Get memory size. -int GetMemSize(const ExprPtr& mem); - -/******************************************************************************/ -// Bit manipulation -/******************************************************************************/ -/// Concatenate two bitvectors (bv only) -ExprPtr Concat(const ExprPtr& hi, const ExprPtr& lo); -/// Extract bit field in the bitvector (bv only) -ExprPtr Extract(const ExprPtr& bv, const int& hi, const int& lo); -/// Zero extend the bitvector to the specified length. -ExprPtr ZExt(const ExprPtr& bv, const int& out_width); -/// Sign extend the bitvector to the specified length. -ExprPtr SExt(const ExprPtr& bv, const int& out_width); -/// Left rotate the bitvector to immediate number of times. -ExprPtr LRotate(const ExprPtr& bv, const int& immediate); -/// Right rotate the bitvector to immediate number of times. -ExprPtr RRotate(const ExprPtr& bv, const int& immediate); - -/******************************************************************************/ -// Function usage -/******************************************************************************/ -/// Apply function with zero argument. -ExprPtr AppFunc(const FuncPtr& func); -/// Apply function with one argument. -ExprPtr AppFunc(const FuncPtr& func, const ExprPtr& arg0); -/// Apply function with two argument. -ExprPtr AppFunc(const FuncPtr& func, const ExprPtr& arg0, const ExprPtr& arg1); -/// Apply function with arguments. -ExprPtr AppFunc(const FuncPtr& func, const ExprPtrVec& args); - -/******************************************************************************/ -// Others -/******************************************************************************/ -/// Logical imply (bool only) -ExprPtr Imply(const ExprPtr& p, const ExprPtr& q); -/// If-then-else (condition bool only) -ExprPtr Ite(const ExprPtr& cnd, const ExprPtr& true_expr, - const ExprPtr& false_expr); - -/******************************************************************************/ -// Non-AST construction utilities -/******************************************************************************/ -/// Topologically equivalent. -bool TopEq(const ExprPtr& a, const ExprPtr& b); - -} // namespace ExprFuse - -} // namespace ilang - -#endif // ILANG_ILA_EXPR_FUSE_H__ diff --git a/src/ila-mngr/p_rewrite_conditional_store.cc b/src/ila-mngr/p_rewrite_conditional_store.cc index a80e4877b..bcc523fa5 100644 --- a/src/ila-mngr/p_rewrite_conditional_store.cc +++ b/src/ila-mngr/p_rewrite_conditional_store.cc @@ -34,10 +34,8 @@ class FuncObjRewrCondStore : public FuncObjRewrExpr { auto IsStore = [=](const ExprPtr& x) { ILA_ASSERT(x && x->is_mem()) << "Invariant violation " << x; - if (x->is_op()) { - return asthub::GetUidExprOp(x) == AstUidExprOp::kStore; - } - return false; + return (x->is_op()) ? (asthub::GetUidExprOp(x) == AstUidExprOp::kStore) + : false; }; // pattern 0 - identical branch @@ -114,11 +112,9 @@ bool RewriteConditionalStore(const InstrLvlAbsPtr& m) { auto func = FuncObjRewrCondStore(); auto Rewr = [=, &func](const ExprPtr& e) { - if (e) { - e->DepthFirstVisitPrePost(func); - return func.get(e); - } - return e; + ILA_NOT_NULL(e); + e->DepthFirstVisitPrePost(func); + return func.get(e); }; return RewriteGeneric(m, Rewr); diff --git a/src/ila/instr_lvl_abs.cc b/src/ila/instr_lvl_abs.cc index bfc05f460..2739a5f4d 100644 --- a/src/ila/instr_lvl_abs.cc +++ b/src/ila/instr_lvl_abs.cc @@ -71,12 +71,11 @@ void InstrLvlAbs::AddInput(const ExprPtr& input_var) { // sanity check ILA_NOT_NULL(input_var); ILA_ASSERT(input_var->is_var()) << "Register non-var to Inputs."; - // should be the first + auto name = input_var->name(); - auto posi = inputs_.find(name); - auto poss = states_.find(name); - ILA_ASSERT(posi == inputs_.end() && poss == states_.end()) - << "Input variable " << input_var << " has been declared."; + ILA_ASSERT(inputs_.find(name) == inputs_.end()) << name; + ILA_ASSERT(states_.find(name) == states_.end()) << name; + // register to the simplifier auto var = Unify(input_var); // register to Inputs @@ -87,12 +86,11 @@ void InstrLvlAbs::AddState(const ExprPtr& state_var) { // sanity check ILA_NOT_NULL(state_var); ILA_ASSERT(state_var->is_var()) << "Register non-var to States."; - // should be the first + auto name = state_var->name(); - auto poss = states_.find(name); - auto posi = inputs_.find(name); - ILA_ASSERT(poss == states_.end() && posi == inputs_.end()) - << "State variable " << state_var << " has been declared."; + ILA_ASSERT(inputs_.find(name) == inputs_.end()); + ILA_ASSERT(states_.find(name) == states_.end()); + // register to the simplifier auto var = Unify(state_var); // register to States