From bc7ec04cabf4eb33d60a780295599bf325e06eb1 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 26 Aug 2009 15:28:21 +0100 Subject: [PATCH] Translate simple generate loops to VHDL This handles generate loops and genvars with no local variables --- tgt-vhdl/scope.cc | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/tgt-vhdl/scope.cc b/tgt-vhdl/scope.cc index 718a32d99..78a6b5235 100644 --- a/tgt-vhdl/scope.cc +++ b/tgt-vhdl/scope.cc @@ -873,9 +873,6 @@ static int draw_skeleton_scope(ivl_scope_t scope, void *_unused) case IVL_SCT_MODULE: create_skeleton_entity_for(scope, depth); break; - case IVL_SCT_GENERATE: - error("No translation for generate statements yet"); - return 1; case IVL_SCT_FORK: error("No translation for fork statements yet"); return 1; @@ -1032,6 +1029,38 @@ static int draw_hierarchy(ivl_scope_t scope, void *_parent) if (ivl_scope_type(scope) == IVL_SCT_MODULE && _parent) { ivl_scope_t parent = static_cast(_parent); + // Skip over any containing generate scopes + // Concatenate the expanded genvar values together to + // make a unique instance name + // This isn't ideal: it would be better to replace the + // Verilog generate with an equivalent VHDL generate, but + // this isn't possible with the current API + ostringstream suffix; + while (ivl_scope_type(parent) == IVL_SCT_GENERATE) { + for (unsigned i = 0; i < ivl_scope_params(parent); i++) { + ivl_parameter_t param = ivl_scope_param(parent, i); + ivl_expr_t e = ivl_parameter_expr(param); + + if (ivl_expr_type(e) == IVL_EX_NUMBER) { + vhdl_expr* value = translate_expr(e); + assert(value); + + value = value->cast(vhdl_type::integer()); + + suffix << "_" << ivl_parameter_basename(param); + value->emit(suffix, 0); + + delete value; + } + else { + error("Only numeric genvars supported at the moment"); + return 1; + } + } + + parent = ivl_scope_parent(parent); + } + if (!is_default_scope_instance(parent)) return 0; // Not generating code for the parent instance so // don't generate for the child @@ -1053,7 +1082,7 @@ static int draw_hierarchy(ivl_scope_t scope, void *_parent) } // And an instantiation statement - string inst_name(ivl_scope_basename(scope)); + string inst_name(ivl_scope_basename(scope) + suffix.str()); if (inst_name == ent->get_name() || parent_scope->have_declared(inst_name)) { // Cannot have instance name the same as type in VHDL inst_name += "_Inst";