Fix for assertion error when expanding macro.
[iverilog.git] / t-dll-api.cc
blob191e130e8ff505876ff47de9c969fcdac4c133c1
1 /*
2 * Copyright (c) 2000 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: t-dll-api.cc,v 1.144 2007/04/02 01:12:34 steve Exp $"
21 #endif
23 # include "config.h"
24 # include "StringHeap.h"
25 # include "t-dll.h"
26 # include <stdlib.h>
27 # include <string.h>
28 #ifdef HAVE_MALLOC_H
29 # include <malloc.h>
30 #endif
32 static StringHeap api_strings;
34 /* THE FOLLOWING ARE FUNCTIONS THAT ARE CALLED FROM THE TARGET. */
36 extern "C" const char*ivl_design_flag(ivl_design_t des, const char*key)
38 return des->self->get_flag(key);
41 extern "C" int ivl_design_process(ivl_design_t des,
42 ivl_process_f func,
43 void*cd)
45 for (ivl_process_t idx = des->threads_; idx; idx = idx->next_) {
46 int rc = (func)(idx, cd);
47 if (rc != 0)
48 return rc;
51 return 0;
54 extern "C" ivl_scope_t ivl_design_root(ivl_design_t des)
56 cerr << "ANACHRONISM: ivl_design_root called. "
57 "Use ivl_design_roots instead." << endl;
59 assert (des->nroots_);
60 return des->roots_[0];
63 extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes,
64 unsigned int *nscopes)
66 assert (nscopes && scopes);
67 *scopes = &des->roots_[0];
68 *nscopes = des->nroots_;
71 extern "C" int ivl_design_time_precision(ivl_design_t des)
73 return des->time_precision;
76 extern "C" unsigned ivl_design_consts(ivl_design_t des)
78 return des->nconsts;
81 extern "C" ivl_net_const_t ivl_design_const(ivl_design_t des, unsigned idx)
83 assert(idx < des->nconsts);
84 return des->consts[idx];
87 extern "C" ivl_expr_type_t ivl_expr_type(ivl_expr_t net)
89 if (net == 0)
90 return IVL_EX_NONE;
91 return net->type_;
95 inline static const char *basename(ivl_scope_t scope, const char *inst)
97 inst += strlen(ivl_scope_name(scope));
98 assert(*inst == '.');
99 return inst+1;
102 extern "C" ivl_variable_type_t ivl_const_type(ivl_net_const_t net)
104 assert(net);
105 return net->type;
108 extern "C" const char*ivl_const_bits(ivl_net_const_t net)
110 assert(net);
111 switch (net->type) {
113 case IVL_VT_LOGIC:
114 if (net->width_ <= sizeof(net->b.bit_))
115 return net->b.bit_;
116 else
117 return net->b.bits_;
119 default:
120 return 0;
124 extern "C" ivl_nexus_t ivl_const_nex(ivl_net_const_t net)
126 assert(net);
127 return net->pin_;
130 extern "C" double ivl_const_real(ivl_net_const_t net)
132 assert(net);
133 assert(net->type == IVL_VT_REAL);
134 return net->b.real_value;
137 extern "C" int ivl_const_signed(ivl_net_const_t net)
139 assert(net);
140 return net->signed_;
143 extern "C" unsigned ivl_const_width(ivl_net_const_t net)
145 assert(net);
146 return net->width_;
149 extern "C" const char* ivl_event_name(ivl_event_t net)
151 static char*name_buffer = 0;
152 static unsigned name_size = 0;
154 ivl_scope_t scope = net->scope;
155 const char*sn = ivl_scope_name(scope);
157 unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
158 if (need > name_size) {
159 name_buffer = (char*)realloc(name_buffer, need);
160 name_size = need;
163 strcpy(name_buffer, sn);
164 char*tmp = name_buffer + strlen(sn);
165 *tmp++ = '.';
166 strcpy(tmp, net->name);
168 cerr << "ANACHRONISM: Call to anachronistic ivl_event_name." << endl;
170 return name_buffer;
173 extern "C" const char* ivl_event_basename(ivl_event_t net)
175 return net->name;
178 extern "C" ivl_scope_t ivl_event_scope(ivl_event_t net)
180 return net->scope;
183 extern "C" unsigned ivl_event_nany(ivl_event_t net)
185 assert(net);
186 return net->nany;
189 extern "C" ivl_nexus_t ivl_event_any(ivl_event_t net, unsigned idx)
191 assert(net);
192 assert(idx < net->nany);
193 return net->pins[idx];
196 extern "C" unsigned ivl_event_nneg(ivl_event_t net)
198 assert(net);
199 return net->nneg;
202 extern "C" ivl_nexus_t ivl_event_neg(ivl_event_t net, unsigned idx)
204 assert(net);
205 assert(idx < net->nneg);
206 return net->pins[net->nany + idx];
209 extern "C" unsigned ivl_event_npos(ivl_event_t net)
211 assert(net);
212 return net->npos;
215 extern "C" ivl_nexus_t ivl_event_pos(ivl_event_t net, unsigned idx)
217 assert(net);
218 assert(idx < net->npos);
219 return net->pins[net->nany + net->nneg + idx];
222 extern "C" const char* ivl_expr_bits(ivl_expr_t net)
224 assert(net && (net->type_ == IVL_EX_NUMBER));
225 return net->u_.number_.bits_;
228 extern "C" ivl_scope_t ivl_expr_def(ivl_expr_t net)
230 assert(net);
232 switch (net->type_) {
234 case IVL_EX_UFUNC:
235 return net->u_.ufunc_.def;
237 default:
238 assert(0);
241 return 0;
244 extern "C" double ivl_expr_dvalue(ivl_expr_t net)
246 assert(net->type_ == IVL_EX_REALNUM);
247 return net->u_.real_.value;
250 extern "C" const char* ivl_expr_name(ivl_expr_t net)
252 switch (net->type_) {
254 case IVL_EX_SFUNC:
255 return net->u_.sfunc_.name_;
257 case IVL_EX_SIGNAL:
258 return net->u_.signal_.sig->name_;
260 default:
261 assert(0);
263 return 0;
266 extern "C" char ivl_expr_opcode(ivl_expr_t net)
268 assert(net);
269 switch (net->type_) {
270 case IVL_EX_BINARY:
271 return net->u_.binary_.op_;
273 case IVL_EX_UNARY:
274 return net->u_.unary_.op_;
276 default:
277 assert(0);
279 return 0;
282 extern "C" ivl_expr_t ivl_expr_oper1(ivl_expr_t net)
284 assert(net);
285 switch (net->type_) {
286 case IVL_EX_BINARY:
287 case IVL_EX_SELECT:
288 return net->u_.binary_.lef_;
290 case IVL_EX_UNARY:
291 return net->u_.unary_.sub_;
293 case IVL_EX_MEMORY:
294 return net->u_.memory_.idx_;
296 case IVL_EX_SIGNAL:
297 return net->u_.signal_.word;
299 case IVL_EX_TERNARY:
300 return net->u_.ternary_.cond;
302 default:
303 assert(0);
306 return 0;
309 extern "C" ivl_expr_t ivl_expr_oper2(ivl_expr_t net)
311 assert(net);
312 switch (net->type_) {
313 case IVL_EX_BINARY:
314 case IVL_EX_SELECT:
315 return net->u_.binary_.rig_;
317 case IVL_EX_TERNARY:
318 return net->u_.ternary_.true_e;
320 default:
321 assert(0);
324 return 0;
327 extern "C" ivl_expr_t ivl_expr_oper3(ivl_expr_t net)
329 assert(net);
330 switch (net->type_) {
332 case IVL_EX_TERNARY:
333 return net->u_.ternary_.false_e;
335 default:
336 assert(0);
338 return 0;
341 extern "C" ivl_parameter_t ivl_expr_parameter(ivl_expr_t net)
343 switch (net->type_) {
344 case IVL_EX_NUMBER:
345 return net->u_.number_.parameter;
346 case IVL_EX_STRING:
347 return net->u_.string_.parameter;
348 case IVL_EX_REALNUM:
349 return net->u_.real_.parameter;
350 default:
351 return 0;
355 extern "C" ivl_expr_t ivl_expr_parm(ivl_expr_t net, unsigned idx)
357 assert(net);
358 switch (net->type_) {
360 case IVL_EX_CONCAT:
361 assert(idx < net->u_.concat_.parms);
362 return net->u_.concat_.parm[idx];
364 case IVL_EX_SFUNC:
365 assert(idx < net->u_.sfunc_.parms);
366 return net->u_.sfunc_.parm[idx];
368 case IVL_EX_UFUNC:
369 assert(idx < net->u_.ufunc_.parms);
370 return net->u_.ufunc_.parm[idx];
372 default:
373 assert(0);
374 return 0;
378 extern "C" unsigned ivl_expr_parms(ivl_expr_t net)
380 assert(net);
381 switch (net->type_) {
383 case IVL_EX_CONCAT:
384 return net->u_.concat_.parms;
386 case IVL_EX_SFUNC:
387 return net->u_.sfunc_.parms;
389 case IVL_EX_UFUNC:
390 return net->u_.ufunc_.parms;
392 default:
393 assert(0);
394 return 0;
398 extern "C" unsigned ivl_expr_repeat(ivl_expr_t net)
400 assert(net);
401 assert(net->type_ == IVL_EX_CONCAT);
402 return net->u_.concat_.rept;
405 extern "C" ivl_event_t ivl_expr_event(ivl_expr_t net)
407 assert(net);
408 assert(net->type_ == IVL_EX_EVENT);
409 return net->u_.event_.event;
412 extern "C" ivl_scope_t ivl_expr_scope(ivl_expr_t net)
414 assert(net);
415 assert(net->type_ == IVL_EX_SCOPE);
416 return net->u_.scope_.scope;
419 extern "C" ivl_signal_t ivl_expr_signal(ivl_expr_t net)
421 assert(net);
422 switch (net->type_) {
424 case IVL_EX_SIGNAL:
425 case IVL_EX_ARRAY:
426 return net->u_.signal_.sig;
428 default:
429 assert(0);
430 return 0;
434 extern "C" int ivl_expr_signed(ivl_expr_t net)
436 assert(net);
437 return net->signed_;
440 extern "C" const char* ivl_expr_string(ivl_expr_t net)
442 assert(net->type_ == IVL_EX_STRING);
443 return net->u_.string_.value_;
446 extern "C" unsigned long ivl_expr_uvalue(ivl_expr_t net)
448 switch (net->type_) {
450 case IVL_EX_ULONG:
451 return net->u_.ulong_.value;
453 case IVL_EX_NUMBER: {
454 unsigned long val = 0;
455 for (unsigned long idx = 0 ; idx < net->width_ ; idx += 1) {
456 if (net->u_.number_.bits_[idx] == '1')
457 val |= 1UL << idx;
460 return val;
463 default:
464 assert(0);
469 extern "C" ivl_variable_type_t ivl_expr_value(ivl_expr_t net)
471 assert(net);
472 return net->value_;
475 extern "C" unsigned ivl_expr_width(ivl_expr_t net)
477 assert(net);
478 return net->width_;
481 extern "C" const char* ivl_logic_attr(ivl_net_logic_t net, const char*key)
483 assert(net);
484 unsigned idx;
486 for (idx = 0 ; idx < net->nattr ; idx += 1) {
488 if (strcmp(net->attr[idx].key, key) == 0)
489 return net->attr[idx].type == IVL_ATT_STR
490 ? net->attr[idx].val.str
491 : 0;
494 return 0;
497 extern "C" unsigned ivl_logic_attr_cnt(ivl_net_logic_t net)
499 return net->nattr;
502 extern "C" ivl_attribute_t ivl_logic_attr_val(ivl_net_logic_t net,
503 unsigned idx)
505 assert(idx < net->nattr);
506 return net->attr + idx;
509 extern "C" ivl_drive_t ivl_logic_drive0(ivl_net_logic_t net)
511 ivl_nexus_t nex = ivl_logic_pin(net, 0);
513 for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
514 ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
515 if (ivl_nexus_ptr_log(cur) != net)
516 continue;
517 if (ivl_nexus_ptr_pin(cur) != 0)
518 continue;
519 return ivl_nexus_ptr_drive0(cur);
522 assert(0);
523 return IVL_DR_STRONG;
526 extern "C" ivl_drive_t ivl_logic_drive1(ivl_net_logic_t net)
528 ivl_nexus_t nex = ivl_logic_pin(net, 0);
530 for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
531 ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
532 if (ivl_nexus_ptr_log(cur) != net)
533 continue;
534 if (ivl_nexus_ptr_pin(cur) != 0)
535 continue;
536 return ivl_nexus_ptr_drive1(cur);
539 assert(0);
540 return IVL_DR_STRONG;
543 extern "C" const char* ivl_logic_name(ivl_net_logic_t net)
545 assert(net);
546 cerr << "ANACHRONISM: Call to anachronistic ivl_logic_name." << endl;
547 return net->name_;
550 extern "C" const char* ivl_logic_basename(ivl_net_logic_t net)
552 assert(net);
553 return net->name_;
556 extern "C" ivl_scope_t ivl_logic_scope(ivl_net_logic_t net)
558 assert(net);
559 return net->scope_;
562 extern "C" ivl_logic_t ivl_logic_type(ivl_net_logic_t net)
564 return net->type_;
567 extern "C" unsigned ivl_logic_pins(ivl_net_logic_t net)
569 return net->npins_;
572 extern "C" ivl_nexus_t ivl_logic_pin(ivl_net_logic_t net, unsigned pin)
574 assert(pin < net->npins_);
575 return net->pins_[pin];
578 extern "C" ivl_udp_t ivl_logic_udp(ivl_net_logic_t net)
580 assert(net->type_ == IVL_LO_UDP);
581 assert(net->udp);
582 return net->udp;
585 extern "C" ivl_expr_t ivl_logic_delay(ivl_net_logic_t net, unsigned transition)
587 assert(transition < 3);
588 return net->delay[transition];
591 extern "C" unsigned ivl_logic_width(ivl_net_logic_t net)
593 assert(net);
594 return net->width_;
597 extern "C" int ivl_udp_sequ(ivl_udp_t net)
599 return net->sequ;
602 extern "C" unsigned ivl_udp_nin(ivl_udp_t net)
604 return net->nin;
607 extern "C" unsigned ivl_udp_init(ivl_udp_t net)
609 return net->init;
612 extern "C" const char* ivl_udp_row(ivl_udp_t net, unsigned idx)
614 assert(idx < net->nrows);
615 assert(net->table);
616 assert(net->table[idx]);
617 return net->table[idx];
620 extern "C" unsigned ivl_udp_rows(ivl_udp_t net)
622 return net->nrows;
625 extern "C" const char* ivl_udp_name(ivl_udp_t net)
627 assert(net->name);
628 return net->name;
631 extern "C" const char* ivl_lpm_basename(ivl_lpm_t net)
633 return net->name;
636 extern "C" ivl_nexus_t ivl_lpm_async_clr(ivl_lpm_t net)
638 assert(net);
639 switch(net->type) {
640 case IVL_LPM_FF:
641 return net->u_.ff.aclr;
642 default:
643 assert(0);
644 return 0;
648 extern "C" ivl_nexus_t ivl_lpm_sync_clr(ivl_lpm_t net)
650 assert(net);
651 switch(net->type) {
652 case IVL_LPM_FF:
653 return net->u_.ff.sclr;
654 default:
655 assert(0);
656 return 0;
660 extern "C" ivl_nexus_t ivl_lpm_async_set(ivl_lpm_t net)
662 assert(net);
663 switch(net->type) {
664 case IVL_LPM_FF:
665 return net->u_.ff.aset;
666 default:
667 assert(0);
668 return 0;
672 extern "C" ivl_nexus_t ivl_lpm_sync_set(ivl_lpm_t net)
674 assert(net);
675 switch(net->type) {
676 case IVL_LPM_FF:
677 return net->u_.ff.sset;
678 default:
679 assert(0);
680 return 0;
684 extern "C" ivl_signal_t ivl_lpm_array(ivl_lpm_t net)
686 assert(net);
687 switch (net->type) {
688 case IVL_LPM_ARRAY:
689 return net->u_.array.sig;
690 default:
691 assert(0);
692 return 0;
696 extern "C" unsigned ivl_lpm_base(ivl_lpm_t net)
698 assert(net);
699 switch (net->type) {
700 case IVL_LPM_PART_VP:
701 case IVL_LPM_PART_PV:
702 case IVL_LPM_PART_BI:
703 return net->u_.part.base;
704 default:
705 assert(0);
706 return 0;
710 extern "C" ivl_nexus_t ivl_lpm_clk(ivl_lpm_t net)
712 assert(net);
713 switch (net->type) {
714 case IVL_LPM_FF:
715 return net->u_.ff.clk;
716 default:
717 assert(0);
718 return 0;
722 extern "C" ivl_expr_t ivl_lpm_aset_value(ivl_lpm_t net)
724 assert(net);
725 switch (net->type) {
726 case IVL_LPM_FF:
727 return net->u_.ff.aset_value;
728 default:
729 assert(0);
730 return 0;
733 extern "C" ivl_expr_t ivl_lpm_sset_value(ivl_lpm_t net)
735 assert(net);
736 switch (net->type) {
737 case IVL_LPM_FF:
738 return net->u_.ff.sset_value;
739 default:
740 assert(0);
741 return 0;
745 extern "C" ivl_scope_t ivl_lpm_define(ivl_lpm_t net)
747 assert(net);
748 switch (net->type) {
749 case IVL_LPM_UFUNC:
750 return net->u_.ufunc.def;
751 default:
752 assert(0);
753 return 0;
757 extern "C" ivl_nexus_t ivl_lpm_enable(ivl_lpm_t net)
759 assert(net);
760 switch (net->type) {
761 case IVL_LPM_FF:
762 return net->u_.ff.we;
763 default:
764 assert(0);
765 return 0;
769 extern "C" ivl_nexus_t ivl_lpm_data(ivl_lpm_t net, unsigned idx)
771 assert(net);
772 switch (net->type) {
773 case IVL_LPM_ADD:
774 case IVL_LPM_CMP_EEQ:
775 case IVL_LPM_CMP_EQ:
776 case IVL_LPM_CMP_GE:
777 case IVL_LPM_CMP_GT:
778 case IVL_LPM_CMP_NE:
779 case IVL_LPM_CMP_NEE:
780 case IVL_LPM_DIVIDE:
781 case IVL_LPM_MOD:
782 case IVL_LPM_MULT:
783 case IVL_LPM_SUB:
784 assert(idx <= 1);
785 if (idx == 0)
786 return net->u_.arith.a;
787 else
788 return net->u_.arith.b;
790 case IVL_LPM_MUX:
791 assert(idx < net->u_.mux.size);
792 return net->u_.mux.d[idx];
794 case IVL_LPM_RE_AND:
795 case IVL_LPM_RE_OR:
796 case IVL_LPM_RE_XOR:
797 case IVL_LPM_RE_NAND:
798 case IVL_LPM_RE_NOR:
799 case IVL_LPM_RE_XNOR:
800 case IVL_LPM_SIGN_EXT:
801 assert(idx == 0);
802 return net->u_.reduce.a;
804 case IVL_LPM_SHIFTL:
805 case IVL_LPM_SHIFTR:
806 assert(idx <= 1);
807 if (idx == 0)
808 return net->u_.shift.d;
809 else
810 return net->u_.shift.s;
812 case IVL_LPM_FF:
813 assert(idx == 0);
814 return net->u_.ff.d.pin;
816 case IVL_LPM_CONCAT:
817 assert(idx < net->u_.concat.inputs);
818 return net->u_.concat.pins[idx+1];
820 case IVL_LPM_PART_VP:
821 case IVL_LPM_PART_PV:
822 case IVL_LPM_PART_BI:
823 assert(idx <= 1);
824 if (idx == 0)
825 return net->u_.part.a;
826 else
827 return net->u_.part.s;
829 case IVL_LPM_REPEAT:
830 assert(idx == 0);
831 return net->u_.repeat.a;
833 case IVL_LPM_SFUNC:
834 // Skip the return port.
835 assert(idx < (net->u_.sfunc.ports-1));
836 return net->u_.sfunc.pins[idx+1];
838 case IVL_LPM_UFUNC:
839 // Skip the return port.
840 assert(idx < (net->u_.ufunc.ports-1));
841 return net->u_.ufunc.pins[idx+1];
843 default:
844 assert(0);
845 return 0;
849 extern "C" ivl_nexus_t ivl_lpm_datab(ivl_lpm_t net, unsigned idx)
851 cerr << "ANACHRONISM: Call to anachronistic ivl_lpm_datab." << endl;
852 assert(net);
853 switch (net->type) {
855 case IVL_LPM_ADD:
856 case IVL_LPM_CMP_EQ:
857 case IVL_LPM_CMP_GE:
858 case IVL_LPM_CMP_GT:
859 case IVL_LPM_CMP_NE:
860 case IVL_LPM_DIVIDE:
861 case IVL_LPM_MOD:
862 case IVL_LPM_MULT:
863 case IVL_LPM_SUB:
864 assert(idx == 0);
865 return net->u_.arith.b;
867 default:
868 assert(0);
869 return 0;
875 * This function returns the hierarchical name for the LPM device. The
876 * name needs to be built up from the scope name and the lpm base
877 * name.
879 * Anachronism: This function is provided for
880 * compatibility. Eventually, it will be removed.
882 extern "C" const char* ivl_lpm_name(ivl_lpm_t net)
884 static char*name_buffer = 0;
885 static unsigned name_size = 0;
887 ivl_scope_t scope = ivl_lpm_scope(net);
888 const char*sn = ivl_scope_name(scope);
890 unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
891 if (need > name_size) {
892 name_buffer = (char*)realloc(name_buffer, need);
893 name_size = need;
896 strcpy(name_buffer, sn);
897 char*tmp = name_buffer + strlen(sn);
898 *tmp++ = '.';
899 strcpy(tmp, net->name);
900 return name_buffer;
904 extern "C" ivl_nexus_t ivl_lpm_q(ivl_lpm_t net, unsigned idx)
906 assert(net);
908 switch (net->type) {
909 case IVL_LPM_ADD:
910 case IVL_LPM_DIVIDE:
911 case IVL_LPM_MOD:
912 case IVL_LPM_MULT:
913 case IVL_LPM_SUB:
914 assert(idx == 0);
915 return net->u_.arith.q;
917 case IVL_LPM_CMP_GE:
918 case IVL_LPM_CMP_GT:
919 case IVL_LPM_CMP_EQ:
920 case IVL_LPM_CMP_NE:
921 case IVL_LPM_CMP_EEQ:
922 case IVL_LPM_CMP_NEE:
923 assert(idx == 0);
924 return net->u_.arith.q;
926 case IVL_LPM_FF:
927 assert(idx == 0);
928 return net->u_.ff.q.pin;
930 case IVL_LPM_MUX:
931 assert(idx == 0);
932 return net->u_.mux.q;
934 case IVL_LPM_RE_AND:
935 case IVL_LPM_RE_OR:
936 case IVL_LPM_RE_XOR:
937 case IVL_LPM_RE_NAND:
938 case IVL_LPM_RE_NOR:
939 case IVL_LPM_RE_XNOR:
940 case IVL_LPM_SIGN_EXT:
941 assert(idx == 0);
942 return net->u_.reduce.q;
944 case IVL_LPM_SHIFTL:
945 case IVL_LPM_SHIFTR:
946 assert(idx == 0);
947 return net->u_.shift.q;
949 case IVL_LPM_SFUNC:
950 assert(idx == 0);
951 return net->u_.sfunc.pins[0];
953 case IVL_LPM_UFUNC:
954 assert(idx == 0);
955 return net->u_.ufunc.pins[0];
957 case IVL_LPM_CONCAT:
958 return net->u_.concat.pins[0];
960 case IVL_LPM_PART_VP:
961 case IVL_LPM_PART_PV:
962 case IVL_LPM_PART_BI:
963 assert(idx == 0);
964 return net->u_.part.q;
966 case IVL_LPM_REPEAT:
967 assert(idx == 0);
968 return net->u_.repeat.q;
970 case IVL_LPM_ARRAY:
971 assert(idx == 0);
972 return net->u_.array.q;
974 default:
975 assert(0);
976 return 0;
980 extern "C" ivl_scope_t ivl_lpm_scope(ivl_lpm_t net)
982 assert(net);
983 return net->scope;
986 extern "C" ivl_nexus_t ivl_lpm_select(ivl_lpm_t net)
988 switch (net->type) {
990 case IVL_LPM_MUX:
991 return net->u_.mux.s;
993 case IVL_LPM_ARRAY:
994 return net->u_.array.a;
996 default:
997 assert(0);
998 return 0;
1002 extern "C" unsigned ivl_lpm_selects(ivl_lpm_t net)
1004 switch (net->type) {
1005 case IVL_LPM_MUX:
1006 return net->u_.mux.swid;
1007 case IVL_LPM_ARRAY:
1008 return net->u_.array.swid;
1009 case IVL_LPM_CONCAT:
1010 return net->u_.concat.inputs;
1011 default:
1012 assert(0);
1013 return 0;
1017 extern "C" int ivl_lpm_signed(ivl_lpm_t net)
1019 assert(net);
1020 switch (net->type) {
1021 case IVL_LPM_FF:
1022 case IVL_LPM_MUX:
1023 return 0;
1024 case IVL_LPM_ADD:
1025 case IVL_LPM_CMP_EEQ:
1026 case IVL_LPM_CMP_EQ:
1027 case IVL_LPM_CMP_GE:
1028 case IVL_LPM_CMP_GT:
1029 case IVL_LPM_CMP_NE:
1030 case IVL_LPM_CMP_NEE:
1031 case IVL_LPM_DIVIDE:
1032 case IVL_LPM_MOD:
1033 case IVL_LPM_MULT:
1034 case IVL_LPM_SUB:
1035 return net->u_.arith.signed_flag;
1036 case IVL_LPM_RE_AND:
1037 case IVL_LPM_RE_OR:
1038 case IVL_LPM_RE_XOR:
1039 case IVL_LPM_RE_NAND:
1040 case IVL_LPM_RE_NOR:
1041 case IVL_LPM_RE_XNOR:
1042 return 0;
1043 case IVL_LPM_SHIFTL:
1044 case IVL_LPM_SHIFTR:
1045 return net->u_.shift.signed_flag;
1046 case IVL_LPM_SIGN_EXT: // Sign extend is always signed.
1047 return 1;
1048 case IVL_LPM_SFUNC:
1049 return 0;
1050 case IVL_LPM_UFUNC:
1051 return 0;
1052 case IVL_LPM_CONCAT: // Concatenations are always unsigned
1053 return 0;
1054 case IVL_LPM_PART_VP:
1055 case IVL_LPM_PART_PV:
1056 case IVL_LPM_PART_BI:
1057 return net->u_.part.signed_flag;
1058 case IVL_LPM_REPEAT:
1059 return 0;
1060 case IVL_LPM_ARRAY: // Array ports take the signedness of the array.
1061 return net->u_.array.sig->signed_;
1062 default:
1063 assert(0);
1064 return 0;
1068 extern "C" unsigned ivl_lpm_size(ivl_lpm_t net)
1070 switch (net->type) {
1071 case IVL_LPM_MUX:
1072 return net->u_.mux.size;
1073 case IVL_LPM_SFUNC:
1074 return net->u_.sfunc.ports - 1;
1075 case IVL_LPM_UFUNC:
1076 return net->u_.ufunc.ports - 1;
1077 case IVL_LPM_REPEAT:
1078 return net->u_.repeat.count;
1079 default:
1080 assert(0);
1081 return 0;
1085 extern "C" const char* ivl_lpm_string(ivl_lpm_t net)
1087 assert(net->type == IVL_LPM_SFUNC);
1088 return net->u_.sfunc.fun_name;
1091 extern "C" ivl_lpm_type_t ivl_lpm_type(ivl_lpm_t net)
1093 return net->type;
1096 extern "C" unsigned ivl_lpm_width(ivl_lpm_t net)
1098 assert(net);
1099 return net->width;
1102 extern "C" ivl_expr_t ivl_lval_mux(ivl_lval_t net)
1104 assert(net);
1105 if (net->type_ == IVL_LVAL_MUX)
1106 return net->idx;
1107 return 0x0;
1110 extern "C" ivl_expr_t ivl_lval_idx(ivl_lval_t net)
1112 assert(net);
1114 if (net->type_ == IVL_LVAL_ARR)
1115 return net->idx;
1116 return 0x0;
1119 extern "C" ivl_expr_t ivl_lval_part_off(ivl_lval_t net)
1121 assert(net);
1122 return net->loff;
1125 extern "C" unsigned ivl_lval_width(ivl_lval_t net)
1127 assert(net);
1128 return net->width_;
1131 extern "C" ivl_signal_t ivl_lval_sig(ivl_lval_t net)
1133 assert(net);
1134 switch (net->type_) {
1135 case IVL_LVAL_REG:
1136 case IVL_LVAL_NET:
1137 case IVL_LVAL_MUX:
1138 case IVL_LVAL_ARR:
1139 return net->n.sig;
1140 default:
1141 return 0;
1146 * The nexus name is rarely needed. (Shouldn't be needed at all!) This
1147 * function will calculate the name if it is not already calculated.
1149 extern "C" const char* ivl_nexus_name(ivl_nexus_t net)
1151 assert(net);
1152 if (net->name_ == 0) {
1153 net->name_ = api_strings.add(net->nexus_->name());
1155 return net->name_;
1158 extern "C" void* ivl_nexus_get_private(ivl_nexus_t net)
1160 assert(net);
1161 return net->private_data;
1164 extern "C" void ivl_nexus_set_private(ivl_nexus_t net, void*data)
1166 assert(net);
1167 net->private_data = data;
1170 extern "C" unsigned ivl_nexus_ptrs(ivl_nexus_t net)
1172 assert(net);
1173 return net->nptr_;
1176 extern "C" ivl_nexus_ptr_t ivl_nexus_ptr(ivl_nexus_t net, unsigned idx)
1178 assert(net);
1179 assert(idx < net->nptr_);
1180 return net->ptrs_ + idx;
1183 extern "C" ivl_drive_t ivl_nexus_ptr_drive0(ivl_nexus_ptr_t net)
1185 assert(net);
1186 return (ivl_drive_t)(net->drive0);
1189 extern "C" ivl_drive_t ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net)
1191 assert(net);
1192 return (ivl_drive_t)(net->drive1);
1195 extern "C" unsigned ivl_nexus_ptr_pin(ivl_nexus_ptr_t net)
1197 assert(net);
1198 return net->pin_;
1201 extern "C" ivl_net_const_t ivl_nexus_ptr_con(ivl_nexus_ptr_t net)
1203 if (net == 0)
1204 return 0;
1205 if (net->type_ != __NEXUS_PTR_CON)
1206 return 0;
1207 return net->l.con;
1210 extern "C" ivl_net_logic_t ivl_nexus_ptr_log(ivl_nexus_ptr_t net)
1212 if (net == 0)
1213 return 0;
1214 if (net->type_ != __NEXUS_PTR_LOG)
1215 return 0;
1216 return net->l.log;
1219 extern "C" ivl_lpm_t ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net)
1221 if (net == 0)
1222 return 0;
1223 if (net->type_ != __NEXUS_PTR_LPM)
1224 return 0;
1225 return net->l.lpm;
1228 extern "C" ivl_signal_t ivl_nexus_ptr_sig(ivl_nexus_ptr_t net)
1230 if (net == 0)
1231 return 0;
1232 if (net->type_ != __NEXUS_PTR_SIG)
1233 return 0;
1234 return net->l.sig;
1237 extern "C" const char* ivl_parameter_basename(ivl_parameter_t net)
1239 assert(net);
1240 return net->basename;
1243 extern "C" ivl_expr_t ivl_parameter_expr(ivl_parameter_t net)
1245 assert(net);
1246 return net->value;
1249 extern "C" ivl_scope_t ivl_parameter_scope(ivl_parameter_t net)
1251 assert(net);
1252 return net->scope;
1255 extern "C" ivl_nexus_t ivl_path_condit(ivl_delaypath_t obj)
1257 assert(obj);
1258 return obj->condit;
1261 extern uint64_t ivl_path_delay(ivl_delaypath_t obj, ivl_path_edge_t edg)
1263 assert(obj);
1264 return obj->delay[edg];
1267 extern ivl_scope_t ivl_path_scope(ivl_delaypath_t obj)
1269 assert(obj);
1270 assert(obj->scope);
1271 return obj->scope;
1274 extern ivl_nexus_t ivl_path_source(ivl_delaypath_t net)
1276 return net->src;
1279 extern int ivl_path_source_posedge(ivl_delaypath_t net)
1281 return net->posedge ? 1 : 0;
1284 extern int ivl_path_source_negedge(ivl_delaypath_t net)
1286 return net->negedge ? 1 : 0;
1289 extern "C" ivl_process_type_t ivl_process_type(ivl_process_t net)
1291 return net->type_;
1294 extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net)
1296 return net->scope_;
1299 extern "C" ivl_statement_t ivl_process_stmt(ivl_process_t net)
1301 return net->stmt_;
1304 extern "C" unsigned ivl_process_attr_cnt(ivl_process_t net)
1306 return net->nattr;
1309 extern "C" ivl_attribute_t ivl_process_attr_val(ivl_process_t net,
1310 unsigned idx)
1312 assert(idx < net->nattr);
1313 return net->attr + idx;
1316 extern "C" unsigned ivl_scope_attr_cnt(ivl_scope_t net)
1318 assert(net);
1319 return net->nattr;
1322 extern "C" ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net,
1323 unsigned idx)
1325 assert(idx < net->nattr);
1326 return net->attr + idx;
1329 extern "C" const char* ivl_scope_basename(ivl_scope_t net)
1331 assert(net);
1333 return net->name_;
1336 extern "C" int ivl_scope_children(ivl_scope_t net,
1337 ivl_scope_f func,
1338 void*cd)
1340 for (ivl_scope_t cur = net->child_; cur; cur = cur->sibling_) {
1341 int rc = func(cur, cd);
1342 if (rc != 0)
1343 return rc;
1346 return 0;
1349 extern "C" ivl_statement_t ivl_scope_def(ivl_scope_t net)
1351 assert(net);
1352 return net->def;
1355 extern "C" unsigned ivl_scope_events(ivl_scope_t net)
1357 assert(net);
1358 return net->nevent_;
1361 extern "C" ivl_event_t ivl_scope_event(ivl_scope_t net, unsigned idx)
1363 assert(net);
1364 assert(idx < net->nevent_);
1365 return net->event_[idx];
1368 extern "C" unsigned ivl_scope_logs(ivl_scope_t net)
1370 assert(net);
1371 return net->nlog_;
1374 extern "C" ivl_net_logic_t ivl_scope_log(ivl_scope_t net, unsigned idx)
1376 assert(net);
1377 assert(idx < net->nlog_);
1378 return net->log_[idx];
1381 extern "C" unsigned ivl_scope_lpms(ivl_scope_t net)
1383 assert(net);
1384 return net->nlpm_;
1387 extern "C" ivl_lpm_t ivl_scope_lpm(ivl_scope_t net, unsigned idx)
1389 assert(net);
1390 assert(idx < net->nlpm_);
1391 return net->lpm_[idx];
1394 static unsigned scope_name_len(ivl_scope_t net)
1396 unsigned len = 0;
1398 for (ivl_scope_t cur = net ; cur ; cur = cur->parent)
1399 len += strlen(cur->name_) + 1;
1401 return len;
1404 static void push_scope_basename(ivl_scope_t net, char*buf)
1406 if (net->parent == 0) {
1407 strcpy(buf, net->name_);
1408 return;
1411 push_scope_basename(net->parent, buf);
1412 strcat(buf, ".");
1413 strcat(buf, net->name_);
1416 extern "C" const char* ivl_scope_name(ivl_scope_t net)
1418 static char*name_buffer = 0;
1419 static unsigned name_size = 0;
1421 if (net->parent == 0)
1422 return net->name_;
1424 unsigned needlen = scope_name_len(net);
1426 if (name_size < needlen) {
1427 name_buffer = (char*)realloc(name_buffer, needlen);
1428 name_size = needlen;
1432 push_scope_basename(net, name_buffer);
1434 return name_buffer;
1437 extern "C" unsigned ivl_scope_params(ivl_scope_t net)
1439 assert(net);
1440 return net->nparam_;
1443 extern "C" ivl_parameter_t ivl_scope_param(ivl_scope_t net, unsigned idx)
1445 assert(net);
1446 assert(idx < net->nparam_);
1447 return net->param_ + idx;
1450 extern "C" ivl_scope_t ivl_scope_parent(ivl_scope_t net)
1452 assert(net);
1453 return net->parent;
1456 extern "C" unsigned ivl_scope_ports(ivl_scope_t net)
1458 assert(net);
1459 assert(net->type_ == IVL_SCT_FUNCTION);
1460 return net->ports;
1463 extern "C" ivl_signal_t ivl_scope_port(ivl_scope_t net, unsigned idx)
1465 assert(net);
1466 assert(net->type_ == IVL_SCT_FUNCTION);
1467 assert(idx < net->ports);
1468 return net->port[idx];
1471 extern "C" unsigned ivl_scope_sigs(ivl_scope_t net)
1473 assert(net);
1474 return net->nsigs_;
1477 extern "C" ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx)
1479 assert(net);
1480 assert(idx < net->nsigs_);
1481 return net->sigs_[idx];
1484 extern "C" int ivl_scope_time_precision(ivl_scope_t net)
1486 assert(net);
1487 return net->time_precision;
1490 extern "C" int ivl_scope_time_units(ivl_scope_t net)
1492 assert(net);
1493 return net->time_units;
1496 extern "C" ivl_scope_type_t ivl_scope_type(ivl_scope_t net)
1498 assert(net);
1499 return net->type_;
1502 extern "C" const char* ivl_scope_tname(ivl_scope_t net)
1504 assert(net);
1505 return net->tname_;
1508 extern "C" int ivl_signal_array_base(ivl_signal_t net)
1510 return net->array_base;
1513 extern "C" unsigned ivl_signal_array_count(ivl_signal_t net)
1515 return net->array_words;
1518 extern "C" unsigned ivl_signal_dimensions(ivl_signal_t net)
1520 return net->array_dimensions_;
1523 extern "C" const char* ivl_signal_attr(ivl_signal_t net, const char*key)
1525 if (net->nattr == 0)
1526 return 0;
1528 for (unsigned idx = 0 ; idx < net->nattr ; idx += 1)
1530 if (strcmp(key, net->attr[idx].key) == 0)
1531 return net->attr[idx].type == IVL_ATT_STR
1532 ? net->attr[idx].val.str
1533 : 0;
1535 return 0;
1538 extern "C" unsigned ivl_signal_attr_cnt(ivl_signal_t net)
1540 return net->nattr;
1543 extern "C" ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx)
1545 assert(idx < net->nattr);
1546 return net->attr + idx;
1549 extern "C" const char* ivl_signal_basename(ivl_signal_t net)
1551 return net->name_;
1554 extern "C" const char* ivl_signal_name(ivl_signal_t net)
1556 static char*name_buffer = 0;
1557 static unsigned name_size = 0;
1559 unsigned needlen = scope_name_len(net->scope_);
1560 needlen += strlen(net->name_) + 2;
1562 if (name_size < needlen) {
1563 name_buffer = (char*)realloc(name_buffer, needlen);
1564 name_size = needlen;
1567 push_scope_basename(net->scope_, name_buffer);
1568 strcat(name_buffer, ".");
1569 strcat(name_buffer, net->name_);
1571 return name_buffer;
1574 extern "C" ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word)
1576 assert(word < net->array_words);
1577 if (net->array_words > 1)
1578 return net->pins[word];
1579 else
1580 return net->pin;
1583 extern "C" int ivl_signal_msb(ivl_signal_t net)
1585 assert(net->lsb_dist == 1 || net->lsb_dist == -1);
1586 return net->lsb_index + net->lsb_dist * (net->width_ - 1);
1589 extern "C" int ivl_signal_lsb(ivl_signal_t net)
1591 return net->lsb_index;
1594 extern "C" unsigned ivl_signal_width(ivl_signal_t net)
1596 return net->width_;
1599 extern "C" ivl_signal_port_t ivl_signal_port(ivl_signal_t net)
1601 return net->port_;
1604 extern "C" int ivl_signal_local(ivl_signal_t net)
1606 return net->local_;
1609 extern "C" int ivl_signal_signed(ivl_signal_t net)
1611 return net->signed_;
1614 extern "C" int ivl_signal_integer(ivl_signal_t net)
1616 return net->isint_;
1619 extern "C" ivl_variable_type_t ivl_signal_data_type(ivl_signal_t net)
1621 return net->data_type;
1624 extern "C" unsigned ivl_signal_npath(ivl_signal_t net)
1626 return net->npath;
1629 extern "C" ivl_delaypath_t ivl_signal_path(ivl_signal_t net, unsigned idx)
1631 assert(idx < net->npath);
1632 return net->path + idx;
1635 extern "C" ivl_signal_type_t ivl_signal_type(ivl_signal_t net)
1637 return net->type_;
1640 extern "C" ivl_statement_type_t ivl_statement_type(ivl_statement_t net)
1642 return net->type_;
1645 extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net)
1647 switch (net->type_) {
1648 case IVL_ST_BLOCK:
1649 case IVL_ST_FORK:
1650 return net->u_.block_.scope;
1651 default:
1652 assert(0);
1653 return 0;
1657 extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net)
1659 switch (net->type_) {
1660 case IVL_ST_BLOCK:
1661 case IVL_ST_FORK:
1662 return net->u_.block_.nstmt_;
1663 default:
1664 assert(0);
1665 return 0;
1669 extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net,
1670 unsigned i)
1672 switch (net->type_) {
1673 case IVL_ST_BLOCK:
1674 case IVL_ST_FORK:
1675 return net->u_.block_.stmt_ + i;
1676 default:
1677 assert(0);
1678 return 0;
1682 extern "C" ivl_scope_t ivl_stmt_call(ivl_statement_t net)
1684 switch (net->type_) {
1685 case IVL_ST_DISABLE:
1686 return net->u_.disable_.scope;
1688 case IVL_ST_UTASK:
1689 return net->u_.utask_.def;
1690 default:
1691 assert(0);
1692 return 0;
1696 extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net)
1698 switch (net->type_) {
1699 case IVL_ST_CASE:
1700 case IVL_ST_CASER:
1701 case IVL_ST_CASEX:
1702 case IVL_ST_CASEZ:
1703 return net->u_.case_.ncase;
1704 default:
1705 assert(0);
1706 return 0;
1710 extern "C" ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned idx)
1712 switch (net->type_) {
1713 case IVL_ST_CASE:
1714 case IVL_ST_CASER:
1715 case IVL_ST_CASEX:
1716 case IVL_ST_CASEZ:
1717 assert(idx < net->u_.case_.ncase);
1718 return net->u_.case_.case_ex[idx];
1720 default:
1721 assert(0);
1722 return 0;
1726 extern "C" ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned idx)
1728 switch (net->type_) {
1729 case IVL_ST_CASE:
1730 case IVL_ST_CASER:
1731 case IVL_ST_CASEX:
1732 case IVL_ST_CASEZ:
1733 assert(idx < net->u_.case_.ncase);
1734 return net->u_.case_.case_st + idx;
1736 default:
1737 assert(0);
1738 return 0;
1742 extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net)
1744 switch (net->type_) {
1745 case IVL_ST_CONDIT:
1746 return net->u_.condit_.cond_;
1748 case IVL_ST_CASE:
1749 case IVL_ST_CASER:
1750 case IVL_ST_CASEX:
1751 case IVL_ST_CASEZ:
1752 return net->u_.case_.cond;
1754 case IVL_ST_REPEAT:
1755 case IVL_ST_WHILE:
1756 return net->u_.while_.cond_;
1758 default:
1759 assert(0);
1760 return 0;
1764 extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net)
1766 assert(net->type_ == IVL_ST_CONDIT);
1767 if (net->u_.condit_.stmt_[1].type_ == IVL_ST_NONE)
1768 return 0;
1769 else
1770 return net->u_.condit_.stmt_ + 1;
1773 extern "C" ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net)
1775 assert(net->type_ == IVL_ST_CONDIT);
1776 if (net->u_.condit_.stmt_[0].type_ == IVL_ST_NONE)
1777 return 0;
1778 else
1779 return net->u_.condit_.stmt_ + 0;
1782 extern "C" ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net)
1784 switch (net->type_) {
1785 case IVL_ST_ASSIGN:
1786 case IVL_ST_ASSIGN_NB:
1787 return net->u_.assign_.delay;
1789 case IVL_ST_DELAYX:
1790 return net->u_.delayx_.expr;
1792 default:
1793 assert(0);
1794 return 0;
1798 extern "C" uint64_t ivl_stmt_delay_val(ivl_statement_t net)
1800 assert(net->type_ == IVL_ST_DELAY);
1801 return net->u_.delay_.delay_;
1804 extern "C" unsigned ivl_stmt_nevent(ivl_statement_t net)
1806 switch (net->type_) {
1807 case IVL_ST_WAIT:
1808 return net->u_.wait_.nevent;
1810 case IVL_ST_TRIGGER:
1811 return 1;
1813 default:
1814 assert(0);
1816 return 0;
1819 extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx)
1821 switch (net->type_) {
1822 case IVL_ST_WAIT:
1823 assert(idx < net->u_.wait_.nevent);
1824 if (net->u_.wait_.nevent == 1)
1825 return net->u_.wait_.event;
1826 else
1827 return net->u_.wait_.events[idx];
1829 case IVL_ST_TRIGGER:
1830 assert(idx == 0);
1831 return net->u_.wait_.event;
1832 default:
1833 assert(0);
1835 return 0;
1838 extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx)
1840 switch (net->type_) {
1841 case IVL_ST_ASSIGN:
1842 case IVL_ST_ASSIGN_NB:
1843 case IVL_ST_CASSIGN:
1844 case IVL_ST_DEASSIGN:
1845 case IVL_ST_FORCE:
1846 case IVL_ST_RELEASE:
1847 assert(idx < net->u_.assign_.lvals_);
1848 return net->u_.assign_.lval_ + idx;
1850 default:
1851 assert(0);
1853 return 0;
1856 extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net)
1858 switch (net->type_) {
1859 case IVL_ST_ASSIGN:
1860 case IVL_ST_ASSIGN_NB:
1861 case IVL_ST_CASSIGN:
1862 case IVL_ST_DEASSIGN:
1863 case IVL_ST_FORCE:
1864 case IVL_ST_RELEASE:
1865 return net->u_.assign_.lvals_;
1867 default:
1868 assert(0);
1870 return 0;
1873 extern "C" unsigned ivl_stmt_lwidth(ivl_statement_t net)
1875 assert((net->type_ == IVL_ST_ASSIGN)
1876 || (net->type_ == IVL_ST_ASSIGN_NB)
1877 || (net->type_ == IVL_ST_CASSIGN)
1878 || (net->type_ == IVL_ST_DEASSIGN)
1879 || (net->type_ == IVL_ST_FORCE)
1880 || (net->type_ == IVL_ST_RELEASE));
1882 unsigned sum = 0;
1884 unsigned nlvals;
1885 struct ivl_lval_s*lvals;
1886 nlvals = net->u_.assign_.lvals_;
1887 lvals = net->u_.assign_.lval_;
1889 for (unsigned idx = 0 ; idx < nlvals ; idx += 1) {
1890 ivl_lval_t cur = lvals + idx;
1891 switch(cur->type_) {
1892 case IVL_LVAL_MUX:
1893 sum += 1;
1894 break;
1895 case IVL_LVAL_REG:
1896 case IVL_LVAL_ARR:
1897 sum += ivl_lval_width(cur);
1898 break;
1899 default:
1900 assert(0);
1904 return sum;
1907 extern "C" const char* ivl_stmt_name(ivl_statement_t net)
1909 switch (net->type_) {
1910 case IVL_ST_STASK:
1911 return net->u_.stask_.name_;
1912 default:
1913 assert(0);
1916 return 0;
1919 extern "C" ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx)
1921 switch (net->type_) {
1922 case IVL_ST_STASK:
1923 assert(idx < net->u_.stask_.nparm_);
1924 return net->u_.stask_.parms_[idx];
1926 default:
1927 assert(0);
1929 return 0;
1932 extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net)
1934 switch (net->type_) {
1935 case IVL_ST_STASK:
1936 return net->u_.stask_.nparm_;
1937 default:
1938 assert(0);
1940 return 0;
1943 extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net)
1945 switch (net->type_) {
1946 case IVL_ST_ASSIGN:
1947 case IVL_ST_ASSIGN_NB:
1948 case IVL_ST_CASSIGN:
1949 case IVL_ST_FORCE:
1950 return net->u_.assign_.rval_;
1951 default:
1952 assert(0);
1955 return 0;
1958 extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net)
1960 switch (net->type_) {
1961 case IVL_ST_DELAY:
1962 return net->u_.delay_.stmt_;
1963 case IVL_ST_DELAYX:
1964 return net->u_.delayx_.stmt_;
1965 case IVL_ST_FOREVER:
1966 return net->u_.forever_.stmt_;
1967 case IVL_ST_WAIT:
1968 return net->u_.wait_.stmt_;
1969 case IVL_ST_REPEAT:
1970 case IVL_ST_WHILE:
1971 return net->u_.while_.stmt_;
1972 default:
1973 assert(0);
1976 return 0;