11 #ifndef ILANG_VERILOG_OUT_VERILOG_GEN_H__
12 #define ILANG_VERILOG_OUT_VERILOG_GEN_H__
16 #include <unordered_map>
24 typedef ExprHash VerilogGenHash;
27 class IntefaceDirectiveRecorder;
28 class TestVerilogExport;
95 typedef std::tuple<vlg_name_t, int, int, int>
128 typedef std::vector<function_app_t> function_app_vec_t;
137 typedef std::map<std::string, state_update_unknown> state_update_ite_unknown_map_t;
140 typedef std::unordered_map<const ExprPtr, vlg_name_t, VerilogGenHash>
ExprMap;
171 bool ExternalMem =
true,
funcOption funcOpt = funcOption::Internal,
172 bool gen_start =
false,
bool pass_name =
false,
bool rand_init =
false,
173 bool ExpandMem =
false,
bool CollectIteUnknownUpdate =
false)
179 bool gen_start,
bool rand_init,
bool ExpandMem,
bool CollectIteUnknownUpdate)
188 friend std::ostream& operator<<(std::ostream& out,
189 const mem_write_entry_t& mwe);
190 friend std::ostream& operator<<(std::ostream& out,
192 friend std::ostream& operator<<(std::ostream& out,
194 friend std::ostream& operator<<(std::ostream& out,
const mem_write_t& mw);
195 friend std::ostream& operator<<(std::ostream& out,
277 std::map<std::string, std::map<unsigned, rport_t>>
ila_rports;
279 std::map<std::string, std::map<unsigned, wport_t>>
ila_wports;
345 int data_width,
int entry_num);
348 int data_width,
int entry_num);
359 const std::string& modName =
"",
360 const std::string& clk =
"clk",
361 const std::string& rst =
"rst");
365 virtual void DumpToFile(std::ostream& fout)
const;
425 using function_app_vec_t = VerilogGeneratorBase::function_app_vec_t;
430 void insertInput(
const ExprPtr& input);
432 void insertState(
const ExprPtr& state);
437 void parseArg(
const ExprPtr& e);
444 vlg_name_t translateApplyFunc(std::shared_ptr<ExprOpAppFunc> func_app_ptr_);
446 vlg_name_t translateBoolOp(
const std::shared_ptr<ExprOp>& e);
448 vlg_name_t translateBvOp(
const std::shared_ptr<ExprOp>& e);
450 void ParseNonMemUpdateExpr(
const ExprPtr& e);
452 bool CheckMemUpdateNode(
const ExprPtr& e,
const std::string& mem_var_name);
460 void addInternalCounter(
vlg_name_t decode_sig_name,
size_t width = 8);
462 void ExportFuncDefs();
465 void ExportCondWrites(
const ExprPtr& mem_var,
470 const std::string& mem_var_name);
479 const std::string& modName =
"",
480 const std::string& clk =
"clk",
481 const std::string& rst =
"rst");
490 #endif // ILANG_VERILOG_OUT_VERILOG_GEN_H__
std::string wen
what to connect for wen
Definition: verilog_gen.h:63
type of write port
Definition: verilog_gen.h:57
void ExportTopLevelInstr(const InstrPtr &instr_ptr_)
Parse an instruction.
vlg_sig_keep_t wires_keep
a map to store if a wire needs to keep
Definition: verilog_gen.h:238
std::set< FuncPtr > func_ptr_set
Definition: verilog_gen.h:318
static vlg_name_t sanitizeName(const vlg_name_t &n)
sanitize a name string, so it will generate illegal verilog identifier
Used in Verilog Verification Target Generation for dealing with interface directives.
Definition: directive.h:28
vlg_sig_t grantAccName
Definition: verilog_gen.h:220
BvVal::BvValType IlaBvValType
The type of bitvector value in ila.
Definition: verilog_gen.h:37
vlg_sigs_map_t inputs
vector of input signals
Definition: verilog_gen.h:226
Class of Verilog Generator.
Definition: verilog_gen.h:373
void add_output(const vlg_name_t &n, int w)
record an output signal
vlg_sigs_t mem_probe_o
vector of signals that probe each element of a memory
Definition: verilog_gen.h:234
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
std::list< mem_write_entry_t > mem_write_entry_list_t
This is type of a list of writes.
Definition: verilog_gen.h:105
vlg_name_t startName
start signal name, may not be used
Definition: verilog_gen.h:214
std::string vlg_const_t
Type of Verilog constants.
Definition: verilog_gen.h:71
std::vector< vlg_sig_t > vlg_sigs_t
Type of Verilog signals (a vector)
Definition: verilog_gen.h:83
std::list< mem_write_entry_list_t > mem_write_entry_list_stack_t
Type of a stack of writes use in visitMemNodes.
Definition: verilog_gen.h:107
void add_input(const vlg_name_t &n, int w)
record an input signal
vlg_sigs_map_t wires
vector of wires to be defined
Definition: verilog_gen.h:236
vlg_sigs_t mem_o
vector of memory output signals
Definition: verilog_gen.h:232
funcOption
whether to treat function as internal module/external module
Definition: verilog_gen.h:155
friend class TestVerilogExport
let the test class use this module
Definition: verilog_gen.h:41
vlg_sig_t decodeAccName
accumulated decode signals
Definition: verilog_gen.h:222
Type of ite update unknown.
Definition: verilog_gen.h:131
bool pass_node_name
whether to set vlg name according to the node name
Definition: verilog_gen.h:159
vlg_sigs_t regs
vector of regs to be defined
Definition: verilog_gen.h:240
bool start_signal
whether to have the start signal
Definition: verilog_gen.h:157
type of read port
Definition: verilog_gen.h:48
VerilogGenerator(const VlgGenConfig &config=VlgGenConfig(), const std::string &modName="", const std::string &clk="clk", const std::string &rst="rst")
vlg_name_t new_id()
get a new id
vlg_mems_rec_t mems_external
vector of mems from outside (will not be defined)
Definition: verilog_gen.h:244
std::string vlg_stmt_t
Type of Verilog statement.
Definition: verilog_gen.h:69
void AnnotateMemory(const memory_export_annotation_t &annotation)
add memory annotation, please invoke right after constructor
void add_internal_mem(const vlg_name_t &mem_name, int addr_width, int data_width, int entry_num)
record an internal memory
std::map< std::string, std::map< unsigned, rport_t > > ila_rports
Definition: verilog_gen.h:277
std::map< vlg_name_t, bool > vlg_sig_keep_t
Type of a map: name -> need to add keep?
Definition: verilog_gen.h:87
CnstMap cmap
Definition: verilog_gen.h:265
state_update_ite_unknown_map_t state_update_ite_unknown
a collection of all state update ite unknown
Definition: verilog_gen.h:283
VlgGenConfig(const VlgGenConfig &c, bool ExternalMem, funcOption funcOpt, bool gen_start, bool rand_init, bool ExpandMem, bool CollectIteUnknownUpdate)
Overwrite configuration, used by vtarget gen.
Definition: verilog_gen.h:178
vlg_stmts_t always_stmts
statements to be used in the always block but out of the reset
Definition: verilog_gen.h:254
void add_reg(const vlg_name_t &n, int w)
record a register
vlg_sigs_map_t outputs
vector of output signals
Definition: verilog_gen.h:228
vlg_sigs_set_t all_valid_names
to hold all valid names, a sanity check
Definition: verilog_gen.h:274
vlg_name_t clkName
Clock signal name.
Definition: verilog_gen.h:204
virtual void DumpToFile(std::ostream &fout) const
friend class TestVerilogExport
let the test class use this module
Definition: verilog_gen.h:377
function_app_t(const vlg_sig_t &res, const std::string fn)
constructor
Definition: verilog_gen.h:125
std::vector< vlg_name_t > vlg_stmts_t
Type of Verilog statements (a vector)
Definition: verilog_gen.h:77
void add_wire(const vlg_name_t &n, int w, bool keep=false)
record a wire
void add_ite_stmt(const vlg_stmt_t &cond, const vlg_stmt_t &tstmt, const vlg_stmt_t &fstmt)
std::string ren
what to connect for ren
Definition: verilog_gen.h:54
This is type of an individual write.
Definition: verilog_gen.h:100
bool extMem
Definition: verilog_gen.h:153
std::string rdata
what to connect for rdata
Definition: verilog_gen.h:52
vlg_ite_stmts_t ite_stmts
Definition: verilog_gen.h:258
vlg_stmts_t init_assumpts
Definition: verilog_gen.h:250
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
mem_write_list_t current_writes
For traverse a mem expression.
Definition: verilog_gen.h:268
uint64_t BvValType
Data type for storing BvVal. NOTE: SHOULD BE SYNCED WITH NumericType!!
Definition: sort_value.h:71
VlgGenConfig(bool ExternalMem=true, funcOption funcOpt=funcOption::Internal, bool gen_start=false, bool pass_name=false, bool rand_init=false, bool ExpandMem=false, bool CollectIteUnknownUpdate=false)
Definition: verilog_gen.h:170
vlg_stmt_t preheader
For auxiliary definitions.
Definition: verilog_gen.h:260
the structure to configure the verilog generator
Definition: verilog_gen.h:150
std::map< std::pair< IlaBvValType, unsigned >, vlg_name_t > CnstMap
Type for cacheing the constant.
Definition: verilog_gen.h:143
std::tuple< vlg_stmt_t, vlg_stmt_t, vlg_stmt_t > vlg_ite_stmt_t
Type of Verilog ITEs (IN sequential block)
Definition: verilog_gen.h:91
bool expand_mem
Definition: verilog_gen.h:164
const std::string func_name
ila func name
Definition: verilog_gen.h:123
std::string vlg_data_t
Type of Verilog data.
Definition: verilog_gen.h:75
std::vector< vlg_ite_stmt_t > vlg_ite_stmts_t
Type of Verilog ITEs statements.
Definition: verilog_gen.h:93
static int get_width(const ExprPtr &n)
Get the width of an ExprPtr, must be supported sort.
std::vector< vlg_sig_t > args
arguments
Definition: verilog_gen.h:119
vlg_names_t decodeNames
Definition: verilog_gen.h:209
std::string vlg_addr_t
Type of Verilog address.
Definition: verilog_gen.h:73
Generating a target (just the invairant or for an instruction)
Definition: vtarget_gen_impl.h:36
std::map< vlg_name_t, int > vlg_sigs_map_t
Type of Verilog signals (a vector)
Definition: verilog_gen.h:85
vlg_name_t counterName
The name of internal counter.
Definition: verilog_gen.h:224
std::unordered_map< const ExprPtr, vlg_name_t, VerilogGenHash > ExprMap
Type for caching the generated expressions.
Definition: verilog_gen.h:140
std::map< std::string, std::map< unsigned, wport_t > > ila_wports
ila write ports
Definition: verilog_gen.h:279
VerilogGeneratorBase::VlgGenConfig VlgGenConfig
the structure to configure the verilog generator
Definition: verilog_gen.h:421
function_app_vec_t ila_func_app
a collection of all function application
Definition: verilog_gen.h:281
const VlgGenConfig cfg_
The configuration.
Definition: verilog_gen.h:313
vlg_mems_rec_t mems_internal
vector of mems to be defined
Definition: verilog_gen.h:242
This is the write and its associated condition.
Definition: verilog_gen.h:109
std::string raddr
what to connect for raddr
Definition: verilog_gen.h:50
std::string wdata
what to connect for wdata
Definition: verilog_gen.h:61
void add_stmt(const vlg_stmt_t &s)
record a stmt (outside the always block)
std::set< vlg_sig_t > vlg_sigs_set_t
Type of set of Verilog signals.
Definition: verilog_gen.h:89
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
static std::string WidthToRange(int w)
convert a widith to a verilog string
VerilogGeneratorBase(const VlgGenConfig &config=VlgGenConfig(), const std::string &modName="", const std::string &clk="clk", const std::string &rst="rst")
void add_always_stmt(const vlg_stmt_t &s)
const vlg_name_t condition
the condition
Definition: verilog_gen.h:133
bool IlaBoolValType
The type of bool value in ila.
Definition: verilog_gen.h:35
void add_assign_stmt(const vlg_name_t &l, const vlg_name_t &r)
record an assignment stmt (outside the always block), will call add_stmt
bool reg_random_init
whether to give random init to the register
Definition: verilog_gen.h:161
std::tuple< vlg_name_t, int, int, int > vlg_mem_t
Type of the memorys that are going to be created.
Definition: verilog_gen.h:96
vlg_name_t validName
Definition: verilog_gen.h:212
Base class of VerilogGenerator.
Definition: verilog_gen.h:31
BvVal::BvValType IlaBvValUnsignedType
The unsigned type of bitvector value in ila.
Definition: verilog_gen.h:39
mem_write_list_t past_writes
Definition: verilog_gen.h:271
unsigned idCounter
The id counter.
Definition: verilog_gen.h:311
void add_external_mem(const vlg_name_t &mem_name, int addr_width, int data_width, int entry_num)
record an external memory
vlg_stmts_t init_stmts
Definition: verilog_gen.h:247
Type of app func.
Definition: verilog_gen.h:117
vlg_stmts_t statements
statements to be outside the always block
Definition: verilog_gen.h:252
VerilogGeneratorBase::vlg_name_t vlg_name_t
Type of Verilog id names'.
Definition: verilog_gen.h:379
static vlg_const_t ToVlgNum(IlaBvValType value, unsigned width)
will force to be hex
std::map< vlg_name_t, vlg_mem_t > vlg_mems_rec_t
Type of collection of memorys.
Definition: verilog_gen.h:98
const vlg_sig_t result
result
Definition: verilog_gen.h:121
std::vector< vlg_name_t > vlg_names_t
Type of Verilog names (a vector)
Definition: verilog_gen.h:79
ExprMap nmap
The map to cache the expression (we only need to store the name)
Definition: verilog_gen.h:262
vlg_name_t moduleName
Verilog Module Name.
Definition: verilog_gen.h:202
std::string waddr
what to connect for waddr
Definition: verilog_gen.h:59
bool check_reserved_name(const vlg_name_t &n) const
Check if a name is reserved (clk/rst/modulename/decodeName/ctrName)
vlg_sigs_t mem_i
vector of memory input signals
Definition: verilog_gen.h:230
std::map< std::string, std::string > reference_name_set
reference name list
Definition: verilog_gen.h:315
vlg_name_t rstName
Reset signal name.
Definition: verilog_gen.h:206
void add_preheader(const vlg_stmt_t &stmt)
add an item to the preheader
std::list< mem_write_t > mem_write_list_t
List of writes w. associated conditions.
Definition: verilog_gen.h:114
std::map< std::string, bool > memory_export_annotation_t
Type for memory annotation.
Definition: verilog_gen.h:145
void add_init_stmt(const vlg_stmt_t &s)
record an assignemnt in the always block (in if(rst) branch )
bool collect_ite_unknown_update
whether to collect the ite(c, v, unknown) thing
Definition: verilog_gen.h:166
void ExportIla(const InstrLvlAbsPtr &ila_ptr_)
Parse an ILA, will gen all its instructions.
std::pair< vlg_name_t, int > vlg_sig_t
Type of Verilog signal, name & bw.
Definition: verilog_gen.h:81
std::string vlg_name_t
Type of Verilog id names.
Definition: verilog_gen.h:67