From df85a3358309735aebe807940351745457f1df6f Mon Sep 17 00:00:00 2001 From: Cary R Date: Fri, 11 Feb 2011 18:14:16 -0800 Subject: [PATCH] vlog95: Rework some of the delay emitting code and enclose unary in () This patch reworks the delay emitting code to handle delay expressions better. It also encloses the emitted unary operators in parenthesis to make sequenced unary operators work properly. --- tgt-vlog95/expr.c | 3 ++- tgt-vlog95/misc.c | 12 ++++++++---- tgt-vlog95/stmt.c | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tgt-vlog95/expr.c b/tgt-vlog95/expr.c index 3379194ca..f1fc3bbaf 100644 --- a/tgt-vlog95/expr.c +++ b/tgt-vlog95/expr.c @@ -404,8 +404,9 @@ static void emit_expr_unary(ivl_scope_t scope, ivl_expr_t expr, unsigned wid) case 'N': case 'X': case '!': - fprintf(vlog_out, "%s", oper); + fprintf(vlog_out, "(%s", oper); emit_expr(scope, ivl_expr_oper1(expr), wid); + fprintf(vlog_out, ")"); break; case '2': case 'i': diff --git a/tgt-vlog95/misc.c b/tgt-vlog95/misc.c index b5e8f91b4..459c6b46f 100644 --- a/tgt-vlog95/misc.c +++ b/tgt-vlog95/misc.c @@ -82,7 +82,10 @@ static void emit_delay(ivl_scope_t scope, ivl_expr_t expr, unsigned is_stmt) */ void emit_scaled_delayx(ivl_scope_t scope, ivl_expr_t expr, unsigned is_stmt) { - if (ivl_expr_type(expr) == IVL_EX_NUMBER) { + ivl_expr_type_t type = ivl_expr_type(expr); + if (type == IVL_EX_DELAY) { + emit_scaled_delay(scope, ivl_expr_delay_val(expr)); + } else if (type == IVL_EX_NUMBER) { assert(! ivl_expr_signed(expr)); int rtype; uint64_t value = get_uint64_from_number(expr, &rtype); @@ -108,9 +111,10 @@ void emit_scaled_delayx(ivl_scope_t scope, ivl_expr_t expr, unsigned is_stmt) } else { int exponent = ivl_scope_time_units(scope) - sim_precision; assert(exponent >= 0); - if (exponent == 0) emit_delay(scope, expr, is_stmt); - /* A real delay variable is not scaled by the compiler. */ - else if (ivl_expr_type(expr) == IVL_EX_SIGNAL) { + if ((exponent == 0) && (type == IVL_EX_SIGNAL)) { + emit_delay(scope, expr, is_stmt); + /* A real delay variable is not scaled by the compiler. */ + } else if (type == IVL_EX_SIGNAL) { ivl_signal_t sig = ivl_expr_signal(expr); if (ivl_signal_data_type(sig) != IVL_VT_REAL) { fprintf(vlog_out, ""); diff --git a/tgt-vlog95/stmt.c b/tgt-vlog95/stmt.c index fe6648ca3..20ae4fa21 100644 --- a/tgt-vlog95/stmt.c +++ b/tgt-vlog95/stmt.c @@ -80,9 +80,9 @@ static void emit_stmt_inter_delay(ivl_scope_t scope, ivl_statement_t stmt) } if (delay) { assert(nevents == 0); - fprintf(vlog_out, "#"); - emit_expr(scope, delay, 0); - fprintf(vlog_out, " "); + fprintf(vlog_out, "#("); + emit_scaled_delayx(scope, delay, 1); + fprintf(vlog_out, ") "); } }