From 0a4d8acefbab879315903cef6b20e424a6a8eec8 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 17 Apr 2013 10:41:39 -0700 Subject: [PATCH] vlog95: Add support for translating a package as a module with a special name This patch finishes the code needed to translate a SystemVerilog package to a module with a special name. It also adds code to report that class scopes are not supported and treats both a class and package as a top level scope. --- tgt-vlog95/misc.c | 45 +++++++++++++++++++++++++++------------------ tgt-vlog95/scope.c | 8 ++++++++ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/tgt-vlog95/misc.c b/tgt-vlog95/misc.c index 4c2196897..d12218b40 100644 --- a/tgt-vlog95/misc.c +++ b/tgt-vlog95/misc.c @@ -743,12 +743,16 @@ void emit_name_of_nexus(ivl_scope_t scope, ivl_nexus_t nex, unsigned allow_UD) /* * This function traverses the scope tree looking for the enclosing module - * scope. When it is found the module scope is returned. + * scope. When it is found the module scope is returned. As far as this + * translation is concerned a package is a special form of a module + * definition and a class is also a top level scope. */ ivl_scope_t get_module_scope(ivl_scope_t scope) { - while (ivl_scope_type(scope) != IVL_SCT_MODULE) { + while ((ivl_scope_type(scope) != IVL_SCT_MODULE) && + (ivl_scope_type(scope) != IVL_SCT_PACKAGE) && + (ivl_scope_type(scope) != IVL_SCT_CLASS)) { ivl_scope_t pscope = ivl_scope_parent(scope); assert(pscope); scope = pscope; @@ -756,6 +760,21 @@ ivl_scope_t get_module_scope(ivl_scope_t scope) return scope; } +/* + * A package is emitted as a module with a special name. This routine + * calculates the name for the package. The returned string must be freed + * by the calling routine. + */ +char * get_package_name(ivl_scope_t scope) +{ + char *package_name; + const char *name = ivl_scope_basename(scope); + package_name = (char *)malloc(strlen(name)+13); + strcpy(package_name, "ivl_package_"); + strcat(package_name, name); + return package_name; +} + static void emit_scope_piece(ivl_scope_t scope, ivl_scope_t call_scope) { ivl_scope_t parent = ivl_scope_parent(call_scope); @@ -764,8 +783,13 @@ static void emit_scope_piece(ivl_scope_t scope, ivl_scope_t call_scope) if ((parent != 0) && (scope != parent)) { emit_scope_piece(scope, parent); } + /* If the scope is a package then add the special part of the name. */ + if (ivl_scope_type(call_scope) == IVL_SCT_PACKAGE) { + char *package_name = get_package_name(call_scope); + emit_id(package_name); + free(package_name); /* Print the base scope. */ - emit_id(ivl_scope_basename(call_scope)); + } else emit_id(ivl_scope_basename(call_scope)); fprintf(vlog_out, "."); } @@ -810,21 +834,6 @@ void emit_scope_call_path(ivl_scope_t scope, ivl_scope_t call_scope) } } -/* - * A package is emitted as a module with a special name. This routine - * calculates the name for the package. The returned string must be freed - * by the calling routine. - */ -char * get_package_name(ivl_scope_t scope) -{ - char *package_name; - const char *name = ivl_scope_basename(scope); - package_name = (char *)malloc(strlen(name)+13); - strcpy(package_name, "ivl_package_"); - strcat(package_name, name); - return package_name; -} - static void emit_scope_path_piece(ivl_scope_t scope, ivl_scope_t call_scope) { ivl_scope_t parent = ivl_scope_parent(call_scope); diff --git a/tgt-vlog95/scope.c b/tgt-vlog95/scope.c index bf54eaaf8..0a3ea0561 100644 --- a/tgt-vlog95/scope.c +++ b/tgt-vlog95/scope.c @@ -934,6 +934,14 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent) package_name = get_package_name(scope); emit_id(package_name); break; + case IVL_SCT_CLASS: + fprintf(stderr, "%s:%u: vlog95 sorry: class scopes are not " + "currently translated \"%s\".\n", + ivl_scope_file(scope), + ivl_scope_lineno(scope), + ivl_scope_tname(scope)); + vlog_errors += 1; + return 0; default: fprintf(stderr, "%s:%u: vlog95 error: Unsupported scope type " "(%d) named: %s.\n", ivl_scope_file(scope),