From 9ad46044b4e3fe9358522218661aa3aed88af5e3 Mon Sep 17 00:00:00 2001 From: Michele Castellana Date: Thu, 30 Jun 2016 17:18:09 +0200 Subject: [PATCH 1/3] Cleanup --- netlist.h | 1 - tgt-vvp/vvp_scope.c | 10 +++++----- vvp/vpi_priv.h | 6 +----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/netlist.h b/netlist.h index b034da71d..f28d18b51 100644 --- a/netlist.h +++ b/netlist.h @@ -250,7 +250,6 @@ class NetPins : public LineInfo { */ class NetObj : public NetPins, public Attrib { - public: public: // The name of the object must be a permallocated string. A // lex_strings string, for example. diff --git a/tgt-vvp/vvp_scope.c b/tgt-vvp/vvp_scope.c index c6e1059ee..f27066a19 100644 --- a/tgt-vvp/vvp_scope.c +++ b/tgt-vvp/vvp_scope.c @@ -1737,29 +1737,29 @@ static void draw_lpm_ff(ivl_lpm_t net) nex = ivl_lpm_data(net,0); assert(nex); fprintf(vvp_out, "%s", draw_net_input(nex)); - assert(width_of_nexus(nex) == width);; + assert(width_of_nexus(nex) == width); nex = ivl_lpm_clk(net); assert(nex); - assert(width_of_nexus(nex) == 1);; + assert(width_of_nexus(nex) == 1); fprintf(vvp_out, ", %s", draw_net_input(nex)); nex = ivl_lpm_enable(net); if (nex) { - assert(width_of_nexus(nex) == 1);; + assert(width_of_nexus(nex) == 1); fprintf(vvp_out, ", %s", draw_net_input(nex)); } else { fprintf(vvp_out, ", C4<1>"); } if ( (nex = ivl_lpm_async_clr(net)) ) { - assert(width_of_nexus(nex) == 1);; + assert(width_of_nexus(nex) == 1); fprintf(vvp_out, ", %s", draw_net_input(nex)); } if ( (nex = ivl_lpm_async_set(net)) ) { ivl_expr_t val = ivl_lpm_aset_value(net); - assert(width_of_nexus(nex) == 1);; + assert(width_of_nexus(nex) == 1); fprintf(vvp_out, ", %s", draw_net_input(nex)); if (val) { unsigned nbits = ivl_expr_width(val); diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index dc040e581..5479a1f0b 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -2,6 +2,7 @@ #define IVL_vpi_priv_H /* * Copyright (c) 2001-2015 Stephen Williams (steve@icarus.com) + * Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -227,11 +228,6 @@ struct __vpiScopedRealtime : public __vpiSystemTime { void vpi_get_value(p_vpi_value val); }; -struct __vpiPortInfo : public __vpiHandle { - -}; - - /* * Scopes are created by .scope statements in the source. These * objects hold the items and properties that are knowingly bound to a From 3aa9d535f1efed2572c44eaeaf76fb3400cd5cf2 Mon Sep 17 00:00:00 2001 From: Michele Castellana Date: Thu, 30 Jun 2016 17:19:29 +0200 Subject: [PATCH 2/3] Avoid out of bounds --- net_scope.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net_scope.cc b/net_scope.cc index bae54dc07..42eab5a51 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -1,5 +1,6 @@ /* * Copyright (c) 2000-2016 Stephen Williams (steve@icarus.com) + * Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -508,6 +509,7 @@ void NetScope::add_module_port_info( unsigned idx, perm_string name, PortType::E unsigned long width ) { assert(type_ == MODULE); + assert(ports_.size() > idx); PortInfo &info = ports_[idx]; info.name = name; info.type = ptype; From 0aa54872141e5c2737cf637423804b6f25328bef Mon Sep 17 00:00:00 2001 From: Michele Castellana Date: Thu, 30 Jun 2016 17:28:03 +0200 Subject: [PATCH 3/3] Check pointers before dereferencing --- t-dll-api.cc | 179 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 165 insertions(+), 14 deletions(-) diff --git a/t-dll-api.cc b/t-dll-api.cc index 9fe60d365..82772e67b 100644 --- a/t-dll-api.cc +++ b/t-dll-api.cc @@ -1,6 +1,7 @@ /* * Copyright (c) 2000-2016 Stephen Williams (steve@icarus.com) * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) + * Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -37,22 +38,28 @@ static StringHeap api_strings; extern "C" ivl_island_t ivl_branch_island(ivl_branch_t net) { + assert(net); return net->island; } extern "C" ivl_nexus_t ivl_branch_terminal(ivl_branch_t net, int idx) { + assert(net); assert(idx >= 0); - assert( idx < 2); + assert(idx < 2); return net->pins[idx]; } extern "C" const char*ivl_design_delay_sel(ivl_design_t des) { + assert(des); + assert(des->self); return des->self->get_delay_sel(); } extern "C" const char*ivl_design_flag(ivl_design_t des, const char*key) { + assert(des); + assert(des->self); return des->self->get_flag(key); } @@ -60,6 +67,7 @@ extern "C" int ivl_design_process(ivl_design_t des, ivl_process_f func, void*cd) { + assert(des); for (ivl_process_t idx = des->threads_; idx; idx = idx->next_) { int rc = (func)(idx, cd); if (rc != 0) @@ -72,8 +80,8 @@ extern "C" int ivl_design_process(ivl_design_t des, extern "C" ivl_scope_t ivl_design_root(ivl_design_t des) { cerr << "ANACHRONISM: ivl_design_root called. " - "Use ivl_design_roots instead." << endl; - + "Use ivl_design_roots instead." << endl; + assert(des); assert (des->roots.size() > 0); return des->roots[0]; } @@ -81,6 +89,7 @@ extern "C" ivl_scope_t ivl_design_root(ivl_design_t des) extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes, unsigned int *nscopes) { + assert(des); assert (nscopes && scopes); if (des->root_scope_list.size() == 0) { size_t fill = 0; @@ -105,16 +114,19 @@ extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes, extern "C" int ivl_design_time_precision(ivl_design_t des) { + assert(des); return des->time_precision; } extern "C" unsigned ivl_design_consts(ivl_design_t des) { + assert(des); return des->consts.size(); } extern "C" ivl_net_const_t ivl_design_const(ivl_design_t des, unsigned idx) { + assert(des); assert(idx < des->consts.size()); return des->consts[idx]; } @@ -134,21 +146,25 @@ extern "C" ivl_discipline_t ivl_design_discipline(ivl_design_t des, unsigned idx extern "C" ivl_dis_domain_t ivl_discipline_domain(ivl_discipline_t net) { + assert(net); return net->domain(); } extern "C" ivl_nature_t ivl_discipline_flow(ivl_discipline_t net) { + assert(net); return net->flow(); } extern "C" const char* ivl_discipline_name(ivl_discipline_t net) { + assert(net); return net->name(); } extern "C" ivl_nature_t ivl_discipline_potential(ivl_discipline_t net) { + assert(net); return net->potential(); } @@ -197,6 +213,7 @@ extern "C" const char*ivl_const_bits(ivl_net_const_t net) extern "C" ivl_expr_t ivl_const_delay(ivl_net_const_t net, unsigned transition) { + assert(net); assert(transition < 3); return net->delay[transition]; } @@ -296,6 +313,7 @@ extern "C" unsigned ivl_enum_lineno(ivl_enumtype_t net) extern "C" const char* ivl_event_name(ivl_event_t net) { + assert(net); static char*name_buffer = 0; static unsigned name_size = 0; @@ -320,6 +338,7 @@ extern "C" const char* ivl_event_name(ivl_event_t net) extern "C" const char* ivl_event_basename(ivl_event_t net) { + assert(net); return net->name; } @@ -337,6 +356,7 @@ extern "C" unsigned ivl_event_lineno(ivl_event_t net) extern "C" ivl_scope_t ivl_event_scope(ivl_event_t net) { + assert(net); return net->scope; } @@ -381,13 +401,15 @@ extern "C" ivl_nexus_t ivl_event_pos(ivl_event_t net, unsigned idx) extern "C" const char* ivl_expr_bits(ivl_expr_t net) { - assert(net && (net->type_ == IVL_EX_NUMBER)); + assert(net); + assert(net->type_ == IVL_EX_NUMBER); return net->u_.number_.bits_; } extern "C" ivl_branch_t ivl_expr_branch(ivl_expr_t net) { - assert(net && (net->type_ == IVL_EX_BACCESS)); + assert(net); + assert(net->type_ == IVL_EX_BACCESS); return net->u_.branch_.branch; } @@ -409,29 +431,34 @@ extern "C" ivl_scope_t ivl_expr_def(ivl_expr_t net) extern "C" uint64_t ivl_expr_delay_val(ivl_expr_t net) { + assert(net); assert(net->type_ == IVL_EX_DELAY); return net->u_.delay_.value; } extern "C" double ivl_expr_dvalue(ivl_expr_t net) { + assert(net); assert(net->type_ == IVL_EX_REALNUM); return net->u_.real_.value; } extern "C" ivl_enumtype_t ivl_expr_enumtype(ivl_expr_t net) { + assert(net); assert(net->type_ == IVL_EX_ENUMTYPE); return net->u_.enumtype_.type; } extern "C" ivl_type_t ivl_expr_net_type(ivl_expr_t net) { + assert(net); return net->net_type; } extern "C" const char* ivl_expr_name(ivl_expr_t net) { + assert(net); switch (net->type_) { case IVL_EX_SFUNC: @@ -455,7 +482,8 @@ extern "C" const char* ivl_expr_name(ivl_expr_t net) extern "C" ivl_nature_t ivl_expr_nature(ivl_expr_t net) { - assert(net && (net->type_ == IVL_EX_BACCESS)); + assert(net); + assert(net->type_ == IVL_EX_BACCESS); return net->u_.branch_.nature; } @@ -685,12 +713,14 @@ extern "C" int ivl_expr_sized(ivl_expr_t net) extern "C" const char* ivl_expr_string(ivl_expr_t net) { + assert(net); assert(net->type_ == IVL_EX_STRING); return net->u_.string_.value_; } extern "C" unsigned long ivl_expr_uvalue(ivl_expr_t net) { + assert(net); switch (net->type_) { case IVL_EX_ULONG: @@ -722,7 +752,7 @@ extern "C" ivl_variable_type_t ivl_expr_value(ivl_expr_t net) extern "C" unsigned ivl_expr_width(ivl_expr_t net) { -// assert(net); + assert(net); return net->width_; } @@ -791,6 +821,7 @@ extern "C" unsigned ivl_file_table_size() extern "C" int ivl_island_flag_set(ivl_island_t net, unsigned flag, int value) { + assert(net); if (flag >= net->flags.size()) { if (value == 0) return 0; @@ -805,6 +836,7 @@ extern "C" int ivl_island_flag_set(ivl_island_t net, unsigned flag, int value) extern "C" int ivl_island_flag_test(ivl_island_t net, unsigned flag) { + assert(net); if (flag >= net->flags.size()) return 0; else @@ -847,12 +879,14 @@ extern "C" const char* ivl_logic_attr(ivl_net_logic_t net, const char*key) extern "C" unsigned ivl_logic_attr_cnt(ivl_net_logic_t net) { + assert(net); return net->nattr; } extern "C" ivl_attribute_t ivl_logic_attr_val(ivl_net_logic_t net, unsigned idx) { + assert(net); assert(idx < net->nattr); return net->attr + idx; } @@ -912,22 +946,26 @@ extern "C" ivl_scope_t ivl_logic_scope(ivl_net_logic_t net) extern "C" ivl_logic_t ivl_logic_type(ivl_net_logic_t net) { + assert(net); return net->type_; } extern "C" unsigned ivl_logic_pins(ivl_net_logic_t net) { + assert(net); return net->npins_; } extern "C" ivl_nexus_t ivl_logic_pin(ivl_net_logic_t net, unsigned pin) { + assert(net); assert(pin < net->npins_); return net->pins_[pin]; } extern "C" ivl_udp_t ivl_logic_udp(ivl_net_logic_t net) { + assert(net); assert(net->type_ == IVL_LO_UDP); assert(net->udp); return net->udp; @@ -935,6 +973,7 @@ extern "C" ivl_udp_t ivl_logic_udp(ivl_net_logic_t net) extern "C" ivl_expr_t ivl_logic_delay(ivl_net_logic_t net, unsigned transition) { + assert(net); assert(transition < 3); return net->delay[transition]; } @@ -947,21 +986,25 @@ extern "C" unsigned ivl_logic_width(ivl_net_logic_t net) extern "C" int ivl_udp_sequ(ivl_udp_t net) { + assert(net); return net->sequ; } extern "C" unsigned ivl_udp_nin(ivl_udp_t net) { + assert(net); return net->nin; } extern "C" char ivl_udp_init(ivl_udp_t net) { + assert(net); return net->init; } extern "C" const char* ivl_udp_port(ivl_udp_t net, unsigned idx) { + assert(net); assert(idx <= net->nin); assert(net->ports); assert(net->ports[idx].c_str()); @@ -970,6 +1013,7 @@ extern "C" const char* ivl_udp_port(ivl_udp_t net, unsigned idx) extern "C" const char* ivl_udp_row(ivl_udp_t net, unsigned idx) { + assert(net); assert(idx < net->nrows); assert(net->table); assert(net->table[idx]); @@ -978,27 +1022,32 @@ extern "C" const char* ivl_udp_row(ivl_udp_t net, unsigned idx) extern "C" unsigned ivl_udp_rows(ivl_udp_t net) { + assert(net); return net->nrows; } extern "C" const char* ivl_udp_name(ivl_udp_t net) { + assert(net); assert(net->name); return net->name; } extern "C" const char* ivl_udp_file(ivl_udp_t net) { + assert(net); return net->file.str(); } extern "C" unsigned ivl_udp_lineno(ivl_udp_t net) { + assert(net); return net->lineno; } extern "C" const char* ivl_lpm_basename(ivl_lpm_t net) { + assert(net); return net->name; } @@ -1028,6 +1077,7 @@ extern "C" ivl_nexus_t ivl_lpm_sync_clr(ivl_lpm_t net) extern "C" ivl_expr_t ivl_lpm_delay(ivl_lpm_t net, unsigned transition) { + assert(net); assert(transition < 3); return net->delay[transition]; } @@ -1158,11 +1208,13 @@ extern "C" ivl_nexus_t ivl_lpm_enable(ivl_lpm_t net) extern "C" const char* ivl_lpm_file(ivl_lpm_t net) { + assert(net); return net->file.str(); } extern "C" unsigned ivl_lpm_lineno(ivl_lpm_t net) { + assert(net); return net->lineno; } @@ -1302,6 +1354,7 @@ extern "C" ivl_nexus_t ivl_lpm_datab(ivl_lpm_t net, unsigned idx) */ extern "C" const char* ivl_lpm_name(ivl_lpm_t net) { + assert(net); static char*name_buffer = 0; static unsigned name_size = 0; @@ -1439,6 +1492,7 @@ extern "C" ivl_scope_t ivl_lpm_scope(ivl_lpm_t net) extern "C" ivl_nexus_t ivl_lpm_select(ivl_lpm_t net) { + assert(net); switch (net->type) { case IVL_LPM_MUX: @@ -1455,6 +1509,7 @@ extern "C" ivl_nexus_t ivl_lpm_select(ivl_lpm_t net) extern "C" unsigned ivl_lpm_selects(ivl_lpm_t net) { + assert(net); switch (net->type) { case IVL_LPM_MUX: return net->u_.mux.swid; @@ -1531,6 +1586,7 @@ extern "C" int ivl_lpm_signed(ivl_lpm_t net) extern "C" unsigned ivl_lpm_size(ivl_lpm_t net) { + assert(net); switch (net->type) { case IVL_LPM_MUX: return net->u_.mux.size; @@ -1583,12 +1639,14 @@ extern "C" unsigned ivl_lpm_size(ivl_lpm_t net) extern "C" const char* ivl_lpm_string(ivl_lpm_t net) { + assert(net); assert(net->type == IVL_LPM_SFUNC); return net->u_.sfunc.fun_name; } extern "C" ivl_lpm_type_t ivl_lpm_type(ivl_lpm_t net) { + assert(net); return net->type; } @@ -1676,6 +1734,7 @@ extern "C" ivl_lval_t ivl_lval_nest(ivl_lval_t net) extern "C" const char* ivl_nature_name(ivl_nature_t net) { + assert(net); return net->name(); } @@ -1885,16 +1944,19 @@ extern ivl_scope_t ivl_path_scope(ivl_delaypath_t obj) extern ivl_nexus_t ivl_path_source(ivl_delaypath_t net) { + assert(net); return net->src; } extern int ivl_path_source_posedge(ivl_delaypath_t net) { + assert(net); return net->posedge ? 1 : 0; } extern int ivl_path_source_negedge(ivl_delaypath_t net) { + assert(net); return net->negedge ? 1 : 0; } @@ -1912,32 +1974,38 @@ extern "C" unsigned ivl_process_lineno(ivl_process_t net) extern "C" ivl_process_type_t ivl_process_type(ivl_process_t net) { + assert(net); return net->type_; } extern "C" int ivl_process_analog(ivl_process_t net) { + assert(net); return net->analog_flag != 0; } extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net) { + assert(net); return net->scope_; } extern "C" ivl_statement_t ivl_process_stmt(ivl_process_t net) { + assert(net); return net->stmt_; } extern "C" unsigned ivl_process_attr_cnt(ivl_process_t net) { + assert(net); return net->nattr; } extern "C" ivl_attribute_t ivl_process_attr_val(ivl_process_t net, unsigned idx) { + assert(net); assert(idx < net->nattr); return net->attr + idx; } @@ -1951,6 +2019,7 @@ extern "C" unsigned ivl_scope_attr_cnt(ivl_scope_t net) extern "C" ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net, unsigned idx) { + assert(net); assert(idx < net->nattr); return net->attr + idx; } @@ -1958,7 +2027,6 @@ extern "C" ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net, extern "C" const char* ivl_scope_basename(ivl_scope_t net) { assert(net); - return net->name_; } @@ -1978,24 +2046,28 @@ extern "C" int ivl_scope_children(ivl_scope_t net, extern "C" size_t ivl_scope_childs(ivl_scope_t net) { + assert(net); assert(net->child.size() == net->children.size()); return net->child.size(); } extern "C" ivl_scope_t ivl_scope_child(ivl_scope_t net, size_t idx) { - assert(net && idx < net->child.size()); + assert(net); + assert(idx < net->child.size()); return net->child[idx]; } extern "C" ivl_type_t ivl_scope_class(ivl_scope_t net, unsigned idx) { + assert(net); assert(idx < net->classes.size()); return net->classes[idx]; } extern "C" unsigned ivl_scope_classes(ivl_scope_t net) { + assert(net); return net->classes.size(); } @@ -2129,6 +2201,7 @@ static unsigned scope_name_len(ivl_scope_t net) static void push_scope_basename(ivl_scope_t net, char*buf) { + assert(net); if (net->parent == 0) { strcpy(buf, net->name_); return; @@ -2141,6 +2214,7 @@ static void push_scope_basename(ivl_scope_t net, char*buf) extern "C" const char* ivl_scope_name(ivl_scope_t net) { + assert(net); static char*name_buffer = 0; static unsigned name_size = 0; @@ -2183,21 +2257,22 @@ extern "C" ivl_scope_t ivl_scope_parent(ivl_scope_t net) extern "C" unsigned ivl_scope_mod_module_ports(ivl_scope_t net) { assert(net); - assert (net->type_ == IVL_SCT_MODULE ); + assert(net->type_ == IVL_SCT_MODULE ); return static_cast(net->module_ports_info.size()); } extern "C" const char *ivl_scope_mod_module_port_name(ivl_scope_t net, unsigned idx ) { assert(net); - assert (net->type_ == IVL_SCT_MODULE ); - assert( idx < net->module_ports_info.size()); + assert(net->type_ == IVL_SCT_MODULE ); + assert(idx < net->module_ports_info.size()); return net->module_ports_info[idx].name; } extern "C" ivl_signal_port_t ivl_scope_mod_module_port_type(ivl_scope_t net, unsigned idx ) { + assert(net); switch( net->module_ports_info[idx].type ) { case PortType::PINPUT : return IVL_SIP_INPUT; @@ -2209,6 +2284,7 @@ extern "C" ivl_signal_port_t ivl_scope_mod_module_port_type(ivl_scope_t net, uns extern "C" unsigned ivl_scope_mod_module_port_width(ivl_scope_t net, unsigned idx ) { + assert(net); return net->module_ports_info[idx].width; } @@ -2291,31 +2367,37 @@ extern "C" const char* ivl_scope_tname(ivl_scope_t net) extern "C" int ivl_signal_array_base(ivl_signal_t net) { + assert(net); return net->array_base; } extern "C" unsigned ivl_signal_array_count(ivl_signal_t net) { + assert(net); return net->array_words; } extern "C" unsigned ivl_signal_array_addr_swapped(ivl_signal_t net) { + assert(net); return net->array_addr_swapped; } extern "C" unsigned ivl_signal_dimensions(ivl_signal_t net) { + assert(net); return net->array_dimensions_; } extern "C" ivl_discipline_t ivl_signal_discipline(ivl_signal_t net) { + assert(net); return net->discipline; } extern "C" const char* ivl_signal_attr(ivl_signal_t net, const char*key) { + assert(net); if (net->nattr == 0) return 0; @@ -2331,22 +2413,26 @@ extern "C" const char* ivl_signal_attr(ivl_signal_t net, const char*key) extern "C" unsigned ivl_signal_attr_cnt(ivl_signal_t net) { + assert(net); return net->nattr; } extern "C" ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx) { + assert(net); assert(idx < net->nattr); return net->attr + idx; } extern "C" const char* ivl_signal_basename(ivl_signal_t net) { + assert(net); return net->name_; } extern "C" const char* ivl_signal_name(ivl_signal_t net) { + assert(net); static char*name_buffer = 0; static unsigned name_size = 0; @@ -2367,6 +2453,7 @@ extern "C" const char* ivl_signal_name(ivl_signal_t net) extern "C" ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word) { + assert(net); assert(word < net->array_words); if (net->array_words > 1) { if (net->pins) { @@ -2383,23 +2470,27 @@ extern "C" ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word) extern "C" unsigned ivl_signal_packed_dimensions(ivl_signal_t net) { + assert(net); return net->packed_dims.size(); } extern "C" int ivl_signal_packed_msb(ivl_signal_t net, unsigned dim) { + assert(net); assert(dim < net->packed_dims.size()); return net->packed_dims[dim].get_msb(); } extern "C" int ivl_signal_packed_lsb(ivl_signal_t net, unsigned dim) { + assert(net); assert(dim < net->packed_dims.size()); return net->packed_dims[dim].get_lsb(); } extern "C" int ivl_signal_msb(ivl_signal_t net) { + assert(net); if (net->packed_dims.empty()) return 0; @@ -2409,6 +2500,7 @@ extern "C" int ivl_signal_msb(ivl_signal_t net) extern "C" int ivl_signal_lsb(ivl_signal_t net) { + assert(net); if (net->packed_dims.empty()) return 0; @@ -2424,31 +2516,39 @@ extern "C" ivl_scope_t ivl_signal_scope(ivl_signal_t net) extern "C" unsigned ivl_signal_width(ivl_signal_t net) { + assert(net); + assert(net->net_type); return net->net_type->packed_width(); } extern "C" ivl_signal_port_t ivl_signal_port(ivl_signal_t net) { + assert(net); return net->port_; } extern "C" int ivl_signal_module_port_index(ivl_signal_t net) { + assert(net); return net->module_port_index_; } extern "C" int ivl_signal_local(ivl_signal_t net) { + assert(net); return net->local_; } extern "C" int ivl_signal_signed(ivl_signal_t net) { + assert(net); + assert(net->net_type); return net->net_type->get_signed()? 1 : 0; } extern "C" unsigned ivl_signal_forced_net(ivl_signal_t net) { + assert(net); return net->forced_net_; } @@ -2466,6 +2566,7 @@ extern "C" unsigned ivl_signal_lineno(ivl_signal_t net) extern "C" int ivl_signal_integer(ivl_signal_t net) { + assert(net); if (const netvector_t*vec = dynamic_cast (net->net_type)) return vec->get_isint()? 1 : 0; else if (const netenum_t*enm = dynamic_cast (net->net_type)) @@ -2476,47 +2577,57 @@ extern "C" int ivl_signal_integer(ivl_signal_t net) extern "C" ivl_variable_type_t ivl_signal_data_type(ivl_signal_t net) { + assert(net); + assert(net->net_type); return net->net_type->base_type(); } extern "C" ivl_type_t ivl_signal_net_type(ivl_signal_t net) { + assert(net); return net->net_type; } extern "C" unsigned ivl_signal_npath(ivl_signal_t net) { + assert(net); return net->npath; } extern "C" ivl_delaypath_t ivl_signal_path(ivl_signal_t net, unsigned idx) { + assert(net); assert(idx < net->npath); return net->path + idx; } extern "C" ivl_signal_type_t ivl_signal_type(ivl_signal_t net) { + assert(net); return net->type_; } extern "C" ivl_statement_type_t ivl_statement_type(ivl_statement_t net) { + assert(net); return net->type_; } extern "C" const char* ivl_stmt_file(ivl_statement_t net) { + assert(net); return net->file.str(); } extern "C" unsigned ivl_stmt_lineno(ivl_statement_t net) { + assert(net); return net->lineno; } extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_BLOCK: case IVL_ST_FORK: @@ -2531,6 +2642,7 @@ extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net) extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_BLOCK: case IVL_ST_FORK: @@ -2546,6 +2658,7 @@ extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net) extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net, unsigned i) { + assert(net); switch (net->type_) { case IVL_ST_BLOCK: case IVL_ST_FORK: @@ -2560,6 +2673,7 @@ extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net, extern "C" ivl_scope_t ivl_stmt_call(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ALLOC: return net->u_.alloc_.scope; @@ -2580,6 +2694,7 @@ extern "C" ivl_scope_t ivl_stmt_call(ivl_statement_t net) extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_CASE: case IVL_ST_CASER: @@ -2594,6 +2709,7 @@ extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net) extern "C" ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned idx) { + assert(net); switch (net->type_) { case IVL_ST_CASE: case IVL_ST_CASER: @@ -2610,6 +2726,7 @@ extern "C" ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned idx) extern "C" ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned idx) { + assert(net); switch (net->type_) { case IVL_ST_CASE: case IVL_ST_CASER: @@ -2626,6 +2743,7 @@ extern "C" ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned idx) extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN_NB: return net->u_.assign_.count; @@ -2652,6 +2770,7 @@ extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net) extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net) { + assert(net); assert(net->type_ == IVL_ST_CONDIT); if (net->u_.condit_.stmt_[1].type_ == IVL_ST_NONE) return 0; @@ -2661,6 +2780,7 @@ extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net) extern "C" ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net) { + assert(net); assert(net->type_ == IVL_ST_CONDIT); if (net->u_.condit_.stmt_[0].type_ == IVL_ST_NONE) return 0; @@ -2670,6 +2790,7 @@ extern "C" ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net) extern "C" ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN: case IVL_ST_ASSIGN_NB: @@ -2686,12 +2807,14 @@ extern "C" ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net) extern "C" uint64_t ivl_stmt_delay_val(ivl_statement_t net) { + assert(net); assert(net->type_ == IVL_ST_DELAY); return net->u_.delay_.value; } extern "C" unsigned ivl_stmt_nevent(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN_NB: return net->u_.assign_.nevent; @@ -2710,6 +2833,7 @@ extern "C" unsigned ivl_stmt_nevent(ivl_statement_t net) extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN_NB: assert(idx < net->u_.assign_.nevent); @@ -2737,6 +2861,7 @@ extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx) extern "C" ivl_expr_t ivl_stmt_lexp(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_CONTRIB: return net->u_.contrib_.lval; @@ -2748,6 +2873,7 @@ extern "C" ivl_expr_t ivl_stmt_lexp(ivl_statement_t net) extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN: case IVL_ST_ASSIGN_NB: @@ -2766,6 +2892,7 @@ extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx) extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN: case IVL_ST_ASSIGN_NB: @@ -2783,6 +2910,7 @@ extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net) extern "C" unsigned ivl_stmt_lwidth(ivl_statement_t net) { + assert(net); assert((net->type_ == IVL_ST_ASSIGN) || (net->type_ == IVL_ST_ASSIGN_NB) || (net->type_ == IVL_ST_CASSIGN) @@ -2815,6 +2943,7 @@ extern "C" unsigned ivl_stmt_lwidth(ivl_statement_t net) extern "C" const char* ivl_stmt_name(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_STASK: return net->u_.stask_.name_; @@ -2827,6 +2956,7 @@ extern "C" const char* ivl_stmt_name(ivl_statement_t net) extern "C" char ivl_stmt_opcode(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN: return net->u_.assign_.oper; @@ -2838,6 +2968,7 @@ extern "C" char ivl_stmt_opcode(ivl_statement_t net) extern "C" ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx) { + assert(net); switch (net->type_) { case IVL_ST_STASK: assert(idx < net->u_.stask_.nparm_); @@ -2851,6 +2982,7 @@ extern "C" ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx) extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_STASK: return net->u_.stask_.nparm_; @@ -2862,6 +2994,7 @@ extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net) extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_ASSIGN: case IVL_ST_ASSIGN_NB: @@ -2879,6 +3012,7 @@ extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net) extern "C" ivl_sfunc_as_task_t ivl_stmt_sfunc_as_task(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_STASK: return net->u_.stask_.sfunc_as_task_; @@ -2891,6 +3025,7 @@ extern "C" ivl_sfunc_as_task_t ivl_stmt_sfunc_as_task(ivl_statement_t net) extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net) { + assert(net); switch (net->type_) { case IVL_ST_DELAY: return net->u_.delay_.stmt_; @@ -2913,67 +3048,80 @@ extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net) extern "C" const char*ivl_switch_basename(ivl_switch_t net) { + assert(net); return net->name; } extern "C" ivl_scope_t ivl_switch_scope(ivl_switch_t net) { + assert(net); return net->scope; } extern "C" ivl_switch_type_t ivl_switch_type(ivl_switch_t net) { + assert(net); return net->type; } extern "C" ivl_nexus_t ivl_switch_a(ivl_switch_t net) { + assert(net); return net->pins[0]; } extern "C" ivl_nexus_t ivl_switch_b(ivl_switch_t net) { + assert(net); return net->pins[1]; } extern "C" ivl_nexus_t ivl_switch_enable(ivl_switch_t net) { + assert(net); return net->pins[2]; } extern "C" unsigned ivl_switch_width(ivl_switch_t net) { + assert(net); return net->width; } extern "C" unsigned ivl_switch_part(ivl_switch_t net) { + assert(net); return net->part; } extern "C" unsigned ivl_switch_offset(ivl_switch_t net) { + assert(net); return net->offset; } extern "C" ivl_expr_t ivl_switch_delay(ivl_switch_t net, unsigned transition) { + assert(net); assert(transition < 3); return net->delay[transition]; } extern "C" const char* ivl_switch_file(ivl_switch_t net) { + assert(net); return net->file; } extern "C" ivl_island_t ivl_switch_island(ivl_switch_t net) { + assert(net); return net->island; } extern "C" unsigned ivl_switch_lineno(ivl_switch_t net) { + assert(net); return net->lineno; } @@ -2994,12 +3142,14 @@ extern "C" ivl_type_t ivl_type_element(ivl_type_t net) extern "C" unsigned ivl_type_packed_dimensions(ivl_type_t net) { + assert(net); vector slice = net->slice_dimensions(); return slice.size(); } extern "C" int ivl_type_packed_lsb(ivl_type_t net, unsigned dim) { + assert(net); vector slice = net->slice_dimensions(); assert(dim < slice.size()); return slice[dim].get_lsb(); @@ -3007,6 +3157,7 @@ extern "C" int ivl_type_packed_lsb(ivl_type_t net, unsigned dim) extern "C" int ivl_type_packed_msb(ivl_type_t net, unsigned dim) { + assert(net); vector slice = net->slice_dimensions(); assert(dim < slice.size()); return slice[dim].get_msb(); @@ -3014,9 +3165,8 @@ extern "C" int ivl_type_packed_msb(ivl_type_t net, unsigned dim) extern "C" const char* ivl_type_name(ivl_type_t net) { - if (const netclass_t*class_type = dynamic_cast(net)) { + if (const netclass_t*class_type = dynamic_cast(net)) return class_type->get_name(); - } return 0; } @@ -3048,5 +3198,6 @@ extern "C" ivl_type_t ivl_type_prop_type(ivl_type_t net, int idx) extern "C" int ivl_type_signed(ivl_type_t net) { + assert(net); return net->get_signed()? 1 : 0; }