diff --git a/tgt-vhdl/cast.cc b/tgt-vhdl/cast.cc index 339e9c8ae..013bb52b6 100644 --- a/tgt-vhdl/cast.cc +++ b/tgt-vhdl/cast.cc @@ -135,7 +135,7 @@ vhdl_expr *vhdl_expr::resize(int newwidth) vhdl_fcall *resize = new vhdl_fcall("Resize", rtype); resize->add_expr(this); resize->add_expr(new vhdl_const_int(newwidth)); - + return resize; } diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index 64630ac57..abd70c7f0 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -60,7 +60,7 @@ static vhdl_var_ref *translate_signal(ivl_expr_t e) assert(scope); const char *renamed = get_renamed_signal(sig).c_str(); - + vhdl_decl *decl = scope->get_decl(renamed); assert(decl); @@ -192,7 +192,12 @@ static vhdl_expr *translate_numeric(vhdl_expr *lhs, vhdl_expr *rhs, else if (rhs->get_type()->get_name() == VHDL_TYPE_BOOLEAN) lhs = lhs->cast(&boolean); - vhdl_type *rtype = new vhdl_type(*lhs->get_type()); + vhdl_type *rtype; + if (op == VHDL_BINOP_MULT) + rtype = new vhdl_type(lhs->get_type()->get_name(), + (lhs->get_type()->get_width()*2) - 1, 0); + else + rtype = new vhdl_type(*lhs->get_type()); return new vhdl_binop_expr(lhs, op, rhs, rtype); } @@ -282,7 +287,7 @@ static vhdl_expr *translate_binary(ivl_expr_t e) case 'E': if (vectorop) result = translate_relation(lhs->cast(&std_logic_vector), - rhs->cast(&std_logic_vector), VHDL_BINOP_EQ); + rhs->cast(&std_logic_vector), VHDL_BINOP_EQ); else result = translate_relation(lhs, rhs, VHDL_BINOP_EQ); break; @@ -292,7 +297,7 @@ static vhdl_expr *translate_binary(ivl_expr_t e) case 'N': if (vectorop) result = translate_relation(lhs->cast(&std_logic_vector), - rhs->cast(&std_logic_vector), VHDL_BINOP_NEQ); + rhs->cast(&std_logic_vector), VHDL_BINOP_NEQ); else result = translate_relation(lhs, rhs, VHDL_BINOP_NEQ); break; @@ -438,7 +443,23 @@ static vhdl_expr *translate_ufunc(ivl_expr_t e) vhdl_type *rettype = expr_to_vhdl_type(e); vhdl_fcall *fcall = new vhdl_fcall(funcname, rettype); - return translate_parms(fcall, e); + int nparams = ivl_expr_parms(e); + for (int i = 0; i < nparams; i++) { + vhdl_expr *param = translate_expr(ivl_expr_parm(e, i)); + if (NULL == param) + return NULL; + + // Ensure the parameter has the correct VHDL type + ivl_signal_t param_sig = ivl_scope_sig(defscope, i); + vhdl_type *param_type = + vhdl_type::type_for(ivl_signal_width(param_sig), + ivl_signal_signed(param_sig) != 0); + + fcall->add_expr(param->cast(param_type)); + delete param_type; + } + + return fcall; } static vhdl_expr *translate_ternary(ivl_expr_t e) diff --git a/tgt-vhdl/stmt.cc b/tgt-vhdl/stmt.cc index 94f550d21..d5bcc6ccc 100644 --- a/tgt-vhdl/stmt.cc +++ b/tgt-vhdl/stmt.cc @@ -254,7 +254,7 @@ void make_assignment(vhdl_procedural *proc, stmt_container *container, return; } } - + T *a = new T(lhs, rhs); container->add_stmt(a);