vhdlpp: Minor code clean up.

This commit is contained in:
Maciej Suminski 2016-01-15 15:47:31 +01:00
parent 52c912c4af
commit 2606d0e897
5 changed files with 76 additions and 100 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright CERN 2015 * Copyright CERN 2016
* @author Maciej Suminski (maciej.suminski@cern.ch) * @author Maciej Suminski (maciej.suminski@cern.ch)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it
@ -24,17 +24,20 @@
static std::map<perm_string,SubprogramHeader*> std_subprograms; static std::map<perm_string,SubprogramHeader*> std_subprograms;
static inline void register_std_subprogram(SubprogramHeader*header)
{
std_subprograms[header->name()] = header;
}
// Special case: to_integer function // Special case: to_integer function
static class SubprogramToInteger : public SubprogramHeader { static class SubprogramToInteger : public SubprogramStdHeader {
public: public:
SubprogramToInteger() SubprogramToInteger()
: SubprogramHeader(perm_string::literal("to_integer"), NULL, &primitive_REAL) { : SubprogramStdHeader(perm_string::literal("to_integer"), NULL, &primitive_REAL) {
ports_ = new std::list<InterfacePort*>(); ports_ = new std::list<InterfacePort*>();
ports_->push_back(new InterfacePort(&primitive_INTEGER)); ports_->push_back(new InterfacePort(&primitive_INTEGER));
} }
bool is_std() const { return true; }
int emit_name(const std::vector<Expression*>&argv, int emit_name(const std::vector<Expression*>&argv,
std::ostream&out, Entity*ent, ScopeBase*scope) const { std::ostream&out, Entity*ent, ScopeBase*scope) const {
bool signed_flag = false; bool signed_flag = false;
@ -59,17 +62,15 @@ static class SubprogramToInteger : public SubprogramHeader {
}*fn_to_integer; }*fn_to_integer;
// Special case: size casting (e.g. conv_std_logic_vector() / resize()). // Special case: size casting (e.g. conv_std_logic_vector() / resize()).
static class SubprogramSizeCast : public SubprogramHeader { static class SubprogramSizeCast : public SubprogramStdHeader {
public: public:
explicit SubprogramSizeCast(perm_string nam) explicit SubprogramSizeCast(perm_string nam)
: SubprogramHeader(nam, NULL, &primitive_STDLOGIC_VECTOR) { : SubprogramStdHeader(nam, NULL, &primitive_STDLOGIC_VECTOR) {
ports_ = new std::list<InterfacePort*>(); ports_ = new std::list<InterfacePort*>();
ports_->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR)); ports_->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
ports_->push_back(new InterfacePort(&primitive_INTEGER)); ports_->push_back(new InterfacePort(&primitive_INTEGER));
} }
bool is_std() const { return true; }
int emit_name(const std::vector<Expression*>&argv, int emit_name(const std::vector<Expression*>&argv,
std::ostream&out, Entity*ent, ScopeBase*scope) const { std::ostream&out, Entity*ent, ScopeBase*scope) const {
int64_t use_size; int64_t use_size;
@ -102,8 +103,6 @@ static class SubprogramReadWrite : public SubprogramBuiltin {
ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
} }
bool is_std() const { return true; }
// Format types handled by $ivlh_read/write (see vpi/vhdl_textio.c) // Format types handled by $ivlh_read/write (see vpi/vhdl_textio.c)
enum format_t { FORMAT_STD, FORMAT_BOOL, FORMAT_TIME, FORMAT_HEX, FORMAT_STRING }; enum format_t { FORMAT_STD, FORMAT_BOOL, FORMAT_TIME, FORMAT_HEX, FORMAT_STRING };
@ -146,8 +145,6 @@ static class SubprogramHexReadWrite : public SubprogramBuiltin {
ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
} }
bool is_std() const { return true; }
int emit_args(const std::vector<Expression*>&argv, int emit_args(const std::vector<Expression*>&argv,
std::ostream&out, Entity*ent, ScopeBase*scope) const { std::ostream&out, Entity*ent, ScopeBase*scope) const {
@ -164,24 +161,6 @@ static class SubprogramHexReadWrite : public SubprogramBuiltin {
} }
}*fn_hread, *fn_hwrite; }*fn_hread, *fn_hwrite;
static SubprogramBuiltin*fn_std_logic_vector;
static SubprogramBuiltin*fn_to_unsigned;
static SubprogramBuiltin*fn_unsigned;
static SubprogramBuiltin*fn_integer;
static SubprogramBuiltin*fn_rising_edge;
static SubprogramBuiltin*fn_falling_edge;
static SubprogramBuiltin*fn_and_reduce;
static SubprogramBuiltin*fn_or_reduce;
static SubprogramBuiltin*fn_file_open;
static SubprogramBuiltin*fn_file_close;
static SubprogramBuiltin*fn_endfile;
static SubprogramBuiltin*fn_readline;
static SubprogramBuiltin*fn_writeline;
void preload_std_funcs(void) void preload_std_funcs(void)
{ {
/* numeric_std library /* numeric_std library
@ -189,19 +168,19 @@ void preload_std_funcs(void)
*/ */
std::list<InterfacePort*>*fn_unsigned_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_unsigned_args = new std::list<InterfacePort*>();
fn_unsigned_args->push_back(new InterfacePort(&primitive_INTEGER)); fn_unsigned_args->push_back(new InterfacePort(&primitive_INTEGER));
fn_unsigned = new SubprogramBuiltin(perm_string::literal("unsigned"), SubprogramBuiltin*fn_unsigned = new SubprogramBuiltin(perm_string::literal("unsigned"),
perm_string::literal("$unsigned"), perm_string::literal("$unsigned"),
fn_unsigned_args, &primitive_UNSIGNED); fn_unsigned_args, &primitive_UNSIGNED);
std_subprograms[fn_unsigned->name()] = fn_unsigned; register_std_subprogram(fn_unsigned);
/* function integer /* function integer
*/ */
std::list<InterfacePort*>*fn_integer_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_integer_args = new std::list<InterfacePort*>();
fn_integer_args->push_back(new InterfacePort(&primitive_INTEGER)); fn_integer_args->push_back(new InterfacePort(&primitive_INTEGER));
fn_integer = new SubprogramBuiltin(perm_string::literal("integer"), SubprogramBuiltin*fn_integer = new SubprogramBuiltin(perm_string::literal("integer"),
perm_string::literal("$signed"), perm_string::literal("$signed"),
fn_integer_args, &primitive_INTEGER); fn_integer_args, &primitive_INTEGER);
std_subprograms[fn_integer->name()] = fn_integer; register_std_subprogram(fn_integer);
/* function std_logic_vector /* function std_logic_vector
Special case: The std_logic_vector function casts its Special case: The std_logic_vector function casts its
@ -210,68 +189,68 @@ void preload_std_funcs(void)
*/ */
std::list<InterfacePort*>*fn_std_logic_vector_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_std_logic_vector_args = new std::list<InterfacePort*>();
fn_std_logic_vector_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR)); fn_std_logic_vector_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
fn_std_logic_vector = new SubprogramBuiltin(perm_string::literal("std_logic_vector"), SubprogramBuiltin*fn_std_logic_vector = new SubprogramBuiltin(perm_string::literal("std_logic_vector"),
empty_perm_string, empty_perm_string,
fn_std_logic_vector_args, &primitive_STDLOGIC_VECTOR); fn_std_logic_vector_args, &primitive_STDLOGIC_VECTOR);
std_subprograms[fn_std_logic_vector->name()] = fn_std_logic_vector; register_std_subprogram(fn_std_logic_vector);
/* function resize /* function resize
*/ */
fn_resize = new SubprogramSizeCast(perm_string::literal("resize")); fn_resize = new SubprogramSizeCast(perm_string::literal("resize"));
std_subprograms[fn_resize->name()] = fn_resize; register_std_subprogram(fn_resize);
/* std_logic_arith library /* std_logic_arith library
* function conv_std_logic_vector(arg: integer; size: integer) return std_logic_vector; * function conv_std_logic_vector(arg: integer; size: integer) return std_logic_vector;
*/ */
fn_conv_std_logic_vector = new SubprogramSizeCast(perm_string::literal("conv_std_logic_vector")); fn_conv_std_logic_vector = new SubprogramSizeCast(perm_string::literal("conv_std_logic_vector"));
std_subprograms[fn_conv_std_logic_vector->name()] = fn_conv_std_logic_vector; register_std_subprogram(fn_conv_std_logic_vector);
/* numeric_bit library /* numeric_bit library
* function to_integer (arg: unsigned) return natural; * function to_integer (arg: unsigned) return natural;
* function to_integer (arg: signed) return integer; * function to_integer (arg: signed) return integer;
*/ */
fn_to_integer = new SubprogramToInteger(); fn_to_integer = new SubprogramToInteger();
std_subprograms[fn_to_integer->name()] = fn_to_integer; register_std_subprogram(fn_to_integer);
/* std_logic_1164 library /* std_logic_1164 library
* function rising_edge (signal s : std_ulogic) return boolean; * function rising_edge (signal s : std_ulogic) return boolean;
*/ */
std::list<InterfacePort*>*fn_rising_edge_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_rising_edge_args = new std::list<InterfacePort*>();
fn_rising_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC)); fn_rising_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC));
fn_rising_edge = new SubprogramBuiltin(perm_string::literal("rising_edge"), SubprogramBuiltin*fn_rising_edge = new SubprogramBuiltin(perm_string::literal("rising_edge"),
perm_string::literal("$ivlh_rising_edge"), perm_string::literal("$ivlh_rising_edge"),
fn_rising_edge_args, &type_BOOLEAN); fn_rising_edge_args, &type_BOOLEAN);
std_subprograms[fn_rising_edge->name()] = fn_rising_edge; register_std_subprogram(fn_rising_edge);
/* std_logic_1164 library /* std_logic_1164 library
* function falling_edge (signal s : std_ulogic) return boolean; * function falling_edge (signal s : std_ulogic) return boolean;
*/ */
std::list<InterfacePort*>*fn_falling_edge_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_falling_edge_args = new std::list<InterfacePort*>();
fn_falling_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC)); fn_falling_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC));
fn_falling_edge = new SubprogramBuiltin(perm_string::literal("falling_edge"), SubprogramBuiltin*fn_falling_edge = new SubprogramBuiltin(perm_string::literal("falling_edge"),
perm_string::literal("$ivlh_falling_edge"), perm_string::literal("$ivlh_falling_edge"),
fn_falling_edge_args, &type_BOOLEAN); fn_falling_edge_args, &type_BOOLEAN);
std_subprograms[fn_falling_edge->name()] = fn_falling_edge; register_std_subprogram(fn_falling_edge);
/* reduce_pack library /* reduce_pack library
* function or_reduce(arg : std_logic_vector) return std_logic; * function or_reduce(arg : std_logic_vector) return std_logic;
*/ */
std::list<InterfacePort*>*fn_or_reduce_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_or_reduce_args = new std::list<InterfacePort*>();
fn_or_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR)); fn_or_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
fn_or_reduce = new SubprogramBuiltin(perm_string::literal("or_reduce"), SubprogramBuiltin*fn_or_reduce = new SubprogramBuiltin(perm_string::literal("or_reduce"),
perm_string::literal("|"), perm_string::literal("|"),
fn_or_reduce_args, &primitive_STDLOGIC); fn_or_reduce_args, &primitive_STDLOGIC);
std_subprograms[fn_or_reduce->name()] = fn_or_reduce; register_std_subprogram(fn_or_reduce);
/* reduce_pack library /* reduce_pack library
* function and_reduce(arg : std_logic_vector) return std_logic; * function and_reduce(arg : std_logic_vector) return std_logic;
*/ */
std::list<InterfacePort*>*fn_and_reduce_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_and_reduce_args = new std::list<InterfacePort*>();
fn_and_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR)); fn_and_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
fn_and_reduce = new SubprogramBuiltin(perm_string::literal("and_reduce"), SubprogramBuiltin*fn_and_reduce = new SubprogramBuiltin(perm_string::literal("and_reduce"),
perm_string::literal("&"), perm_string::literal("&"),
fn_and_reduce_args, &primitive_STDLOGIC); fn_and_reduce_args, &primitive_STDLOGIC);
std_subprograms[fn_and_reduce->name()] = fn_and_reduce; register_std_subprogram(fn_and_reduce);
/* fixed_pkg library /* fixed_pkg library
* function to_unsigned ( * function to_unsigned (
@ -282,10 +261,10 @@ void preload_std_funcs(void)
std::list<InterfacePort*>*fn_to_unsigned_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_to_unsigned_args = new std::list<InterfacePort*>();
fn_to_unsigned_args->push_back(new InterfacePort(&primitive_REAL)); fn_to_unsigned_args->push_back(new InterfacePort(&primitive_REAL));
fn_to_unsigned_args->push_back(new InterfacePort(&primitive_NATURAL)); fn_to_unsigned_args->push_back(new InterfacePort(&primitive_NATURAL));
fn_to_unsigned = new SubprogramBuiltin(perm_string::literal("to_unsigned"), SubprogramBuiltin*fn_to_unsigned = new SubprogramBuiltin(perm_string::literal("to_unsigned"),
perm_string::literal("$ivlh_to_unsigned"), perm_string::literal("$ivlh_to_unsigned"),
fn_to_unsigned_args, &primitive_UNSIGNED); fn_to_unsigned_args, &primitive_UNSIGNED);
std_subprograms[fn_to_unsigned->name()] = fn_to_unsigned; register_std_subprogram(fn_to_unsigned);
/* procedure file_open (file f: text; filename: in string, file_open_kind: in mode); /* procedure file_open (file f: text; filename: in string, file_open_kind: in mode);
*/ */
@ -293,48 +272,48 @@ void preload_std_funcs(void)
fn_file_open_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); fn_file_open_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
fn_file_open_args->push_back(new InterfacePort(&primitive_STRING, PORT_IN)); fn_file_open_args->push_back(new InterfacePort(&primitive_STRING, PORT_IN));
fn_file_open_args->push_back(new InterfacePort(&type_FILE_OPEN_KIND, PORT_IN)); fn_file_open_args->push_back(new InterfacePort(&type_FILE_OPEN_KIND, PORT_IN));
fn_file_open = new SubprogramBuiltin(perm_string::literal("file_open"), SubprogramBuiltin*fn_file_open = new SubprogramBuiltin(perm_string::literal("file_open"),
perm_string::literal("$ivlh_file_open"), perm_string::literal("$ivlh_file_open"),
fn_file_open_args, NULL); fn_file_open_args, NULL);
std_subprograms[fn_file_open->name()] = fn_file_open; register_std_subprogram(fn_file_open);
/* std.textio library /* std.textio library
* procedure file_close (file f: text); * procedure file_close (file f: text);
*/ */
std::list<InterfacePort*>*fn_file_close_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_file_close_args = new std::list<InterfacePort*>();
fn_file_close_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); fn_file_close_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
fn_file_close = new SubprogramBuiltin(perm_string::literal("file_close"), SubprogramBuiltin*fn_file_close = new SubprogramBuiltin(perm_string::literal("file_close"),
perm_string::literal("$fclose"), perm_string::literal("$fclose"),
fn_file_close_args, NULL); fn_file_close_args, NULL);
std_subprograms[fn_file_close->name()] = fn_file_close; register_std_subprogram(fn_file_close);
/* std.textio library /* std.textio library
* procedure read (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time); * procedure read (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
*/ */
fn_read = new SubprogramReadWrite(perm_string::literal("read"), fn_read = new SubprogramReadWrite(perm_string::literal("read"),
perm_string::literal("$ivlh_read")); perm_string::literal("$ivlh_read"));
std_subprograms[fn_read->name()] = fn_read; register_std_subprogram(fn_read);
/* std.textio library /* std.textio library
* procedure write (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time); * procedure write (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
*/ */
fn_write = new SubprogramReadWrite(perm_string::literal("write"), fn_write = new SubprogramReadWrite(perm_string::literal("write"),
perm_string::literal("$ivlh_write")); perm_string::literal("$ivlh_write"));
std_subprograms[fn_write->name()] = fn_write; register_std_subprogram(fn_write);
/* std.textio library /* std.textio library
* procedure hread (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time); * procedure hread (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
*/ */
fn_hread = new SubprogramHexReadWrite(perm_string::literal("hread"), fn_hread = new SubprogramHexReadWrite(perm_string::literal("hread"),
perm_string::literal("$ivlh_read")); perm_string::literal("$ivlh_read"));
std_subprograms[fn_hread->name()] = fn_hread; register_std_subprogram(fn_hread);
/* std.textio library /* std.textio library
* procedure hwrite (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time); * procedure hwrite (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
*/ */
fn_hwrite = new SubprogramHexReadWrite(perm_string::literal("hwrite"), fn_hwrite = new SubprogramHexReadWrite(perm_string::literal("hwrite"),
perm_string::literal("$ivlh_write")); perm_string::literal("$ivlh_write"));
std_subprograms[fn_hwrite->name()] = fn_hwrite; register_std_subprogram(fn_hwrite);
/* std.textio library /* std.textio library
* procedure readline (file f: text; l: inout line); * procedure readline (file f: text; l: inout line);
@ -342,10 +321,10 @@ void preload_std_funcs(void)
std::list<InterfacePort*>*fn_readline_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_readline_args = new std::list<InterfacePort*>();
fn_readline_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); fn_readline_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
fn_readline_args->push_back(new InterfacePort(&primitive_STRING, PORT_OUT)); fn_readline_args->push_back(new InterfacePort(&primitive_STRING, PORT_OUT));
fn_readline = new SubprogramBuiltin(perm_string::literal("readline"), SubprogramBuiltin*fn_readline = new SubprogramBuiltin(perm_string::literal("readline"),
perm_string::literal("$ivlh_readline"), perm_string::literal("$ivlh_readline"),
fn_readline_args, NULL); fn_readline_args, NULL);
std_subprograms[fn_readline->name()] = fn_readline; register_std_subprogram(fn_readline);
/* std.textio library /* std.textio library
* procedure writeline (file f: text; l: inout line); * procedure writeline (file f: text; l: inout line);
@ -353,19 +332,19 @@ void preload_std_funcs(void)
std::list<InterfacePort*>*fn_writeline_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_writeline_args = new std::list<InterfacePort*>();
fn_writeline_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); fn_writeline_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
fn_writeline_args->push_back(new InterfacePort(&primitive_STRING, PORT_IN)); fn_writeline_args->push_back(new InterfacePort(&primitive_STRING, PORT_IN));
fn_writeline = new SubprogramBuiltin(perm_string::literal("writeline"), SubprogramBuiltin*fn_writeline = new SubprogramBuiltin(perm_string::literal("writeline"),
perm_string::literal("$ivlh_writeline"), perm_string::literal("$ivlh_writeline"),
fn_writeline_args, NULL); fn_writeline_args, NULL);
std_subprograms[fn_writeline->name()] = fn_writeline; register_std_subprogram(fn_writeline);
/* function endline (file f: text) return boolean; /* function endline (file f: text) return boolean;
*/ */
std::list<InterfacePort*>*fn_endfile_args = new std::list<InterfacePort*>(); std::list<InterfacePort*>*fn_endfile_args = new std::list<InterfacePort*>();
fn_endfile_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN)); fn_endfile_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
fn_endfile = new SubprogramBuiltin(perm_string::literal("endfile"), SubprogramBuiltin*fn_endfile = new SubprogramBuiltin(perm_string::literal("endfile"),
perm_string::literal("$feof"), perm_string::literal("$feof"),
fn_endfile_args, &type_BOOLEAN); fn_endfile_args, &type_BOOLEAN);
std_subprograms[fn_endfile->name()] = fn_endfile; register_std_subprogram(fn_endfile);
} }
void delete_std_funcs() void delete_std_funcs()

View File

@ -1,7 +1,7 @@
#ifndef IVL_std_funcs_H #ifndef IVL_std_funcs_H
#define IVL_std_funcs_H #define IVL_std_funcs_H
/* /*
* Copyright CERN 2015 * Copyright CERN 2016
* @author Maciej Suminski (maciej.suminski@cern.ch) * @author Maciej Suminski (maciej.suminski@cern.ch)
* *
* This source code is free software; you can redistribute it * This source code is free software; you can redistribute it

View File

@ -334,13 +334,3 @@ void SubprogramHeader::write_to_stream(ostream&fd) const
return_type_->write_to_stream(fd); return_type_->write_to_stream(fd);
} }
} }
SubprogramBuiltin::SubprogramBuiltin(perm_string vhdl_name, perm_string sv_name,
std::list<InterfacePort*>*ports, const VType*return_type)
: SubprogramHeader(vhdl_name, ports, return_type), sv_name_(sv_name)
{
}
SubprogramBuiltin::~SubprogramBuiltin()
{
}

View File

@ -133,14 +133,25 @@ class SubprogramHeader : public LineInfo {
}; };
// Class to define functions headers defined in the standard VHDL libraries. // Class to define functions headers defined in the standard VHDL libraries.
class SubprogramBuiltin : public SubprogramHeader class SubprogramStdHeader : public SubprogramHeader
{
public:
SubprogramStdHeader(perm_string name, std::list<InterfacePort*>*ports,
const VType*return_type) :
SubprogramHeader(name, ports, return_type) {}
virtual ~SubprogramStdHeader() {};
bool is_std() const { return true; }
};
// The simplest case, when only function name has to be changed.
class SubprogramBuiltin : public SubprogramStdHeader
{ {
public: public:
SubprogramBuiltin(perm_string vhdl_name, perm_string sv_name, SubprogramBuiltin(perm_string vhdl_name, perm_string sv_name,
std::list<InterfacePort*>*ports, const VType*return_type); std::list<InterfacePort*>*ports, const VType*return_type) :
~SubprogramBuiltin(); SubprogramStdHeader(vhdl_name, ports, return_type), sv_name_(sv_name) {}
~SubprogramBuiltin() {}
bool is_std() const { return true; }
int emit_name(const std::vector<Expression*>&, std::ostream&out, Entity*, ScopeBase*) const; int emit_name(const std::vector<Expression*>&, std::ostream&out, Entity*, ScopeBase*) const;

View File

@ -40,12 +40,17 @@ struct monitor_data {
static struct monitor_data **mdata = 0; static struct monitor_data **mdata = 0;
static unsigned mdata_count = 0; static unsigned mdata_count = 0;
typedef enum { EVENT = 0, RISING_EDGE = 1, FALLING_EDGE = 2 } event_type_t; typedef enum {
static const char* func_names[] = { EVENT = 0,
RISING_EDGE = 1,
FALLING_EDGE = 2
} event_type_t;
static const char* attr_func_names[] = {
"$ivlh_attribute_event", "$ivlh_attribute_event",
"$ivlh_rising_edge", "$ivlh_rising_edge",
"$ivlh_falling_edge" "$ivlh_falling_edge"
}; };
};
/* To keep valgrind happy free the allocated memory. */ /* To keep valgrind happy free the allocated memory. */
static PLI_INT32 cleanup_mdata(p_cb_data cause) static PLI_INT32 cleanup_mdata(p_cb_data cause)
@ -93,7 +98,7 @@ static PLI_INT32 ivlh_attribute_event_compiletf(ICARUS_VPI_CONST PLI_BYTE8*data)
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, sys), vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, sys),
(int)vpi_get(vpiLineNo, sys)); (int)vpi_get(vpiLineNo, sys));
vpi_printf("(compiler error) %s requires a single argument.\n", vpi_printf("(compiler error) %s requires a single argument.\n",
func_names[type]); attr_func_names[type]);
vpi_control(vpiFinish, 1); vpi_control(vpiFinish, 1);
return 0; return 0;
} }
@ -127,7 +132,7 @@ static PLI_INT32 ivlh_attribute_event_compiletf(ICARUS_VPI_CONST PLI_BYTE8*data)
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, sys), vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, sys),
(int)vpi_get(vpiLineNo, sys)); (int)vpi_get(vpiLineNo, sys));
vpi_printf("(compiler error) %s only takes a single argument.\n", vpi_printf("(compiler error) %s only takes a single argument.\n",
func_names[type]); attr_func_names[type]);
vpi_free_object(argv); vpi_free_object(argv);
vpi_control(vpiFinish, 1); vpi_control(vpiFinish, 1);
} }
@ -186,32 +191,23 @@ static void vhdl_register(void)
s_cb_data cb; s_cb_data cb;
vpiHandle res; vpiHandle res;
/* Event attribute functions */
tf_data.type = vpiSysFunc; tf_data.type = vpiSysFunc;
tf_data.sysfunctype = vpiSizedFunc; tf_data.sysfunctype = vpiSizedFunc;
tf_data.calltf = ivlh_attribute_event_calltf; tf_data.calltf = ivlh_attribute_event_calltf;
tf_data.compiletf = ivlh_attribute_event_compiletf; tf_data.compiletf = ivlh_attribute_event_compiletf;
tf_data.sizetf = ivlh_attribute_event_sizetf; tf_data.sizetf = ivlh_attribute_event_sizetf;
tf_data.tfname = func_names[EVENT]; tf_data.tfname = attr_func_names[EVENT];
tf_data.user_data = (PLI_BYTE8*) EVENT; tf_data.user_data = (PLI_BYTE8*) EVENT;
res = vpi_register_systf(&tf_data); res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res); vpip_make_systf_system_defined(res);
tf_data.type = vpiSysFunc; tf_data.tfname = attr_func_names[RISING_EDGE];
tf_data.sysfunctype = vpiSizedFunc;
tf_data.calltf = ivlh_attribute_event_calltf;
tf_data.compiletf = ivlh_attribute_event_compiletf;
tf_data.sizetf = ivlh_attribute_event_sizetf;
tf_data.tfname = func_names[RISING_EDGE];
tf_data.user_data = (PLI_BYTE8*) RISING_EDGE; tf_data.user_data = (PLI_BYTE8*) RISING_EDGE;
res = vpi_register_systf(&tf_data); res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res); vpip_make_systf_system_defined(res);
tf_data.type = vpiSysFunc; tf_data.tfname = attr_func_names[FALLING_EDGE];
tf_data.sysfunctype = vpiSizedFunc;
tf_data.calltf = ivlh_attribute_event_calltf;
tf_data.compiletf = ivlh_attribute_event_compiletf;
tf_data.sizetf = ivlh_attribute_event_sizetf;
tf_data.tfname = func_names[FALLING_EDGE];
tf_data.user_data = (PLI_BYTE8*) FALLING_EDGE; tf_data.user_data = (PLI_BYTE8*) FALLING_EDGE;
res = vpi_register_systf(&tf_data); res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res); vpip_make_systf_system_defined(res);