From 2e734857bff256a56f46126337e90549b7036096 Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Thu, 8 Feb 2024 12:46:06 -0500 Subject: [PATCH] add log_st, log_p, and log_nl commands to enable logline generation in CHP --- chpsim.cc | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/chpsim.cc b/chpsim.cc index bbd34f5..440c15d 100644 --- a/chpsim.cc +++ b/chpsim.cc @@ -1500,12 +1500,13 @@ int ChpSim::Step (Event *ev) if (name) { name->sPrint (buf, 10240); } - if (strcmp (stmt->u.fn.name, "log") == 0) { + if (strcmp (stmt->u.fn.name, "log") == 0 || strcmp (stmt->u.fn.name, "log_p") == 0) { + bool is_full = strcmp (stmt->u.fn.name, "log") == 0; if (_sc->isFiltered (buf)) { int int_is_zero = 0; int int_type = 0; int int_width = -1; - msgPrefix (actsim_log_fp()); + if (is_full) msgPrefix (actsim_log_fp()); for (listitem_t *li = list_first (stmt->u.fn.l); li; li = list_next (li)) { act_func_arguments_t *arg = (act_func_arguments_t *) list_value (li); if (arg->isstring) { @@ -1520,7 +1521,7 @@ int ChpSim::Step (Event *ev) _process_print_int (v, int_is_zero, int_type, int_width); } } - actsim_log ("\n"); + if (is_full) actsim_log ("\n"); actsim_log_flush (); } } @@ -1538,7 +1539,7 @@ int ChpSim::Step (Event *ev) if (exprEval (arg->u.e).isZero()) { condition = false; msgPrefix (actsim_log_fp()); - actsim_log ("Assertion failed: "); + actsim_log ("ASSERTION failed: "); // everything is fine, nothing more to do } else { @@ -1565,6 +1566,18 @@ int ChpSim::Step (Event *ev) _breakpt = 1; } } + else if (strcmp (stmt->u.fn.name, "log_nl") == 0) { + if (_sc->isFiltered (buf)) { + actsim_log ("\n"); + actsim_log_flush (); + } + } + else if (strcmp (stmt->u.fn.name, "log_st") == 0) { + if (_sc->isFiltered (buf)) { + msgPrefix (actsim_log_fp()); + actsim_log_flush (); + } + } pc = _updatepc (pc); } break; @@ -2336,12 +2349,12 @@ void ChpSim::_run_chp (Function *f, act_chp_lang_t *c) break; case ACT_CHP_FUNC: - if (strcmp (string_char (c->u.func.name), "log") == 0) { + if (strcmp (string_char (c->u.func.name), "log") == 0 || strcmp (string_char (c->u.func.name), "log_p") == 0) { listitem_t *li; int int_is_zero = 0; int int_type = 0; int int_width = -1; - msgPrefix (actsim_log_fp()); + if (strcmp (string_char (c->u.func.name), "log") == 0) msgPrefix (actsim_log_fp()); for (li = list_first (c->u.func.rhs); li; li = list_next (li)) { act_func_arguments_t *tmp = (act_func_arguments_t *)list_value (li); if (tmp->isstring) { @@ -2356,7 +2369,7 @@ void ChpSim::_run_chp (Function *f, act_chp_lang_t *c) _process_print_int (v, int_is_zero, int_type, int_width); } } - actsim_log ("\n"); + if (strcmp (string_char (c->u.func.name), "log") == 0) actsim_log ("\n"); actsim_log_flush (); } else if (strcmp (string_char (c->u.func.name), "assert") == 0) { @@ -2373,6 +2386,7 @@ void ChpSim::_run_chp (Function *f, act_chp_lang_t *c) if (exprEval (tmp->u.e).isZero()) { // the assertion failed! msgPrefix (actsim_log_fp()); + actsim_log ("ASSERTION failed: "); condition = false; } // the condition is true; nothing further to do @@ -2396,6 +2410,14 @@ void ChpSim::_run_chp (Function *f, act_chp_lang_t *c) } } } + else if (strcmp (string_char (c->u.func.name), "log_nl") == 0) { + actsim_log ("\n"); + actsim_log_flush (); + } + else if (strcmp (string_char (c->u.func.name), "log_st") == 0) { + msgPrefix (actsim_log_fp()); + actsim_log_flush (); + } else { warning ("Built-in function `%s' is not known; valid values: log, assert", string_char (c->u.func.name)); @@ -5157,7 +5179,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc, break; case ACT_CHP_FUNC: - if (strcmp (string_char (c->u.func.name), "log") == 0) { + if (strcmp (string_char (c->u.func.name), "log") == 0 || strcmp (string_char (c->u.func.name), "log_p") == 0) { listitem_t *li; ret = new ChpSimGraph (sc); NEW (ret->stmt, chpsimstmt); @@ -5217,6 +5239,19 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc, } (*stop) = ret; } + else if (strcmp (string_char (c->u.func.name), "log_nl") == 0 || strcmp (string_char (c->u.func.name), "log_st") == 0) { + listitem_t *li; + bool condition = true; + ret = new ChpSimGraph (sc); + NEW (ret->stmt, chpsimstmt); + ret->stmt->delay_cost = 0; + ret->stmt->energy_cost = 0; + ret->stmt->bw_cost = 0; + ret->stmt->type = CHPSIM_FUNC; + ret->stmt->u.fn.name = string_char (c->u.func.name); + ret->stmt->u.fn.l = list_new(); + (*stop) = ret; + } else { warning ("Built-in function `%s' is not known; valid values: log, assert", string_char (c->u.func.name));