Merge branch 'master' into verilog-ams
[sverilog.git] / t-dll-api.cc
blobaa2733854f64f991f65d3db4b8711290292360c7
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_ABS:
868 assert(idx == 0);
869 return net->u_.arith.a;
871 case IVL_LPM_ADD:
872 case IVL_LPM_CMP_EEQ:
873 case IVL_LPM_CMP_EQ:
874 case IVL_LPM_CMP_GE:
875 case IVL_LPM_CMP_GT:
876 case IVL_LPM_CMP_NE:
877 case IVL_LPM_CMP_NEE:
878 case IVL_LPM_DIVIDE:
879 case IVL_LPM_MOD:
880 case IVL_LPM_MULT:
881 case IVL_LPM_POW:
882 case IVL_LPM_SUB:
883 assert(idx <= 1);
884 if (idx == 0)
885 return net->u_.arith.a;
886 else
887 return net->u_.arith.b;
889 case IVL_LPM_MUX:
890 assert(idx < net->u_.mux.size);
891 return net->u_.mux.d[idx];
893 case IVL_LPM_RE_AND:
894 case IVL_LPM_RE_OR:
895 case IVL_LPM_RE_XOR:
896 case IVL_LPM_RE_NAND:
897 case IVL_LPM_RE_NOR:
898 case IVL_LPM_RE_XNOR:
899 case IVL_LPM_SIGN_EXT:
900 assert(idx == 0);
901 return net->u_.reduce.a;
903 case IVL_LPM_SHIFTL:
904 case IVL_LPM_SHIFTR:
905 assert(idx <= 1);
906 if (idx == 0)
907 return net->u_.shift.d;
908 else
909 return net->u_.shift.s;
911 case IVL_LPM_FF:
912 assert(idx == 0);
913 return net->u_.ff.d.pin;
915 case IVL_LPM_CONCAT:
916 assert(idx < net->u_.concat.inputs);
917 return net->u_.concat.pins[idx+1];
919 case IVL_LPM_PART_VP:
920 case IVL_LPM_PART_PV:
921 case IVL_LPM_PART_BI:
922 assert(idx <= 1);
923 if (idx == 0)
924 return net->u_.part.a;
925 else
926 return net->u_.part.s;
928 case IVL_LPM_REPEAT:
929 assert(idx == 0);
930 return net->u_.repeat.a;
932 case IVL_LPM_SFUNC:
933 // Skip the return port.
934 assert(idx < (net->u_.sfunc.ports-1));
935 return net->u_.sfunc.pins[idx+1];
937 case IVL_LPM_UFUNC:
938 // Skip the return port.
939 assert(idx < (net->u_.ufunc.ports-1));
940 return net->u_.ufunc.pins[idx+1];
942 default:
943 assert(0);
944 return 0;
948 extern "C" ivl_nexus_t ivl_lpm_datab(ivl_lpm_t net, unsigned idx)
950 cerr << "ANACHRONISM: Call to anachronistic ivl_lpm_datab." << endl;
951 assert(net);
952 switch (net->type) {
954 case IVL_LPM_ADD:
955 case IVL_LPM_CMP_EQ:
956 case IVL_LPM_CMP_GE:
957 case IVL_LPM_CMP_GT:
958 case IVL_LPM_CMP_NE:
959 case IVL_LPM_DIVIDE:
960 case IVL_LPM_MOD:
961 case IVL_LPM_MULT:
962 case IVL_LPM_POW:
963 case IVL_LPM_SUB:
964 assert(idx == 0);
965 return net->u_.arith.b;
967 default:
968 assert(0);
969 return 0;
975 * This function returns the hierarchical name for the LPM device. The
976 * name needs to be built up from the scope name and the lpm base
977 * name.
979 * Anachronism: This function is provided for
980 * compatibility. Eventually, it will be removed.
982 extern "C" const char* ivl_lpm_name(ivl_lpm_t net)
984 static char*name_buffer = 0;
985 static unsigned name_size = 0;
987 ivl_scope_t scope = ivl_lpm_scope(net);
988 const char*sn = ivl_scope_name(scope);
990 unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
991 if (need > name_size) {
992 name_buffer = (char*)realloc(name_buffer, need);
993 name_size = need;
996 strcpy(name_buffer, sn);
997 char*tmp = name_buffer + strlen(sn);
998 *tmp++ = '.';
999 strcpy(tmp, net->name);
1000 return name_buffer;
1004 extern "C" ivl_nexus_t ivl_lpm_q(ivl_lpm_t net, unsigned idx)
1006 assert(net);
1008 switch (net->type) {
1009 case IVL_LPM_ABS:
1010 case IVL_LPM_ADD:
1011 case IVL_LPM_DIVIDE:
1012 case IVL_LPM_MOD:
1013 case IVL_LPM_MULT:
1014 case IVL_LPM_POW:
1015 case IVL_LPM_SUB:
1016 assert(idx == 0);
1017 return net->u_.arith.q;
1019 case IVL_LPM_CMP_GE:
1020 case IVL_LPM_CMP_GT:
1021 case IVL_LPM_CMP_EQ:
1022 case IVL_LPM_CMP_NE:
1023 case IVL_LPM_CMP_EEQ:
1024 case IVL_LPM_CMP_NEE:
1025 assert(idx == 0);
1026 return net->u_.arith.q;
1028 case IVL_LPM_FF:
1029 assert(idx == 0);
1030 return net->u_.ff.q.pin;
1032 case IVL_LPM_MUX:
1033 assert(idx == 0);
1034 return net->u_.mux.q;
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 case IVL_LPM_SIGN_EXT:
1043 assert(idx == 0);
1044 return net->u_.reduce.q;
1046 case IVL_LPM_SHIFTL:
1047 case IVL_LPM_SHIFTR:
1048 assert(idx == 0);
1049 return net->u_.shift.q;
1051 case IVL_LPM_SFUNC:
1052 assert(idx == 0);
1053 return net->u_.sfunc.pins[0];
1055 case IVL_LPM_UFUNC:
1056 assert(idx == 0);
1057 return net->u_.ufunc.pins[0];
1059 case IVL_LPM_CONCAT:
1060 return net->u_.concat.pins[0];
1062 case IVL_LPM_PART_VP:
1063 case IVL_LPM_PART_PV:
1064 case IVL_LPM_PART_BI:
1065 assert(idx == 0);
1066 return net->u_.part.q;
1068 case IVL_LPM_REPEAT:
1069 assert(idx == 0);
1070 return net->u_.repeat.q;
1072 case IVL_LPM_ARRAY:
1073 assert(idx == 0);
1074 return net->u_.array.q;
1076 default:
1077 assert(0);
1078 return 0;
1082 extern "C" ivl_scope_t ivl_lpm_scope(ivl_lpm_t net)
1084 assert(net);
1085 return net->scope;
1088 extern "C" ivl_nexus_t ivl_lpm_select(ivl_lpm_t net)
1090 switch (net->type) {
1092 case IVL_LPM_MUX:
1093 return net->u_.mux.s;
1095 case IVL_LPM_ARRAY:
1096 return net->u_.array.a;
1098 default:
1099 assert(0);
1100 return 0;
1104 extern "C" unsigned ivl_lpm_selects(ivl_lpm_t net)
1106 switch (net->type) {
1107 case IVL_LPM_MUX:
1108 return net->u_.mux.swid;
1109 case IVL_LPM_ARRAY:
1110 return net->u_.array.swid;
1111 case IVL_LPM_CONCAT:
1112 return net->u_.concat.inputs;
1113 default:
1114 assert(0);
1115 return 0;
1119 extern "C" int ivl_lpm_signed(ivl_lpm_t net)
1121 assert(net);
1122 switch (net->type) {
1123 case IVL_LPM_FF:
1124 case IVL_LPM_MUX:
1125 return 0;
1126 case IVL_LPM_ABS:
1127 case IVL_LPM_ADD:
1128 case IVL_LPM_CMP_EEQ:
1129 case IVL_LPM_CMP_EQ:
1130 case IVL_LPM_CMP_GE:
1131 case IVL_LPM_CMP_GT:
1132 case IVL_LPM_CMP_NE:
1133 case IVL_LPM_CMP_NEE:
1134 case IVL_LPM_DIVIDE:
1135 case IVL_LPM_MOD:
1136 case IVL_LPM_MULT:
1137 case IVL_LPM_POW:
1138 case IVL_LPM_SUB:
1139 return net->u_.arith.signed_flag;
1140 case IVL_LPM_RE_AND:
1141 case IVL_LPM_RE_OR:
1142 case IVL_LPM_RE_XOR:
1143 case IVL_LPM_RE_NAND:
1144 case IVL_LPM_RE_NOR:
1145 case IVL_LPM_RE_XNOR:
1146 return 0;
1147 case IVL_LPM_SHIFTL:
1148 case IVL_LPM_SHIFTR:
1149 return net->u_.shift.signed_flag;
1150 case IVL_LPM_SIGN_EXT: // Sign extend is always signed.
1151 return 1;
1152 case IVL_LPM_SFUNC:
1153 return 0;
1154 case IVL_LPM_UFUNC:
1155 return 0;
1156 case IVL_LPM_CONCAT: // Concatenations are always unsigned
1157 return 0;
1158 case IVL_LPM_PART_VP:
1159 case IVL_LPM_PART_PV:
1160 case IVL_LPM_PART_BI:
1161 return net->u_.part.signed_flag;
1162 case IVL_LPM_REPEAT:
1163 return 0;
1164 case IVL_LPM_ARRAY: // Array ports take the signedness of the array.
1165 return net->u_.array.sig->signed_;
1166 default:
1167 assert(0);
1168 return 0;
1172 extern "C" unsigned ivl_lpm_size(ivl_lpm_t net)
1174 switch (net->type) {
1175 case IVL_LPM_MUX:
1176 return net->u_.mux.size;
1177 case IVL_LPM_SFUNC:
1178 return net->u_.sfunc.ports - 1;
1179 case IVL_LPM_UFUNC:
1180 return net->u_.ufunc.ports - 1;
1181 case IVL_LPM_REPEAT:
1182 return net->u_.repeat.count;
1183 default:
1184 assert(0);
1185 return 0;
1189 extern "C" const char* ivl_lpm_string(ivl_lpm_t net)
1191 assert(net->type == IVL_LPM_SFUNC);
1192 return net->u_.sfunc.fun_name;
1195 extern "C" ivl_lpm_type_t ivl_lpm_type(ivl_lpm_t net)
1197 return net->type;
1200 extern "C" unsigned ivl_lpm_width(ivl_lpm_t net)
1202 assert(net);
1203 return net->width;
1206 extern "C" ivl_expr_t ivl_lval_mux(ivl_lval_t net)
1208 assert(net);
1209 if (net->type_ == IVL_LVAL_MUX)
1210 return net->idx;
1211 return 0x0;
1214 extern "C" ivl_expr_t ivl_lval_idx(ivl_lval_t net)
1216 assert(net);
1218 if (net->type_ == IVL_LVAL_ARR)
1219 return net->idx;
1220 return 0x0;
1223 extern "C" ivl_expr_t ivl_lval_part_off(ivl_lval_t net)
1225 assert(net);
1226 return net->loff;
1229 extern "C" unsigned ivl_lval_width(ivl_lval_t net)
1231 assert(net);
1232 return net->width_;
1235 extern "C" ivl_signal_t ivl_lval_sig(ivl_lval_t net)
1237 assert(net);
1238 switch (net->type_) {
1239 case IVL_LVAL_REG:
1240 case IVL_LVAL_NET:
1241 case IVL_LVAL_MUX:
1242 case IVL_LVAL_ARR:
1243 return net->n.sig;
1244 default:
1245 return 0;
1250 * The nexus name is rarely needed. (Shouldn't be needed at all!) This
1251 * function will calculate the name if it is not already calculated.
1253 extern "C" const char* ivl_nexus_name(ivl_nexus_t net)
1255 assert(net);
1256 if (net->name_ == 0) {
1257 net->name_ = api_strings.add(net->nexus_->name());
1259 return net->name_;
1262 extern "C" void* ivl_nexus_get_private(ivl_nexus_t net)
1264 assert(net);
1265 return net->private_data;
1268 extern "C" void ivl_nexus_set_private(ivl_nexus_t net, void*data)
1270 assert(net);
1271 net->private_data = data;
1274 extern "C" unsigned ivl_nexus_ptrs(ivl_nexus_t net)
1276 assert(net);
1277 return net->nptr_;
1280 extern "C" ivl_nexus_ptr_t ivl_nexus_ptr(ivl_nexus_t net, unsigned idx)
1282 assert(net);
1283 assert(idx < net->nptr_);
1284 return net->ptrs_ + idx;
1287 extern "C" ivl_drive_t ivl_nexus_ptr_drive0(ivl_nexus_ptr_t net)
1289 assert(net);
1290 return (ivl_drive_t)(net->drive0);
1293 extern "C" ivl_drive_t ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net)
1295 assert(net);
1296 return (ivl_drive_t)(net->drive1);
1299 extern "C" unsigned ivl_nexus_ptr_pin(ivl_nexus_ptr_t net)
1301 assert(net);
1302 return net->pin_;
1305 extern "C" ivl_net_const_t ivl_nexus_ptr_con(ivl_nexus_ptr_t net)
1307 if (net == 0)
1308 return 0;
1309 if (net->type_ != __NEXUS_PTR_CON)
1310 return 0;
1311 return net->l.con;
1314 extern "C" ivl_net_logic_t ivl_nexus_ptr_log(ivl_nexus_ptr_t net)
1316 if (net == 0)
1317 return 0;
1318 if (net->type_ != __NEXUS_PTR_LOG)
1319 return 0;
1320 return net->l.log;
1323 extern "C" ivl_lpm_t ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net)
1325 if (net == 0)
1326 return 0;
1327 if (net->type_ != __NEXUS_PTR_LPM)
1328 return 0;
1329 return net->l.lpm;
1332 extern "C" ivl_signal_t ivl_nexus_ptr_sig(ivl_nexus_ptr_t net)
1334 if (net == 0)
1335 return 0;
1336 if (net->type_ != __NEXUS_PTR_SIG)
1337 return 0;
1338 return net->l.sig;
1341 extern "C" const char* ivl_parameter_basename(ivl_parameter_t net)
1343 assert(net);
1344 return net->basename;
1347 extern "C" ivl_expr_t ivl_parameter_expr(ivl_parameter_t net)
1349 assert(net);
1350 return net->value;
1353 extern "C" const char* ivl_parameter_file(ivl_parameter_t net)
1355 assert(net);
1356 return net->file.str();
1359 extern "C" unsigned ivl_parameter_lineno(ivl_parameter_t net)
1361 assert(net);
1362 return net->lineno;
1365 extern "C" ivl_scope_t ivl_parameter_scope(ivl_parameter_t net)
1367 assert(net);
1368 return net->scope;
1371 extern "C" ivl_nexus_t ivl_path_condit(ivl_delaypath_t obj)
1373 assert(obj);
1374 return obj->condit;
1377 extern "C" int ivl_path_is_condit(ivl_delaypath_t obj)
1379 assert(obj);
1380 return obj->conditional ? 1 : 0;
1383 extern uint64_t ivl_path_delay(ivl_delaypath_t obj, ivl_path_edge_t edg)
1385 assert(obj);
1386 return obj->delay[edg];
1389 extern ivl_scope_t ivl_path_scope(ivl_delaypath_t obj)
1391 assert(obj);
1392 assert(obj->scope);
1393 return obj->scope;
1396 extern ivl_nexus_t ivl_path_source(ivl_delaypath_t net)
1398 return net->src;
1401 extern int ivl_path_source_posedge(ivl_delaypath_t net)
1403 return net->posedge ? 1 : 0;
1406 extern int ivl_path_source_negedge(ivl_delaypath_t net)
1408 return net->negedge ? 1 : 0;
1411 extern "C" ivl_process_type_t ivl_process_type(ivl_process_t net)
1413 return net->type_;
1416 extern "C" ivl_scope_t ivl_process_scope(ivl_process_t net)
1418 return net->scope_;
1421 extern "C" ivl_statement_t ivl_process_stmt(ivl_process_t net)
1423 return net->stmt_;
1426 extern "C" unsigned ivl_process_attr_cnt(ivl_process_t net)
1428 return net->nattr;
1431 extern "C" ivl_attribute_t ivl_process_attr_val(ivl_process_t net,
1432 unsigned idx)
1434 assert(idx < net->nattr);
1435 return net->attr + idx;
1438 extern "C" unsigned ivl_scope_attr_cnt(ivl_scope_t net)
1440 assert(net);
1441 return net->nattr;
1444 extern "C" ivl_attribute_t ivl_scope_attr_val(ivl_scope_t net,
1445 unsigned idx)
1447 assert(idx < net->nattr);
1448 return net->attr + idx;
1451 extern "C" const char* ivl_scope_basename(ivl_scope_t net)
1453 assert(net);
1455 return net->name_;
1458 extern "C" int ivl_scope_children(ivl_scope_t net,
1459 ivl_scope_f func,
1460 void*cd)
1462 for (ivl_scope_t cur = net->child_; cur; cur = cur->sibling_) {
1463 int rc = func(cur, cd);
1464 if (rc != 0)
1465 return rc;
1468 return 0;
1471 extern "C" ivl_statement_t ivl_scope_def(ivl_scope_t net)
1473 assert(net);
1474 return net->def;
1477 extern "C" const char*ivl_scope_def_file(ivl_scope_t net)
1479 assert(net);
1480 return net->def_file.str();
1483 extern "C" unsigned ivl_scope_def_lineno(ivl_scope_t net)
1485 assert(net);
1486 return net->def_lineno;
1489 extern "C" unsigned ivl_scope_events(ivl_scope_t net)
1491 assert(net);
1492 return net->nevent_;
1495 extern "C" ivl_event_t ivl_scope_event(ivl_scope_t net, unsigned idx)
1497 assert(net);
1498 assert(idx < net->nevent_);
1499 return net->event_[idx];
1502 extern "C" const char*ivl_scope_file(ivl_scope_t net)
1504 assert(net);
1505 return net->file.str();
1508 extern "C" unsigned ivl_scope_lineno(ivl_scope_t net)
1510 assert(net);
1511 return net->lineno;
1514 extern "C" unsigned ivl_scope_logs(ivl_scope_t net)
1516 assert(net);
1517 return net->nlog_;
1520 extern "C" ivl_net_logic_t ivl_scope_log(ivl_scope_t net, unsigned idx)
1522 assert(net);
1523 assert(idx < net->nlog_);
1524 return net->log_[idx];
1527 extern "C" unsigned ivl_scope_lpms(ivl_scope_t net)
1529 assert(net);
1530 return net->nlpm_;
1533 extern "C" ivl_lpm_t ivl_scope_lpm(ivl_scope_t net, unsigned idx)
1535 assert(net);
1536 assert(idx < net->nlpm_);
1537 return net->lpm_[idx];
1540 static unsigned scope_name_len(ivl_scope_t net)
1542 unsigned len = 0;
1544 for (ivl_scope_t cur = net ; cur ; cur = cur->parent)
1545 len += strlen(cur->name_) + 1;
1547 return len;
1550 static void push_scope_basename(ivl_scope_t net, char*buf)
1552 if (net->parent == 0) {
1553 strcpy(buf, net->name_);
1554 return;
1557 push_scope_basename(net->parent, buf);
1558 strcat(buf, ".");
1559 strcat(buf, net->name_);
1562 extern "C" const char* ivl_scope_name(ivl_scope_t net)
1564 static char*name_buffer = 0;
1565 static unsigned name_size = 0;
1567 if (net->parent == 0)
1568 return net->name_;
1570 unsigned needlen = scope_name_len(net);
1572 if (name_size < needlen) {
1573 name_buffer = (char*)realloc(name_buffer, needlen);
1574 name_size = needlen;
1578 push_scope_basename(net, name_buffer);
1580 return name_buffer;
1583 extern "C" unsigned ivl_scope_params(ivl_scope_t net)
1585 assert(net);
1586 return net->nparam_;
1589 extern "C" ivl_parameter_t ivl_scope_param(ivl_scope_t net, unsigned idx)
1591 assert(net);
1592 assert(idx < net->nparam_);
1593 return net->param_ + idx;
1596 extern "C" ivl_scope_t ivl_scope_parent(ivl_scope_t net)
1598 assert(net);
1599 return net->parent;
1602 extern "C" unsigned ivl_scope_ports(ivl_scope_t net)
1604 assert(net);
1605 assert(net->type_ == IVL_SCT_FUNCTION);
1606 return net->ports;
1609 extern "C" ivl_signal_t ivl_scope_port(ivl_scope_t net, unsigned idx)
1611 assert(net);
1612 assert(net->type_ == IVL_SCT_FUNCTION);
1613 assert(idx < net->ports);
1614 return net->port[idx];
1617 extern "C" unsigned ivl_scope_sigs(ivl_scope_t net)
1619 assert(net);
1620 return net->nsigs_;
1623 extern "C" ivl_signal_t ivl_scope_sig(ivl_scope_t net, unsigned idx)
1625 assert(net);
1626 assert(idx < net->nsigs_);
1627 return net->sigs_[idx];
1630 extern "C" unsigned ivl_scope_switches(ivl_scope_t net)
1632 assert(net);
1633 return net->switches.size();
1636 extern "C" ivl_switch_t ivl_scope_switch(ivl_scope_t net, unsigned idx)
1638 assert(net);
1639 assert(idx < net->switches.size());
1640 return net->switches[idx];
1643 extern "C" int ivl_scope_time_precision(ivl_scope_t net)
1645 assert(net);
1646 return net->time_precision;
1649 extern "C" int ivl_scope_time_units(ivl_scope_t net)
1651 assert(net);
1652 return net->time_units;
1655 extern "C" ivl_scope_type_t ivl_scope_type(ivl_scope_t net)
1657 assert(net);
1658 return net->type_;
1661 extern "C" const char* ivl_scope_tname(ivl_scope_t net)
1663 assert(net);
1664 return net->tname_;
1667 extern "C" int ivl_signal_array_base(ivl_signal_t net)
1669 return net->array_base;
1672 extern "C" unsigned ivl_signal_array_count(ivl_signal_t net)
1674 return net->array_words;
1677 extern "C" unsigned ivl_signal_dimensions(ivl_signal_t net)
1679 return net->array_dimensions_;
1682 extern "C" const char* ivl_signal_attr(ivl_signal_t net, const char*key)
1684 if (net->nattr == 0)
1685 return 0;
1687 for (unsigned idx = 0 ; idx < net->nattr ; idx += 1)
1689 if (strcmp(key, net->attr[idx].key) == 0)
1690 return net->attr[idx].type == IVL_ATT_STR
1691 ? net->attr[idx].val.str
1692 : 0;
1694 return 0;
1697 extern "C" unsigned ivl_signal_attr_cnt(ivl_signal_t net)
1699 return net->nattr;
1702 extern "C" ivl_attribute_t ivl_signal_attr_val(ivl_signal_t net, unsigned idx)
1704 assert(idx < net->nattr);
1705 return net->attr + idx;
1708 extern "C" const char* ivl_signal_basename(ivl_signal_t net)
1710 return net->name_;
1713 extern "C" const char* ivl_signal_name(ivl_signal_t net)
1715 static char*name_buffer = 0;
1716 static unsigned name_size = 0;
1718 unsigned needlen = scope_name_len(net->scope_);
1719 needlen += strlen(net->name_) + 2;
1721 if (name_size < needlen) {
1722 name_buffer = (char*)realloc(name_buffer, needlen);
1723 name_size = needlen;
1726 push_scope_basename(net->scope_, name_buffer);
1727 strcat(name_buffer, ".");
1728 strcat(name_buffer, net->name_);
1730 return name_buffer;
1733 extern "C" ivl_nexus_t ivl_signal_nex(ivl_signal_t net, unsigned word)
1735 assert(word < net->array_words);
1736 if (net->array_words > 1)
1737 return net->pins[word];
1738 else
1739 return net->pin;
1742 extern "C" int ivl_signal_msb(ivl_signal_t net)
1744 assert(net->lsb_dist == 1 || net->lsb_dist == -1);
1745 return net->lsb_index + net->lsb_dist * (net->width_ - 1);
1748 extern "C" int ivl_signal_lsb(ivl_signal_t net)
1750 return net->lsb_index;
1753 extern "C" unsigned ivl_signal_width(ivl_signal_t net)
1755 return net->width_;
1758 extern "C" ivl_signal_port_t ivl_signal_port(ivl_signal_t net)
1760 return net->port_;
1763 extern "C" int ivl_signal_local(ivl_signal_t net)
1765 return net->local_;
1768 extern "C" int ivl_signal_signed(ivl_signal_t net)
1770 return net->signed_;
1773 extern "C" const char* ivl_signal_file(ivl_signal_t net)
1775 assert(net);
1776 return net->file.str();
1779 extern "C" unsigned ivl_signal_lineno(ivl_signal_t net)
1781 assert(net);
1782 return net->lineno;
1785 extern "C" int ivl_signal_integer(ivl_signal_t net)
1787 return net->isint_;
1790 extern "C" ivl_variable_type_t ivl_signal_data_type(ivl_signal_t net)
1792 return net->data_type;
1795 extern "C" unsigned ivl_signal_npath(ivl_signal_t net)
1797 return net->npath;
1800 extern "C" ivl_delaypath_t ivl_signal_path(ivl_signal_t net, unsigned idx)
1802 assert(idx < net->npath);
1803 return net->path + idx;
1806 extern "C" ivl_signal_type_t ivl_signal_type(ivl_signal_t net)
1808 return net->type_;
1811 extern "C" ivl_statement_type_t ivl_statement_type(ivl_statement_t net)
1813 return net->type_;
1816 extern "C" const char* ivl_stmt_file(ivl_statement_t net)
1818 return net->file.str();
1821 extern "C" unsigned ivl_stmt_lineno(ivl_statement_t net)
1823 return net->lineno;
1826 extern "C" ivl_scope_t ivl_stmt_block_scope(ivl_statement_t net)
1828 switch (net->type_) {
1829 case IVL_ST_BLOCK:
1830 case IVL_ST_FORK:
1831 return net->u_.block_.scope;
1832 default:
1833 assert(0);
1834 return 0;
1838 extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net)
1840 switch (net->type_) {
1841 case IVL_ST_BLOCK:
1842 case IVL_ST_FORK:
1843 return net->u_.block_.nstmt_;
1844 default:
1845 assert(0);
1846 return 0;
1850 extern "C" ivl_statement_t ivl_stmt_block_stmt(ivl_statement_t net,
1851 unsigned i)
1853 switch (net->type_) {
1854 case IVL_ST_BLOCK:
1855 case IVL_ST_FORK:
1856 return net->u_.block_.stmt_ + i;
1857 default:
1858 assert(0);
1859 return 0;
1863 extern "C" ivl_scope_t ivl_stmt_call(ivl_statement_t net)
1865 switch (net->type_) {
1866 case IVL_ST_DISABLE:
1867 return net->u_.disable_.scope;
1869 case IVL_ST_UTASK:
1870 return net->u_.utask_.def;
1871 default:
1872 assert(0);
1873 return 0;
1877 extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net)
1879 switch (net->type_) {
1880 case IVL_ST_CASE:
1881 case IVL_ST_CASER:
1882 case IVL_ST_CASEX:
1883 case IVL_ST_CASEZ:
1884 return net->u_.case_.ncase;
1885 default:
1886 assert(0);
1887 return 0;
1891 extern "C" ivl_expr_t ivl_stmt_case_expr(ivl_statement_t net, unsigned idx)
1893 switch (net->type_) {
1894 case IVL_ST_CASE:
1895 case IVL_ST_CASER:
1896 case IVL_ST_CASEX:
1897 case IVL_ST_CASEZ:
1898 assert(idx < net->u_.case_.ncase);
1899 return net->u_.case_.case_ex[idx];
1901 default:
1902 assert(0);
1903 return 0;
1907 extern "C" ivl_statement_t ivl_stmt_case_stmt(ivl_statement_t net, unsigned idx)
1909 switch (net->type_) {
1910 case IVL_ST_CASE:
1911 case IVL_ST_CASER:
1912 case IVL_ST_CASEX:
1913 case IVL_ST_CASEZ:
1914 assert(idx < net->u_.case_.ncase);
1915 return net->u_.case_.case_st + idx;
1917 default:
1918 assert(0);
1919 return 0;
1923 extern "C" ivl_expr_t ivl_stmt_cond_expr(ivl_statement_t net)
1925 switch (net->type_) {
1926 case IVL_ST_CONDIT:
1927 return net->u_.condit_.cond_;
1929 case IVL_ST_CASE:
1930 case IVL_ST_CASER:
1931 case IVL_ST_CASEX:
1932 case IVL_ST_CASEZ:
1933 return net->u_.case_.cond;
1935 case IVL_ST_REPEAT:
1936 case IVL_ST_WHILE:
1937 return net->u_.while_.cond_;
1939 default:
1940 assert(0);
1941 return 0;
1945 extern "C" ivl_statement_t ivl_stmt_cond_false(ivl_statement_t net)
1947 assert(net->type_ == IVL_ST_CONDIT);
1948 if (net->u_.condit_.stmt_[1].type_ == IVL_ST_NONE)
1949 return 0;
1950 else
1951 return net->u_.condit_.stmt_ + 1;
1954 extern "C" ivl_statement_t ivl_stmt_cond_true(ivl_statement_t net)
1956 assert(net->type_ == IVL_ST_CONDIT);
1957 if (net->u_.condit_.stmt_[0].type_ == IVL_ST_NONE)
1958 return 0;
1959 else
1960 return net->u_.condit_.stmt_ + 0;
1963 extern "C" ivl_expr_t ivl_stmt_delay_expr(ivl_statement_t net)
1965 switch (net->type_) {
1966 case IVL_ST_ASSIGN:
1967 case IVL_ST_ASSIGN_NB:
1968 return net->u_.assign_.delay;
1970 case IVL_ST_DELAYX:
1971 return net->u_.delayx_.expr;
1973 default:
1974 assert(0);
1975 return 0;
1979 extern "C" uint64_t ivl_stmt_delay_val(ivl_statement_t net)
1981 assert(net->type_ == IVL_ST_DELAY);
1982 return net->u_.delay_.delay_;
1985 extern "C" unsigned ivl_stmt_nevent(ivl_statement_t net)
1987 switch (net->type_) {
1988 case IVL_ST_WAIT:
1989 return net->u_.wait_.nevent;
1991 case IVL_ST_TRIGGER:
1992 return 1;
1994 default:
1995 assert(0);
1997 return 0;
2000 extern "C" ivl_event_t ivl_stmt_events(ivl_statement_t net, unsigned idx)
2002 switch (net->type_) {
2003 case IVL_ST_WAIT:
2004 assert(idx < net->u_.wait_.nevent);
2005 if (net->u_.wait_.nevent == 1)
2006 return net->u_.wait_.event;
2007 else
2008 return net->u_.wait_.events[idx];
2010 case IVL_ST_TRIGGER:
2011 assert(idx == 0);
2012 return net->u_.wait_.event;
2013 default:
2014 assert(0);
2016 return 0;
2019 extern "C" ivl_lval_t ivl_stmt_lval(ivl_statement_t net, unsigned idx)
2021 switch (net->type_) {
2022 case IVL_ST_ASSIGN:
2023 case IVL_ST_ASSIGN_NB:
2024 case IVL_ST_CASSIGN:
2025 case IVL_ST_DEASSIGN:
2026 case IVL_ST_FORCE:
2027 case IVL_ST_RELEASE:
2028 assert(idx < net->u_.assign_.lvals_);
2029 return net->u_.assign_.lval_ + idx;
2031 default:
2032 assert(0);
2034 return 0;
2037 extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net)
2039 switch (net->type_) {
2040 case IVL_ST_ASSIGN:
2041 case IVL_ST_ASSIGN_NB:
2042 case IVL_ST_CASSIGN:
2043 case IVL_ST_DEASSIGN:
2044 case IVL_ST_FORCE:
2045 case IVL_ST_RELEASE:
2046 return net->u_.assign_.lvals_;
2048 default:
2049 assert(0);
2051 return 0;
2054 extern "C" unsigned ivl_stmt_lwidth(ivl_statement_t net)
2056 assert((net->type_ == IVL_ST_ASSIGN)
2057 || (net->type_ == IVL_ST_ASSIGN_NB)
2058 || (net->type_ == IVL_ST_CASSIGN)
2059 || (net->type_ == IVL_ST_DEASSIGN)
2060 || (net->type_ == IVL_ST_FORCE)
2061 || (net->type_ == IVL_ST_RELEASE));
2063 unsigned sum = 0;
2065 unsigned nlvals;
2066 struct ivl_lval_s*lvals;
2067 nlvals = net->u_.assign_.lvals_;
2068 lvals = net->u_.assign_.lval_;
2070 for (unsigned idx = 0 ; idx < nlvals ; idx += 1) {
2071 ivl_lval_t cur = lvals + idx;
2072 switch(cur->type_) {
2073 case IVL_LVAL_MUX:
2074 sum += 1;
2075 break;
2076 case IVL_LVAL_REG:
2077 case IVL_LVAL_ARR:
2078 sum += ivl_lval_width(cur);
2079 break;
2080 default:
2081 assert(0);
2085 return sum;
2088 extern "C" const char* ivl_stmt_name(ivl_statement_t net)
2090 switch (net->type_) {
2091 case IVL_ST_STASK:
2092 return net->u_.stask_.name_;
2093 default:
2094 assert(0);
2097 return 0;
2100 extern "C" ivl_expr_t ivl_stmt_parm(ivl_statement_t net, unsigned idx)
2102 switch (net->type_) {
2103 case IVL_ST_STASK:
2104 assert(idx < net->u_.stask_.nparm_);
2105 return net->u_.stask_.parms_[idx];
2107 default:
2108 assert(0);
2110 return 0;
2113 extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net)
2115 switch (net->type_) {
2116 case IVL_ST_STASK:
2117 return net->u_.stask_.nparm_;
2118 default:
2119 assert(0);
2121 return 0;
2124 extern "C" ivl_expr_t ivl_stmt_rval(ivl_statement_t net)
2126 switch (net->type_) {
2127 case IVL_ST_ASSIGN:
2128 case IVL_ST_ASSIGN_NB:
2129 case IVL_ST_CASSIGN:
2130 case IVL_ST_FORCE:
2131 return net->u_.assign_.rval_;
2132 default:
2133 assert(0);
2136 return 0;
2139 extern "C" ivl_statement_t ivl_stmt_sub_stmt(ivl_statement_t net)
2141 switch (net->type_) {
2142 case IVL_ST_DELAY:
2143 return net->u_.delay_.stmt_;
2144 case IVL_ST_DELAYX:
2145 return net->u_.delayx_.stmt_;
2146 case IVL_ST_FOREVER:
2147 return net->u_.forever_.stmt_;
2148 case IVL_ST_WAIT:
2149 return net->u_.wait_.stmt_;
2150 case IVL_ST_REPEAT:
2151 case IVL_ST_WHILE:
2152 return net->u_.while_.stmt_;
2153 default:
2154 assert(0);
2157 return 0;
2160 extern "C" const char*ivl_switch_basename(ivl_switch_t net)
2162 return net->name;
2165 extern "C" ivl_switch_type_t ivl_switch_type(ivl_switch_t net)
2167 return net->type;
2170 extern "C" ivl_nexus_t ivl_switch_a(ivl_switch_t net)
2172 return net->pins[0];
2175 extern "C" ivl_nexus_t ivl_switch_b(ivl_switch_t net)
2177 return net->pins[1];
2180 extern "C" ivl_nexus_t ivl_switch_enable(ivl_switch_t net)
2182 return net->pins[2];