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)
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 #ident "$Id: t-dll-api.cc,v 1.144 2007/04/02 01:12:34 steve Exp $"
24 # include "StringHeap.h"
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
,
45 for (ivl_process_t idx
= des
->threads_
; idx
; idx
= idx
->next_
) {
46 int rc
= (func
)(idx
, cd
);
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
)
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
)
95 inline static const char *basename(ivl_scope_t scope
, const char *inst
)
97 inst
+= strlen(ivl_scope_name(scope
));
102 extern "C" ivl_variable_type_t
ivl_const_type(ivl_net_const_t net
)
108 extern "C" const char*ivl_const_bits(ivl_net_const_t net
)
114 if (net
->width_
<= sizeof(net
->b
.bit_
))
124 extern "C" ivl_nexus_t
ivl_const_nex(ivl_net_const_t net
)
130 extern "C" double ivl_const_real(ivl_net_const_t 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
)
143 extern "C" unsigned ivl_const_width(ivl_net_const_t net
)
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
);
163 strcpy(name_buffer
, sn
);
164 char*tmp
= name_buffer
+ strlen(sn
);
166 strcpy(tmp
, net
->name
);
168 cerr
<< "ANACHRONISM: Call to anachronistic ivl_event_name." << endl
;
173 extern "C" const char* ivl_event_basename(ivl_event_t net
)
178 extern "C" ivl_scope_t
ivl_event_scope(ivl_event_t net
)
183 extern "C" unsigned ivl_event_nany(ivl_event_t net
)
189 extern "C" ivl_nexus_t
ivl_event_any(ivl_event_t net
, unsigned idx
)
192 assert(idx
< net
->nany
);
193 return net
->pins
[idx
];
196 extern "C" unsigned ivl_event_nneg(ivl_event_t net
)
202 extern "C" ivl_nexus_t
ivl_event_neg(ivl_event_t net
, unsigned idx
)
205 assert(idx
< net
->nneg
);
206 return net
->pins
[net
->nany
+ idx
];
209 extern "C" unsigned ivl_event_npos(ivl_event_t net
)
215 extern "C" ivl_nexus_t
ivl_event_pos(ivl_event_t net
, unsigned idx
)
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
)
232 switch (net
->type_
) {
235 return net
->u_
.ufunc_
.def
;
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_
) {
255 return net
->u_
.sfunc_
.name_
;
258 return net
->u_
.signal_
.sig
->name_
;
266 extern "C" char ivl_expr_opcode(ivl_expr_t net
)
269 switch (net
->type_
) {
271 return net
->u_
.binary_
.op_
;
274 return net
->u_
.unary_
.op_
;
282 extern "C" ivl_expr_t
ivl_expr_oper1(ivl_expr_t net
)
285 switch (net
->type_
) {
288 return net
->u_
.binary_
.lef_
;
291 return net
->u_
.unary_
.sub_
;
294 return net
->u_
.memory_
.idx_
;
297 return net
->u_
.signal_
.word
;
300 return net
->u_
.ternary_
.cond
;
309 extern "C" ivl_expr_t
ivl_expr_oper2(ivl_expr_t net
)
312 switch (net
->type_
) {
315 return net
->u_
.binary_
.rig_
;
318 return net
->u_
.ternary_
.true_e
;
327 extern "C" ivl_expr_t
ivl_expr_oper3(ivl_expr_t net
)
330 switch (net
->type_
) {
333 return net
->u_
.ternary_
.false_e
;
341 extern "C" ivl_parameter_t
ivl_expr_parameter(ivl_expr_t net
)
343 switch (net
->type_
) {
345 return net
->u_
.number_
.parameter
;
347 return net
->u_
.string_
.parameter
;
349 return net
->u_
.real_
.parameter
;
355 extern "C" ivl_expr_t
ivl_expr_parm(ivl_expr_t net
, unsigned idx
)
358 switch (net
->type_
) {
361 assert(idx
< net
->u_
.concat_
.parms
);
362 return net
->u_
.concat_
.parm
[idx
];
365 assert(idx
< net
->u_
.sfunc_
.parms
);
366 return net
->u_
.sfunc_
.parm
[idx
];
369 assert(idx
< net
->u_
.ufunc_
.parms
);
370 return net
->u_
.ufunc_
.parm
[idx
];
378 extern "C" unsigned ivl_expr_parms(ivl_expr_t net
)
381 switch (net
->type_
) {
384 return net
->u_
.concat_
.parms
;
387 return net
->u_
.sfunc_
.parms
;
390 return net
->u_
.ufunc_
.parms
;
398 extern "C" unsigned ivl_expr_repeat(ivl_expr_t 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
)
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
)
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
)
422 switch (net
->type_
) {
426 return net
->u_
.signal_
.sig
;
434 extern "C" int ivl_expr_signed(ivl_expr_t net
)
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_
) {
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')
469 extern "C" ivl_variable_type_t
ivl_expr_value(ivl_expr_t net
)
475 extern "C" unsigned ivl_expr_width(ivl_expr_t net
)
481 extern "C" const char* ivl_logic_attr(ivl_net_logic_t net
, const char*key
)
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
497 extern "C" unsigned ivl_logic_attr_cnt(ivl_net_logic_t net
)
502 extern "C" ivl_attribute_t
ivl_logic_attr_val(ivl_net_logic_t net
,
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
)
517 if (ivl_nexus_ptr_pin(cur
) != 0)
519 return ivl_nexus_ptr_drive0(cur
);
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
)
534 if (ivl_nexus_ptr_pin(cur
) != 0)
536 return ivl_nexus_ptr_drive1(cur
);
540 return IVL_DR_STRONG
;
543 extern "C" const char* ivl_logic_name(ivl_net_logic_t net
)
546 cerr
<< "ANACHRONISM: Call to anachronistic ivl_logic_name." << endl
;
550 extern "C" const char* ivl_logic_basename(ivl_net_logic_t net
)
556 extern "C" ivl_scope_t
ivl_logic_scope(ivl_net_logic_t net
)
562 extern "C" ivl_logic_t
ivl_logic_type(ivl_net_logic_t net
)
567 extern "C" unsigned ivl_logic_pins(ivl_net_logic_t net
)
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
);
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
)
597 extern "C" int ivl_udp_sequ(ivl_udp_t net
)
602 extern "C" unsigned ivl_udp_nin(ivl_udp_t net
)
607 extern "C" unsigned ivl_udp_init(ivl_udp_t net
)
612 extern "C" const char* ivl_udp_row(ivl_udp_t net
, unsigned idx
)
614 assert(idx
< net
->nrows
);
616 assert(net
->table
[idx
]);
617 return net
->table
[idx
];
620 extern "C" unsigned ivl_udp_rows(ivl_udp_t net
)
625 extern "C" const char* ivl_udp_name(ivl_udp_t net
)
631 extern "C" const char* ivl_lpm_basename(ivl_lpm_t net
)
636 extern "C" ivl_nexus_t
ivl_lpm_async_clr(ivl_lpm_t net
)
641 return net
->u_
.ff
.aclr
;
648 extern "C" ivl_nexus_t
ivl_lpm_sync_clr(ivl_lpm_t net
)
653 return net
->u_
.ff
.sclr
;
660 extern "C" ivl_nexus_t
ivl_lpm_async_set(ivl_lpm_t net
)
665 return net
->u_
.ff
.aset
;
672 extern "C" ivl_nexus_t
ivl_lpm_sync_set(ivl_lpm_t net
)
677 return net
->u_
.ff
.sset
;
684 extern "C" ivl_signal_t
ivl_lpm_array(ivl_lpm_t net
)
689 return net
->u_
.array
.sig
;
696 extern "C" unsigned ivl_lpm_base(ivl_lpm_t net
)
700 case IVL_LPM_PART_VP
:
701 case IVL_LPM_PART_PV
:
702 case IVL_LPM_PART_BI
:
703 return net
->u_
.part
.base
;
710 extern "C" ivl_nexus_t
ivl_lpm_clk(ivl_lpm_t net
)
715 return net
->u_
.ff
.clk
;
722 extern "C" ivl_expr_t
ivl_lpm_aset_value(ivl_lpm_t net
)
727 return net
->u_
.ff
.aset_value
;
733 extern "C" ivl_expr_t
ivl_lpm_sset_value(ivl_lpm_t net
)
738 return net
->u_
.ff
.sset_value
;
745 extern "C" ivl_scope_t
ivl_lpm_define(ivl_lpm_t net
)
750 return net
->u_
.ufunc
.def
;
757 extern "C" ivl_nexus_t
ivl_lpm_enable(ivl_lpm_t net
)
762 return net
->u_
.ff
.we
;
769 extern "C" ivl_nexus_t
ivl_lpm_data(ivl_lpm_t net
, unsigned idx
)
774 case IVL_LPM_CMP_EEQ
:
779 case IVL_LPM_CMP_NEE
:
786 return net
->u_
.arith
.a
;
788 return net
->u_
.arith
.b
;
791 assert(idx
< net
->u_
.mux
.size
);
792 return net
->u_
.mux
.d
[idx
];
797 case IVL_LPM_RE_NAND
:
799 case IVL_LPM_RE_XNOR
:
800 case IVL_LPM_SIGN_EXT
:
802 return net
->u_
.reduce
.a
;
808 return net
->u_
.shift
.d
;
810 return net
->u_
.shift
.s
;
814 return net
->u_
.ff
.d
.pin
;
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
:
825 return net
->u_
.part
.a
;
827 return net
->u_
.part
.s
;
831 return net
->u_
.repeat
.a
;
834 // Skip the return port.
835 assert(idx
< (net
->u_
.sfunc
.ports
-1));
836 return net
->u_
.sfunc
.pins
[idx
+1];
839 // Skip the return port.
840 assert(idx
< (net
->u_
.ufunc
.ports
-1));
841 return net
->u_
.ufunc
.pins
[idx
+1];
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
;
865 return net
->u_
.arith
.b
;
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
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
);
896 strcpy(name_buffer
, sn
);
897 char*tmp
= name_buffer
+ strlen(sn
);
899 strcpy(tmp
, net
->name
);
904 extern "C" ivl_nexus_t
ivl_lpm_q(ivl_lpm_t net
, unsigned idx
)
915 return net
->u_
.arith
.q
;
921 case IVL_LPM_CMP_EEQ
:
922 case IVL_LPM_CMP_NEE
:
924 return net
->u_
.arith
.q
;
928 return net
->u_
.ff
.q
.pin
;
932 return net
->u_
.mux
.q
;
937 case IVL_LPM_RE_NAND
:
939 case IVL_LPM_RE_XNOR
:
940 case IVL_LPM_SIGN_EXT
:
942 return net
->u_
.reduce
.q
;
947 return net
->u_
.shift
.q
;
951 return net
->u_
.sfunc
.pins
[0];
955 return net
->u_
.ufunc
.pins
[0];
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
:
964 return net
->u_
.part
.q
;
968 return net
->u_
.repeat
.q
;
972 return net
->u_
.array
.q
;
980 extern "C" ivl_scope_t
ivl_lpm_scope(ivl_lpm_t net
)
986 extern "C" ivl_nexus_t
ivl_lpm_select(ivl_lpm_t net
)
991 return net
->u_
.mux
.s
;
994 return net
->u_
.array
.a
;
1002 extern "C" unsigned ivl_lpm_selects(ivl_lpm_t net
)
1004 switch (net
->type
) {
1006 return net
->u_
.mux
.swid
;
1008 return net
->u_
.array
.swid
;
1009 case IVL_LPM_CONCAT
:
1010 return net
->u_
.concat
.inputs
;
1017 extern "C" int ivl_lpm_signed(ivl_lpm_t net
)
1020 switch (net
->type
) {
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
:
1035 return net
->u_
.arith
.signed_flag
;
1036 case IVL_LPM_RE_AND
:
1038 case IVL_LPM_RE_XOR
:
1039 case IVL_LPM_RE_NAND
:
1040 case IVL_LPM_RE_NOR
:
1041 case IVL_LPM_RE_XNOR
:
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.
1052 case IVL_LPM_CONCAT
: // Concatenations are always unsigned
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
:
1060 case IVL_LPM_ARRAY
: // Array ports take the signedness of the array.
1061 return net
->u_
.array
.sig
->signed_
;
1068 extern "C" unsigned ivl_lpm_size(ivl_lpm_t net
)
1070 switch (net
->type
) {
1072 return net
->u_
.mux
.size
;
1074 return net
->u_
.sfunc
.ports
- 1;
1076 return net
->u_
.ufunc
.ports
- 1;
1077 case IVL_LPM_REPEAT
:
1078 return net
->u_
.repeat
.count
;
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
)
1096 extern "C" unsigned ivl_lpm_width(ivl_lpm_t net
)
1102 extern "C" ivl_expr_t
ivl_lval_mux(ivl_lval_t net
)
1105 if (net
->type_
== IVL_LVAL_MUX
)
1110 extern "C" ivl_expr_t
ivl_lval_idx(ivl_lval_t net
)
1114 if (net
->type_
== IVL_LVAL_ARR
)
1119 extern "C" ivl_expr_t
ivl_lval_part_off(ivl_lval_t net
)
1125 extern "C" unsigned ivl_lval_width(ivl_lval_t net
)
1131 extern "C" ivl_signal_t
ivl_lval_sig(ivl_lval_t net
)
1134 switch (net
->type_
) {
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
)
1152 if (net
->name_
== 0) {
1153 net
->name_
= api_strings
.add(net
->nexus_
->name());
1158 extern "C" void* ivl_nexus_get_private(ivl_nexus_t net
)
1161 return net
->private_data
;
1164 extern "C" void ivl_nexus_set_private(ivl_nexus_t net
, void*data
)
1167 net
->private_data
= data
;
1170 extern "C" unsigned ivl_nexus_ptrs(ivl_nexus_t net
)
1176 extern "C" ivl_nexus_ptr_t
ivl_nexus_ptr(ivl_nexus_t net
, unsigned idx
)
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
)
1186 return (ivl_drive_t
)(net
->drive0
);
1189 extern "C" ivl_drive_t
ivl_nexus_ptr_drive1(ivl_nexus_ptr_t net
)
1192 return (ivl_drive_t
)(net
->drive1
);
1195 extern "C" unsigned ivl_nexus_ptr_pin(ivl_nexus_ptr_t net
)
1201 extern "C" ivl_net_const_t
ivl_nexus_ptr_con(ivl_nexus_ptr_t net
)
1205 if (net
->type_
!= __NEXUS_PTR_CON
)
1210 extern "C" ivl_net_logic_t
ivl_nexus_ptr_log(ivl_nexus_ptr_t net
)
1214 if (net
->type_
!= __NEXUS_PTR_LOG
)
1219 extern "C" ivl_lpm_t
ivl_nexus_ptr_lpm(ivl_nexus_ptr_t net
)
1223 if (net
->type_
!= __NEXUS_PTR_LPM
)
1228 extern "C" ivl_signal_t
ivl_nexus_ptr_sig(ivl_nexus_ptr_t net
)
1232 if (net
->type_
!= __NEXUS_PTR_SIG
)
1237 extern "C" const char* ivl_parameter_basename(ivl_parameter_t net
)
1240 return net
->basename
;
1243 extern "C" ivl_expr_t
ivl_parameter_expr(ivl_parameter_t net
)
1249 extern "C" ivl_scope_t
ivl_parameter_scope(ivl_parameter_t net
)
1255 extern "C" ivl_nexus_t
ivl_path_condit(ivl_delaypath_t obj
)
1261 extern uint64_t ivl_path_delay(ivl_delaypath_t obj
, ivl_path_edge_t edg
)
1264 return obj
->delay
[edg
];
1267 extern ivl_scope_t
ivl_path_scope(ivl_delaypath_t obj
)
1274 extern ivl_nexus_t
ivl_path_source(ivl_delaypath_t net
)
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
)
1294 extern "C" ivl_scope_t
ivl_process_scope(ivl_process_t net
)
1299 extern "C" ivl_statement_t
ivl_process_stmt(ivl_process_t net
)
1304 extern "C" unsigned ivl_process_attr_cnt(ivl_process_t net
)
1309 extern "C" ivl_attribute_t
ivl_process_attr_val(ivl_process_t net
,
1312 assert(idx
< net
->nattr
);
1313 return net
->attr
+ idx
;
1316 extern "C" unsigned ivl_scope_attr_cnt(ivl_scope_t net
)
1322 extern "C" ivl_attribute_t
ivl_scope_attr_val(ivl_scope_t net
,
1325 assert(idx
< net
->nattr
);
1326 return net
->attr
+ idx
;
1329 extern "C" const char* ivl_scope_basename(ivl_scope_t net
)
1336 extern "C" int ivl_scope_children(ivl_scope_t net
,
1340 for (ivl_scope_t cur
= net
->child_
; cur
; cur
= cur
->sibling_
) {
1341 int rc
= func(cur
, cd
);
1349 extern "C" ivl_statement_t
ivl_scope_def(ivl_scope_t net
)
1355 extern "C" unsigned ivl_scope_events(ivl_scope_t net
)
1358 return net
->nevent_
;
1361 extern "C" ivl_event_t
ivl_scope_event(ivl_scope_t net
, unsigned idx
)
1364 assert(idx
< net
->nevent_
);
1365 return net
->event_
[idx
];
1368 extern "C" unsigned ivl_scope_logs(ivl_scope_t net
)
1374 extern "C" ivl_net_logic_t
ivl_scope_log(ivl_scope_t net
, unsigned idx
)
1377 assert(idx
< net
->nlog_
);
1378 return net
->log_
[idx
];
1381 extern "C" unsigned ivl_scope_lpms(ivl_scope_t net
)
1387 extern "C" ivl_lpm_t
ivl_scope_lpm(ivl_scope_t net
, unsigned idx
)
1390 assert(idx
< net
->nlpm_
);
1391 return net
->lpm_
[idx
];
1394 static unsigned scope_name_len(ivl_scope_t net
)
1398 for (ivl_scope_t cur
= net
; cur
; cur
= cur
->parent
)
1399 len
+= strlen(cur
->name_
) + 1;
1404 static void push_scope_basename(ivl_scope_t net
, char*buf
)
1406 if (net
->parent
== 0) {
1407 strcpy(buf
, net
->name_
);
1411 push_scope_basename(net
->parent
, 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)
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
);
1437 extern "C" unsigned ivl_scope_params(ivl_scope_t net
)
1440 return net
->nparam_
;
1443 extern "C" ivl_parameter_t
ivl_scope_param(ivl_scope_t net
, unsigned idx
)
1446 assert(idx
< net
->nparam_
);
1447 return net
->param_
+ idx
;
1450 extern "C" ivl_scope_t
ivl_scope_parent(ivl_scope_t net
)
1456 extern "C" unsigned ivl_scope_ports(ivl_scope_t net
)
1459 assert(net
->type_
== IVL_SCT_FUNCTION
);
1463 extern "C" ivl_signal_t
ivl_scope_port(ivl_scope_t net
, unsigned idx
)
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
)
1477 extern "C" ivl_signal_t
ivl_scope_sig(ivl_scope_t net
, unsigned idx
)
1480 assert(idx
< net
->nsigs_
);
1481 return net
->sigs_
[idx
];
1484 extern "C" int ivl_scope_time_precision(ivl_scope_t net
)
1487 return net
->time_precision
;
1490 extern "C" int ivl_scope_time_units(ivl_scope_t net
)
1493 return net
->time_units
;
1496 extern "C" ivl_scope_type_t
ivl_scope_type(ivl_scope_t net
)
1502 extern "C" const char* ivl_scope_tname(ivl_scope_t net
)
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)
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
1538 extern "C" unsigned ivl_signal_attr_cnt(ivl_signal_t net
)
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
)
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_
);
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
];
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
)
1599 extern "C" ivl_signal_port_t
ivl_signal_port(ivl_signal_t net
)
1604 extern "C" int ivl_signal_local(ivl_signal_t net
)
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
)
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
)
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
)
1640 extern "C" ivl_statement_type_t
ivl_statement_type(ivl_statement_t net
)
1645 extern "C" ivl_scope_t
ivl_stmt_block_scope(ivl_statement_t net
)
1647 switch (net
->type_
) {
1650 return net
->u_
.block_
.scope
;
1657 extern "C" unsigned ivl_stmt_block_count(ivl_statement_t net
)
1659 switch (net
->type_
) {
1662 return net
->u_
.block_
.nstmt_
;
1669 extern "C" ivl_statement_t
ivl_stmt_block_stmt(ivl_statement_t net
,
1672 switch (net
->type_
) {
1675 return net
->u_
.block_
.stmt_
+ i
;
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
;
1689 return net
->u_
.utask_
.def
;
1696 extern "C" unsigned ivl_stmt_case_count(ivl_statement_t net
)
1698 switch (net
->type_
) {
1703 return net
->u_
.case_
.ncase
;
1710 extern "C" ivl_expr_t
ivl_stmt_case_expr(ivl_statement_t net
, unsigned idx
)
1712 switch (net
->type_
) {
1717 assert(idx
< net
->u_
.case_
.ncase
);
1718 return net
->u_
.case_
.case_ex
[idx
];
1726 extern "C" ivl_statement_t
ivl_stmt_case_stmt(ivl_statement_t net
, unsigned idx
)
1728 switch (net
->type_
) {
1733 assert(idx
< net
->u_
.case_
.ncase
);
1734 return net
->u_
.case_
.case_st
+ idx
;
1742 extern "C" ivl_expr_t
ivl_stmt_cond_expr(ivl_statement_t net
)
1744 switch (net
->type_
) {
1746 return net
->u_
.condit_
.cond_
;
1752 return net
->u_
.case_
.cond
;
1756 return net
->u_
.while_
.cond_
;
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
)
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
)
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_
) {
1786 case IVL_ST_ASSIGN_NB
:
1787 return net
->u_
.assign_
.delay
;
1790 return net
->u_
.delayx_
.expr
;
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_
) {
1808 return net
->u_
.wait_
.nevent
;
1810 case IVL_ST_TRIGGER
:
1819 extern "C" ivl_event_t
ivl_stmt_events(ivl_statement_t net
, unsigned idx
)
1821 switch (net
->type_
) {
1823 assert(idx
< net
->u_
.wait_
.nevent
);
1824 if (net
->u_
.wait_
.nevent
== 1)
1825 return net
->u_
.wait_
.event
;
1827 return net
->u_
.wait_
.events
[idx
];
1829 case IVL_ST_TRIGGER
:
1831 return net
->u_
.wait_
.event
;
1838 extern "C" ivl_lval_t
ivl_stmt_lval(ivl_statement_t net
, unsigned idx
)
1840 switch (net
->type_
) {
1842 case IVL_ST_ASSIGN_NB
:
1843 case IVL_ST_CASSIGN
:
1844 case IVL_ST_DEASSIGN
:
1846 case IVL_ST_RELEASE
:
1847 assert(idx
< net
->u_
.assign_
.lvals_
);
1848 return net
->u_
.assign_
.lval_
+ idx
;
1856 extern "C" unsigned ivl_stmt_lvals(ivl_statement_t net
)
1858 switch (net
->type_
) {
1860 case IVL_ST_ASSIGN_NB
:
1861 case IVL_ST_CASSIGN
:
1862 case IVL_ST_DEASSIGN
:
1864 case IVL_ST_RELEASE
:
1865 return net
->u_
.assign_
.lvals_
;
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
));
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_
) {
1897 sum
+= ivl_lval_width(cur
);
1907 extern "C" const char* ivl_stmt_name(ivl_statement_t net
)
1909 switch (net
->type_
) {
1911 return net
->u_
.stask_
.name_
;
1919 extern "C" ivl_expr_t
ivl_stmt_parm(ivl_statement_t net
, unsigned idx
)
1921 switch (net
->type_
) {
1923 assert(idx
< net
->u_
.stask_
.nparm_
);
1924 return net
->u_
.stask_
.parms_
[idx
];
1932 extern "C" unsigned ivl_stmt_parm_count(ivl_statement_t net
)
1934 switch (net
->type_
) {
1936 return net
->u_
.stask_
.nparm_
;
1943 extern "C" ivl_expr_t
ivl_stmt_rval(ivl_statement_t net
)
1945 switch (net
->type_
) {
1947 case IVL_ST_ASSIGN_NB
:
1948 case IVL_ST_CASSIGN
:
1950 return net
->u_
.assign_
.rval_
;
1958 extern "C" ivl_statement_t
ivl_stmt_sub_stmt(ivl_statement_t net
)
1960 switch (net
->type_
) {
1962 return net
->u_
.delay_
.stmt_
;
1964 return net
->u_
.delayx_
.stmt_
;
1965 case IVL_ST_FOREVER
:
1966 return net
->u_
.forever_
.stmt_
;
1968 return net
->u_
.wait_
.stmt_
;
1971 return net
->u_
.while_
.stmt_
;