vhdlpp: Allow initializers for variables.

This commit is contained in:
Maciej Suminski 2015-06-09 10:59:33 +02:00
parent c28000c55f
commit 3c437874e2
3 changed files with 20 additions and 8 deletions

View File

@ -331,8 +331,8 @@ static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
%type <expr> expression_logical_xnor expression_logical_xor
%type <expr> name prefix selected_name
%type <expr> shift_expression signal_declaration_assign_opt
%type <expr> simple_expression simple_expression_2 term waveform_element
%type <expr> interface_element_expression
%type <expr> simple_expression simple_expression_2 term
%type <expr> variable_declaration_assign_opt waveform_element interface_element_expression
%type <expr_list> waveform waveform_elements
%type <expr_list> name_list expression_list
@ -2661,11 +2661,12 @@ variable_assignment
;
variable_declaration /* IEEE 1076-2008 P6.4.2.4 */
: K_shared_opt K_variable identifier_list ':' subtype_indication ';'
: K_shared_opt K_variable identifier_list ':' subtype_indication
variable_declaration_assign_opt ';'
{ /* Save the signal declaration in the block_signals map. */
for (std::list<perm_string>::iterator cur = $3->begin()
; cur != $3->end() ; ++cur) {
Variable*sig = new Variable(*cur, $5);
Variable*sig = new Variable(*cur, $5, $6);
FILE_NAME(sig, @2);
active_scope->bind_name(*cur, sig);
}
@ -2677,6 +2678,11 @@ variable_declaration /* IEEE 1076-2008 P6.4.2.4 */
}
;
variable_declaration_assign_opt
: VASSIGN expression { $$ = $2; }
| { $$ = 0; }
;
wait_statement
: K_wait K_for expression ';'
{ WaitForStmt*tmp = new WaitForStmt($3);

View File

@ -66,7 +66,7 @@ int Signal::emit(ostream&out, Entity*ent, ScopeBase*scope)
return errors;
}
int Variable::emit(ostream&out, Entity*, ScopeBase*)
int Variable::emit(ostream&out, Entity*ent, ScopeBase*scope)
{
int errors = 0;
@ -75,6 +75,12 @@ int Variable::emit(ostream&out, Entity*, ScopeBase*)
if (peek_refcnt_sequ_() > 0 || !peek_type()->can_be_packed())
decl.reg_flag = true;
errors += decl.emit(out, peek_name());
Expression*init_expr = peek_init_expr();
if (init_expr) {
out << " = ";
init_expr->emit(out, ent, scope);
}
out << ";" << endl;
return errors;
}

View File

@ -77,7 +77,7 @@ class Signal : public SigVarBase {
class Variable : public SigVarBase {
public:
Variable(perm_string name, const VType*type);
Variable(perm_string name, const VType*type, Expression*init_expr = NULL);
int emit(ostream&out, Entity*ent, ScopeBase*scope);
void write_to_stream(std::ostream&fd);
@ -93,8 +93,8 @@ inline Signal::Signal(perm_string name, const VType*type, Expression*init_expr)
{
}
inline Variable::Variable(perm_string name, const VType*type)
: SigVarBase(name, type, 0)
inline Variable::Variable(perm_string name, const VType*type, Expression*init_expr)
: SigVarBase(name, type, init_expr)
{
}