forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht-dll-api.cc
3316 lines (2816 loc) · 67.9 KB
/
t-dll-api.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000-2024 Stephen Williams ([email protected])
* Copyright CERN 2013 / Stephen Williams ([email protected])
* Copyright (c) 2016 CERN Michele Castellana ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "config.h"
# include "StringHeap.h"
# include "t-dll.h"
# include "discipline.h"
# include "netclass.h"
# include "netdarray.h"
# include "netenum.h"
# include "netvector.h"
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include "ivl_alloc.h"
using namespace std;
static StringHeap api_strings;
/* THE FOLLOWING ARE FUNCTIONS THAT ARE CALLED FROM THE TARGET. */
extern "C" ivl_island_t ivl_branch_island(ivl_branch_t net)
{
assert(net);
return net->island;
}
extern "C" ivl_nexus_t ivl_branch_terminal(ivl_branch_t net, int idx)
{
assert(net);
assert(idx >= 0);
assert(idx < 2);
return net->pins[idx];
}
extern "C" const char*ivl_design_delay_sel(ivl_design_t des)
{
assert(des);
assert(des->self);
return des->self->get_delay_sel();
}
extern "C" const char*ivl_design_flag(ivl_design_t des, const char*key)
{
assert(des);
assert(des->self);
return des->self->get_flag(key);
}
extern "C" int ivl_design_process(ivl_design_t des,
ivl_process_f func,
void*cd)
{
assert(des);
for (ivl_process_t idx = des->threads_; idx; idx = idx->next_) {
int rc = (func)(idx, cd);
if (rc != 0)
return rc;
}
return 0;
}
extern "C" ivl_scope_t ivl_design_root(ivl_design_t des)
{
cerr << "ANACHRONISM: ivl_design_root called. "
"Use ivl_design_roots instead." << endl;
assert(des);
assert (des->roots.size() > 0);
return des->roots[0];
}
extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes,
unsigned int *nscopes)
{
assert(des);
assert (nscopes && scopes);
if (des->root_scope_list.size() == 0) {
size_t fill = 0;
des->root_scope_list.resize(des->packages.size() + des->roots.size());
for (size_t idx = 0 ; idx < des->packages.size() ; idx += 1)
des->root_scope_list[fill++] = des->packages[idx];
for (size_t idx = 0 ; idx < des->roots.size() ; idx += 1)
des->root_scope_list[fill++] = des->roots[idx];
}
*scopes = &des->root_scope_list[0];
*nscopes = des->root_scope_list.size();
}
extern "C" int ivl_design_time_precision(ivl_design_t des)
{
assert(des);
return des->time_precision;
}
extern "C" unsigned ivl_design_consts(ivl_design_t des)
{
assert(des);
return des->consts.size();
}
extern "C" ivl_net_const_t ivl_design_const(ivl_design_t des, unsigned idx)
{
assert(des);
assert(idx < des->consts.size());
return des->consts[idx];
}
extern "C" unsigned ivl_design_disciplines(ivl_design_t des)
{
assert(des);
return des->disciplines.size();
}
extern "C" ivl_discipline_t ivl_design_discipline(ivl_design_t des, unsigned idx)
{
assert(des);
assert(idx < des->disciplines.size());
return des->disciplines[idx];
}
extern "C" ivl_dis_domain_t ivl_discipline_domain(ivl_discipline_t net)
{
assert(net);
return net->domain();
}
extern "C" ivl_nature_t ivl_discipline_flow(ivl_discipline_t net)
{
assert(net);
return net->flow();
}
extern "C" const char* ivl_discipline_name(ivl_discipline_t net)
{
assert(net);
return net->name();
}
extern "C" ivl_nature_t ivl_discipline_potential(ivl_discipline_t net)
{
assert(net);
return net->potential();
}
extern "C" ivl_expr_type_t ivl_expr_type(ivl_expr_t net)
{
if (net == 0)
return IVL_EX_NONE;
return net->type_;
}
extern "C" const char*ivl_expr_file(ivl_expr_t net)
{
assert(net);
return net->file.str();
}
extern "C" unsigned ivl_expr_lineno(ivl_expr_t net)
{
assert(net);
return net->lineno;
}
extern "C" ivl_variable_type_t ivl_const_type(ivl_net_const_t net)
{
assert(net);
return net->type;
}
extern "C" const char*ivl_const_bits(ivl_net_const_t net)
{
assert(net);
switch (net->type) {
case IVL_VT_BOOL:
case IVL_VT_LOGIC:
case IVL_VT_STRING:
if (net->width_ <= sizeof(net->b.bit_))
return net->b.bit_;
else
return net->b.bits_;
default:
return 0;
}
}
extern "C" ivl_expr_t ivl_const_delay(ivl_net_const_t net, unsigned transition)
{
assert(net);
assert(transition < 3);
return net->delay[transition];
}
extern "C" const char*ivl_const_file(ivl_net_const_t net)
{
assert(net);
return net->file.str();
}
extern "C" unsigned ivl_const_lineno(ivl_net_const_t net)
{
assert(net);
return net->lineno;
}
extern "C" ivl_nexus_t ivl_const_nex(ivl_net_const_t net)
{
assert(net);
return net->pin_;
}
extern "C" double ivl_const_real(ivl_net_const_t net)
{
assert(net);
assert(net->type == IVL_VT_REAL);
return net->b.real_value;
}
extern "C" ivl_scope_t ivl_const_scope(ivl_net_const_t net)
{
assert(net);
return net->scope;
}
extern "C" int ivl_const_signed(ivl_net_const_t net)
{
assert(net);
return net->signed_;
}
extern "C" unsigned ivl_const_width(ivl_net_const_t net)
{
assert(net);
return net->width_;
}
extern "C" unsigned ivl_enum_names(ivl_enumtype_t net)
{
assert(net);
return net->size();
}
extern "C" const char* ivl_enum_name(ivl_enumtype_t net, unsigned idx)
{
assert(net);
assert(idx < net->size());
return net->name_at(idx);
}
extern "C" const char* ivl_enum_bits(ivl_enumtype_t net, unsigned idx)
{
assert(net);
assert(idx < net->size());
return net->bits_at(idx);
}
extern "C" ivl_variable_type_t ivl_enum_type(ivl_enumtype_t net)
{
assert(net);
return net->base_type();
}
extern "C" unsigned ivl_enum_width(ivl_enumtype_t net)
{
assert(net);
return net->packed_width();
}
extern "C" int ivl_enum_signed(ivl_enumtype_t net)
{
assert(net);
return net->get_signed();
}
extern "C" const char*ivl_enum_file(ivl_enumtype_t net)
{
assert(net);
return net->get_file().str();
}
extern "C" unsigned ivl_enum_lineno(ivl_enumtype_t net)
{
assert(net);
return net->get_lineno();
}
extern "C" const char* ivl_event_name(ivl_event_t net)
{
assert(net);
static char*name_buffer = 0;
static unsigned name_size = 0;
ivl_scope_t scope = net->scope;
const char*sn = ivl_scope_name(scope);
unsigned need = strlen(sn) + 1 + strlen(net->name) + 1;
if (need > name_size) {
name_buffer = (char*)realloc(name_buffer, need);
name_size = need;
}
strcpy(name_buffer, sn);
char*tmp = name_buffer + strlen(sn);
*tmp++ = '.';
strcpy(tmp, net->name);
cerr << "ANACHRONISM: Call to anachronistic ivl_event_name." << endl;
return name_buffer;
}
extern "C" const char* ivl_event_basename(ivl_event_t net)
{
assert(net);
return net->name;
}
extern "C" const char*ivl_event_file(ivl_event_t net)
{
assert(net);
return net->file.str();
}
extern "C" unsigned ivl_event_lineno(ivl_event_t net)
{
assert(net);
return net->lineno;
}
extern "C" ivl_scope_t ivl_event_scope(ivl_event_t net)
{
assert(net);
return net->scope;
}
extern "C" unsigned ivl_event_nany(ivl_event_t net)
{
assert(net);
return net->nany;
}
extern "C" ivl_nexus_t ivl_event_any(ivl_event_t net, unsigned idx)
{
assert(net);
assert(idx < net->nany);
return net->pins[idx];
}
extern "C" unsigned ivl_event_nedg(ivl_event_t net)
{
assert(net);
return net->nedg;
}
extern "C" ivl_nexus_t ivl_event_edg(ivl_event_t net, unsigned idx)
{
assert(net);
assert(idx < net->nedg);
return net->pins[net->nany + net->nneg + net->npos + idx];
}
extern "C" unsigned ivl_event_nneg(ivl_event_t net)
{
assert(net);
return net->nneg;
}
extern "C" ivl_nexus_t ivl_event_neg(ivl_event_t net, unsigned idx)
{
assert(net);
assert(idx < net->nneg);
return net->pins[net->nany + idx];
}
extern "C" unsigned ivl_event_npos(ivl_event_t net)
{
assert(net);
return net->npos;
}
extern "C" ivl_nexus_t ivl_event_pos(ivl_event_t net, unsigned idx)
{
assert(net);
assert(idx < net->npos);
return net->pins[net->nany + net->nneg + idx];
}
extern "C" const char* ivl_expr_bits(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_NUMBER);
return net->u_.number_.bits_;
}
extern "C" ivl_branch_t ivl_expr_branch(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_BACCESS);
return net->u_.branch_.branch;
}
extern "C" ivl_scope_t ivl_expr_def(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_UFUNC:
return net->u_.ufunc_.def;
default:
assert(0);
}
return 0;
}
extern "C" uint64_t ivl_expr_delay_val(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_DELAY);
return net->u_.delay_.value;
}
extern "C" double ivl_expr_dvalue(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_REALNUM);
return net->u_.real_.value;
}
extern "C" ivl_enumtype_t ivl_expr_enumtype(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_ENUMTYPE);
return net->u_.enumtype_.type;
}
extern "C" ivl_type_t ivl_expr_net_type(ivl_expr_t net)
{
assert(net);
return net->net_type;
}
extern "C" const char* ivl_expr_name(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_SFUNC:
return net->u_.sfunc_.name_;
case IVL_EX_SIGNAL:
return net->u_.signal_.sig->name_;
case IVL_EX_PROPERTY:
{ ivl_signal_t sig = ivl_expr_signal(net);
ivl_type_t use_type = ivl_signal_net_type(sig);
unsigned idx = ivl_expr_property_idx(net);
return ivl_type_prop_name(use_type, idx);
}
default:
assert(0);
}
return 0;
}
extern "C" ivl_nature_t ivl_expr_nature(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_BACCESS);
return net->u_.branch_.nature;
}
extern "C" char ivl_expr_opcode(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_BINARY:
return net->u_.binary_.op_;
case IVL_EX_UNARY:
return net->u_.unary_.op_;
default:
assert(0);
}
return 0;
}
extern "C" ivl_expr_t ivl_expr_oper1(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_BINARY:
return net->u_.binary_.lef_;
case IVL_EX_PROPERTY:
return net->u_.property_.index;
case IVL_EX_SELECT:
return net->u_.select_.expr_;
case IVL_EX_UNARY:
return net->u_.unary_.sub_;
case IVL_EX_MEMORY:
return net->u_.memory_.idx_;
case IVL_EX_NEW:
return net->u_.new_.size;
case IVL_EX_SHALLOWCOPY:
return net->u_.shallow_.dest;
case IVL_EX_SIGNAL:
return net->u_.signal_.word;
case IVL_EX_TERNARY:
return net->u_.ternary_.cond;
default:
assert(0);
}
return 0;
}
extern "C" ivl_expr_t ivl_expr_oper2(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_BINARY:
return net->u_.binary_.rig_;
case IVL_EX_NEW:
return net->u_.new_.init_val;
case IVL_EX_SELECT:
return net->u_.select_.base_;
case IVL_EX_SHALLOWCOPY:
return net->u_.shallow_.src;
case IVL_EX_TERNARY:
return net->u_.ternary_.true_e;
default:
assert(0);
}
return 0;
}
extern "C" ivl_expr_t ivl_expr_oper3(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_TERNARY:
return net->u_.ternary_.false_e;
default:
assert(0);
}
return 0;
}
extern "C" ivl_parameter_t ivl_expr_parameter(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_NUMBER:
return net->u_.number_.parameter;
case IVL_EX_STRING:
return net->u_.string_.parameter;
case IVL_EX_REALNUM:
return net->u_.real_.parameter;
default:
return 0;
}
}
extern "C" ivl_expr_t ivl_expr_parm(ivl_expr_t net, unsigned idx)
{
assert(net);
switch (net->type_) {
case IVL_EX_ARRAY_PATTERN:
assert(idx < net->u_.array_pattern_.parms);
return net->u_.array_pattern_.parm[idx];
case IVL_EX_CONCAT:
assert(idx < net->u_.concat_.parms);
return net->u_.concat_.parm[idx];
case IVL_EX_SFUNC:
assert(idx < net->u_.sfunc_.parms);
return net->u_.sfunc_.parm[idx];
case IVL_EX_UFUNC:
assert(idx < net->u_.ufunc_.parms);
return net->u_.ufunc_.parm[idx];
default:
assert(0);
return 0;
}
}
extern "C" unsigned ivl_expr_parms(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_ARRAY_PATTERN:
return net->u_.array_pattern_.parms;
case IVL_EX_CONCAT:
return net->u_.concat_.parms;
case IVL_EX_SFUNC:
return net->u_.sfunc_.parms;
case IVL_EX_UFUNC:
return net->u_.ufunc_.parms;
default:
assert(0);
return 0;
}
}
extern "C" unsigned ivl_expr_repeat(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_CONCAT);
return net->u_.concat_.rept;
}
extern "C" ivl_event_t ivl_expr_event(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_EVENT);
return net->u_.event_.event;
}
extern "C" int ivl_expr_property_idx(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_PROPERTY);
return net->u_.property_.prop_idx;
}
extern "C" ivl_scope_t ivl_expr_scope(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_SCOPE);
return net->u_.scope_.scope;
}
extern "C" ivl_select_type_t ivl_expr_sel_type(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_SELECT);
return net->u_.select_.sel_type_;
}
extern "C" ivl_signal_t ivl_expr_signal(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_SIGNAL:
case IVL_EX_ARRAY:
return net->u_.signal_.sig;
case IVL_EX_PROPERTY:
return net->u_.property_.sig;
default:
assert(0);
return 0;
}
}
extern "C" int ivl_expr_signed(ivl_expr_t net)
{
assert(net);
return net->signed_;
}
extern "C" int ivl_expr_sized(ivl_expr_t net)
{
assert(net);
return net->sized_;
}
extern "C" const char* ivl_expr_string(ivl_expr_t net)
{
assert(net);
assert(net->type_ == IVL_EX_STRING);
return net->u_.string_.value_;
}
extern "C" unsigned long ivl_expr_uvalue(ivl_expr_t net)
{
assert(net);
switch (net->type_) {
case IVL_EX_ULONG:
return net->u_.ulong_.value;
case IVL_EX_NUMBER: {
unsigned long val = 0;
for (unsigned long idx = 0 ; idx < net->width_ ; idx += 1) {
if (net->u_.number_.bits_[idx] == '1')
val |= 1UL << idx;
}
return val;
}
default:
assert(0);
}
assert(0);
return 0;
}
extern "C" ivl_variable_type_t ivl_expr_value(ivl_expr_t net)
{
assert(net);
return net->value_;
}
extern "C" unsigned ivl_expr_width(ivl_expr_t net)
{
assert(net);
return net->width_;
}
/*
* ivl_file_table_index puts entries in the map as needed and returns
* the appropriate index.
* ivl_file_table_size returns the number of entries in the table.
* ivl_file_table_item returns the file name for the given index.
*/
struct ltstr
{
bool operator()(const char*s1, const char*s2) const
{
return strcmp(s1, s2) < 0;
}
};
static map<const char*, unsigned, ltstr> fn_map;
static vector<const char*> fn_vector;
static void ivl_file_table_init()
{
/* The first two index entries do not depend on a real
* file name and are always available. */
fn_vector.push_back("N/A");
fn_map["N/A"] = 0;
fn_vector.push_back("<interactive>");
fn_map["<interactive>"] = 1;
}
extern "C" const char* ivl_file_table_item(unsigned idx)
{
if (fn_vector.empty()) {
ivl_file_table_init();
}
assert(idx < fn_vector.size());
return fn_vector[idx];
}
extern "C" unsigned ivl_file_table_index(const char*name)
{
if (fn_vector.empty()) {
ivl_file_table_init();
}
if (name == NULL) return 0;
/* The new index is the current map size. This is inserted only
* if the file name is not currently in the map. */
pair<map<const char*, unsigned, ltstr>::iterator, bool> result;
result = fn_map.insert(make_pair(name, fn_vector.size()));
if (result.second) {
fn_vector.push_back(name);
}
return result.first->second;
}
extern "C" unsigned ivl_file_table_size()
{
if (fn_vector.empty()) {
ivl_file_table_init();
}
return fn_vector.size();
}
extern "C" int ivl_island_flag_set(ivl_island_t net, unsigned flag, int value)
{
assert(net);
if (flag >= net->flags.size()) {
if (value == 0)
return 0;
else
net->flags.resize(flag+1, false);
}
int old_flag = net->flags[flag];
net->flags[flag] = value != 0;
return old_flag;
}
extern "C" int ivl_island_flag_test(ivl_island_t net, unsigned flag)
{
assert(net);
if (flag >= net->flags.size())
return 0;
else
return net->flags[flag];
}
extern "C" const char*ivl_logic_file(ivl_net_logic_t net)
{
assert(net);
return net->file.str();
}
extern "C" unsigned ivl_logic_lineno(ivl_net_logic_t net)
{
assert(net);
return net->lineno;
}
extern "C" unsigned ivl_logic_is_cassign(ivl_net_logic_t net)
{
assert(net);
return net->is_cassign;
}
extern "C" const char* ivl_logic_attr(ivl_net_logic_t net, const char*key)
{
assert(net);
unsigned idx;
for (idx = 0 ; idx < net->nattr ; idx += 1) {
if (strcmp(net->attr[idx].key, key) == 0)
return net->attr[idx].type == IVL_ATT_STR
? net->attr[idx].val.str
: 0;
}
return 0;
}
extern "C" unsigned ivl_logic_attr_cnt(ivl_net_logic_t net)
{
assert(net);
return net->nattr;
}
extern "C" ivl_attribute_t ivl_logic_attr_val(ivl_net_logic_t net,
unsigned idx)
{
assert(net);
assert(idx < net->nattr);
return net->attr + idx;
}
extern "C" ivl_drive_t ivl_logic_drive0(ivl_net_logic_t net)
{
ivl_nexus_t nex = ivl_logic_pin(net, 0);
for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
if (ivl_nexus_ptr_log(cur) != net)
continue;
if (ivl_nexus_ptr_pin(cur) != 0)
continue;
return ivl_nexus_ptr_drive0(cur);
}
assert(0);
return IVL_DR_STRONG;
}
extern "C" ivl_drive_t ivl_logic_drive1(ivl_net_logic_t net)
{
ivl_nexus_t nex = ivl_logic_pin(net, 0);
for (unsigned idx = 0 ; idx < ivl_nexus_ptrs(nex) ; idx += 1) {
ivl_nexus_ptr_t cur = ivl_nexus_ptr(nex, idx);
if (ivl_nexus_ptr_log(cur) != net)
continue;
if (ivl_nexus_ptr_pin(cur) != 0)
continue;
return ivl_nexus_ptr_drive1(cur);
}
assert(0);
return IVL_DR_STRONG;
}
extern "C" const char* ivl_logic_name(ivl_net_logic_t net)
{
assert(net);
cerr << "ANACHRONISM: Call to anachronistic ivl_logic_name." << endl;
return net->name_;
}
extern "C" const char* ivl_logic_basename(ivl_net_logic_t net)
{
assert(net);
return net->name_;
}
extern "C" ivl_scope_t ivl_logic_scope(ivl_net_logic_t net)
{
assert(net);
return net->scope_;
}
extern "C" ivl_logic_t ivl_logic_type(ivl_net_logic_t net)
{
assert(net);
return net->type_;
}
extern "C" unsigned ivl_logic_pins(ivl_net_logic_t net)
{
assert(net);
return net->npins_;
}
extern "C" ivl_nexus_t ivl_logic_pin(ivl_net_logic_t net, unsigned pin)
{
assert(net);
assert(pin < net->npins_);
return net->pins_[pin];
}
extern "C" ivl_udp_t ivl_logic_udp(ivl_net_logic_t net)
{
assert(net);
assert(net->type_ == IVL_LO_UDP);
assert(net->udp);
return net->udp;
}
extern "C" ivl_expr_t ivl_logic_delay(ivl_net_logic_t net, unsigned transition)
{
assert(net);
assert(transition < 3);
return net->delay[transition];
}
extern "C" unsigned ivl_logic_width(ivl_net_logic_t net)
{
assert(net);
return net->width_;
}
extern "C" unsigned ivl_logic_port_buffer(ivl_net_logic_t net)
{
assert(net);
return net->is_port_buffer;
}