Add file and line information for parameters, etc.
[sverilog.git] / t-dll-api.cc
blob4d3a90feff543e8778ecf1279c6598311492b0bc
1 /*
2 * Copyright (c) 2000-2008 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
20 # include "config.h"
21 # include "StringHeap.h"
22 # include "t-dll.h"
23 # include <stdlib.h>
24 # include <string.h>
25 #ifdef HAVE_MALLOC_H
26 # include <malloc.h>
27 #endif
29 static StringHeap api_strings;
31 /* THE FOLLOWING ARE FUNCTIONS THAT ARE CALLED FROM THE TARGET. */
33 extern "C" const char*ivl_design_flag(ivl_design_t des, const char*key)
35 return des->self->get_flag(key);
38 extern "C" int ivl_design_process(ivl_design_t des,
39 ivl_process_f func,
40 void*cd)
42 for (ivl_process_t idx = des->threads_; idx; idx = idx->next_) {
43 int rc = (func)(idx, cd);
44 if (rc != 0)
45 return rc;
48 return 0;
51 extern "C" ivl_scope_t ivl_design_root(ivl_design_t des)
53 cerr << "ANACHRONISM: ivl_design_root called. "
54 "Use ivl_design_roots instead." << endl;
56 assert (des->nroots_);
57 return des->roots_[0];
60 extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes,
61 unsigned int *nscopes)
63 assert (nscopes && scopes);
64 *scopes = &des->roots_[0];
65 *nscopes = des->nroots_;
68 extern "C" int ivl_design_time_precision(ivl_design_t des)
70 return des->time_precision;
73 extern "C" unsigned ivl_design_consts(ivl_design_t des)
75 return des->nconsts;
78 extern "C" ivl_net_const_t ivl_design_const(ivl_design_t des, unsigned idx)
80 assert(idx < des->nconsts);
81 return des->consts[idx];
84 extern "C" ivl_expr_type_t ivl_expr_type(ivl_expr_t net)
86 if (net == 0)
87 return IVL_EX_NONE;
88 return net->type_;
91 extern "C" const char*ivl_expr_file(ivl_expr_t net)
93 assert(net);
94 return net->file.str();
97 extern "C" unsigned ivl_expr_lineno(ivl_expr_t net)
99 assert(net);
100 return net->lineno;
103 inline static const char *basename(ivl_scope_t scope, const char *inst)
105 inst += strlen(ivl_scope_name(scope));
106 assert(*inst == '.');
107 return inst+1;
110 extern "C" ivl_variable_type_t ivl_const_type(ivl_net_const_t net)
112 assert(net);
113 return net->type;
116 extern "C" const char*ivl_const_bits(ivl_net_const_t net)
118 assert(net);
119 switch (net->type) {
121 case IVL_VT_LOGIC:
122 if (net->width_ <= sizeof(net->b.bit_))
123 return net->b.bit_;
124 else
125 return net->b.bits_;
127 default:
128 return 0;
132 extern "C" ivl_expr_t ivl_const_delay(ivl_net_const_t net, unsigned transition)
134 assert(transition < 3);
135 return net->delay[transition];
138 extern "C" ivl_nexus_t ivl_const_nex(ivl_net_const_t net)
140 assert(net);
141 return net->pin_;
144 extern "C" double ivl_const_real(ivl_net_const_t net)
146 assert(net);
147 assert(net->type == IVL_VT_REAL);
148 return net->b.real_value;
151 extern "C" int ivl_const_signed(ivl_net_const_t net)
153 assert(net);
154 return net->signed_;
157 extern "C" unsigned ivl_const_width(ivl_net_const_t net)
159 assert(net);
160 return net->width_;
163 extern "C" const char* ivl_event_name(ivl_event_t net)
165 static char*name_buffer = 0;
166 static unsigned name_size = 0;
168 ivl_scope_t scope = net->scope;
169 const char*sn = ivl_scope_name(scope);
171 unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
172 if (need > name_size) {
173 name_buffer = (char*)realloc(name_buffer, need);
174 name_size = need;
177 strcpy(name_buffer, sn);
178 char*tmp = name_buffer + strlen(sn);
179 *tmp++ = '.';
180 strcpy(tmp, net->name);
182 cerr << "ANACHRONISM: Call to anachronistic ivl_event_name." << endl;
184 return name_buffer;
187 extern "C" const char* ivl_event_basename(ivl_event_t net)
189 return net->name;
192 extern "C" ivl_scope_t ivl_event_scope(ivl_event_t net)
194 return net->scope;
197 extern "C" unsigned ivl_event_nany(ivl_event_t net)
199 assert(net);
200 return net->nany;
203 extern "C" ivl_nexus_t ivl_event_any(ivl_event_t net, unsigned idx)
205 assert(net);
206 assert(idx < net->nany);
207 return net->pins[idx];
210 extern "C" unsigned ivl_event_nneg(ivl_event_t net)
212 assert(net);
213 return net->nneg;
216 extern "C" ivl_nexus_t ivl_event_neg(ivl_event_t net, unsigned idx)
218 assert(net);
219 assert(idx < net->nneg);
220 return net->pins[net->nany + idx];
223 extern "C" unsigned ivl_event_npos(ivl_event_t net)
225 assert(net);
226 return net->npos;
229 extern "C" ivl_nexus_t ivl_event_pos(ivl_event_t net, unsigned idx)
231 assert(net);
232 assert(idx < net->npos);
233 return net->pins[net->nany + net->nneg + idx];
236 extern "C" const char* ivl_expr_bits(ivl_expr_t net)
238 assert(net && (net->type_ == IVL_EX_NUMBER));
239 return net->u_.number_.bits_;
242 extern "C" ivl_scope_t ivl_expr_def(ivl_expr_t net)
244 assert(net);
246 switch (net->type_) {
248 case IVL_EX_UFUNC:
249 return net->u_.ufunc_.def;
251 default:
252 assert(0);
255 return 0;
258 extern "C" double ivl_expr_dvalue(ivl_expr_t net)
260 assert(net->type_ == IVL_EX_REALNUM);
261 return net->u_.real_.value;
264 extern "C" const char* ivl_expr_name(ivl_expr_t net)
266 switch (net->type_) {
268 case IVL_EX_SFUNC:
269 return net->u_.sfunc_.name_;
271 case IVL_EX_SIGNAL:
272 return net->u_.signal_.sig->name_;
274 default:
275 assert(0);
277 return 0;
280 extern "C" char ivl_expr_opcode(ivl_expr_t net)
282 assert(net);
283 switch (net->type_) {
284 case IVL_EX_BINARY:
285 return net->u_.binary_.op_;
287 case IVL_EX_UNARY:
288 return net->u_.unary_.op_;
290 default:
291 assert(0);
293 return 0;
296 extern "C" ivl_expr_t ivl_expr_oper1(ivl_expr_t net)
298 assert(net);
299 switch (net->type_) {
300 case IVL_EX_BINARY:
301 case IVL_EX_SELECT:
302 return net->u_.binary_.lef_;
304 case IVL_EX_UNARY:
305 return net->u_.unary_.sub_;
307 case IVL_EX_MEMORY:
308 return net->u_.memory_.idx_;
310 case IVL_EX_SIGNAL:
311 return net->u_.signal_.word;
313 case IVL_EX_TERNARY:
314 return net->u_.ternary_.cond;
316 default:
317 assert(0);
320 return 0;
323 extern "C" ivl_expr_t ivl_expr_oper2(ivl_expr_t net)
325 assert(net);
326 switch (net->type_) {
327 case IVL_EX_BINARY:
328 case IVL_EX_SELECT:
329 return net->u_.binary_.rig_;
331 case IVL_EX_TERNARY:
332 return net->u_.ternary_.true_e;
334 default:
335 assert(0);
338 return 0;
341 extern "C" ivl_expr_t ivl_expr_oper3(ivl_expr_t net)
343 assert(net);
344 switch (net->type_) {
346 case IVL_EX_TERNARY:
347 return net->u_.ternary_.false_e;
349 default:
350 assert(0);
352 return 0;
355 extern "C" ivl_parameter_t ivl_expr_parameter(ivl_expr_t net)
357 switch (net->type_) {
358 case IVL_EX_NUMBER:
359 return net->u_.number_.parameter;
360 case IVL_EX_STRING:
361 return net->u_.string_.parameter;
362 case IVL_EX_REALNUM:
363 return net->u_.real_.parameter;
364 default:
365 return 0;
369 extern "C" ivl_expr_t ivl_expr_parm(ivl_expr_t net, unsigned idx)
371 assert(net);
372 switch (net->type_) {
374 case IVL_EX_CONCAT:
375 assert(idx < net->u_.concat_.parms);
376 return net->u_.concat_.parm[idx];
378 case IVL_EX_SFUNC:
379 assert(idx < net->u_.sfunc_.parms);
380 return net->u_.sfunc_.parm[idx];
382 case IVL_EX_UFUNC:
383 assert(idx < net->u_.ufunc_.parms);
384 return net->u_.ufunc_.parm[idx];
386 default:
387 assert(0);
388 return 0;
392 extern "C" unsigned ivl_expr_parms(ivl_expr_t net)
394 assert(net);
395 switch (net->type_) {
397 case IVL_EX_CONCAT:
398 return net->u_.concat_.parms;
400 case IVL_EX_SFUNC:
401 return net->u_.sfunc_.parms;
403 case IVL_EX_UFUNC:
404 return net->u_.ufunc_.parms;
406 default:
407 assert(0);
408 return 0;
412 extern "C" unsigned ivl_expr_repeat(ivl_expr_t net)
414 assert(net);
415 assert(net->type_ == IVL_EX_CONCAT);
416 return net->u_.concat_.rept;
419 extern "C" ivl_event_t ivl_expr_event(ivl_expr_t net)
421 assert(net);
422 assert(net->type_ == IVL_EX_EVENT);
423 return net->u_.event_.event;
426 extern "C" ivl_scope_t ivl_expr_scope(ivl_expr_t net)
428 assert(net);
429 assert(net->type_ == IVL_EX_SCOPE);
430 return net->u_.scope_.scope;
433 extern "C" ivl_signal_t ivl_expr_signal(ivl_expr_t net)
435 assert(net);
436 switch (net->type_) {
438 case IVL_EX_SIGNAL:
439 case IVL_EX_ARRAY:
440 return net->u_.signal_.sig;
442 default:
443 assert(0);
444 return 0;
448 extern "C" int ivl_expr_signed(ivl_expr_t net)
450 assert(net);
451 return net->signed_;
454 extern "C" const char* ivl_expr_string(ivl_expr_t net)
456 assert(net->type_ == IVL_EX_STRING);
457 return net->u_.string_.value_;
460 extern "C" unsigned long ivl_expr_uvalue(ivl_expr_t net)
462 switch (net->type_) {
464 case IVL_EX_ULONG:
465 return net->u_.ulong_.value;
467 case IVL_EX_NUMBER: {
468 unsigned long val = 0;
469 for (unsigned long idx = 0 ; idx < net->width_ ; idx += 1) {
470 if (net->u_.number_.bits_[idx] == '1')
471 val |= 1UL << idx;
474 return val;
477 default:
478 assert(0);
483 extern "C" ivl_variable_type_t ivl_expr_value(ivl_expr_t net)
485 assert(net);
486 return net->value_;
489 extern "C" unsigned ivl_expr_width(ivl_expr_t net)
491 assert(net);
492 return net->width_;
496 * ivl_file_table_index puts entries in the map as needed and returns
497 * the appropriate index.
498 * ivl_file_table_size returns the number of entries in the table.
499 * ivl_file_table_item returns the file name for the given index.
501 struct ltstr
503 bool operator()(const char*s1, const char*s2) const
505 return strcmp(s1, s2) < 0;
508 static map<const char*, unsigned, ltstr> fn_map;
509 static vector<const char*> fn_vector;
511 static void ivl_file_table_init()
513 /* The first two index entries do not depend on a real
514 * file name and are always available. */
515 fn_vector.push_back("N/A");
516 fn_map["N/A"] = 0;
517 fn_vector.push_back("<interactive>");
518 fn_map["<interactive>"] = 1;
521 extern "C" const char* ivl_file_table_item(unsigned idx)
523 if (fn_vector.empty()) {
524 ivl_file_table_init();
527 assert(idx < fn_vector.size());
528 return fn_vector[idx];
531 extern "C" unsigned ivl_file_table_index(const char*name)
533 if (fn_vector.empty()) {
534 ivl_file_table_init();
537 if (name == NULL) return 0;
539 /* The new index is the current map size. This is inserted only
540 * if the file name is not currently in the map. */
541 pair<map<const char*, unsigned, ltstr>::iterator, bool> result;
542 result = fn_map.insert(make_pair(name, fn_vector.size()));
543 if (result.second) {
544 fn_vector.push_back(name);
546 return result.first->second;
549 extern "C" unsigned ivl_file_table_size()
551 if (fn_vector.empty()) {
552 ivl_file_table_init();
555 return fn_vector.size();
558 extern "C" const char* ivl_logic_attr(ivl_net_logic_t net, const char*key)
560 assert(net);
561 unsigned idx;
563 for (idx = 0 ; idx < net->nattr ; idx += 1) {
565 if (strcmp(net->attr[idx].key, key) == 0)
566 return net->attr[idx].type == IVL_ATT_STR
567 ? net->attr[idx].val.str
568 : 0;
571 return 0;
574 extern "C" unsigned ivl_logic_attr_cnt(ivl_net_logic_t net)
576 return net->nattr;
579 extern "C" ivl_attribute_t ivl_logic_attr_val(ivl_net_logic_t net,
580 unsigned idx)
582 assert(idx < net->nattr);
583 return net->attr + idx;
586 extern "C" ivl_drive_t ivl_logic_drive0(ivl_net_logic_t net)
588 ivl_nexus_t nex = ivl_logic_pin(net, 0);
590 for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
591 ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
592 if (ivl_nexus_ptr_log(cur) != net)
593 continue;
594 if (ivl_nexus_ptr_pin(cur) != 0)
595 continue;
596 return ivl_nexus_ptr_drive0(cur);
599 assert(0);
600 return IVL_DR_STRONG;
603 extern "C" ivl_drive_t ivl_logic_drive1(ivl_net_logic_t net)
605 ivl_nexus_t nex = ivl_logic_pin(net, 0);
607 for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
608 ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
609 if (ivl_nexus_ptr_log(cur) != net)
610 continue;
611 if (ivl_nexus_ptr_pin(cur) != 0)
612 continue;
613 return ivl_nexus_ptr_drive1(cur);
616 assert(0);
617 return IVL_DR_STRONG;
620 extern "C" const char* ivl_logic_name(ivl_net_logic_t net)
622 assert(net);
623 cerr << "ANACHRONISM: Call to anachronistic ivl_logic_name." << endl;
624 return net->name_;
627 extern "C" const char* ivl_logic_basename(ivl_net_logic_t net)
629 assert(net);
630 return net->name_;
633 extern "C" ivl_scope_t ivl_logic_scope(ivl_net_logic_t net)
635 assert(net);
636 return net->scope_;
639 extern "C" ivl_logic_t ivl_logic_type(ivl_net_logic_t net)
641 return net->type_;
644 extern "C" unsigned ivl_logic_pins(ivl_net_logic_t net)
646 return net->npins_;
649 extern "C" ivl_nexus_t ivl_logic_pin(ivl_net_logic_t net, unsigned pin)
651 assert(pin < net->npins_);
652 return net->pins_[pin];
655 extern "C" ivl_udp_t ivl_logic_udp(ivl_net_logic_t net)
657 assert(net->type_ == IVL_LO_UDP);
658 assert(net->udp);
659 return net->udp;
662 extern "C" ivl_expr_t ivl_logic_delay(ivl_net_logic_t net, unsigned transition)
664 assert(transition < 3);
665 return net->delay[transition];
668 extern "C" unsigned ivl_logic_width(ivl_net_logic_t net)
670 assert(net);
671 return net->width_;
674 extern "C" int ivl_udp_sequ(ivl_udp_t net)
676 return net->sequ;
679 extern "C" unsigned ivl_udp_nin(ivl_udp_t net)
681 return net->nin;
684 extern "C" unsigned ivl_udp_init(ivl_udp_t net)
686 return net->init;
689 extern "C" const char* ivl_udp_row(ivl_udp_t net, unsigned idx)
691 assert(idx < net->nrows);
692 assert(net->table);
693 assert(net->table[idx]);
694 return net->table[idx];
697 extern "C" unsigned ivl_udp_rows(ivl_udp_t net)
699 return net->nrows;
702 extern "C" const char* ivl_udp_name(ivl_udp_t net)
704 assert(net->name);
705 return net->name;
708 extern "C" const char* ivl_lpm_basename(ivl_lpm_t net)
710 return net->name;
713 extern "C" ivl_nexus_t ivl_lpm_async_clr(ivl_lpm_t net)
715 assert(net);
716 switch(net->type) {
717 case IVL_LPM_FF:
718 return net->u_.ff.aclr;
719 default:
720 assert(0);
721 return 0;
725 extern "C" ivl_nexus_t ivl_lpm_sync_clr(ivl_lpm_t net)
727 assert(net);
728 switch(net->type) {
729 case IVL_LPM_FF:
730 return net->u_.ff.sclr;
731 default:
732 assert(0);
733 return 0;
737 extern "C" ivl_expr_t ivl_lpm_delay(ivl_lpm_t net, unsigned transition)
739 assert(transition < 3);
740 return net->delay[transition];
743 extern "C" ivl_nexus_t ivl_lpm_async_set(ivl_lpm_t net)
745 assert(net);
746 switch(net->type) {
747 case IVL_LPM_FF:
748 return net->u_.ff.aset;
749 default:
750 assert(0);
751 return 0;
755 extern "C" ivl_nexus_t ivl_lpm_sync_set(ivl_lpm_t net)
757 assert(net);
758 switch(net->type) {
759 case IVL_LPM_FF:
760 return net->u_.ff.sset;
761 default:
762 assert(0);
763 return 0;
767 extern "C" ivl_signal_t ivl_lpm_array(ivl_lpm_t net)
769 assert(net);
770 switch (net->type) {
771 case IVL_LPM_ARRAY:
772 return net->u_.array.sig;
773 default:
774 assert(0);
775 return 0;
779 extern "C" unsigned ivl_lpm_base(ivl_lpm_t net)
781 assert(net);
782 switch (net->type) {
783 case IVL_LPM_PART_VP:
784 case IVL_LPM_PART_PV:
785 case IVL_LPM_PART_BI:
786 return net->u_.part.base;
787 default:
788 assert(0);
789 return 0;
793 extern "C" ivl_nexus_t ivl_lpm_clk(ivl_lpm_t net)
795 assert(net);
796 switch (net->type) {
797 case IVL_LPM_FF:
798 return net->u_.ff.clk;
799 default:
800 assert(0);
801 return 0;
805 extern "C" ivl_expr_t ivl_lpm_aset_value(ivl_lpm_t net)
807 assert(net);
808 switch (net->type) {
809 case IVL_LPM_FF:
810 return net->u_.ff.aset_value;
811 default:
812 assert(0);
813 return 0;
816 extern "C" ivl_expr_t ivl_lpm_sset_value(ivl_lpm_t net)
818 assert(net);
819 switch (net->type) {
820 case IVL_LPM_FF:
821 return net->u_.ff.sset_value;
822 default:
823 assert(0);
824 return 0;
828 extern "C" ivl_scope_t ivl_lpm_define(ivl_lpm_t net)
830 assert(net);
831 switch (net->type) {
832 case IVL_LPM_UFUNC:
833 return net->u_.ufunc.def;
834 default:
835 assert(0);
836 return 0;
840 extern "C" ivl_nexus_t ivl_lpm_enable(ivl_lpm_t net)
842 assert(net);
843 switch (net->type) {
844 case IVL_LPM_FF:
845 return net->u_.ff.we;
846 default:
847 assert(0);
848 return 0;
852 /* The file name and line number are only set for system functions! */
853 extern "C" const char* ivl_lpm_file(ivl_lpm_t net)
855 return net->file.str();
858 extern "C" unsigned ivl_lpm_lineno(ivl_lpm_t net)
860 return net->lineno;
863 extern "C" ivl_nexus_t ivl_lpm_data(ivl_lpm_t net, unsigned idx)
865 assert(net);
866 switch (net->type) {
867 case IVL_LPM_ADD:
868 case IVL_LPM_CMP_EEQ:
869 case IVL_LPM_CMP_EQ:
870 case IVL_LPM_CMP_GE:
871 case IVL_LPM_CMP_GT:
872 case IVL_LPM_CMP_NE:
873 case IVL_LPM_CMP_NEE:
874 case IVL_LPM_DIVIDE:
875 case IVL_LPM_MOD:
876 case IVL_LPM_MULT:
877 case IVL_LPM_POW:
878 case IVL_LPM_SUB:
879 assert(idx <= 1);
880 if (idx == 0)
881 return net->u_.arith.a;
882 else
883 return net->u_.arith.b;
885 case IVL_LPM_MUX:
886 assert(idx < net->u_.mux.size);
887 return net->u_.mux.d[idx];
889 case IVL_LPM_RE_AND:
890 case IVL_LPM_RE_OR:
891 case IVL_LPM_RE_XOR:
892 case IVL_LPM_RE_NAND:
893 case IVL_LPM_RE_NOR:
894 case IVL_LPM_RE_XNOR:
895 case IVL_LPM_SIGN_EXT:
896 assert(idx == 0);
897 return net->u_.reduce.a;
899 case IVL_LPM_SHIFTL:
900 case IVL_LPM_SHIFTR:
901 assert(idx <= 1);
902 if (idx == 0)
903 return net->u_.shift.d;
904 else
905 return net->u_.shift.s;
907 case IVL_LPM_FF:
908 assert(idx == 0);
909 return net->u_.ff.d.pin;
911 case IVL_LPM_CONCAT:
912 assert(idx < net->u_.concat.inputs);
913 return net->u_.concat.pins[idx+1];
915 case IVL_LPM_PART_VP:
916 case IVL_LPM_PART_PV:
917 case IVL_LPM_PART_BI:
918 assert(idx <= 1);
919 if (idx == 0)
920 return net->u_.part.a;
921 else
922 return net->u_.part.s;
924 case IVL_LPM_REPEAT:
925 assert(idx == 0);
926 return net->u_.repeat.a;
928 case IVL_LPM_SFUNC:
929 // Skip the return port.
930 assert(idx < (net->u_.sfunc.ports-1));
931 return net->u_.sfunc.pins[idx+1];
933 case IVL_LPM_UFUNC:
934 // Skip the return port.
935 assert(idx < (net->u_.ufunc.ports-1));
936 return net->u_.ufunc.pins[idx+1];
938 default:
939 assert(0);
940 return 0;
944 extern "C" ivl_nexus_t ivl_lpm_datab(ivl_lpm_t net, unsigned idx)
946 cerr << "ANACHRONISM: Call to anachronistic ivl_lpm_datab." << endl;
947 assert(net);
948 switch (net->type) {
950 case IVL_LPM_ADD:
951 case IVL_LPM_CMP_EQ:
952 case IVL_LPM_CMP_GE:
953 case IVL_LPM_CMP_GT:
954 case IVL_LPM_CMP_NE:
955 case IVL_LPM_DIVIDE:
956 case IVL_LPM_MOD:
957 case IVL_LPM_MULT:
958 case IVL_LPM_POW:
959 case IVL_LPM_SUB:
960 assert(idx == 0);
961 return net->u_.arith.b;
963 default:
964 assert(0);
965 return 0;
971 * This function returns the hierarchical name for the LPM device. The
972 * name needs to be built up from the scope name and the lpm base
973 * name.
975 * Anachronism: This function is provided for
976 * compatibility. Eventually, it will be removed.
978 extern "C" const char* ivl_lpm_name(ivl_lpm_t net)
980 static char*name_buffer = 0;
981 static unsigned name_size = 0;
983 ivl_scope_t scope = ivl_lpm_scope(net);
984 const char*sn = ivl_scope_name(scope);
986 unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
987 if (need > name_size) {
988 name_buffer = (char*)realloc(name_buffer, need);
989 name_size = need;
992 strcpy(name_buffer, sn);
993 char*tmp = name_buffer + strlen(sn);
994 *tmp++ = '.';
995 strcpy(tmp, net->name);
996 return name_buffer;
1000 extern "C" ivl_nexus_t ivl_lpm_q(ivl_lpm_t net, unsigned idx)
1002 assert(net);
1004 switch (net->type) {
1005 case IVL_LPM_ADD:
1006 case IVL_LPM_DIVIDE:
1007 case IVL_LPM_MOD:
1008 case IVL_LPM_MULT:
1009 case IVL_LPM_POW:
1010 case IVL_LPM_SUB:
1011 assert(idx == 0);
1012 return net->u_.arith.q;
1014 case IVL_LPM_CMP_GE:
1015 case IVL_LPM_CMP_GT:
1016 case IVL_LPM_CMP_EQ:
1017 case IVL_LPM_CMP_NE:
1018 case IVL_LPM_CMP_EEQ:
1019 case IVL_LPM_CMP_NEE:
1020 assert(idx == 0);
1021 return net->u_.arith.q;
1023 case IVL_LPM_FF:
1024 assert(idx == 0);
1025 return net->u_.ff.q.pin;
1027 case IVL_LPM_MUX:
1028 assert(idx == 0);
1029 return net->u_.mux.q;
1031 case IVL_LPM_RE_AND:
1032 case IVL_LPM_RE_OR:
1033 case IVL_LPM_RE_XOR:
1034 case IVL_LPM_RE_NAND:
1035 case IVL_LPM_RE_NOR:
1036 case IVL_LPM_RE_XNOR:
1037 case IVL_LPM_SIGN_EXT:
1038 assert(idx == 0);
1039 return net->u_.reduce.q;
1041 case IVL_LPM_SHIFTL:
1042 case IVL_LPM_SHIFTR:
1043 assert(idx == 0);
1044 return net->u_.shift.q;
1046 case IVL_LPM_SFUNC:
1047 assert(idx == 0);
1048 return net->u_.sfunc.pins[0];
1050 case IVL_LPM_UFUNC:
1051 assert(idx == 0);
1052 return net->u_.ufunc.pins[0];
1054 case IVL_LPM_CONCAT:
1055 return net->u_.concat.pins[0];
1057 case IVL_LPM_PART_VP:
1058 case IVL_LPM_PART_PV:
1059 case IVL_LPM_PART_BI:
1060 assert(idx == 0);
1061 return net->u_.part.q;
1063 case IVL_LPM_REPEAT:
1064 assert(idx == 0);
1065 return net->u_.repeat.q;
1067 case IVL_LPM_ARRAY:
1068 assert(idx == 0);
1069 return net->u_.array.q;
1071 default:
1072 assert(0);
1073 return 0;
1077 extern "C" ivl_scope_t ivl_lpm_scope(ivl_lpm_t net)
1079 assert(net);
1080 return net->scope;
1083 extern "C" ivl_nexus_t ivl_lpm_select(ivl_lpm_t net)
1085 switch (net->type) {
1087 case IVL_LPM_MUX:
1088 return net->u_.mux.s;
1090 case IVL_LPM_ARRAY:
1091 return net->u_.array.a;
1093 default:
1094 assert(0);
1095 return 0;
1099 extern "C" unsigned ivl_lpm_selects(ivl_lpm_t net)
1101 switch (net->type) {
1102 case IVL_LPM_MUX:
1103 return net->u_.mux.swid;
1104 case IVL_LPM_ARRAY:
1105 return net->u_.array.swid;
1106 case IVL_LPM_CONCAT:
1107 return net->u_.concat.inputs;
1108 default:
1109 assert(0);
1110 return 0;
1114 extern "C" int ivl_lpm_signed(ivl_lpm_t net)
1116 assert(net);
1117 switch (net->type) {
1118 case IVL_LPM_FF:
1119 case IVL_LPM_MUX:
1120 return 0;
1121 case IVL_LPM_ADD:
1122 case IVL_LPM_CMP_EEQ:
1123 case IVL_LPM_CMP_EQ:
1124 case IVL_LPM_CMP_GE:
1125 case IVL_LPM_CMP_GT:
1126 case IVL_LPM_CMP_NE:
1127 case IVL_LPM_CMP_NEE:
1128 case IVL_LPM_DIVIDE:
1129 case IVL_LPM_MOD:
1130 case IVL_LPM_MULT:
1131 case IVL_LPM_POW:
1132 case IVL_LPM_SUB:
1133 return net->u_.arith.signed_flag;
1134 case IVL_LPM_RE_AND:
1135 case IVL_LPM_RE_OR:
1136 case IVL_LPM_RE_XOR:
1137 case IVL_LPM_RE_NAND:
1138 case IVL_LPM_RE_NOR:
1139 case IVL_LPM_RE_XNOR:
1140 return 0;
1141 case IVL_LPM_SHIFTL:
1142 case IVL_LPM_SHIFTR:
1143 return net->u_.shift.signed_flag;
1144 case IVL_LPM_SIGN_EXT: // Sign extend is always signed.
1145 return 1;
1146 case IVL_LPM_SFUNC:
1147 return 0;
1148 case IVL_LPM_UFUNC:
1149 return 0;
1150 case IVL_LPM_CONCAT: // Concatenations are always unsigned
1151 return 0;
1152 case IVL_LPM_PART_VP:
1153 case IVL_LPM_PART_PV:
1154 case IVL_LPM_PART_BI:
1155 return net->u_.part.signed_flag;
1156 case IVL_LPM_REPEAT:
1157 return 0;
1158 case IVL_LPM_ARRAY: // Array ports take the signedness of the array.
1159 return net->u_.array.sig->signed_;
1160 default:
1161 assert(0);
1162 return 0;
1166 extern "C" unsigned ivl_lpm_size(ivl_lpm_t net)
1168 switch (net->type) {
1169 case IVL_LPM_MUX:
1170 return net->u_.mux.size;
1171 case IVL_LPM_SFUNC:
1172 return net->u_.sfunc.ports - 1;
1173 case IVL_LPM_UFUNC:
1174 return net->u_.ufunc.ports - 1;
1175 case IVL_LPM_REPEAT:
1176 return net->u_.repeat.count;
1177 default:
1178 assert(0);
1179 return 0;
1183 extern "C" const char* ivl_lpm_string(ivl_lpm_t net)
1185 assert(net->type == IVL_LPM_SFUNC);
1186 return net->u_.sfunc.fun_name;
1189 extern "C" ivl_lpm_type_t ivl_lpm_type(ivl_lpm_t net)
1191 return net->type;
1194 extern "C" unsigned ivl_lpm_width(ivl_lpm_t net)
1196 assert(net);
1197 return net->width;
1200 extern "C" ivl_expr_t ivl_lval_mux(ivl_lval_t net)
1202 assert(net);
1203 if (net->type_ == IVL_LVAL_MUX)
1204 return net->idx;
1205 return 0x0;
1208 extern "C" ivl_expr_t ivl_lval_idx(ivl_lval_t net)
1210 assert(net);
1212 if (net->type_ == IVL_LVAL_ARR)
1213 return net->idx;
1214 return 0x0;
1217 extern "C" ivl_expr_t ivl_lval_part_off(ivl_lval_t net)
1219 assert(net);
1220 return net->loff;
1223 extern "C" unsigned ivl_lval_width(ivl_lval_t net)
1225 assert(net);
1226 return net->width_;
1229 extern "C" ivl_signal_t ivl_lval_sig(ivl_lval_t net)
1231 assert(net);
1232 switch (net->type_) {
1233 case IVL_LVAL_REG:
1234 case IVL_LVAL_NET:
1235 case IVL_LVAL_MUX:
1236 case IVL_LVAL_ARR:
1237 return net->n.sig;
1238 default:
1239 return 0;
1244 * The nexus name is rarely needed. (Shouldn't be needed at all!) This
1245 * function will calculate the name if it is not already calculated.
1247 extern "C" const char* ivl_nexus_name(ivl_nexus_t net)
1249 assert(net);
1250 if (net->name_ == 0) {
1251 net->name_ = api_strings.add(net->nexus_->name());
1253 return net->name_;
1256 extern "C" void* ivl_nexus_get_private(ivl_nexus_t net)
1258 assert(net);
1259 return net->private_data;
1262 extern "C" void ivl_nexus_set_private(ivl_nexus_t net, void*data)
1264 assert(net);
1265 net->private_data = data;
1268 extern "C" unsigned ivl_nexus_ptrs(ivl_nexus_t net)
1270 assert(net);
1271 return net->nptr_;
1274 extern "C" ivl_nexus_ptr_t ivl_nexus_ptr(ivl_nexus_t net, unsigned idx)
1276 assert(net);
1277 assert(idx < net->nptr_);
1278 return net->ptrs_ + idx;
1281 extern "C" ivl_drive_t ivl_nexus_ptr_drive0(ivl_nexus_ptr_t net)
1283 assert(net);
1284 return (ivl_drive_t)(net->drive0);
1287 extern "C" ivl_drive_t ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net)
1289 assert(net);
1290 return (ivl_drive_t)(net->drive1);
1293 extern "C" unsigned ivl_nexus_ptr_pin(ivl_nexus_ptr_t net)
1295 assert(net);
1296 return net->pin_;
1299 extern "C" ivl_net_const_t ivl_nexus_ptr_con(ivl_nexus_ptr_t net)
1301 if (net == 0)
1302 return 0;
1303 if (net->type_ != __NEXUS_PTR_CON)
1304 return 0;
1305 return net->l.con;
1308 extern "C" ivl_net_logic_t ivl_nexus_ptr_log(ivl_nexus_ptr_t net)
1310 if (net == 0)
1311 return 0;
1312 if (net->type_ != __NEXUS_PTR_LOG)
1313 return 0;
1314 return net->l.log;
1317 extern "C" ivl_lpm_t ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net)
1319 if (net == 0)
1320 return 0;
1321 if (net->type_ != __NEXUS_PTR_LPM)
1322 return 0;
1323 return net->l.lpm;
1326 extern "C" ivl_signal_t ivl_nexus_ptr_sig(ivl_nexus_ptr_t net)
1328 if (net == 0)
1329 return 0;
1330 if (net->type_ != __NEXUS_PTR_SIG)
1331 return 0;
1332 return net->l.sig;
1335 extern "C" const char* ivl_parameter_basename(ivl_parameter_t net)
1337 assert(net);
1338 return net->basename;
1341 extern "C" ivl_expr_t ivl_parameter_expr(ivl_parameter_t net)
1343 assert(net);
1344 return net->value;
1347 extern "C" const char* ivl_parameter_file(ivl_parameter_t net)
1349 assert(net);
1350 return net->file.str();
1353 extern "C" unsigned ivl_parameter_lineno(ivl_parameter_t net)
1355 assert(net);
1356 return net->lineno;
1359 extern "C" ivl_scope_t ivl_parameter_scope(ivl_parameter_t net)
1361 assert(net);
1362 return net->scope;
1365 extern "C" ivl_nexus_t ivl_path_condit(ivl_delaypath_t obj)
1367 assert(obj);
1368 return obj->condit;
1371 extern "C" int ivl_path_is_condit(ivl_delaypath_t obj)
1373 assert(obj);
1374 return obj->conditional ? 1 : 0;
1377 extern uint64_t ivl_path_delay(ivl_delaypath_t obj, ivl_path_edge_t edg)
1379 assert(obj);
1380 return obj->delay[edg];
1383 extern ivl_scope_t ivl_path_scope(ivl_delaypath_t obj)
1385 assert(obj);
1386 assert(obj->scope);
1387 return obj->scope;
1390 extern ivl_nexus_t ivl_path_source(ivl_delaypath_t net)
1392 return net->src;
1395 extern int ivl_path_source_posedge(ivl_delaypath_t net)
1397 return net->posedge ? 1 : 0;
1400 extern int ivl_path_source_negedge(ivl_delaypath_t net)
1402 return net->negedge ? 1 : 0;
1405 extern "C" ivl_process_type_t ivl_process_type(ivl_process_t net)
1407 return net->type_;
1410 extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net)
1412 return net->scope_;
1415 extern "C" ivl_statement_t ivl_process_stmt(ivl_process_t net)
1417 return net->stmt_;
1420 extern "C" unsigned ivl_process_attr_cnt(ivl_process_t net)
1422 return net->nattr;
1425 extern "C" ivl_attribute_t ivl_process_attr_val(ivl_process_t net,
1426 unsigned idx)
1428 assert(idx < net->nattr);
1429 return net->attr + idx;
1432 extern "C" unsigned ivl_scope_attr_cnt(ivl_scope_t net)
1434 assert(net);
1435 return net->nattr;
1438 extern "C" ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net,
1439 unsigned idx)
1441 assert(idx < net->nattr);
1442 return net->attr + idx;
1445 extern "C" const char* ivl_scope_basename(ivl_scope_t net)
1447 assert(net);
1449 return net->name_;
1452 extern "C" int ivl_scope_children(ivl_scope_t net,
1453 ivl_scope_f func,
1454 void*cd)
1456 for (ivl_scope_t cur = net->child_; cur; cur = cur->sibling_) {
1457 int rc = func(cur, cd);
1458 if (rc != 0)
1459 return rc;
1462 return 0;
1465 extern "C" ivl_statement_t ivl_scope_def(ivl_scope_t net)
1467 assert(net);
1468 return net->def;
1471 extern "C" const char*ivl_scope_def_file(ivl_scope_t net)
1473 assert(net);
1474 return net->def_file.str();
1477 extern "C" unsigned ivl_scope_def_lineno(ivl_scope_t net)
1479 assert(net);
1480 return net->def_lineno;
1483 extern "C" unsigned ivl_scope_events(ivl_scope_t net)
1485 assert(net);
1486 return net->nevent_;
1489 extern "C" ivl_event_t ivl_scope_event(ivl_scope_t net, unsigned idx)
1491 assert(net);
1492 assert(idx < net->nevent_);
1493 return net->event_[idx];
1496 extern "C" const char*ivl_scope_file(ivl_scope_t net)
1498 assert(net);
1499 return net->file.str();
1502 extern "C" unsigned ivl_scope_lineno(ivl_scope_t net)
1504 assert(net);
1505 return net->lineno;
1508 extern "C" unsigned ivl_scope_logs(ivl_scope_t net)
1510 assert(net);
1511 return net->nlog_;
1514 extern "C" ivl_net_logic_t ivl_scope_log(ivl_scope_t net, unsigned idx)
1516 assert(net);
1517 assert(idx < net->nlog_);
1518 return net->log_[idx];
1521 extern "C" unsigned ivl_scope_lpms(ivl_scope_t net)
1523 assert(net);
1524 return net->nlpm_;
1527 extern "C" ivl_lpm_t ivl_scope_lpm(ivl_scope_t net, unsigned idx)
1529 assert(net);
1530 assert(idx < net->nlpm_);
1531 return net->lpm_[idx];
1534 static unsigned scope_name_len(ivl_scope_t net)
1536 unsigned len = 0;
1538 for (ivl_scope_t cur = net ; cur ; cur = cur->parent)
1539 len += strlen(cur->name_) + 1;
1541 return len;
1544 static void push_scope_basename(ivl_scope_t net, char*buf)
1546 if (net->parent == 0) {
1547 strcpy(buf, net->name_);
1548 return;
1551 push_scope_basename(net->parent, buf);
1552 strcat(buf, ".");
1553 strcat(buf, net->name_);
1556 extern "C" const char* ivl_scope_name(ivl_scope_t net)
1558 static char*name_buffer = 0;
1559 static unsigned name_size = 0;
1561 if (net->parent == 0)
1562 return net->name_;
1564 unsigned needlen = scope_name_len(net);
1566 if (name_size < needlen) {
1567 name_buffer = (char*)realloc(name_buffer, needlen);
1568 name_size = needlen;
1572 push_scope_basename(net, name_buffer);
1574 return name_buffer;
1577 extern "C" unsigned ivl_scope_params(ivl_scope_t net)
1579 assert(net);
1580 return net->nparam_;
1583 extern "C" ivl_parameter_t ivl_scope_param(ivl_scope_t net, unsigned idx)
1585 assert(net);
1586 assert(idx < net->nparam_);
1587 return net->param_ + idx;
1590 extern "C" ivl_scope_t ivl_scope_parent(ivl_scope_t net)
1592 assert(net);
1593 return net->parent;
1596 extern "C" unsigned ivl_scope_ports(ivl_scope_t net)
1598 assert(net);
1599 assert(net->type_ == IVL_SCT_FUNCTION);
1600 return net->ports;
1603 extern "C" ivl_signal_t ivl_scope_port(ivl_scope_t net, unsigned idx)
1605 assert(net);
1606 assert(net->type_ == IVL_SCT_FUNCTION);
1607 assert(idx < net->ports);
1608 return net->port[idx];
1611 extern "C" unsigned ivl_scope_sigs(ivl_scope_t net)
1613 assert(net);
1614 return net->nsigs_;
1617 extern "C" ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx)
1619 assert(net);
1620 assert(idx < net->nsigs_);
1621 return net->sigs_[idx];
1624 extern "C" int ivl_scope_time_precision(ivl_scope_t net)
1626 assert(net);
1627 return net->time_precision;
1630 extern "C" int ivl_scope_time_units(ivl_scope_t net)
1632 assert(net);
1633 return net->time_units;
1636 extern "C" ivl_scope_type_t ivl_scope_type(ivl_scope_t net)
1638 assert(net);
1639 return net->type_;
1642 extern "C" const char* ivl_scope_tname(ivl_scope_t net)
1644 assert(net);
1645 return net->tname_;
1648 extern "C" int ivl_signal_array_base(ivl_signal_t net)
1650 return net->array_base;
1653 extern "C" unsigned ivl_signal_array_count(ivl_signal_t net)
1655 return net->array_words;
1658 extern "C" unsigned ivl_signal_dimensions(ivl_signal_t net)
1660 return net->array_dimensions_;
1663 extern "C" const char* ivl_signal_attr(ivl_signal_t net, const char*key)
1665 if (net->nattr == 0)
1666 return 0;
1668 for (unsigned idx = 0 ; idx < net->nattr ; idx += 1)
1670 if (strcmp(key, net->attr[idx].key) == 0)
1671 return net->attr[idx].type == IVL_ATT_STR
1672 ? net->attr[idx].val.str
1673 : 0;
1675 return 0;
1678 extern "C" unsigned ivl_signal_attr_cnt(ivl_signal_t net)
1680 return net->nattr;
1683 extern "C" ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx)
1685 assert(idx < net->nattr);
1686 return net->attr + idx;
1689 extern "C" const char* ivl_signal_basename(ivl_signal_t net)
1691 return net->name_;
1694 extern "C" const char* ivl_signal_name(ivl_signal_t net)
1696 static char*name_buffer = 0;
1697 static unsigned name_size = 0;
1699 unsigned needlen = scope_name_len(net->scope_);
1700 needlen += strlen(net->name_) + 2;
1702 if (name_size < needlen) {
1703 name_buffer = (char*)realloc(name_buffer, needlen);
1704 name_size = needlen;
1707 push_scope_basename(net->scope_, name_buffer);
1708 strcat(name_buffer, ".");
1709 strcat(name_buffer, net->name_);
1711 return name_buffer;
1714 extern "C" ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word)
1716 assert(word < net->array_words);
1717 if (net->array_words > 1)
1718 return net->pins[word];
1719 else
1720 return net->pin;
1723 extern "C" int ivl_signal_msb(ivl_signal_t net)
1725 assert(net->lsb_dist == 1 || net->lsb_dist == -1);
1726 return net->lsb_index + net->lsb_dist * (net->width_ - 1);
1729 extern "C" int ivl_signal_lsb(ivl_signal_t net)
1731 return net->lsb_index;
1734 extern "C" unsigned ivl_signal_width(ivl_signal_t net)
1736 return net->width_;
1739 extern "C" ivl_signal_port_t ivl_signal_port(ivl_signal_t net)
1741 return net->port_;
1744 extern "C" int ivl_signal_local(ivl_signal_t net)
1746 return net->local_;
1749 extern "C" int ivl_signal_signed(ivl_signal_t net)
1751 return net->signed_;
1754 extern "C" const char* ivl_signal_file(ivl_signal_t net)
1756 assert(net);
1757 return net->file.str();
1760 extern "C" unsigned ivl_signal_lineno(ivl_signal_t net)
1762 assert(net);
1763 return net->lineno;
1766 extern "C" int ivl_signal_integer(ivl_signal_t net)
1768 return net->isint_;
1771 extern "C" ivl_variable_type_t ivl_signal_data_type(ivl_signal_t net)
1773 return net->data_type;
1776 extern "C" unsigned ivl_signal_npath(ivl_signal_t net)
1778 return net->npath;
1781 extern "C" ivl_delaypath_t ivl_signal_path(ivl_signal_t net, unsigned idx)
1783 assert(idx < net->npath);
1784 return net->path + idx;
1787 extern "C" ivl_signal_type_t ivl_signal_type(ivl_signal_t net)
1789 return net->type_;
1792 extern "C" ivl_statement_type_t ivl_statement_type(ivl_statement_t net)
1794 return net->type_;
1797 extern "C" const char* ivl_stmt_file(ivl_statement_t net)
1799 return net->file.str();
1802 extern "C" unsigned ivl_stmt_lineno(ivl_statement_t net)
1804 return net->lineno;
1807 extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net)
1809 switch (net->type_) {
1810 case IVL_ST_BLOCK:
1811 case IVL_ST_FORK:
1812 return net->u_.block_.scope;
1813 default:
1814 assert(0);
1815 return 0;
1819 extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net)
1821 switch (net->type_) {
1822 case IVL_ST_BLOCK:
1823 case IVL_ST_FORK:
1824 return net->u_.block_.nstmt_;
1825 default:
1826 assert(0);
1827 return 0;
1831 extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net,
1832 unsigned i)
1834 switch (net->type_) {
1835 case IVL_ST_BLOCK:
1836 case IVL_ST_FORK:
1837 return net->u_.block_.stmt_ + i;
1838 default:
1839 assert(0);
1840 return 0;
1844 extern "C" ivl_scope_t ivl_stmt_call(ivl_statement_t net)
1846 switch (net->type_) {
1847 case IVL_ST_DISABLE:
1848 return net->u_.disable_.scope;
1850 case IVL_ST_UTASK:
1851 return net->u_.utask_.def;
1852 default:
1853 assert(0);
1854 return 0;
1858 extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net)
1860 switch (net->type_) {
1861 case IVL_ST_CASE:
1862 case IVL_ST_CASER:
1863 case IVL_ST_CASEX:
1864 case IVL_ST_CASEZ:
1865 return net->u_.case_.ncase;
1866 default:
1867 assert(0);
1868 return 0;
1872 extern "C" ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned idx)
1874 switch (net->type_) {
1875 case IVL_ST_CASE:
1876 case IVL_ST_CASER:
1877 case IVL_ST_CASEX:
1878 case IVL_ST_CASEZ:
1879 assert(idx < net->u_.case_.ncase);
1880 return net->u_.case_.case_ex[idx];
1882 default:
1883 assert(0);
1884 return 0;
1888 extern "C" ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned idx)
1890 switch (net->type_) {
1891 case IVL_ST_CASE:
1892 case IVL_ST_CASER:
1893 case IVL_ST_CASEX:
1894 case IVL_ST_CASEZ:
1895 assert(idx < net->u_.case_.ncase);
1896 return net->u_.case_.case_st + idx;
1898 default:
1899 assert(0);
1900 return 0;
1904 extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net)
1906 switch (net->type_) {
1907 case IVL_ST_CONDIT:
1908 return net->u_.condit_.cond_;
1910 case IVL_ST_CASE:
1911 case IVL_ST_CASER:
1912 case IVL_ST_CASEX:
1913 case IVL_ST_CASEZ:
1914 return net->u_.case_.cond;
1916 case IVL_ST_REPEAT:
1917 case IVL_ST_WHILE:
1918 return net->u_.while_.cond_;
1920 default:
1921 assert(0);
1922 return 0;
1926 extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net)
1928 assert(net->type_ == IVL_ST_CONDIT);
1929 if (net->u_.condit_.stmt_[1].type_ == IVL_ST_NONE)
1930 return 0;
1931 else
1932 return net->u_.condit_.stmt_ + 1;
1935 extern "C" ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net)
1937 assert(net->type_ == IVL_ST_CONDIT);
1938 if (net->u_.condit_.stmt_[0].type_ == IVL_ST_NONE)
1939 return 0;
1940 else
1941 return net->u_.condit_.stmt_ + 0;
1944 extern "C" ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net)
1946 switch (net->type_) {
1947 case IVL_ST_ASSIGN:
1948 case IVL_ST_ASSIGN_NB:
1949 return net->u_.assign_.delay;
1951 case IVL_ST_DELAYX:
1952 return net->u_.delayx_.expr;
1954 default:
1955 assert(0);
1956 return 0;
1960 extern "C" uint64_t ivl_stmt_delay_val(ivl_statement_t net)
1962 assert(net->type_ == IVL_ST_DELAY);
1963 return net->u_.delay_.delay_;
1966 extern "C" unsigned ivl_stmt_nevent(ivl_statement_t net)
1968 switch (net->type_) {
1969 case IVL_ST_WAIT:
1970 return net->u_.wait_.nevent;
1972 case IVL_ST_TRIGGER:
1973 return 1;
1975 default:
1976 assert(0);
1978 return 0;
1981 extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx)
1983 switch (net->type_) {
1984 case IVL_ST_WAIT:
1985 assert(idx < net->u_.wait_.nevent);
1986 if (net->u_.wait_.nevent == 1)
1987 return net->u_.wait_.event;
1988 else
1989 return net->u_.wait_.events[idx];
1991 case IVL_ST_TRIGGER:
1992 assert(idx == 0);
1993 return net->u_.wait_.event;
1994 default:
1995 assert(0);
1997 return 0;
2000 extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx)
2002 switch (net->type_) {
2003 case IVL_ST_ASSIGN:
2004 case IVL_ST_ASSIGN_NB:
2005 case IVL_ST_CASSIGN:
2006 case IVL_ST_DEASSIGN:
2007 case IVL_ST_FORCE:
2008 case IVL_ST_RELEASE:
2009 assert(idx < net->u_.assign_.lvals_);
2010 return net->u_.assign_.lval_ + idx;
2012 default:
2013 assert(0);
2015 return 0;
2018 extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net)
2020 switch (net->type_) {
2021 case IVL_ST_ASSIGN:
2022 case IVL_ST_ASSIGN_NB:
2023 case IVL_ST_CASSIGN:
2024 case IVL_ST_DEASSIGN:
2025 case IVL_ST_FORCE:
2026 case IVL_ST_RELEASE:
2027 return net->u_.assign_.lvals_;
2029 default:
2030 assert(0);
2032 return 0;
2035 extern "C" unsigned ivl_stmt_lwidth(ivl_statement_t net)
2037 assert((net->type_ == IVL_ST_ASSIGN)
2038 || (net->type_ == IVL_ST_ASSIGN_NB)
2039 || (net->type_ == IVL_ST_CASSIGN)
2040 || (net->type_ == IVL_ST_DEASSIGN)
2041 || (net->type_ == IVL_ST_FORCE)
2042 || (net->type_ == IVL_ST_RELEASE));
2044 unsigned sum = 0;
2046 unsigned nlvals;
2047 struct ivl_lval_s*lvals;
2048 nlvals = net->u_.assign_.lvals_;
2049 lvals = net->u_.assign_.lval_;
2051 for (unsigned idx = 0 ; idx < nlvals ; idx += 1) {
2052 ivl_lval_t cur = lvals + idx;
2053 switch(cur->type_) {
2054 case IVL_LVAL_MUX:
2055 sum += 1;
2056 break;
2057 case IVL_LVAL_REG:
2058 case IVL_LVAL_ARR:
2059 sum += ivl_lval_width(cur);
2060 break;
2061 default:
2062 assert(0);
2066 return sum;
2069 extern "C" const char* ivl_stmt_name(ivl_statement_t net)
2071 switch (net->type_) {
2072 case IVL_ST_STASK:
2073 return net->u_.stask_.name_;
2074 default:
2075 assert(0);
2078 return 0;
2081 extern "C" ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx)
2083 switch (net->type_) {
2084 case IVL_ST_STASK:
2085 assert(idx < net->u_.stask_.nparm_);
2086 return net->u_.stask_.parms_[idx];
2088 default:
2089 assert(0);
2091 return 0;
2094 extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net)
2096 switch (net->type_) {
2097 case IVL_ST_STASK:
2098 return net->u_.stask_.nparm_;
2099 default:
2100 assert(0);
2102 return 0;
2105 extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net)
2107 switch (net->type_) {
2108 case IVL_ST_ASSIGN:
2109 case IVL_ST_ASSIGN_NB:
2110 case IVL_ST_CASSIGN:
2111 case IVL_ST_FORCE:
2112 return net->u_.assign_.rval_;
2113 default:
2114 assert(0);
2117 return 0;
2120 extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net)
2122 switch (net->type_) {
2123 case IVL_ST_DELAY:
2124 return net->u_.delay_.stmt_;
2125 case IVL_ST_DELAYX:
2126 return net->u_.delayx_.stmt_;
2127 case IVL_ST_FOREVER:
2128 return net->u_.forever_.stmt_;
2129 case IVL_ST_WAIT:
2130 return net->u_.wait_.stmt_;
2131 case IVL_ST_REPEAT:
2132 case IVL_ST_WHILE:
2133 return net->u_.while_.stmt_;
2134 default:
2135 assert(0);
2138 return 0;