Refactor the expression->time code into a single function
This commit is contained in:
parent
1409207def
commit
e4c2400eb2
|
|
@ -484,3 +484,21 @@ vhdl_expr *translate_expr(ivl_expr_t e)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Translate an expression into a time. This is achieved simply
|
||||||
|
* by multiplying the expression by 1ns.
|
||||||
|
*/
|
||||||
|
vhdl_expr *translate_time_expr(ivl_expr_t e)
|
||||||
|
{
|
||||||
|
vhdl_expr *time = translate_expr(e);
|
||||||
|
if (NULL == time)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
vhdl_type integer(VHDL_TYPE_INTEGER);
|
||||||
|
time = time->cast(&integer);
|
||||||
|
|
||||||
|
vhdl_expr *ns1 = new vhdl_const_time(1, TIME_UNIT_NS);
|
||||||
|
return new vhdl_binop_expr(time, VHDL_BINOP_MULT, ns1,
|
||||||
|
vhdl_type::time());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,19 +247,8 @@ static void declare_logic(vhdl_arch *arch, ivl_scope_t scope)
|
||||||
vhdl_cassign_stmt *ass = new vhdl_cassign_stmt(lhs, rhs);
|
vhdl_cassign_stmt *ass = new vhdl_cassign_stmt(lhs, rhs);
|
||||||
|
|
||||||
ivl_expr_t delay = ivl_logic_delay(log, 1);
|
ivl_expr_t delay = ivl_logic_delay(log, 1);
|
||||||
vhdl_expr *after;
|
if (delay)
|
||||||
if (delay && (after = translate_expr(delay))) {
|
ass->set_after(translate_time_expr(delay));
|
||||||
// Need to make 'after' a time value
|
|
||||||
// we can do this by multiplying by 1ns
|
|
||||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
||||||
after = after->cast(&integer);
|
|
||||||
|
|
||||||
vhdl_expr *ns1 = new vhdl_const_time(1, TIME_UNIT_NS);
|
|
||||||
after = new vhdl_binop_expr(after, VHDL_BINOP_MULT, ns1,
|
|
||||||
vhdl_type::time());
|
|
||||||
|
|
||||||
ass->set_after(after);
|
|
||||||
}
|
|
||||||
|
|
||||||
arch->add_stmt(ass);
|
arch->add_stmt(ass);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,19 +269,8 @@ static T *make_assignment(vhdl_procedural *proc, stmt_container *container,
|
||||||
container->add_stmt(a);
|
container->add_stmt(a);
|
||||||
|
|
||||||
ivl_expr_t i_delay;
|
ivl_expr_t i_delay;
|
||||||
if (NULL == after && (i_delay = ivl_stmt_delay_expr(stmt))) {
|
if (NULL == after && (i_delay = ivl_stmt_delay_expr(stmt)))
|
||||||
if ((after = translate_expr(i_delay)) == NULL)
|
after = translate_time_expr(i_delay);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// Need to make 'after' a time value
|
|
||||||
// we can do this by multiplying by 1ns
|
|
||||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
||||||
after = after->cast(&integer);
|
|
||||||
|
|
||||||
vhdl_expr *ns1 = new vhdl_const_time(1, TIME_UNIT_NS);
|
|
||||||
after = new vhdl_binop_expr(after, VHDL_BINOP_MULT, ns1,
|
|
||||||
vhdl_type::time());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (after != NULL)
|
if (after != NULL)
|
||||||
a->set_after(after);
|
a->set_after(after);
|
||||||
|
|
@ -349,16 +338,9 @@ static int draw_delay(vhdl_procedural *proc, stmt_container *container,
|
||||||
time = new vhdl_const_time(value, TIME_UNIT_NS);
|
time = new vhdl_const_time(value, TIME_UNIT_NS);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
time = translate_expr(ivl_stmt_delay_expr(stmt));
|
time = translate_time_expr(ivl_stmt_delay_expr(stmt));
|
||||||
if (NULL == time)
|
if (NULL == time)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
vhdl_type integer(VHDL_TYPE_INTEGER);
|
|
||||||
time = time->cast(&integer);
|
|
||||||
|
|
||||||
vhdl_expr *ns1 = new vhdl_const_time(1, TIME_UNIT_NS);
|
|
||||||
time = new vhdl_binop_expr(time, VHDL_BINOP_MULT, ns1,
|
|
||||||
vhdl_type::time());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the sub-statement is an assignment then VHDL lets
|
// If the sub-statement is an assignment then VHDL lets
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ int draw_stmt(vhdl_procedural *proc, stmt_container *container,
|
||||||
int draw_lpm(vhdl_arch *arch, ivl_lpm_t lpm);
|
int draw_lpm(vhdl_arch *arch, ivl_lpm_t lpm);
|
||||||
|
|
||||||
vhdl_expr *translate_expr(ivl_expr_t e);
|
vhdl_expr *translate_expr(ivl_expr_t e);
|
||||||
|
vhdl_expr *translate_time_expr(ivl_expr_t e);
|
||||||
vhdl_var_ref *lpm_output(vhdl_scope *scope, ivl_lpm_t lpm);
|
vhdl_var_ref *lpm_output(vhdl_scope *scope, ivl_lpm_t lpm);
|
||||||
|
|
||||||
void remember_entity(vhdl_entity *ent);
|
void remember_entity(vhdl_entity *ent);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue