diff --git a/parse.y b/parse.y index 71a17b01a..75491e45a 100644 --- a/parse.y +++ b/parse.y @@ -122,19 +122,6 @@ list* make_range_from_width(uint64_t wid) return rlist; } -static list* make_range_from_pair(list*rpair) -{ - pform_range_t range; - assert(rpair && rpair->size() == 2); - range.first = rpair->front(); - range.second = rpair->back(); - delete rpair; - - list*rlist = new list; - rlist->push_back(range); - return rlist; -} - static list* list_from_identifier(char*id) { list*tmp = new list; @@ -391,6 +378,7 @@ static void current_function_set_statement(const YYLTYPE&loc, vector data_type_t*data_type; class_type_t*class_type; + real_type_t::type_t real_type; verinum* number; @@ -592,7 +580,8 @@ static void current_function_set_statement(const YYLTYPE&loc, vector %type specify_simple_path specify_simple_path_decl %type specify_edge_path specify_edge_path_decl -%type atom2_type non_integer_type +%type non_integer_type +%type atom2_type %type module_start module_end %token K_TAND @@ -1239,9 +1228,9 @@ method_qualifier_opt non_integer_type /* IEEE1800-2005: A.2.2.1 */ - : K_real { $$ = K_real; } - | K_realtime { $$ = K_real; } - | K_shortreal { $$ = K_shortreal; } + : K_real { $$ = real_type_t::REAL; } + | K_realtime { $$ = real_type_t::REAL; } + | K_shortreal { $$ = real_type_t::SHORTREAL; } ; number : BASED_NUMBER @@ -3467,6 +3456,7 @@ list_of_port_declarations port_declaration_context.port_net_type, port_declaration_context.var_type, port_declaration_context.sign_flag, + port_declaration_context.data_type, port_declaration_context.range, 0); delete[]$3; $$ = tmp; @@ -3484,39 +3474,19 @@ list_of_port_declarations ; port_declaration - : attribute_list_opt - K_input net_type_opt primitive_type_opt unsigned_signed_opt range_opt IDENTIFIER - { Module::port_t*ptmp; - perm_string name = lex_strings.make($7); - ptmp = pform_module_port_reference(name, @2.text, - @2.first_line); - pform_module_define_port(@2, name, NetNet::PINPUT, - $3, $4, $5, $6, $1); - port_declaration_context.port_type = NetNet::PINPUT; - port_declaration_context.port_net_type = $3; - port_declaration_context.var_type = $4; - port_declaration_context.sign_flag = $5; - delete port_declaration_context.range; - port_declaration_context.range = $6; - delete[]$7; - $$ = ptmp; - } - | attribute_list_opt - K_input atom2_type signed_unsigned_opt IDENTIFIER + : attribute_list_opt K_input net_type_opt data_type_or_implicit IDENTIFIER { Module::port_t*ptmp; perm_string name = lex_strings.make($5); - list* use_range = make_range_from_width($3); - ptmp = pform_module_port_reference(name, @2.text, - @2.first_line); - pform_module_define_port(@2, name, NetNet::PINPUT, - NetNet::UNRESOLVED_WIRE, IVL_VT_BOOL, - $4, use_range, $1); + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::PINPUT, $3, IVL_VT_NO_TYPE, + false, $4, 0, $1); port_declaration_context.port_type = NetNet::PINPUT; - port_declaration_context.port_net_type = NetNet::UNRESOLVED_WIRE; - port_declaration_context.var_type = IVL_VT_BOOL; - port_declaration_context.sign_flag = $4; + port_declaration_context.port_net_type = $3; + port_declaration_context.var_type = IVL_VT_NO_TYPE; + port_declaration_context.sign_flag = false; delete port_declaration_context.range; - port_declaration_context.range = use_range; + port_declaration_context.range = 0; + port_declaration_context.data_type = $4; delete[]$5; $$ = ptmp; } @@ -3527,31 +3497,31 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::PINPUT, - NetNet::WIRE, IVL_VT_REAL, true, 0, $1); + NetNet::WIRE, IVL_VT_REAL, true, 0, 0, $1); port_declaration_context.port_type = NetNet::PINPUT; port_declaration_context.port_net_type = NetNet::WIRE; port_declaration_context.var_type = IVL_VT_REAL; port_declaration_context.sign_flag = true; delete port_declaration_context.range; port_declaration_context.range = 0; + port_declaration_context.data_type = 0; delete[]$4; $$ = ptmp; } - | attribute_list_opt - K_inout net_type_opt primitive_type_opt unsigned_signed_opt range_opt IDENTIFIER + | attribute_list_opt K_inout net_type_opt data_type_or_implicit IDENTIFIER { Module::port_t*ptmp; - perm_string name = lex_strings.make($7); - ptmp = pform_module_port_reference(name, @2.text, - @2.first_line); - pform_module_define_port(@2, name, NetNet::PINOUT, - $3, $4, $5, $6, $1); + perm_string name = lex_strings.make($5); + ptmp = pform_module_port_reference(name, @2.text, @2.first_line); + pform_module_define_port(@2, name, NetNet::PINOUT, $3, IVL_VT_NO_TYPE, + false, $4, 0, $1); port_declaration_context.port_type = NetNet::PINOUT; port_declaration_context.port_net_type = $3; - port_declaration_context.var_type = $4; - port_declaration_context.sign_flag = $5; + port_declaration_context.var_type = IVL_VT_NO_TYPE; + port_declaration_context.sign_flag = false; delete port_declaration_context.range; - port_declaration_context.range = $6; - delete[]$7; + port_declaration_context.range = 0; + port_declaration_context.data_type = $4; + delete[]$5; $$ = ptmp; } | attribute_list_opt @@ -3561,13 +3531,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::PINOUT, - NetNet::WIRE, IVL_VT_REAL, true, 0, $1); + NetNet::WIRE, IVL_VT_REAL, true, 0, 0, $1); port_declaration_context.port_type = NetNet::PINOUT; port_declaration_context.port_net_type = NetNet::WIRE; port_declaration_context.var_type = IVL_VT_REAL; port_declaration_context.sign_flag = true; delete port_declaration_context.range; port_declaration_context.range = 0; + port_declaration_context.data_type = 0; delete[]$4; $$ = ptmp; } @@ -3578,13 +3549,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, - $3, $4, $5, $6, $1); + $3, $4, $5, 0, $6, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = $3; port_declaration_context.var_type = $4; port_declaration_context.sign_flag = $5; delete port_declaration_context.range; port_declaration_context.range = $6; + port_declaration_context.data_type = 0; delete[]$7; $$ = ptmp; } @@ -3595,13 +3567,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, - $3, $4, $5, $6, $1); + $3, $4, $5, 0, $6, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = $3; port_declaration_context.var_type = $4; port_declaration_context.sign_flag = $5; delete port_declaration_context.range; port_declaration_context.range = $6; + port_declaration_context.data_type = 0; delete[]$7; $$ = ptmp; } @@ -3612,13 +3585,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, - $3, $4, $5, $6, $1); + $3, $4, $5, 0, $6, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = $3; port_declaration_context.var_type = $4; port_declaration_context.sign_flag = $5; delete port_declaration_context.range; port_declaration_context.range = $6; + port_declaration_context.data_type = 0; pform_make_reginit(@7, name, $9); @@ -3634,13 +3608,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, - t, $4, $5, $6, $1); + t, $4, $5, 0, $6, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = t; port_declaration_context.var_type = $4; port_declaration_context.sign_flag = $5; delete port_declaration_context.range; port_declaration_context.range = $6; + port_declaration_context.data_type = 0; pform_make_reginit(@7, name, $9); @@ -3656,13 +3631,14 @@ port_declaration @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, NetNet::IMPLICIT_REG, IVL_VT_BOOL, - $4, use_range, $1); + $4, 0, use_range, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = NetNet::IMPLICIT_REG; port_declaration_context.var_type = IVL_VT_BOOL; port_declaration_context.sign_flag = $4; delete port_declaration_context.range; port_declaration_context.range = use_range; + port_declaration_context.data_type = 0; delete[]$5; $$ = ptmp; } @@ -3675,13 +3651,14 @@ port_declaration @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, NetNet::IMPLICIT_REG, IVL_VT_BOOL, - $4, use_range, $1); + $4, 0, use_range, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = NetNet::IMPLICIT_REG; port_declaration_context.var_type = IVL_VT_BOOL; port_declaration_context.sign_flag = $4; delete port_declaration_context.range; port_declaration_context.range = use_range; + port_declaration_context.data_type = 0; pform_make_reginit(@5, name, $7); @@ -3695,13 +3672,14 @@ port_declaration ptmp = pform_module_port_reference(name, @2.text, @2.first_line); pform_module_define_port(@2, name, NetNet::POUTPUT, - NetNet::WIRE, IVL_VT_REAL, true, 0, $1); + NetNet::WIRE, IVL_VT_REAL, true, 0, 0, $1); port_declaration_context.port_type = NetNet::POUTPUT; port_declaration_context.port_net_type = NetNet::WIRE; port_declaration_context.var_type = IVL_VT_REAL; port_declaration_context.sign_flag = true; delete port_declaration_context.range; port_declaration_context.range = 0; + port_declaration_context.data_type = 0; delete[]$4; $$ = ptmp; } diff --git a/parse_misc.h b/parse_misc.h index 037fefffe..5b18f72e6 100644 --- a/parse_misc.h +++ b/parse_misc.h @@ -35,6 +35,7 @@ struct vlltype { unsigned last_line; unsigned last_column; const char*text; + std::string get_fileline() const; }; # define YYLTYPE struct vlltype diff --git a/pform.cc b/pform.cc index a21ae1182..4b98c029a 100644 --- a/pform.cc +++ b/pform.cc @@ -45,6 +45,15 @@ map pform_modules; map pform_primitives; +std::string vlltype::get_fileline() const +{ + ostringstream buf; + buf << (text? text : "") << ":" << first_line; + string res = buf.str(); + return res; + +} + /* * Parse configuration file with format =, where key * is the hierarchical name of a valid parameter name, and value @@ -1893,6 +1902,7 @@ void pform_module_define_port(const struct vlltype&li, NetNet::Type type, ivl_variable_type_t data_type, bool signed_flag, + data_type_t*vtype, list*range, list*attr) { @@ -1906,6 +1916,37 @@ void pform_module_define_port(const struct vlltype&li, return; } + if (vtype) { + ivl_assert(li, data_type == IVL_VT_NO_TYPE); + ivl_assert(li, range == 0); + } + + if (vector_type_t*vec_type = dynamic_cast (vtype)) { + data_type = vec_type->base_type; + signed_flag = vec_type->signed_flag; + range = vec_type->pdims.get(); + + } else if (atom2_type_t*atype = dynamic_cast(vtype)) { + data_type = IVL_VT_BOOL; + signed_flag = atype->signed_flag; + range = make_range_from_width(atype->type_code); + + } else if (real_type_t*rtype = dynamic_cast(vtype)) { + data_type = IVL_VT_REAL; + signed_flag = true; + range = 0; + + if (rtype->type_code != real_type_t::REAL) { + VLerror(li, "sorry: Only real (not shortreal) supported here (%s:%d).", + __FILE__, __LINE__); + } + + } else if (vtype) { + VLerror(li, "sorry: Given type %s not supported here (%s:%d).", + typeid(*vtype).name(), __FILE__, __LINE__); + } + + // The default type for all flavor of ports is LOGIC. if (data_type == IVL_VT_NO_TYPE) data_type = IVL_VT_LOGIC; diff --git a/pform.h b/pform.h index c17a2e2b6..9fd2a3d80 100644 --- a/pform.h +++ b/pform.h @@ -160,6 +160,7 @@ extern void pform_module_define_port(const struct vlltype&li, NetNet::Type type, ivl_variable_type_t data_type, bool signed_flag, + data_type_t*vtype, list*range, list*attr); diff --git a/pform_types.h b/pform_types.h index ed3f20f53..6fe835e77 100644 --- a/pform_types.h +++ b/pform_types.h @@ -118,8 +118,9 @@ struct vector_type_t : public data_type_t { }; struct real_type_t : public data_type_t { - inline explicit real_type_t(int tc) : type_code(tc) { } - int type_code; + enum type_t { REAL, SHORTREAL }; + inline explicit real_type_t(type_t tc) : type_code(tc) { } + type_t type_code; }; struct class_type_t : public data_type_t {