vlog95: Emit a package as a module with a special name.

This commit is contained in:
Cary R 2013-03-11 10:43:29 -07:00
parent b378dccbe9
commit 03ebd2f98d
3 changed files with 51 additions and 9 deletions

View File

@ -810,6 +810,21 @@ 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);
@ -819,8 +834,13 @@ static void emit_scope_path_piece(ivl_scope_t scope, ivl_scope_t call_scope)
emit_scope_path_piece(scope, parent);
fprintf(vlog_out, ".");
}
/* 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));
}
/*

View File

@ -827,6 +827,7 @@ static unsigned emitting_scopes = 0;
int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
{
char *package_name = 0;
ivl_scope_type_t sc_type = ivl_scope_type(scope);
unsigned is_auto = ivl_scope_is_auto(scope);
unsigned idx, count;
@ -918,13 +919,21 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
vlog_errors += 1;
return 0;
case IVL_SCT_PACKAGE:
fprintf(stderr, "%s:%u: vlog95 sorry: package scopes are not "
"currently translated \"%s\".\n",
ivl_scope_file(scope),
ivl_scope_lineno(scope),
ivl_scope_tname(scope));
vlog_errors += 1;
return 0;
assert(indent == 0);
assert(! parent);
/* Set the time scale for this scope. */
fprintf(vlog_out, "\n`timescale %s/%s\n",
get_time_const(ivl_scope_time_units(scope)),
get_time_const(ivl_scope_time_precision(scope)));
/* Emit a package as a module with a special name. */
fprintf(vlog_out, "/* This package (module) was originally "
"defined in file %s at line %u. */\n",
ivl_scope_def_file(scope),
ivl_scope_def_lineno(scope));
fprintf(vlog_out, "module ");
package_name = get_package_name(scope);
emit_id(package_name);
break;
default:
fprintf(stderr, "%s:%u: vlog95 error: Unsupported scope type "
"(%d) named: %s.\n", ivl_scope_file(scope),
@ -1025,6 +1034,12 @@ int emit_scope(ivl_scope_t scope, ivl_scope_t parent)
fprintf(vlog_out, "%*cendtask /* %s */\n", indent, ' ',
ivl_scope_tname(scope));
break;
case IVL_SCT_PACKAGE:
fprintf(vlog_out, "endmodule /* ");
emit_id(package_name);
free(package_name);
fprintf(vlog_out, " */\n");
break;
default:
assert(0);
break;

View File

@ -1,7 +1,7 @@
#ifndef __vlog95_priv_H
#define __vlog95_priv_H
/*
* Copyright (C) 2010-2011 Cary R. (cygcary@yahoo.com)
* Copyright (C) 2010-2013 Cary R. (cygcary@yahoo.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -119,6 +119,13 @@ extern int32_t get_int32_from_number(ivl_expr_t expr, int *return_type);
extern int64_t get_int64_from_number(ivl_expr_t expr, int *return_type);
extern uint64_t get_uint64_from_number(ivl_expr_t expr, int *return_type);
/*
* A package is translated to a module with a special name. This routine
* does that translation. To avoid a memory leak the calling routine must
* use free() to cleanup the string returned.
*/
extern char * get_package_name(ivl_scope_t scope);
/*
* Get the appropriate MSB and LSB for a signal.
*/