From 1db19b8703e58d0334571cf1901bfc6629115987 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 22 Dec 2007 09:31:24 -0500 Subject: [PATCH] Make statement file lineno available to targets. Make the Verilog file/lineno of statements available to loadable code generators. Make sure the information is properly set for system task calls. --- LineInfo.h | 2 ++ elaborate.cc | 1 + ivl.def | 2 ++ ivl_target.h | 7 +++++++ t-dll-api.cc | 10 ++++++++++ t-dll-proc.cc | 27 +++++++++++++++++++++++++++ t-dll.h | 3 +++ tgt-stub/statement.c | 5 +++-- 8 files changed, 55 insertions(+), 2 deletions(-) diff --git a/LineInfo.h b/LineInfo.h index 3fef2fb4f..f9b0b9dd8 100644 --- a/LineInfo.h +++ b/LineInfo.h @@ -47,6 +47,8 @@ class LineInfo { void set_file(perm_string f); void set_lineno(unsigned n); + perm_string get_file() const { return file_; } + unsigned get_lineno() const { return lineno_; } private: perm_string file_; unsigned lineno_; diff --git a/elaborate.cc b/elaborate.cc index dd2bc600d..18bd76f7c 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -2102,6 +2102,7 @@ NetProc* PCallTask::elaborate_sys(Design*des, NetScope*scope) const } NetSTask*cur = new NetSTask(peek_tail_name(path_), eparms); + cur->set_line(*this); return cur; } diff --git a/ivl.def b/ivl.def index ba7b44444..c3dcd1696 100644 --- a/ivl.def +++ b/ivl.def @@ -170,6 +170,8 @@ ivl_process_scope ivl_process_stmt ivl_process_type +ivl_statement_file +ivl_statement_lineno ivl_statement_type ivl_stmt_block_count diff --git a/ivl_target.h b/ivl_target.h index 5d75dd150..cd8ffa1e8 100644 --- a/ivl_target.h +++ b/ivl_target.h @@ -1611,9 +1611,16 @@ extern ivl_attribute_t ivl_process_attr_val(ivl_process_t net, unsigned idx); * The ivl_statement_type() function returns the type code for the * statement. This is the major type, and implies which of the later * functions are applicable to the statement. + * + * the ivl_statement_file() and _lineno() functions return the source + * file and line number of the statement in the Verilog source. This + * information is useful for diagnostic information. */ extern ivl_statement_type_t ivl_statement_type(ivl_statement_t net); +extern const char* ivl_statement_file(ivl_statement_t net); +extern unsigned ivl_statement_lineno(ivl_statement_t net); + /* * The following functions retrieve specific single values from the * statement. These values are the bits of data and parameters that diff --git a/t-dll-api.cc b/t-dll-api.cc index 191e130e8..792c8c390 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -1642,6 +1642,16 @@ extern "C" ivl_statement_type_t ivl_statement_type(ivl_statement_t net) return net->type_; } +extern "C" const char* ivl_statement_file(ivl_statement_t net) +{ + return net->file.str(); +} + +extern "C" unsigned ivl_statement_lineno(ivl_statement_t net) +{ + return net->lineno; +} + extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net) { switch (net->type_) { diff --git a/t-dll-proc.cc b/t-dll-proc.cc index 0fa9b2de9..c85777ec5 100644 --- a/t-dll-proc.cc +++ b/t-dll-proc.cc @@ -34,6 +34,15 @@ #endif # include +/* + * The FILE_NAME function is a shorthand for attaching file/line + * information to the statement object. + */ +static inline void FILE_NAME(ivl_statement_t stmt, const LineInfo*info) +{ + stmt->file = info->get_file(); + stmt->lineno = info->get_lineno(); +} bool dll_target::process(const NetProcTop*net) { @@ -196,6 +205,7 @@ void dll_target::proc_assign(const NetAssign*net) assert(stmt_cur_->type_ == IVL_ST_NONE); stmt_cur_->type_ = IVL_ST_ASSIGN; + FILE_NAME(stmt_cur_, net); stmt_cur_->u_.assign_.delay = 0; @@ -223,6 +233,8 @@ void dll_target::proc_assign_nb(const NetAssignNB*net) assert(stmt_cur_->type_ == IVL_ST_NONE); stmt_cur_->type_ = IVL_ST_ASSIGN_NB; + FILE_NAME(stmt_cur_, net); + stmt_cur_->u_.assign_.delay = 0; /* Make the lval fields. */ @@ -254,6 +266,7 @@ bool dll_target::proc_block(const NetBlock*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); /* First, count the statements in the block. */ unsigned count = 0; @@ -317,6 +330,7 @@ void dll_target::proc_case(const NetCase*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); switch (net->type()) { case NetCase::EQ: @@ -377,6 +391,7 @@ bool dll_target::proc_cassign(const NetCAssign*net) assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_CASSIGN; @@ -395,6 +410,7 @@ bool dll_target::proc_condit(const NetCondit*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_CONDIT; stmt_cur_->u_.condit_.stmt_ = (struct ivl_statement_s*) @@ -421,6 +437,7 @@ bool dll_target::proc_deassign(const NetDeassign*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_DEASSIGN; @@ -434,6 +451,7 @@ bool dll_target::proc_delay(const NetPDelay*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); ivl_statement_t tmp = (struct ivl_statement_s*) calloc(1, sizeof(struct ivl_statement_s)); @@ -474,6 +492,7 @@ bool dll_target::proc_disable(const NetDisable*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_DISABLE; stmt_cur_->u_.disable_.scope = lookup_scope_(net->target()); @@ -503,6 +522,7 @@ void dll_target::proc_forever(const NetForever*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_FOREVER; @@ -522,6 +542,7 @@ bool dll_target::proc_release(const NetRelease*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_RELEASE; @@ -535,6 +556,7 @@ void dll_target::proc_repeat(const NetRepeat*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_REPEAT; @@ -560,6 +582,7 @@ void dll_target::proc_stask(const NetSTask*net) unsigned nparms = net->nparms(); assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_STASK; /* System task names are lex_strings strings. */ @@ -581,6 +604,7 @@ bool dll_target::proc_trigger(const NetEvTrig*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_TRIGGER; stmt_cur_->u_.wait_.nevent = 1; @@ -606,6 +630,7 @@ void dll_target::proc_utask(const NetUTask*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_UTASK; stmt_cur_->u_.utask_.def = lookup_scope_(net->task()); @@ -615,6 +640,7 @@ bool dll_target::proc_wait(const NetEvWait*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_WAIT; stmt_cur_->u_.wait_.stmt_ = (struct ivl_statement_s*) @@ -708,6 +734,7 @@ void dll_target::proc_while(const NetWhile*net) { assert(stmt_cur_); assert(stmt_cur_->type_ == IVL_ST_NONE); + FILE_NAME(stmt_cur_, net); stmt_cur_->type_ = IVL_ST_WHILE; stmt_cur_->u_.while_.stmt_ = (struct ivl_statement_s*) diff --git a/t-dll.h b/t-dll.h index faea12b63..1f6ab711b 100644 --- a/t-dll.h +++ b/t-dll.h @@ -607,6 +607,9 @@ struct ivl_signal_s { */ struct ivl_statement_s { enum ivl_statement_type_e type_; + perm_string file; + unsigned lineno; + union { struct { /* IVL_ST_ASSIGN IVL_ST_ASSIGN_NB IVL_ST_CASSIGN, IVL_ST_DEASSIGN */ diff --git a/tgt-stub/statement.c b/tgt-stub/statement.c index df4b904a6..2ee84c700 100644 --- a/tgt-stub/statement.c +++ b/tgt-stub/statement.c @@ -323,8 +323,9 @@ void show_statement(ivl_statement_t net, unsigned ind) break; case IVL_ST_STASK: { - fprintf(out, "%*sCall %s(%u parameters);\n", ind, "", - ivl_stmt_name(net), ivl_stmt_parm_count(net)); + fprintf(out, "%*sCall %s(%u parameters); /* %s:%u */\n", + ind, "", ivl_stmt_name(net), ivl_stmt_parm_count(net), + ivl_statement_file(net), ivl_statement_lineno(net)); for (idx = 0 ; idx < ivl_stmt_parm_count(net) ; idx += 1) if (ivl_stmt_parm(net, idx)) show_expression(ivl_stmt_parm(net, idx), ind+4);