This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystask.cc
2118 lines (1874 loc) · 52.7 KB
/
systask.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 1994-2005, Elliot Mednick and Mark Hummel
* This file is part of Veriwell.
*
* Veriwell is free software; you can redistribute it and/or modify
* it 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.
*
* Veriwell 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 Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/* SYSTASK.C - System tasks and functions */
#define SYSTASK_C
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <limits.h>
#include "vtypes.h"
#include "tree.h"
#include "lex.h"
#include "flags.h"
#include "runtime.h"
#include "schedule.h"
#include "print.h"
#include "io.h"
#include "macro.h"
#include "glue.h"
#include "dumpvar.h"
#include "pass3.h"
#include "strobe.h"
#include "scope.h"
#include "veriuser.h"
#include "eval.h"
#include "timescal.h"
#include "specify.h"
#include "veriwell.h"
#include "pass2.h"
#include "store.h"
#include "trace.h"
#include "acc_user.h"
#include "pli.h"
#include "systask.h"
#include "usertask.h"
#include "random.h"
int systime_once = 0; /* initialize the following only once */
tree systime_return; /* variable for returning $time value */
int sysstime_once = 0; /* initialize the following only once */
tree sysstime_return; /* variable for returning $stime value */
int sysrealtime_once = 0; /* initialize the following only once */
tree sysrealtime_return; /* variable for returning $realtime value */
int sysopen_once = 0; /* initialize the following only once */
tree sysopen_return; /* variable for returning $fopen value */
int sysrand_once = 0; /* initialize the following only once */
tree sysrand_return; /* variable for returning $random value */
int sysplus_once = 0; /* initialize the following only once */
tree sysplus_return; /* variable for returning $test$plusargs value */
int roFlag = FALSE; /* true when in a misc routine for rosynch */
static tree pliInstanceList; /* linked list of all pli instances */
struct monitor_info monitor_info = { 1, NULL_TREE };
struct monitor_info mwaves_info = { 1, NULL_TREE };
/* There are 3 kinds of system tasks/functions (names that start with '$'):
- internal tasks implemented either before there were PLI hooks or that
require direct access to VeriWell structures -- these are implemented
here;
- internal tasks written using all PLI functions as if they were
user-defined functions -- they are implemented elsewhere but the
name resolution is here;
- user-defined tasks using PLI functions implemented outside VeriWell --
the name resolution is also done here.
*/
/* [tf: task/function] */
/* These are the internal non-PLI tasks/functions: (some could eventually
be re-written into PLI...) */
struct systask_info systask_info[] = {
"$scope", SCOPE,
"$showscopes", SHOWSCOPES,
"$display", DISPLAY,
"$displayh", DISPLAYH,
"$displayb", DISPLAYB,
"$displayo", DISPLAYO,
"$write", WRITE,
"$writeh", WRITEH,
"$writeb", WRITEB,
"$writeo", WRITEO,
"$fdisplay", FDISPLAY,
"$fdisplayh", FDISPLAYH,
"$fdisplayb", FDISPLAYB,
"$fdisplayo", FDISPLAYO,
"$fwrite", T_FWRITE,
"$fwriteh", T_FWRITEH,
"$fwriteb", T_FWRITEB,
"$fwriteo", T_FWRITEO,
"$monitor", MONITOR,
"$monitorb", MONITORB,
"$monitorh", MONITORH,
"$monitoro", MONITORO,
"$fmonitor", FMONITOR,
"$fmonitorb", FMONITORB,
"$fmonitorh", FMONITORH,
"$fmonitoro", FMONITORO,
"$strobe", STROBE,
"$strobeb", STROBEB,
"$strobeh", STROBEH,
"$strobeo", STROBEO,
"$fstrobe", FSTROBE,
"$fstrobeb", FSTROBEB,
"$fstrobeh", FSTROBEH,
"$fstrobeo", FSTROBEO,
"$monitoron", T_MONITORON,
"$monitoroff", T_MONITOROFF,
"$stop", STOP,
"$finish", FINISH,
"$settrace", SETTRACE,
"$cleartrace", CLEARTRACE,
"$showstats", SHOWSTATS,
"$fclose", T_FCLOSE,
"$log", T_LOG,
"$nolog", T_NOLOG,
"$key", T_KEY,
"$nokey", T_NOKEY,
"$input", T_INPUT,
"$showvars", T_SHOWVARS,
"$readmemh", T_READMEMH,
"$readmemb", T_READMEMB,
"$dumpvars", T_DUMPVARS,
"$dumpon", T_DUMPON,
"$dumpoff", T_DUMPOFF,
"$dumpfile", T_DUMPFILE,
"$dumpall", T_DUMPALL,
"$dumpflush", T_DUMPFLUSH,
"$update_timings", T_UPDATETIMINGS,
"$timeformat", T_TIMEFORMAT,
0, (enum systask_type) 0
};
struct sysfunction_info sysfunction_info[] = {
"$stime", F_STIME,
"$time", F_TIME,
"$realtime", F_REALTIME,
"$fopen", F_FOPEN,
"$random", F_RANDOM,
"$test$plusargs", F_TEST_PLUSARGS,
0, (enum sysfunction_type) 0
};
tree current_tf_instance; /* node of systask being executed or compiled */
int globalSeed = 0; /* seed for random number generator */
extern s_tfcell veriusertfs[]; /* Hooks into user tfs */
extern s_tfcell verisystfs[]; /* Hooks into internal tfs */
void broadcast_tf(int reason)
{
tree t;
t = pliInstanceList;
while (t) {
current_tf_instance = t;
switch (TREE_CODE(t)) {
case SYSFUNCTION_REF:
call_misc_tf(FUNC_REF_USERTF(t), reason);
t = FUNC_REF_NEXT(t);
break;
case SYSTASK_STMT:
call_misc_tf(STMT_SYSTASK_USERTF(t), reason);
t = STMT_SYSTASK_NEXT(t);
break;
}
}
}
/* lookup by name a PLI tf either user or internal (user first since it can
override an internal tf); retun pointer to structure. */
p_tfcell lookup_user_tf(char *name)
{
int i;
p_tfcell userFunction = Usertask_Lookup(name);
if (userFunction) {
return userFunction;
}
for (i = 0; verisystfs[i].type; i++) {
if (!strcmp(name, verisystfs[i].tfname))
return &verisystfs[i];
}
return 0;
}
/* Lookup a PLI _task_ (either internal or user-defined); return pointer
to structure */
p_tfcell lookup_user_task(char *name)
{
p_tfcell p_tf = lookup_user_tf(name); /* look it up in both tables */
if (p_tf == 0) /* not found */
return 0;
if (p_tf->type != USERTASK) /* its not a task */
return 0;
else
return p_tf;
}
/* Same as above but for a function */
p_tfcell lookup_user_func(char *name)
{
p_tfcell p_tf = lookup_user_tf(name); /* look it up in both tables */
if (p_tf == 0) /* not found */
return 0;
if (p_tf->type != USERFUNCTION) /* its not a function */
return 0;
else
return p_tf;
}
/* Call the correct _check_ routine for the given user task/function */
void call_check_tf(p_tfcell p_tf)
{
if (p_tf->checktf)
(p_tf->checktf) (p_tf->data, (int) REASON_CHECKTF);
}
/* Call the correct _call_ routine for the given user task/function */
void call_call_tf(p_tfcell p_tf)
{
if (p_tf->calltf)
(p_tf->calltf) (p_tf->data, (int) REASON_CALLTF);
}
/* Call the correct _size_ routine for the given user task/function */
int call_size_tf(p_tfcell p_tf)
{
if (p_tf->sizetf)
return (p_tf->sizetf) (p_tf->data, (int) REASON_SIZETF);
return 0;
}
/* Call the correct _misc_ routine for the given user task/function */
void call_misc_tf(p_tfcell p_tf, int reason)
{
if (p_tf->misctf)
(p_tf->misctf) (p_tf->data, reason);
}
void call_misc_tf1(p_tfcell p_tf, int reason, int arg)
{
if (p_tf->misctf)
((int (*)(int, int, int)) p_tf->misctf) (p_tf->data, reason, arg);
}
void systaskDoDelay(tree delayNode)
{
tree node;
ASSERT(delayNode != NULL);
ASSERT(TREE_CODE(delayNode) == PLI_DELAY);
node = PLI_DELAY_NODE(delayNode);
ASSERT(node != NULL);
current_tf_instance = node;
switch (TREE_CODE(node)) {
case SYSFUNCTION_REF:
call_misc_tf(FUNC_REF_USERTF(node), reason_reactivate);
break;
case SYSTASK_STMT:
call_misc_tf(STMT_SYSTASK_USERTF(node), reason_reactivate);
break;
}
}
void pli_asynccall(PliInfo_t * info)
{
tree node;
node = info->instance;
if (ASYNCH_ATTR(node)) {
roFlag = TRUE;
info->pvc = TRUE;
current_tf_instance = node;
switch (TREE_CODE(node)) {
case SYSFUNCTION_REF:
call_misc_tf1(FUNC_REF_USERTF(node),
reason_paramvc, info->argNumber);
break;
case SYSTASK_STMT:
call_misc_tf1(STMT_SYSTASK_USERTF(node),
reason_paramvc, info->argNumber);
break;
}
roFlag = FALSE;
}
}
/* "top-level" lookup called from pass3; look for user PLI, internal PLI,
internal custom, in that order. Return the enum of the internal
tf and the pointer to the PLI tf through the arg list */
enum systask_type lookup_systask(char *name, p_tfcell * pp_tf)
{
int i;
*pp_tf = lookup_user_task(name);
if (*pp_tf)
return USER_TASK; /* found PLI, pass pointer through arg list */
for (i = 0; systask_info[i].name; i++) {
if (!strcmp(name, systask_info[i].name))
return systask_info[i].type;
}
return (enum systask_type) -1;
}
enum sysfunction_type lookup_sysfunction(char *name, p_tfcell * pp_tf)
{
int i;
*pp_tf = lookup_user_func(name);
if (*pp_tf)
return USER_FUNC;
for (i = 0; sysfunction_info[i].name; i++) {
if (!strcmp(name, sysfunction_info[i].name))
return sysfunction_info[i].type;
}
return (enum sysfunction_type) -1;
}
/* Convert bits in a group to a null-terminated string. It is assumed that
'buffer' is large enough to handle the string. */
void bits_to_string(char *buffer, Group * g, nbits_t nbits)
{
char *p = buffer;
ngroups_t ngroups, i;
int j, c;
Group *g1;
ngroups = bits_to_groups(nbits);
// start_bit = ((nbits - 1) % (sizeof (Bit) * 8)) + 1;
g1 = g + ngroups;
for (i = ngroups; i >= 0; i--, g1--)
for (j = sizeof(Bit) - 1; j >= 0; j--) {
#ifdef WORDS_BIGENDIAN
c = *(((char *) &AVAL(g1)) + sizeof(Bit) - 1 - j); /* endianess problem */
#else
c = (AVAL(g1) >> j * 8) & 255;
#endif
if (c)
*p++ = c;
}
*p = 0;
}
handle_t get_handle(tree * code)
{
nbits_t nbits;
Group *val;
val = eval_(code, &nbits);
return check_handle((handle_t) AVAL(val));
}
tree init_function_return(char *name, int size, enum tree_code code)
{
tree var_name = make_node(IDENTIFIER_NODE);
tree rtn = make_node(code);
IDENTIFIER_LENGTH(var_name) = strlen(name);
IDENTIFIER_POINTER(var_name) = name;
DECL_NAME(rtn) = var_name;
// if (code == REG_VECTOR_DECL)
TREE_NBITS(rtn) = size;
DECL_STORAGE(rtn) = (Group *) malloc_X(bits_to_groups(size) + 1);
if (!DECL_STORAGE(rtn))
fatal("Not enough memory to allocate for '%s' system function",
name);
// STMT_TASK_ARGS (node) = NULL_TREE;
return rtn;
}
int args_one(int num_args, char *taskname)
{
if (num_args > 1)
error("Unexpected arguments in system function '%s'", taskname,
NULL);
else if (num_args == 0)
error("Missing arguments in call to system function '%s'",
taskname, NULL);
else
return 1;
return 0;
}
int args_zero(int num_args, char *taskname)
{
if (num_args != 0)
error("Unexpected arguments in system function '%s'", taskname,
NULL);
else
return 1;
return 0;
}
int args_zero_or_one(int num_args, char *taskname)
{
if (num_args > 1)
error("Unexpected arguments in system function '%s'", taskname,
NULL);
else
return 1;
return 0;
}
void arg_common(tree args)
{
tree t;
for (t = args; t; t = TREE_CHAIN(t))
if (TREE_EXPR(t))
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
}
int count_args(tree node)
{
tree t;
int arg_count = 0;
if (TREE_CODE(node) == SYSTASK_STMT)
t = STMT_TASK_ARGS(node);
else if (TREE_CODE(node) == SYSFUNCTION_REF)
t = FUNC_REF_ARGS(node);
else {
error("Illegal node type", NULL, NULL); /* do error handling later */
return 0;
}
if (!t || !TREE_EXPR(t)) /* This covers $foo; and $foo(); */
return 0;
for (; t; t = TREE_CHAIN(t))
arg_count++;
return arg_count;
}
void init_sysfunction(tree node)
{
int num_args;
tree t;
enum tree_code code;
PliInfo_t *info;
int count;
/* First, count the number of arguments */
num_args = count_args(node);
TREE_NBITS(node) = 1; /* make sure this is something if error causes early exit */
switch (FUNC_REF_SYSTYPE(node)) {
case USER_FUNC:
FUNC_REF_NEXT(node) = pliInstanceList;
pliInstanceList = node;
FUNC_REF_DELAYSCB(node) = NULL;
// setup for async marker
count = 1;
// ??? mdh - change
// for (t = STMT_TASK_ARGS (node); t; t = TREE_CHAIN (t)) {
for (t = FUNC_REF_ARGS(node); t; t = TREE_CHAIN(t)) {
info = (PliInfo_t *) xmalloc(sizeof(PliInfo_t));
info->storage = NULL;
info->pvc = FALSE;
info->saved_pvc = FALSE;
info->vclSet = FALSE;
info->instance = node;
info->argNumber = count;
info->marker = NULL;
TREE_PLIINFO(t) = (tree) info;
count++;
if (TREE_EXPR(t)) {
// ??? mdh - but this version doen't install markers so
// pvc calls won't be performed
TREE_EXPR_CODE(t) = pass3_expr_intrude(TREE_EXPR(t), 1);
// ??? mdh - this destroys function return code
// TREE_EXPR_CODE (t) = pass3_expr_marker (TREE_EXPR (t),
// &info->marker, (enum marker_flags)(M_ASYNCH + M_FIXED), (tree)info, NULL_TREE );
}
}
current_tf_instance = node;
ASYNCH_ATTR(node) = FALSE;
call_check_tf(FUNC_REF_USERTF(node));
// arg_common (FUNC_REF_ARGS (node));
TREE_NBITS(node) = call_size_tf(FUNC_REF_USERTF(node));
FUNC_REF_RETURNDECL(node) =
init_function_return(((p_tfcell) FUNC_REF_USERTF(node))->
tfname, TREE_NBITS(node),
REG_VECTOR_DECL);
return;
case F_STIME:
if (!args_zero(num_args, "$stime"))
break;
TREE_NBITS(node) = 32;
if (!sysstime_once) {
sysstime_return =
init_function_return("$stime", 32, REG_VECTOR_DECL);
sysstime_once = 1;
}
break;
case F_TIME:
if (!args_zero(num_args, "$time"))
break;
TREE_NBITS(node) = 64;
if (!systime_once) {
systime_return =
init_function_return("$time", 64, REG_VECTOR_DECL);
systime_once = 1;
}
break;
case F_REALTIME:
if (!args_zero(num_args, "$realtime"))
break;
TREE_NBITS(node) = 32;
TREE_REAL_ATTR(node) = 1; /* make $realtime a real (not int) node */
if (!sysrealtime_once) {
sysrealtime_return =
init_function_return("$realtime", 32, REAL_DECL);
sysrealtime_once = 1;
}
break;
case F_RANDOM:
if (!args_zero_or_one(num_args, "$random"))
break;
if (num_args == 1) {
t = TREE_PURPOSE(FUNC_REF_ARGS(node)); /* 1st arg */
if (HIERARCHICAL_ATTR(t)) {
FUNC_REF_INASSIGN(node) = resolve_hierarchical_name(t);
if (FUNC_REF_INASSIGN(node) == error_mark_node) {
TREE_NBITS(t) = 1;
break;
}
} else
FUNC_REF_INASSIGN(node) = t;
code = TREE_CODE(FUNC_REF_INASSIGN(node));
if (code != REG_VECTOR_DECL && code != INTEGER_DECL
&& code != TIME_DECL) {
error("Illegal arguments is call to $random", NULL, NULL);
break;
}
}
TREE_NBITS(node) = 32;
if (!sysrand_once) {
sysrand_return =
init_function_return("$random", 32, REG_VECTOR_DECL);
sysrand_once = 1;
}
break;
case F_FOPEN:
if (!args_one(num_args, "$fopen"))
break;
FUNC_REF_INASSIGN(node) = build_tree_list((tree)
pass3_expr_intrude
(TREE_PURPOSE
(FUNC_REF_ARGS(node)),
1), NULL_TREE);
TREE_NBITS(node) = 32;
if (!sysopen_once) {
sysopen_return =
init_function_return("$fopen", 32, REG_VECTOR_DECL);
sysopen_once = 1;
}
break;
case F_TEST_PLUSARGS:
if (!args_one(num_args, "$test$plusargs"))
break;
if (num_args == 0)
yyerror
("Missing arguments in call to system function '$test$plusargs'");
FUNC_REF_INASSIGN(node) = build_tree_list((tree)
pass3_expr_intrude
(TREE_PURPOSE
(FUNC_REF_ARGS(node)),
1), NULL_TREE);
TREE_NBITS(node) = 1;
if (!sysplus_once) {
sysplus_return =
init_function_return("$test$plusargs", 1, REG_SCALAR_DECL);
sysplus_once = 1;
}
break;
}
}
void init_systask(tree node)
{
int num_args;
int is_file = 0;
tree t;
tree decl;
PliInfo_t *info;
int count;
/* First, count the number of arguments */
num_args = count_args(node);
R_alloc(10, 10);
TREE_NBITS(node) = 1; /* in case an error causes an early exit */
switch (STMT_SYSTASK_TYPE(node)) {
case USER_TASK:
// setup for async marker
STMT_SYSTASK_NEXT(node) = pliInstanceList;
pliInstanceList = node;
STMT_SYSTASK_DELAYSCB(node) = NULL;
count = 1;
for (t = STMT_TASK_ARGS(node); t; t = TREE_CHAIN(t)) {
info = (PliInfo_t *) xmalloc(sizeof(PliInfo_t));
info->storage = NULL;
info->pvc = FALSE;
info->saved_pvc = FALSE;
info->instance = node;
info->argNumber = count;
info->marker = NULL;
TREE_PLIINFO(t) = (tree) info;
count++;
if (TREE_EXPR(t)) {
TREE_EXPR_CODE(t) = pass3_expr_marker(TREE_EXPR(t),
&info->marker,
(enum
marker_flags)
(M_ASYNCH + M_FIXED),
(tree) info,
NULL_TREE);
}
}
current_tf_instance = node;
call_check_tf(STMT_SYSTASK_USERTF(node));
// arg_common (STMT_TASK_ARGS (node));
ASYNCH_ATTR(node) = FALSE;
break;
case SCOPE:
if (!args_one(num_args, "$scope"))
break;
t = TREE_PURPOSE(STMT_TASK_ARGS(node));
// if (*tree_code_type [TREE_CODE (t)] != 'b' && !HIERARCHICAL_ATTR (t))
if (TREE_CODE(t) != BLOCK_DECL && !HIERARCHICAL_ATTR(t))
yyerror("Illegal argument type for $scope system task");
break;
case SHOWSCOPES:
case T_NOLOG:
case T_NOKEY:
case T_MONITORON:
case T_MONITOROFF:
case T_DUMPON:
case T_DUMPOFF:
case T_DUMPALL:
case T_DUMPFLUSH:
case T_UPDATETIMINGS:
if (!args_zero(num_args, STMT_TASK_NAME(node)))
break;
break;
case T_SHOWVARS:
if (num_args > 1)
yyerror("Unexpected arguments in system task $showvars");
else if (num_args == 1)
arg_common(STMT_TASK_ARGS(node));
break;
case T_LOG:
case T_KEY:
if (num_args > 1 || STMT_TASK_ARGS(node)
&& !TREE_EXPR(STMT_TASK_ARGS(node)))
error("Unexpected arguments in system task %s",
STMT_TASK_NAME(node), NULL_CHAR);
else
arg_common(STMT_TASK_ARGS(node));
break;
case T_FCLOSE:
case T_INPUT:
case T_DUMPFILE:
if (args_one(num_args, STMT_TASK_NAME(node)))
arg_common(STMT_TASK_ARGS(node));
break;
case FDISPLAY:
case FDISPLAYB:
case FDISPLAYH:
case FDISPLAYO:
case T_FWRITE:
case T_FWRITEB:
case T_FWRITEH:
case T_FWRITEO:
case FSTROBE:
case FSTROBEB:
case FSTROBEH:
case FSTROBEO:
case FMONITOR:
case FMONITORB:
case FMONITORH:
case FMONITORO:
is_file = 1;
case DISPLAY:
case DISPLAYB:
case DISPLAYH:
case DISPLAYO:
case WRITE:
case WRITEB:
case WRITEH:
case WRITEO:
case STROBE:
case STROBEB:
case STROBEH:
case STROBEO:
case MONITOR:
case MONITORB:
case MONITORH:
case MONITORO:
if (!disp_common(node, DEC, is_file, 1)) {
error("Illegal arguments in call to %s", STMT_TASK_NAME(node),
NULL_CHAR);
break;
}
arg_common(STMT_TASK_ARGS(node));
break;
case T_READMEMH:
case T_READMEMB:
if (num_args < 2) {
error("Missing arguments in call to %s", STMT_TASK_NAME(node),
NULL_CHAR);
break;
}
if (num_args > 4) {
error("Too many arguments in call to %s", STMT_TASK_NAME(node),
NULL_CHAR);
break;
}
/* Process file name */
t = STMT_TASK_ARGS(node);
if (TREE_EXPR(t))
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
else {
error("Missing file name in call to %s", STMT_TASK_NAME(node),
NULL_CHAR);
break;
}
/* Make sure 2nd argument is an array */
t = TREE_CHAIN(t);
decl = TREE_EXPR(t);
if (HIERARCHICAL_ATTR(decl))
decl = resolve_hierarchical_name(decl);
if (TREE_CODE(decl) != ARRAY_DECL) {
error("Second argument to %s must be an array",
STMT_TASK_NAME(node), NULL_CHAR);
break;
}
for (t = TREE_CHAIN(t); t; t = TREE_CHAIN(t))
if (TREE_EXPR(t)) {
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
if (TREE_NBITS(*TREE_EXPR_CODE(t)) > MAX_BITS_IN_NUMBER)
yyerror("Array index must be within 32 bits");
} else
error("Missing argument in call to %s",
STMT_TASK_NAME(node), NULL_CHAR);
break;
case T_WWAVES:
/* For waves, make sure arguments are in label-signal pairs */
for (t = STMT_TASK_ARGS(node); t; t = TREE_CHAIN(t)) {
if (is_string(TREE_EXPR(t)))
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
else {
error("Missing label in call to %s", STMT_TASK_NAME(node),
NULL_CHAR);
break;
}
if (((t = TREE_CHAIN(t)) == NULL_TREE) || !TREE_EXPR(t)) {
error("Missing argument in call to %s",
STMT_TASK_NAME(node), NULL_CHAR);
break;
}
if (is_array(TREE_EXPR(t))) {
error("Illegal array reference in call to %s",
STMT_TASK_NAME(node), NULL_CHAR);
break;
}
if (is_string(TREE_EXPR(t))) {
error("Missing signal in call to %s",
STMT_TASK_NAME(node), NULL_CHAR);
break;
}
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
}
break;
case T_DUMPVARS:
dumpvar.markers_first = NULL;
dumpvar.markers_last = NULL;
dumpvar.printed = NULL;
dumpvar.unprinted = NULL;
dumpvar.disallow_dumpvars = 0;
dumpvar.first_dumpvars = 1;
dumpvar.enabled = 0;
dumpvar.new_time = 1;
if (!num_args) /* No args, simple case */
break;
t = STMT_TASK_ARGS(node);
if (is_block(TREE_EXPR(t), &decl))
error("Illegal type in first argument of $dumpvars", NULL,
NULL);
else
TREE_EXPR_CODE(t) = pass3_expr(TREE_EXPR(t));
/* Put actual decl or block node in TREE_STMT */
for (t = TREE_CHAIN(t); t; t = TREE_CHAIN(t))
if (is_var(TREE_EXPR(t), &TREE_STMT(t))
|| is_block(TREE_EXPR(t), &TREE_STMT(t)));
else
error("Illegal argument in $dumpvars list", NULL, NULL);
break;
case T_TIMEFORMAT:
default:
arg_common(STMT_TASK_ARGS(node));
}
}
void exec_systask(tree node)
{
tree t, t1;
extern tree current_scope;
extern char *token_buffer;
enum radii radix;
int is_file = 0; /* to distiguish between $display and $fdisplay, etc */
int level = 0;
if (TREE_CODE(node) == TIMING_CHECK) {
timingCheck(node);
return;
}
switch (STMT_SYSTASK_TYPE(node)) {
case USER_TASK:
current_tf_instance = node;
{
strobe_queue_t *queue = is_strobe_active(node);
/* Get here because of call to user task, call call_tf */
if (!queue)
call_call_tf(STMT_SYSTASK_USERTF(node));
/* Get here at end of time unit and [ro]synchronize had been armed */
else {
if (queue == &idle_strobe_queue)
call_misc_tf(STMT_SYSTASK_USERTF(node), REASON_SYNCH);
else {
roFlag = TRUE;
call_misc_tf(STMT_SYSTASK_USERTF(node),
REASON_ROSYNCH);
roFlag = FALSE;
}
}
}
break;
case SCOPE:
/* arg is either string or block node */
t1 = TREE_PURPOSE(STMT_TASK_ARGS(node));
// if (*tree_code_type [TREE_CODE (t1)] != 'b') {
if (TREE_CODE(t1) != BLOCK_DECL) {
strcpy(token_buffer, IDENTIFIER_POINTER(t1));
t = search_scope(token_buffer, 0); /* traverse the scope */
if (t != error_mark_node) {
strcpy(token_buffer, IDENTIFIER_POINTER(t1));
search_scope(token_buffer, 1); /* actually set the scope */
}
} else {
t = DECL_THREAD(t1);
if (!t)
error("'%s' not declared", IDENT(DECL_NAME(t)), NULL_CHAR);
else
look_for_and_set_scope(t);
}
// if (BLOCK_UP (t) == current_scope) /* down one */
// set_scope (t);
// else
// lookupward_scope (t); /* go up and set scope */
// }
broadcast_tf(reason_scope);
break;
case SHOWSCOPES:
printf_V("Directory of scopes at current scope level:\n");
for (t = BLOCK_DOWN(current_scope); t; t = TREE_CHAIN(t)) {
if (TREE_CODE(t) == MODULE_BLOCK) {
printf_V("module (%s), instance (%s)\n",
MODULE_NAME(t), IDENT(BLOCK_NAME(t)));
} else if (TREE_CODE(t) == TASK_BLOCK) {
printf_V("task (%s)\n", IDENT(BLOCK_NAME(t)));
} else if (TREE_CODE(t) == FUNCTION_BLOCK) {
printf_V("function (%s)\n", IDENT(BLOCK_NAME(t)));
} else if (TREE_CODE(t) == NAMED_BLOCK) {
printf_V("named block (%s)\n", IDENT(BLOCK_NAME(t)));
}
}
printf_V("\nCurrent scope is (");
print_scope((handle_t) 1, current_scope);
printf_V(")\n");
print_top_modules();
break;
case T_SHOWVARS:
if (STMT_TASK_ARGS(node) && TREE_EXPR(STMT_TASK_ARGS(node)))
showvar(*TREE_EXPR_CODE(STMT_TASK_ARGS(node)));
else {
for (t = BLOCK_PORTS(current_scope); t; t = TREE_CHAIN(t))
showvar(t);
for (t = BLOCK_DECL(current_scope); t; t = TREE_CHAIN(t))
showvar(t);
/* only module blocks have spec parameters */
if (TREE_CODE(current_scope) == MODULE_BLOCK) {
for (t = MODULE_SPECDEFS(current_scope); t;
t = TREE_CHAIN(t))
if (TREE_CODE(t) == SPECPARAM_DECL) {
showvar(t);
}
}
}