From caf83b02c1d65062003a1188b09936bb9b352056 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 18 Feb 2018 14:09:03 +0000 Subject: [PATCH] Enable variable declarations/initialisations in the compilation unit scope. --- elaborate.cc | 4 ++++ pform.cc | 21 ++++++++++++++------- pform_dump.cc | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/elaborate.cc b/elaborate.cc index 87a85b059..ffd9b2d34 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -5684,6 +5684,10 @@ bool PPackage::elaborate(Design*des, NetScope*scope) const // Elaborate class definitions. elaborate_classes(des, scope, classes); + // Elaborate the variable initialization statements, making a + // single initial process out of them. + result_flag &= elaborate_var_inits_(des, scope); + return result_flag; } diff --git a/pform.cc b/pform.cc index 189528985..f16a91c74 100644 --- a/pform.cc +++ b/pform.cc @@ -2682,7 +2682,8 @@ void pform_makewire(const vlltype&li, * net_decl_assign_t argument. */ void pform_makewire(const struct vlltype&li, - std::list*, str_pair_t , + std::list*delay, + str_pair_t str, std::list*assign_list, NetNet::Type type, data_type_t*data_type) @@ -2691,10 +2692,6 @@ void pform_makewire(const struct vlltype&li, VLerror(li, "error: variable declarations must be contained within a module."); return; } - if (is_compilation_unit(lexical_scope)) { - VLerror(li, "sorry: variable declarations in the $root scope are not yet supported."); - return; - } list*names = new list; @@ -2709,8 +2706,18 @@ void pform_makewire(const struct vlltype&li, while (! assign_list->empty()) { decl_assignment_t*first = assign_list->front(); assign_list->pop_front(); - // For now, do not handle assignment expressions. - assert(! first->expr.get()); + if (PExpr*expr = first->expr.release()) { + if (type == NetNet::REG || type == NetNet::IMPLICIT_REG) { + pform_make_var_init(li, first->name, expr); + } else { + PWire*cur = pform_get_wire_in_scope(first->name); + assert(cur); + PEIdent*lval = new PEIdent(first->name); + FILE_NAME(lval, li.text, li.first_line); + PGAssign*ass = pform_make_pgassign(lval, expr, delay, str); + FILE_NAME(ass, li.text, li.first_line); + } + } delete first; } } diff --git a/pform_dump.cc b/pform_dump.cc index b04f348a6..c0f329f86 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -1720,8 +1720,10 @@ void PPackage::pform_dump(std::ostream&out) const dump_localparams_(out, 4); dump_parameters_(out, 4); dump_enumerations_(out, 4); + dump_wires_(out, 4); dump_tasks_(out, 4); dump_funcs_(out, 4); + dump_var_inits_(out, 4); out << "endpackage" << endl; }