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.
This commit is contained in:
parent
632fd006c5
commit
0a4d8acefb
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in New Issue