forked from rmanohar/actsim
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cc
1821 lines (1580 loc) · 41.9 KB
/
main.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
/*************************************************************************
*
* This file is part of the ACT library
*
* Copyright (c) 2020 Rajit Manohar
*
* This program 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.
*
* 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 <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <act/act.h>
#include <act/passes.h>
#include <common/config.h>
#include "actsim.h"
#include "chpsim.h"
#include <lisp.h>
#include <lispCli.h>
#include <ctype.h>
static ActId *my_parse_id (const char *s)
{
return ActId::parseId (s);
}
static void signal_handler (int sig)
{
LispInterruptExecution = 1;
SimDES::interrupt();
}
static void clr_interrupt (void)
{
LispInterruptExecution = 0;
SimDES::resume();
}
static void usage (char *name)
{
fprintf (stderr, "Usage: %s [-n] [-S <sdf>] <actfile> <process>\n", name);
fprintf (stderr, " %s [-n] [-S <sdf>] -p <process> <actfile>\n", name);
fprintf (stderr, "\n");
fprintf (stderr, " -t <tm> : set simulation time scale to <tm> seconds\n");
fprintf (stderr, " -n : turn off name unmangling.\n");
fprintf (stderr, " -S <sdf> : use delay from the specified SDF file.\n");
fprintf (stderr, " -p <proc> : set <proc> as the top-level for simulation.\n");
exit (1);
}
class DummyObject : public ActSimDES {
public:
DummyObject() { gid = -1; };
~DummyObject() { };
int Step (Event *ev) { return 1; }
void computeFanout() { }
int causeGlobalIdx() { return gid; }
void setGid(int id) { gid = id; }
void sPrintCause(char *buf, int sz) { snprintf (buf, sz, "-cmd-"); }
private:
int gid;
};
static ActStatePass *glob_sp;
ActSim *glob_sim;
static Act *glob_act;
static Process *glob_top;
DummyObject *glob_dummy;
int is_rand_excl()
{
return glob_sim->isRandomChoice();
}
int process_cycle (int argc, char **argv)
{
if (argc != 1) {
fprintf (stderr, "Usage: %s\n", argv[0]);
return LISP_RET_ERROR;
}
if (glob_sim->isResetMode()) {
while (!LispInterruptExecution) {
if (!SimDES::matchPendingEvent (_match_hseprs)) {
// no prs or hse pending events!
break;
}
glob_sim->Step (1); // ignores breakpoints
}
}
else {
glob_sim->runSim (NULL);
}
return LISP_RET_TRUE;
}
int process_step (int argc, char **argv)
{
long nsteps;
if (argc != 1 && argc != 2) {
fprintf (stderr, "Usage: %s [num]\n", argv[0]);
return LISP_RET_ERROR;
}
if (argc == 1) {
nsteps = 1;
}
else {
sscanf (argv[1], "%ld", &nsteps);
if (nsteps <= 0) {
fprintf (stderr, "%s: zero/negative steps?\n", argv[0]);
return LISP_RET_ERROR;
}
}
glob_sim->Step (nsteps);
if (SimDES::hasPendingEvent()) {
return LISP_RET_TRUE;
}
else {
return LISP_RET_FALSE;
}
}
int process_advance (int argc, char **argv)
{
long nsteps;
if (argc != 2) {
fprintf (stderr, "Usage: %s <delay>\n", argv[0]);
return LISP_RET_ERROR;
}
sscanf (argv[1], "%ld", &nsteps);
if (nsteps <= 0) {
fprintf (stderr, "%s: zero/negative delay?\n", argv[0]);
return LISP_RET_ERROR;
}
glob_sim->Advance (nsteps);
if (SimDES::hasPendingEvent()) {
return LISP_RET_TRUE;
}
else {
return LISP_RET_FALSE;
}
}
int process_initialize (int argc, char **argv)
{
if (argc != 2) {
fprintf (stderr, "Usage: %s <process>\n", argv[0]);
return LISP_RET_ERROR;
}
Process *p = glob_act->findProcess (argv[1]);
if (!p) {
fprintf (stderr, "%s: could not find process %s\n", argv[0], argv[1]);
return LISP_RET_ERROR;
}
if (!p->isExpanded()) {
fprintf (stderr, "%s: `%s' is not an expanded process\n", argv[0], argv[1]);
return LISP_RET_ERROR;
}
if (glob_sim) {
delete glob_sim;
delete glob_sp;
}
SimDES::Init ();
glob_sp = new ActStatePass (glob_act);
glob_sp->run (p);
glob_sim = new ActSim (p);
glob_sim->runInit ();
return LISP_RET_TRUE;
}
static void dump_state (FILE *fp, ActInstTable *x)
{
if (!x) {
warning ("Didn't find info; is this a valid instance?");
return;
}
if (x->obj) {
x->obj->dumpState (fp);
}
if (x->H) {
hash_bucket_t *b;
hash_iter_t i;
hash_iter_init (x->H, &i);
while ((b = hash_iter_next (x->H, &i))) {
ActInstTable *tmp = (ActInstTable *) b->v;
dump_state (fp, tmp);
}
}
}
static void dump_coverage (FILE *fp, ActInstTable *x)
{
if (!x) {
warning ("Didn't find info; is this a valid instance?");
return;
}
if (x->obj) {
ChpSim *cobj = dynamic_cast <ChpSim *> (x->obj);
if (cobj) {
cobj->dumpStats (fp);
}
}
if (x->H) {
hash_bucket_t *b;
hash_iter_t i;
hash_iter_init (x->H, &i);
while ((b = hash_iter_next (x->H, &i))) {
ActInstTable *tmp = (ActInstTable *) b->v;
dump_coverage (fp, tmp);
}
}
}
static unsigned long _get_energy (FILE *fp,
ActInstTable *x, double *lk,
unsigned long *area,
bool print_type,
int ts = 0)
{
unsigned long tot;
unsigned long sub;
double totl, subl;
unsigned long suba, tota;
if (!x) {
warning ("Didn't find info; is this a valid instance?");
*lk = 0;
return 0;
}
tot = 0;
totl = 0;
tota = 0;
if (x->obj) {
tot = x->obj->getEnergy ();
totl = x->obj->getLeakage ();
tota = x->obj->getArea ();
if (tot > 0 || totl > 0 || tota > 0) {
for (int i=0; i < ts; i++) {
fprintf (fp, " ");
}
fprintf (fp, " - ");
if (x->obj->getName()) {
x->obj->getName()->Print (fp);
}
else {
fprintf (fp, "-top-");
}
if (print_type) {
fprintf (fp, " [ ");
Process *p = x->obj->getProc();
if (p->getns() && p->getns() != ActNamespace::Global()) {
char *ns = p->getns()->Name();
fprintf (fp, "%s::", ns);
FREE (ns);
}
fprintf (fp, "%s ] ", p->getName());
}
fprintf (fp, " %lu (%g W); area: %lu\n", tot, totl, tota);
}
}
sub = tot;
subl = totl;
suba = tota;
if (x->H) {
hash_bucket_t *b;
hash_iter_t i;
double tmpl;
unsigned long tmpa;
hash_iter_init (x->H, &i);
while ((b = hash_iter_next (x->H, &i))) {
ActInstTable *tmp = (ActInstTable *) b->v;
tot += _get_energy (fp, tmp, &tmpl, &tmpa, print_type, ts+1);
totl += tmpl;
tota += tmpa;
}
if ((tot - sub) > 0 || ((totl - subl) > 0) || ((tota - suba) > 0)) {
for (int i=0; i < ts; i++) {
fprintf (fp, " ");
}
fprintf (fp, " ---:subtree %lu (%g W); area: %lu\n",
tot - sub, totl - subl, tota - suba);
}
}
*lk = totl;
*area = tota;
return tot;
}
ActInstTable *find_table (ActId *id, ActInstTable *x)
{
char buf[1024];
hash_bucket_t *b;
if (!id) { return x; }
if (!x->H) { return NULL; }
ActId *tmp = id->Rest();
id->prune();
id->sPrint (buf, 1024);
id->Append (tmp);
b = hash_lookup (x->H, buf);
if (!b) {
return NULL;
}
else {
return find_table (id->Rest(), (ActInstTable *)b->v);
}
}
ActSimObj *find_object (ActId **id, ActInstTable *x)
{
char buf[1024];
hash_bucket_t *b;
if (!(*id)) { return x->obj; }
if (!x->H) { return x->obj; }
if ((*id)->isNamespace()) {
return x->obj;
}
ActId *tmp = (*id)->Rest();
(*id)->prune();
(*id)->sPrint (buf, 1024);
(*id)->Append (tmp);
b = hash_lookup (x->H, buf);
if (!b) {
return x->obj;
}
else {
(*id) = (*id)->Rest();
return find_object (id, (ActInstTable *)b->v);
}
}
int process_procinfo (int argc, char **argv)
{
ActId *id;
FILE *fp;
if (argc != 2 && argc != 3) {
fprintf (stderr, "Usage: %s <filename> [<instance-name>]\n", argv[0]);
return LISP_RET_ERROR;
}
if (strcmp (argv[1], "-") == 0) {
fp = stdout;
}
else {
fp = fopen (argv[1], "w");
if (!fp) {
fprintf (stderr, "%s: could not open file `%s' for writing\n",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
}
if (argc == 2) {
/* all */
id = NULL;
}
else {
id = my_parse_id (argv[1]);
if (id == NULL) {
fprintf (stderr, "Could not parse `%s' into an instance name\n",
argv[1]);
return LISP_RET_ERROR;
}
}
if (!id) {
/*-- print state of each process --*/
dump_state (fp, glob_sim->getInstTable ());
}
else {
/*-- find this process --*/
ActInstTable *inst = find_table (id, glob_sim->getInstTable());
dump_state (fp, inst);
delete id;
}
if (fp != stdout) {
fclose (fp);
}
return LISP_RET_TRUE;
}
int process_getenergy (int argc, char **argv)
{
ActId *id;
double lk;
unsigned long area;
FILE *fp;
if (argc != 2 && argc != 3 && argc != 4) {
fprintf (stderr, "Usage: %s [-v] <filename> [<instance-name>]\n", argv[0]);
return LISP_RET_ERROR;
}
int add_one = 0;
bool flag = false;
if (strcmp (argv[1], "-v") == 0) {
flag = true;
add_one = 1;
if (argc == 2) {
fprintf (stderr, "Usage: %s [-v] <filename> [<instance-name>]\n", argv[0]);
return LISP_RET_ERROR;
}
}
if (strcmp (argv[1+add_one], "-") == 0) {
fp = stdout;
}
else {
fp = fopen (argv[1+add_one], "w");
if (!fp) {
fprintf (stderr, "%s: could not open file `%s' for writing\n",
argv[0], argv[1+add_one]);
return LISP_RET_ERROR;
}
}
if (argc == 2+add_one) {
/* all */
id = NULL;
}
else {
id = my_parse_id (argv[2+add_one]);
if (id == NULL) {
fprintf (stderr, "Could not parse `%s' into an instance name\n",
argv[2+add_one]);
return LISP_RET_ERROR;
}
}
if (!id) {
/*-- print state of each process --*/
fprintf (fp, "Total: %lu",
_get_energy (fp, glob_sim->getInstTable (), &lk, &area,
flag));
fprintf (fp, " (%g W); area: %lu\n", lk, area);
}
else {
/*-- find this process --*/
ActInstTable *inst = find_table (id, glob_sim->getInstTable());
fprintf (fp, "Total: %lu", _get_energy (fp, inst, &lk, &area, flag));
fprintf (fp, " (%g W); area: %lu\n", lk, area);
delete id;
}
if (fp != stdout) {
fclose (fp);
}
return LISP_RET_TRUE;
}
int process_coverage (int argc, char **argv)
{
ActId *id;
FILE *fp;
if (argc != 2 && argc != 3) {
fprintf (stderr, "Usage: %s <filename> [<instance-name>]\n", argv[0]);
return LISP_RET_ERROR;
}
if (strcmp (argv[1], "-") == 0) {
fp = stdout;
}
else {
fp = fopen (argv[1], "w");
if (!fp) {
fprintf (stderr, "%s: could not open file `%s' for writing\n",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
}
if (argc == 2) {
/* all */
id = NULL;
}
else {
id = my_parse_id (argv[1]);
if (id == NULL) {
fprintf (stderr, "Could not parse `%s' into an instance name\n",
argv[1]);
return LISP_RET_ERROR;
}
}
if (!id) {
/*-- print state of each process --*/
dump_coverage (fp, glob_sim->getInstTable ());
}
else {
/*-- find this process --*/
ActInstTable *inst = find_table (id, glob_sim->getInstTable());
dump_coverage (fp, inst);
delete id;
}
if (fp != stdout) {
fclose (fp);
}
return LISP_RET_TRUE;
}
int process_goto (int argc, char **argv)
{
ActId *id;
FILE *fp;
if (argc != 3 && argc != 2) {
fprintf (stderr, "Usage: %s [<inst-name>] <label>\n", argv[0]);
return LISP_RET_ERROR;
}
if (argc == 3) {
id = my_parse_id (argv[1]);
if (id == NULL) {
fprintf (stderr, "Could not parse `%s' into an instance name\n",
argv[1]);
return LISP_RET_ERROR;
}
}
else {
id = NULL;
}
/*-- find this process --*/
ActInstTable *inst = find_table (id, glob_sim->getInstTable());
if (!inst) {
fprintf (stderr, "Could not find instance `%s'\n", argv[1]);
return LISP_RET_ERROR;
}
ChpSim *chp = dynamic_cast<ChpSim *>(inst->obj);
if (!chp) {
fprintf (stderr, "Instance `%s' is not a CHP process.\n", argv[1]);
return LISP_RET_ERROR;
}
if (chp->jumpTo (argv[argc-1])) {
return LISP_RET_TRUE;
}
else {
return LISP_RET_ERROR;
}
}
static int id_to_siminfo_raw (char *s, int *ptype, int *poffset, ActSimObj **pobj)
{
ActId *id = my_parse_id (s);
if (!id) {
fprintf (stderr, "Could not parse `%s' into an identifier\n", s);
return 0;
}
/* -- find object / id combo -- */
ActId *tmp = id;
ActSimObj *obj = find_object (&tmp, glob_sim->getInstTable());
stateinfo_t *si;
int offset, type;
int res;
act_connection *c;
if (!obj) {
fprintf (stderr, "Could not find `%s' in simulation\n", s);
delete id;
return 0;
}
/* -- now convert tmp into a local offset -- */
si = glob_sp->getStateInfo (obj->getProc ());
if (!si) {
fprintf (stderr, "Could not find info for process `%s'\n", obj->getProc()->getName());
delete id;
return 0;
}
if (!si->bnl->cur->FullLookup (tmp, NULL)) {
fprintf (stderr, "Could not find identifier `%s' within process `%s'\n",
s, obj->getProc()->getName());
delete id;
return 0;
}
if (!tmp->validateDeref (si->bnl->cur)) {
fprintf (stderr, "Array index is missing/out of bounds in `%s'!\n", s);
return 0;
}
c = tmp->Canonical (si->bnl->cur);
Assert (c, "What?");
res = glob_sp->getTypeOffset (si, c, &offset, &type, NULL);
if (!res) {
/* it is possible that it is an array reference */
Array *ta = NULL;
while (tmp->Rest()) {
tmp = tmp->Rest();
}
ta = tmp->arrayInfo();
if (ta) {
tmp->setArray (NULL);
if (!si->bnl->cur->FullLookup (tmp, NULL)) {
fprintf (stderr, "Could not find identifier `%s' within process `%s'\n",
s, obj->getProc()->getName());
delete id;
return 0;
}
c = tmp->Canonical (si->bnl->cur);
Assert (c, "Hmm...");
res = glob_sp->getTypeOffset (si, c, &offset, &type, NULL);
if (res) {
InstType *it = si->bnl->cur->FullLookup (tmp, NULL);
Assert (it->arrayInfo(), "What?");
offset += it->arrayInfo()->Offset (ta);
}
tmp->setArray (ta);
}
if (!res) {
fprintf (stderr, "Could not find identifier `%s' within process `%s'\n",
s, obj->getProc()->getName());
delete id;
return 0;
}
}
*ptype = type;
*poffset = offset;
if (pobj) {
*pobj = obj;
}
delete id;
return 1;
}
static int id_to_siminfo (char *s, int *ptype, int *poffset, ActSimObj **pobj)
{
int v = id_to_siminfo_raw (s, ptype, poffset, pobj);
if (*ptype == 3) {
*ptype = 2;
}
return v;
}
static int id_to_siminfo_glob (char *s,
int *ptype, int *poffset, ActSimObj **pobj)
{
ActSimObj *myobj;
myobj = NULL;
if (!id_to_siminfo (s, ptype, poffset, &myobj)) {
return 0;
}
if (!myobj) {
return 0;
}
if (pobj) {
*pobj = myobj;
}
*poffset = myobj->getGlobalOffset (*poffset, *ptype);
return 1;
}
static int id_to_siminfo_glob_raw (char *s,
int *ptype, int *poffset, ActSimObj **pobj)
{
ActSimObj *myobj;
myobj = NULL;
if (!id_to_siminfo_raw (s, ptype, poffset, &myobj)) {
return 0;
}
if (!myobj) {
return 0;
}
if (pobj) {
*pobj = myobj;
}
*poffset = myobj->getGlobalOffset (*poffset, (*ptype == 3 ? 2 : *ptype));
return 1;
}
int process_set (int argc, char **argv)
{
if (argc != 3) {
fprintf (stderr, "Usage: %s <name> <val>\n", argv[0]);
return LISP_RET_ERROR;
}
int type, offset;
if (!id_to_siminfo_glob (argv[1], &type, &offset, NULL)) {
return LISP_RET_ERROR;
}
if (type == 2 || type == 3) {
printf ("'%s' is a channel; not currently supported!\n", argv[1]);
return LISP_RET_ERROR;
}
int val;
if (type == 0) {
if (strcmp (argv[2], "0") == 0 || strcmp (argv[2], "#f") == 0) {
val = 0;
}
else if (strcmp (argv[2], "1") == 0 || strcmp (argv[2], "#t") == 0) {
val = 1;
}
else if (strcmp (argv[2], "X") == 0) {
val = 2;
}
else {
fprintf (stderr, "Boolean must be set to either 0, 1, or X\n");
return LISP_RET_ERROR;
}
const ActSim::watchpt_bucket *nm;
if ((nm = glob_sim->chkWatchPt (0, offset))) {
int oval = glob_sim->getBool (offset);
if (oval != val) {
BigInt tm = SimDES::CurTime();
printf ("[");
tm.decPrint (stdout, 20);
printf ("] <[env]> ");
printf ("%s := %c\n", nm->s, (val == 2 ? 'X' : ((char)val + '0')));
BigInt tmpv;
tmpv = val;
glob_sim->recordTrace (nm, type, ACT_CHAN_IDLE, tmpv);
}
}
glob_sim->setBool (offset, val);
}
else if (type == 1) {
BigInt *otmp = glob_sim->getInt (offset);
val = atoi (argv[2]);
if (val < 0) {
fprintf (stderr, "Integers are unsigned.\n");
return LISP_RET_ERROR;
}
BigInt x(64, 0, 0);
x = val;
x.setWidth (otmp->getWidth());
const ActSim::watchpt_bucket *nm;
if ((nm = glob_sim->chkWatchPt (1, offset))) {
if (*otmp != x) {
BigInt tm = SimDES::CurTime();
printf ("[");
tm.decPrint (stdout, 20);
printf ("] <[env]> ");
printf ("%s := ", nm->s);
x.decPrint (stdout);
printf (" (0x");
x.hexPrint (stdout);
printf (")\n");
glob_sim->recordTrace (nm, type, ACT_CHAN_IDLE, x);
}
}
glob_sim->setInt (offset, x);
}
else {
fatal_error ("Should not be here");
}
SimDES **arr;
arr = glob_sim->getFO (offset, type);
glob_dummy->setGid (offset);
for (int i=0; i < glob_sim->numFanout (offset, type); i++) {
ActSimDES *p = dynamic_cast <ActSimDES *> (arr[i]);
Assert (p, "Hmm?");
p->propagate (glob_dummy);
}
return LISP_RET_TRUE;
}
int process_wakeup (int argc, char **argv)
{
if (argc != 2) {
fprintf (stderr, "Usage: %s <name>\n", argv[0]);
return LISP_RET_ERROR;
}
ActId *id = my_parse_id (argv[1]);
ActId *orig = id;
if (!id) {
fprintf (stderr, "%s: could not parse `%s' into an identifier",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
ActSimObj *obj = find_object (&id, glob_sim->getInstTable());
if (!obj) {
fprintf (stderr, "%s: could not find instance `%s'\n", argv[0], argv[1]);
delete orig;
return LISP_RET_ERROR;
}
if (id) {
fprintf (stderr, "%s: please specify process name\n", argv[0]);
delete orig;
return LISP_RET_ERROR;
}
delete orig;
ChpSim *chp = dynamic_cast<ChpSim *>(obj);
if (!chp) {
fprintf (stderr, "%s: only supported for CHP/HSE components\n", argv[0]);
return LISP_RET_ERROR;
}
chp->awakenDeadlockedGC ();
return LISP_RET_TRUE;
}
int process_skipcomm (int argc, char **argv)
{
if (argc != 2) {
fprintf (stderr, "Usage: %s <name>\n", argv[0]);
return LISP_RET_ERROR;
}
int type, offset;
if (!id_to_siminfo_glob_raw (argv[1], &type, &offset, NULL)) {
return LISP_RET_ERROR;
}
if (!(type == 2 || type == 3)) {
printf ("%s: '%s' is a not a channel!\n", argv[0], argv[1]);
return LISP_RET_ERROR;
}
ActId *id = my_parse_id (argv[1]);
ActId *orig = id;
if (!id) {
fprintf (stderr, "%s: could not parse `%s' into an identifier",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
ActSimObj *obj = find_object (&id, glob_sim->getInstTable());
if (!obj) {
fprintf (stderr, "%s: could not find instance `%s'\n", argv[0], argv[1]);
delete orig;
return LISP_RET_ERROR;
}
delete orig;
ChpSim *chp = dynamic_cast<ChpSim *>(obj);
if (!chp) {
fprintf (stderr, "%s: only supported for CHP/HSE components\n", argv[0]);
return LISP_RET_ERROR;
}
act_channel_state *c = glob_sim->getChan (offset);
if (WAITING_SENDER (c)) {
if (type != 3) {
printf ("%s: state is waiting-send; use this command for the sending process.\n", argv[1]);
return LISP_RET_ERROR;
}
chp->skipChannelAction (1, offset);
}
else if (WAITING_RECEIVER (c)) {
if (type != 2) {
printf ("%s: state is waiting-recv; use this command for the receiving process.\n", argv[1]);
return LISP_RET_ERROR;
}
chp->skipChannelAction (0, offset);
}
else {
printf ("%s: channel `%s' is not in a state where it can be skipped.\n",
argv[0], argv[1]);
return LISP_RET_ERROR;
}
return LISP_RET_TRUE;
}
int process_get (int argc, char **argv)
{
if (argc != 2 && argc != 3) {
fprintf (stderr, "Usage: %s <name> [#f]\n", argv[0]);
return LISP_RET_ERROR;
}
int type, offset;
if (!id_to_siminfo_glob (argv[1], &type, &offset, NULL)) {
return LISP_RET_ERROR;
}
unsigned long val;
if (type == 0) {
val = glob_sim->getBool (offset);
LispSetReturnInt (val);
if (argc == 2) {
if (val == 0) {
printf ("%s: 0\n", argv[1]);
}
else if (val == 1) {
printf ("%s: 1\n", argv[1]);
}
else {
printf ("%s: X\n", argv[1]);
}
}
}
else if (type == 1) {
BigInt *ival = glob_sim->getInt (offset);
val = ival->getVal (0);
LispSetReturnInt (val);
if (argc == 2) {
printf ("%s: %lu (0x%lx)\n", argv[1], val, val);
}
}
else {
act_channel_state *c = glob_sim->getChan (offset);
if (WAITING_SENDER (c)) {
printf ("%s: waiting sender\n", argv[1]);
LispSetReturnInt(1);
}
else if (WAITING_SEND_PROBE (c)) {
printf ("%s: waiting sender probe\n", argv[1]);
LispSetReturnInt(2);
}
else if (WAITING_RECEIVER(c)) {
printf ("%s: waiting receiver\n", argv[1]);
LispSetReturnInt(3);
}
else if (WAITING_RECV_PROBE(c)) {
printf ("%s: waiting receiver probe\n", argv[1]);
LispSetReturnInt(4);
}
else {
printf ("%s: idle\n", argv[1]);
LispSetReturnInt(0);
}
}
return LISP_RET_INT;
}
int process_mget (int argc, char **argv)
{
if (argc < 2) {
fprintf (stderr, "Usage: %s <name1> <name2> ...\n", argv[0]);
return LISP_RET_ERROR;
}
int type, offset;
for (int i=1; i < argc; i++) {
if (!id_to_siminfo_glob (argv[i], &type, &offset, NULL)) {
return LISP_RET_ERROR;
}
if (type == 2 || type == 3) {
printf ("'%s' is a channel; not currently supported!\n", argv[i]);
return LISP_RET_ERROR;