vhdlpp: Code cleaning (std_funcs).
This commit is contained in:
parent
cc729e8dd9
commit
414f240694
|
|
@ -30,11 +30,11 @@ static inline void register_std_subprogram(SubprogramHeader*header)
|
|||
}
|
||||
|
||||
// Special case: to_integer function
|
||||
static class SubprogramToInteger : public SubprogramStdHeader {
|
||||
class SubprogramToInteger : public SubprogramStdHeader {
|
||||
public:
|
||||
SubprogramToInteger()
|
||||
: SubprogramStdHeader(perm_string::literal("to_integer"), NULL, &primitive_REAL) {
|
||||
ports_ = new std::list<InterfacePort*>();
|
||||
ports_ = new list<InterfacePort*>();
|
||||
ports_->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
}
|
||||
|
||||
|
|
@ -59,14 +59,14 @@ static class SubprogramToInteger : public SubprogramStdHeader {
|
|||
out << (signed_flag ? "$signed" : "$unsigned");
|
||||
return 0;
|
||||
}
|
||||
}*fn_to_integer;
|
||||
};
|
||||
|
||||
// Special case: size casting (e.g. conv_std_logic_vector() / resize()).
|
||||
static class SubprogramSizeCast : public SubprogramStdHeader {
|
||||
class SubprogramSizeCast : public SubprogramStdHeader {
|
||||
public:
|
||||
explicit SubprogramSizeCast(perm_string nam)
|
||||
: SubprogramStdHeader(nam, NULL, &primitive_STDLOGIC_VECTOR) {
|
||||
ports_ = new std::list<InterfacePort*>();
|
||||
ports_ = new list<InterfacePort*>();
|
||||
ports_->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
ports_->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
}
|
||||
|
|
@ -91,13 +91,13 @@ static class SubprogramSizeCast : public SubprogramStdHeader {
|
|||
|
||||
return argv[0]->emit(out, ent, scope);
|
||||
}
|
||||
}*fn_conv_std_logic_vector, *fn_resize;
|
||||
};
|
||||
|
||||
static class SubprogramReadWrite : public SubprogramBuiltin {
|
||||
class SubprogramReadWrite : public SubprogramBuiltin {
|
||||
public:
|
||||
SubprogramReadWrite(perm_string nam, perm_string newnam)
|
||||
: SubprogramBuiltin(nam, newnam, NULL, NULL) {
|
||||
ports_ = new std::list<InterfacePort*>();
|
||||
ports_ = new list<InterfacePort*>();
|
||||
ports_->push_back(new InterfacePort(&primitive_STRING, PORT_INOUT));
|
||||
ports_->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR, PORT_INOUT));
|
||||
ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
|
|
@ -133,13 +133,13 @@ static class SubprogramReadWrite : public SubprogramBuiltin {
|
|||
|
||||
return errors;
|
||||
}
|
||||
}*fn_read, *fn_write;
|
||||
};
|
||||
|
||||
static class SubprogramHexReadWrite : public SubprogramBuiltin {
|
||||
class SubprogramHexReadWrite : public SubprogramBuiltin {
|
||||
public:
|
||||
SubprogramHexReadWrite(perm_string nam, perm_string newnam)
|
||||
: SubprogramBuiltin(nam, newnam, NULL, NULL) {
|
||||
ports_ = new std::list<InterfacePort*>();
|
||||
ports_ = new list<InterfacePort*>();
|
||||
ports_->push_back(new InterfacePort(&primitive_STRING, PORT_INOUT));
|
||||
ports_->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR, PORT_INOUT));
|
||||
ports_->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
|
|
@ -159,10 +159,12 @@ static class SubprogramHexReadWrite : public SubprogramBuiltin {
|
|||
|
||||
return errors;
|
||||
}
|
||||
}*fn_hread, *fn_hwrite;
|
||||
};
|
||||
|
||||
void preload_std_funcs(void)
|
||||
{
|
||||
list<InterfacePort*>*args;
|
||||
|
||||
/* function now */
|
||||
SubprogramBuiltin*fn_now = new SubprogramBuiltin(perm_string::literal("now"),
|
||||
perm_string::literal("$time"), NULL, NULL);
|
||||
|
|
@ -171,113 +173,101 @@ void preload_std_funcs(void)
|
|||
/* numeric_std library
|
||||
* function unsigned
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_unsigned_args = new std::list<InterfacePort*>();
|
||||
fn_unsigned_args->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
SubprogramBuiltin*fn_unsigned = new SubprogramBuiltin(perm_string::literal("unsigned"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("unsigned"),
|
||||
perm_string::literal("$unsigned"),
|
||||
fn_unsigned_args, &primitive_UNSIGNED);
|
||||
register_std_subprogram(fn_unsigned);
|
||||
args, &primitive_UNSIGNED));
|
||||
|
||||
/* function integer
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_integer_args = new std::list<InterfacePort*>();
|
||||
fn_integer_args->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
SubprogramBuiltin*fn_integer = new SubprogramBuiltin(perm_string::literal("integer"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("integer"),
|
||||
perm_string::literal("$signed"),
|
||||
fn_integer_args, &primitive_INTEGER);
|
||||
register_std_subprogram(fn_integer);
|
||||
args, &primitive_INTEGER));
|
||||
|
||||
/* function std_logic_vector
|
||||
Special case: The std_logic_vector function casts its
|
||||
argument to std_logic_vector. Internally, we don't
|
||||
have to do anything for that to work.
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_std_logic_vector_args = new std::list<InterfacePort*>();
|
||||
fn_std_logic_vector_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
SubprogramBuiltin*fn_std_logic_vector = new SubprogramBuiltin(perm_string::literal("std_logic_vector"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("std_logic_vector"),
|
||||
empty_perm_string,
|
||||
fn_std_logic_vector_args, &primitive_STDLOGIC_VECTOR);
|
||||
register_std_subprogram(fn_std_logic_vector);
|
||||
args, &primitive_STDLOGIC_VECTOR));
|
||||
|
||||
/* numeric_std library
|
||||
* function shift_left (arg: unsigned; count: natural) return unsigned;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_shift_left_args = new std::list<InterfacePort*>();
|
||||
fn_shift_left_args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
fn_shift_left_args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
SubprogramBuiltin*fn_shift_left = new SubprogramBuiltin(perm_string::literal("shift_left"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("shift_left"),
|
||||
perm_string::literal("$ivlh_shift_left"),
|
||||
fn_shift_left_args, &primitive_UNSIGNED);
|
||||
register_std_subprogram(fn_shift_left);
|
||||
args, &primitive_UNSIGNED));
|
||||
|
||||
/* numeric_std library
|
||||
* function shift_right (arg: unsigned; count: natural) return unsigned;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_shift_right_args = new std::list<InterfacePort*>();
|
||||
fn_shift_right_args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
fn_shift_right_args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
SubprogramBuiltin*fn_shift_right = new SubprogramBuiltin(perm_string::literal("shift_right"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
args->push_back(new InterfacePort(&primitive_UNSIGNED));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("shift_right"),
|
||||
perm_string::literal("$ivlh_shift_right"),
|
||||
fn_shift_right_args, &primitive_UNSIGNED);
|
||||
register_std_subprogram(fn_shift_right);
|
||||
args, &primitive_UNSIGNED));
|
||||
|
||||
/* function resize
|
||||
*/
|
||||
fn_resize = new SubprogramSizeCast(perm_string::literal("resize"));
|
||||
register_std_subprogram(fn_resize);
|
||||
register_std_subprogram(new SubprogramSizeCast(perm_string::literal("resize")));
|
||||
|
||||
/* std_logic_arith library
|
||||
* 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"));
|
||||
register_std_subprogram(fn_conv_std_logic_vector);
|
||||
register_std_subprogram(new SubprogramSizeCast(perm_string::literal("conv_std_logic_vector")));
|
||||
|
||||
/* numeric_bit library
|
||||
* function to_integer (arg: unsigned) return natural;
|
||||
* function to_integer (arg: signed) return integer;
|
||||
*/
|
||||
fn_to_integer = new SubprogramToInteger();
|
||||
register_std_subprogram(fn_to_integer);
|
||||
register_std_subprogram(new SubprogramToInteger());
|
||||
|
||||
/* std_logic_1164 library
|
||||
* function rising_edge (signal s : std_ulogic) return boolean;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_rising_edge_args = new std::list<InterfacePort*>();
|
||||
fn_rising_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC));
|
||||
SubprogramBuiltin*fn_rising_edge = new SubprogramBuiltin(perm_string::literal("rising_edge"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_STDLOGIC));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("rising_edge"),
|
||||
perm_string::literal("$ivlh_rising_edge"),
|
||||
fn_rising_edge_args, &type_BOOLEAN);
|
||||
register_std_subprogram(fn_rising_edge);
|
||||
args, &type_BOOLEAN));
|
||||
|
||||
/* std_logic_1164 library
|
||||
* function falling_edge (signal s : std_ulogic) return boolean;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_falling_edge_args = new std::list<InterfacePort*>();
|
||||
fn_falling_edge_args->push_back(new InterfacePort(&primitive_STDLOGIC));
|
||||
SubprogramBuiltin*fn_falling_edge = new SubprogramBuiltin(perm_string::literal("falling_edge"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_STDLOGIC));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("falling_edge"),
|
||||
perm_string::literal("$ivlh_falling_edge"),
|
||||
fn_falling_edge_args, &type_BOOLEAN);
|
||||
register_std_subprogram(fn_falling_edge);
|
||||
args, &type_BOOLEAN));
|
||||
|
||||
/* reduce_pack library
|
||||
* function or_reduce(arg : std_logic_vector) return std_logic;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_or_reduce_args = new std::list<InterfacePort*>();
|
||||
fn_or_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
SubprogramBuiltin*fn_or_reduce = new SubprogramBuiltin(perm_string::literal("or_reduce"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("or_reduce"),
|
||||
perm_string::literal("|"),
|
||||
fn_or_reduce_args, &primitive_STDLOGIC);
|
||||
register_std_subprogram(fn_or_reduce);
|
||||
args, &primitive_STDLOGIC));
|
||||
|
||||
/* reduce_pack library
|
||||
* function and_reduce(arg : std_logic_vector) return std_logic;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_and_reduce_args = new std::list<InterfacePort*>();
|
||||
fn_and_reduce_args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
SubprogramBuiltin*fn_and_reduce = new SubprogramBuiltin(perm_string::literal("and_reduce"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_STDLOGIC_VECTOR));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("and_reduce"),
|
||||
perm_string::literal("&"),
|
||||
fn_and_reduce_args, &primitive_STDLOGIC);
|
||||
register_std_subprogram(fn_and_reduce);
|
||||
args, &primitive_STDLOGIC));
|
||||
|
||||
/* fixed_pkg library
|
||||
* function to_unsigned (
|
||||
|
|
@ -285,93 +275,83 @@ void preload_std_funcs(void)
|
|||
* constant size : natural) -- length of output
|
||||
* return unsigned;
|
||||
*/
|
||||
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_NATURAL));
|
||||
SubprogramBuiltin*fn_to_unsigned = new SubprogramBuiltin(perm_string::literal("to_unsigned"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_REAL));
|
||||
args->push_back(new InterfacePort(&primitive_NATURAL));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("to_unsigned"),
|
||||
perm_string::literal("$ivlh_to_unsigned"),
|
||||
fn_to_unsigned_args, &primitive_UNSIGNED);
|
||||
register_std_subprogram(fn_to_unsigned);
|
||||
args, &primitive_UNSIGNED));
|
||||
|
||||
/* procedure file_open (file f: text; filename: in string, file_open_kind: in mode);
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_file_open_args = new std::list<InterfacePort*>();
|
||||
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(&type_FILE_OPEN_KIND, PORT_IN));
|
||||
SubprogramBuiltin*fn_file_open = new SubprogramBuiltin(perm_string::literal("file_open"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
args->push_back(new InterfacePort(&primitive_STRING, PORT_IN));
|
||||
args->push_back(new InterfacePort(&type_FILE_OPEN_KIND, PORT_IN));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("file_open"),
|
||||
perm_string::literal("$ivlh_file_open"),
|
||||
fn_file_open_args, NULL);
|
||||
register_std_subprogram(fn_file_open);
|
||||
args, NULL));
|
||||
|
||||
/* std.textio library
|
||||
* procedure file_close (file f: text);
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_file_close_args = new std::list<InterfacePort*>();
|
||||
fn_file_close_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
SubprogramBuiltin*fn_file_close = new SubprogramBuiltin(perm_string::literal("file_close"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("file_close"),
|
||||
perm_string::literal("$fclose"),
|
||||
fn_file_close_args, NULL);
|
||||
register_std_subprogram(fn_file_close);
|
||||
args, NULL));
|
||||
|
||||
/* std.textio library
|
||||
* procedure read (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
|
||||
*/
|
||||
fn_read = new SubprogramReadWrite(perm_string::literal("read"),
|
||||
perm_string::literal("$ivlh_read"));
|
||||
register_std_subprogram(fn_read);
|
||||
register_std_subprogram(new SubprogramReadWrite(perm_string::literal("read"),
|
||||
perm_string::literal("$ivlh_read")));
|
||||
|
||||
/* std.textio library
|
||||
* procedure write (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
|
||||
*/
|
||||
fn_write = new SubprogramReadWrite(perm_string::literal("write"),
|
||||
perm_string::literal("$ivlh_write"));
|
||||
register_std_subprogram(fn_write);
|
||||
register_std_subprogram(new SubprogramReadWrite(perm_string::literal("write"),
|
||||
perm_string::literal("$ivlh_write")));
|
||||
|
||||
/* std.textio library
|
||||
* procedure hread (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
|
||||
*/
|
||||
fn_hread = new SubprogramHexReadWrite(perm_string::literal("hread"),
|
||||
perm_string::literal("$ivlh_read"));
|
||||
register_std_subprogram(fn_hread);
|
||||
register_std_subprogram(new SubprogramHexReadWrite(perm_string::literal("hread"),
|
||||
perm_string::literal("$ivlh_read")));
|
||||
|
||||
/* std.textio library
|
||||
* procedure hwrite (l: inout line; value: out bit/bit_vector/boolean/character/integer/real/string/time);
|
||||
*/
|
||||
fn_hwrite = new SubprogramHexReadWrite(perm_string::literal("hwrite"),
|
||||
perm_string::literal("$ivlh_write"));
|
||||
register_std_subprogram(fn_hwrite);
|
||||
register_std_subprogram(new SubprogramHexReadWrite(perm_string::literal("hwrite"),
|
||||
perm_string::literal("$ivlh_write")));
|
||||
|
||||
/* std.textio library
|
||||
* procedure readline (file f: text; l: inout line);
|
||||
*/
|
||||
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_STRING, PORT_OUT));
|
||||
SubprogramBuiltin*fn_readline = new SubprogramBuiltin(perm_string::literal("readline"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
args->push_back(new InterfacePort(&primitive_STRING, PORT_OUT));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("readline"),
|
||||
perm_string::literal("$ivlh_readline"),
|
||||
fn_readline_args, NULL);
|
||||
register_std_subprogram(fn_readline);
|
||||
args, NULL));
|
||||
|
||||
/* std.textio library
|
||||
* procedure writeline (file f: text; l: inout line);
|
||||
*/
|
||||
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_STRING, PORT_IN));
|
||||
SubprogramBuiltin*fn_writeline = new SubprogramBuiltin(perm_string::literal("writeline"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
args->push_back(new InterfacePort(&primitive_STRING, PORT_IN));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("writeline"),
|
||||
perm_string::literal("$ivlh_writeline"),
|
||||
fn_writeline_args, NULL);
|
||||
register_std_subprogram(fn_writeline);
|
||||
args, NULL));
|
||||
|
||||
/* function endline (file f: text) return boolean;
|
||||
*/
|
||||
std::list<InterfacePort*>*fn_endfile_args = new std::list<InterfacePort*>();
|
||||
fn_endfile_args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
SubprogramBuiltin*fn_endfile = new SubprogramBuiltin(perm_string::literal("endfile"),
|
||||
args = new list<InterfacePort*>();
|
||||
args->push_back(new InterfacePort(&primitive_INTEGER, PORT_IN));
|
||||
register_std_subprogram(new SubprogramBuiltin(perm_string::literal("endfile"),
|
||||
perm_string::literal("$feof"),
|
||||
fn_endfile_args, &type_BOOLEAN);
|
||||
register_std_subprogram(fn_endfile);
|
||||
args, &type_BOOLEAN));
|
||||
}
|
||||
|
||||
void delete_std_funcs()
|
||||
|
|
|
|||
Loading…
Reference in New Issue