-
Notifications
You must be signed in to change notification settings - Fork 7
/
chpsim.cc
5795 lines (5233 loc) · 123 KB
/
chpsim.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) 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 <common/config.h>
#include "chpsim.h"
#include <common/simdes.h>
#include <dlfcn.h>
#include <common/pp.h>
class ChpSim;
#ifndef MAX
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#endif
int ChpSimGraph::cur_pending_count = 0;
int ChpSimGraph::max_pending_count = 0;
int ChpSimGraph::max_stats = 0;
extern ActSim *glob_sim;
/*
*
* Dummy object used for adding an "idle" to the channel trace log
*
*/
class ChanTraceDelayed : public SimDES {
public:
ChanTraceDelayed (const ActSim::watchpt_bucket *n) { _n = n; _has_val = 0; }
ChanTraceDelayed (const ActSim::watchpt_bucket *n, const BigInt &x) { _n = n; _has_val = 1; _v = x; }
~ChanTraceDelayed () { _n = NULL; }
int Step (Event *ev) {
BigInt xtm = SimDES::CurTime();
float tm = glob_sim->curTimeMetricUnits ();
int len = xtm.getLen();
unsigned long tval;
unsigned long *ptm;
if (len == 1) {
tval = xtm.getVal (0);
ptm = &tval;
}
else {
MALLOC (ptm, unsigned long, len);
for (int i=0; i < len; i++) {
ptm[i] = xtm.getVal (i);
}
}
unsigned long *value;
value = NULL;
if (_has_val) {
if (_v.getLen() > 1) {
MALLOC (value, unsigned long, _v.getLen());
for (int i=0; i < _v.getLen(); i++) {
value[i] = _v.getVal (i);
}
}
}
for (int fmt=0; fmt < TRACE_NUM_FORMATS; fmt++) {
act_trace_t *tr = glob_sim->getTrace (fmt);
if (tr && !((_n->ignore_fmt >> fmt) & 1)) {
if (act_trace_has_alt (tr->t)) {
if (_has_val) {
if (_v.getLen() == 1) {
act_trace_chan_change_alt (tr, _n->node[fmt], len, ptm,
ACT_CHAN_VALUE, _v.getVal (0));
}
else {
act_trace_wide_chan_change_alt (tr, _n->node[fmt], len, ptm,
ACT_CHAN_VALUE,
_v.getLen(), value);
}
}
else {
act_trace_chan_change_alt (tr, _n->node[fmt], len, ptm,
ACT_CHAN_IDLE, 0);
}
}
else {
if (_has_val) {
if (_v.getLen() == 1) {
act_trace_chan_change (tr, _n->node[fmt], tm,
ACT_CHAN_VALUE, _v.getVal (0));
}
else {
act_trace_wide_chan_change (tr, _n->node[fmt], tm,
ACT_CHAN_VALUE, _v.getLen(), value);
}
}
else {
act_trace_chan_change (tr, _n->node[fmt], tm, ACT_CHAN_IDLE, 0);
}
}
}
}
if (len > 1) {
FREE (ptm);
}
if (_has_val && _v.getLen() > 1) {
FREE (value);
}
delete this;
return 1;
}
private:
const ActSim::watchpt_bucket *_n;
unsigned int _has_val:1;
BigInt _v;
};
//#define DUMP_ALL
static int stat_count = 0;
static void _chp_print (pp_t *pp, act_chp_lang_t *c, int prec = 0)
{
int lprec = 0;
if (!c) return;
if (c->label) {
pp_printf (pp, "%s: ", c->label);
pp_setb (pp);
}
switch (c->type) {
case ACT_CHP_COMMA:
case ACT_CHP_SEMI:
{
listitem_t *li;
for (li = list_first (c->u.semi_comma.cmd); li; li = list_next (li)) {
_chp_print (pp, (act_chp_lang_t *)list_value (li), lprec);
}
}
break;
case ACT_CHP_LOOP:
case ACT_CHP_DOLOOP:
case ACT_CHP_SELECT:
case ACT_CHP_SELECT_NONDET:
if (c->type == ACT_CHP_LOOP || c->type == ACT_CHP_DOLOOP) {
pp_printf (pp, "*");
}
pp_printf (pp, "[");
if (c->type == ACT_CHP_SELECT_NONDET) {
pp_printf (pp, "|");
}
pp_setb (pp);
pp_printf (pp, " ");
{
act_chp_gc_t *gc = c->u.gc;
if (c->type == ACT_CHP_DOLOOP) {
pp_printf (pp, " ");
_chp_print (pp, gc->s, 0);
pp_printf (pp, " <- ");
if (gc->g) {
char buf[10240];
sprint_uexpr (buf, 10240, gc->g);
pp_printf (pp, "%s", buf);
}
else {
pp_printf (pp, "true");
}
pp_printf (pp, " { %d }", stat_count++);
}
else {
while (gc) {
pp_setb (pp);
if (!gc->g) {
if (c->type == ACT_CHP_LOOP) {
pp_printf (pp, "true");
}
else {
pp_printf (pp, "else");
}
}
else {
char buf[10240];
sprint_uexpr (buf, 10240, gc->g);
pp_printf (pp, "%s", buf);
}
pp_printf (pp, " { %d }", stat_count++);
if (gc->s) {
pp_printf (pp, " -> ");
pp_lazy (pp, 0);
_chp_print (pp, gc->s, 0);
}
pp_endb (pp);
if (gc->next) {
pp_united (pp, -1);
pp_printf (pp, " [] ");
}
gc = gc->next;
}
}
}
pp_endb (pp);
pp_printf (pp, " ");
pp_lazy (pp, 0);
if (c->type == ACT_CHP_SELECT_NONDET) {
pp_printf (pp, "|");
}
pp_printf (pp, "]");
pp_lazy (pp, 0);
break;
case ACT_CHP_SKIP:
case ACT_CHP_ASSIGN:
case ACT_CHP_ASSIGNSELF:
case ACT_CHP_SEND:
case ACT_CHP_RECV:
case ACT_CHP_FUNC:
case ACT_CHP_MACRO:
pp_printf (pp, ".");
pp_lazy (pp, 0);
break;
case ACT_HSE_FRAGMENTS:
do {
_chp_print (pp, c->u.frag.body);
pp_printf (pp, " : %s", c->u.frag.nextlabel);
c = c->u.frag.next;
if (c) {
pp_printf (pp, ";\n");
pp_forced (pp, 0);
pp_printf (pp, "%s : ", c->label);
}
} while (c);
break;
default:
fatal_error ("Unknown type");
break;
}
if (c->label) {
pp_endb (pp);
}
}
static void chp_print_stats (pp_t *pp, act_chp_lang_t *c)
{
stat_count = 0;
_chp_print (pp, c);
}
static void _get_costs (stateinfo_t *si, ActId *id, chpsimstmt *stmt)
{
char buf[1024];
char *nsname;
if (si->bnl->p->getns() != ActNamespace::Global()) {
nsname = si->bnl->p->getns()->Name();
}
else {
nsname = NULL;
}
char tmpbuf[900];
if (nsname) {
snprintf (tmpbuf, 900, "%s::%s", nsname+2, si->bnl->p->getName());
FREE (nsname);
nsname = NULL;
}
else {
snprintf (tmpbuf, 900, "%s", si->bnl->p->getName());
}
if (debug_metrics) {
fprintf (stderr, "Looking for metrics for: %s\n", tmpbuf);
}
snprintf (buf, 1024, "sim.chp.%s.%s.D", tmpbuf, id->getName());
if (config_exists (buf)) {
if (debug_metrics) fprintf (stderr, " >> found %s\n", buf);
stmt->delay_cost = config_get_int (buf);
}
else {
// default delay is 10
stmt->delay_cost = config_get_int ("sim.chp.default_delay");
}
snprintf (buf, 1024, "sim.chp.%s.%s.D_bw", tmpbuf, id->getName());
if (config_exists (buf)) {
if (debug_metrics) fprintf (stderr, " >> found %s\n", buf);
stmt->bw_cost = config_get_int (buf);
}
else {
stmt->bw_cost = 0;
}
snprintf (buf, 1024, "sim.chp.%s.%s.E", tmpbuf, id->getName());
if (config_exists (buf)) {
if (debug_metrics) fprintf (stderr, " >> found %s\n", buf);
stmt->energy_cost = config_get_int (buf);
}
else {
// default energy is 0
stmt->energy_cost = config_get_int ("sim.chp.default_energy");
}
}
static pHashtable *_ZEROHASH = NULL;
static int _addhash (ChpSimGraph *g)
{
phash_bucket_t *b;
if (!_ZEROHASH) {
_ZEROHASH = phash_new (16);
}
b = phash_lookup (_ZEROHASH, g);
if (b) {
return 1;
}
b = phash_add (_ZEROHASH, g);
return 0;
}
static void _clrhash ()
{
phash_free (_ZEROHASH);
_ZEROHASH = NULL;
}
ChpSim::ChpSim (ChpSimGraph *g, int max_cnt, int max_stats,
act_chp_lang_t *c, ActSimCore *sim, Process *p)
: ActSimObj (sim, p)
{
char buf[1024];
_deadlock_pc = NULL;
_stalled_pc = list_new ();
_probe = NULL;
_savedc = c;
_energy_cost = 0;
_leakage_cost = 0.0;
_area_cost = 0;
_statestk = NULL;
_cureval = NULL;
_frag_ch = NULL;
_hse_mode = 0; /* default is CHP */
_maxstats = max_stats;
if (_maxstats > 0) {
MALLOC (_stats, unsigned long, _maxstats);
for (int i=0; i < _maxstats; i++) {
_stats[i] = 0;
}
}
if (p) {
char *nsname;
if (p->getns() != ActNamespace::Global()) {
nsname = p->getns()->Name();
}
else {
nsname = NULL;
}
char tmpbuf[900];
if (nsname) {
snprintf (tmpbuf, 900, "%s::%s", nsname+2, p->getName());
FREE (nsname);
}
else {
snprintf (tmpbuf, 900, "%s", p->getName());
}
snprintf (buf, 1024, "sim.chp.%s.leakage", tmpbuf);
if (config_exists (buf)) {
_leakage_cost = config_get_real (buf);
}
else {
_leakage_cost = config_get_real ("sim.chp.default_leakage");
}
snprintf (buf, 1024, "sim.chp.%s.area", tmpbuf);
if (config_exists (buf)) {
_area_cost = config_get_int (buf);
}
else {
_area_cost = config_get_int ("sim.chp.default_area");
}
}
if (c) {
/*
Analyze the chp body to find out the maximum number of concurrent
threads; those are the event types.
*/
_npc = _max_program_counters (c);
_pcused = 1;
Assert (_npc >= 1, "What?");
if (_npc > SIM_EV_MAX-1) {
fatal_error ("Currently there is a hard limit of %d concurrent modules within a single CHP block. Your program requires %d.", SIM_EV_MAX, _npc);
}
_pc = (ChpSimGraph **)
sim->getState()->allocState (sizeof (ChpSimGraph *)*_npc);
_holes = (int *) sim->getState()->allocState (sizeof (int)*_npc);
for (int i=0; i < _npc; i++) {
_pc[i] = NULL;
_holes[i] = i;
}
_holes[0] = -1;
if (max_cnt > 0) {
_tot = (int *)sim->getState()->allocState (sizeof (int)*max_cnt);
for (int i=0; i < max_cnt; i++) {
_tot[i] = 0;
}
}
else {
_tot = NULL;
}
Assert (_npc >= 1, "What?");
_pc[0] = g;
_statestk = list_new ();
_initEvent ();
}
else {
_pc = NULL;
_npc = 0;
}
}
void ChpSim::zeroInit ()
{
if (_pc && _pc[0]) {
_zeroAllIntsChans (_pc[0]);
_clrhash ();
}
}
void ChpSim::reStart (ChpSimGraph *g, int max_cnt)
{
for (int i=0; i < _npc; i++) {
_pc[i] = NULL;
}
for (int i=0; i < max_cnt; i++) {
_tot[i] = 0;
}
_pc[0] = g;
_nextEvent (0);
}
ChpSim::~ChpSim()
{
if (_statestk) {
list_free (_statestk);
}
list_free (_stalled_pc);
if (_deadlock_pc) {
list_free (_deadlock_pc);
}
if (_maxstats > 0) {
FREE (_stats);
}
}
int ChpSim::_nextEvent (int pc)
{
while (_pc[pc] && !_pc[pc]->stmt) {
pc = _updatepc (pc);
}
if (_pc[pc]) {
new Event (this, SIM_EV_MKTYPE (pc,0) /* pc */,
_sc->getDelay (_pc[pc]->stmt->delay_cost));
return 1;
}
return 0;
}
void ChpSim::_initEvent ()
{
_nextEvent (0);
}
void ChpSim::computeFanout ()
{
if (_savedc) {
_compute_used_variables (_savedc);
}
}
int ChpSim::_updatepc (int pc)
{
int joined;
_pc[pc] = _pc[pc]->completed(pc, _tot, &joined);
if (!_pc[pc]) {
#ifdef DUMP_ALL
printf (" [released slot %d (pcused now: %d)]", pc, _pcused-1);
#endif
Assert (_pcused > 0, "What?");
_holes[_pcused-1] = pc;
_pcused--;
}
if (joined) {
#ifdef DUMP_ALL
printf (" [joined #%d / %d %d]", pc, _pcused, _pc[pc]->wait);
#endif
}
#if 0
if (pc >= _pcused) {
ChpSimGraph *tmp = _pc[pc];
_pc[pc] = NULL;
for (int i=_pcused-1; i >= 0; i--) {
if (!_pc[i]) {
pc = i;
_pc[pc] = tmp;
tmp = NULL;
break;
}
}
Assert (tmp == NULL, "What?");
#ifdef DUMP_ALL
printf (" [pc-adjust %d]", pc);
#endif
}
#endif
return pc;
}
int ChpSim::_collect_sharedvars (Expr *e, int pc, int undo)
{
int ret = 0;
if (!e) return ret;
switch (e->type) {
case E_TRUE:
case E_FALSE:
case E_INT:
case E_REAL:
break;
/* binary */
case E_AND:
case E_OR:
case E_PLUS:
case E_MINUS:
case E_MULT:
case E_DIV:
case E_MOD:
case E_LSL:
case E_LSR:
case E_ASR:
case E_XOR:
case E_LT:
case E_GT:
case E_LE:
case E_GE:
case E_EQ:
case E_NE:
ret = ret | _collect_sharedvars (e->u.e.l, pc, undo);
ret = ret | _collect_sharedvars (e->u.e.r, pc, undo);
break;
case E_UMINUS:
case E_COMPLEMENT:
case E_NOT:
case E_BUILTIN_BOOL:
case E_BUILTIN_INT:
ret = ret | _collect_sharedvars (e->u.e.l, pc, undo);
break;
case E_QUERY:
ret = ret | _collect_sharedvars (e->u.e.l, pc, undo);
ret = ret | _collect_sharedvars (e->u.e.r->u.e.l, pc, undo);
ret = ret | _collect_sharedvars (e->u.e.r->u.e.r, pc, undo);
break;
case E_COLON:
case E_COMMA:
fatal_error ("Should have been handled elsewhere");
break;
case E_CONCAT:
do {
ret = ret | _collect_sharedvars (e->u.e.l, pc, undo);
e = e->u.e.r;
} while (e);
break;
case E_BITFIELD:
ret = ret | _collect_sharedvars (e->u.e.l, pc, undo);
break;
case E_CHP_BITFIELD:
if (((struct chpsimderef *)e->u.e.l)->offset < 0) {
ret = 1;
}
break;
case E_CHP_VARBOOL:
case E_CHP_VARINT:
case E_VAR:
// don't need to deal with shared variables here
// since this is pre-computed
case E_CHP_VARCHAN:
break;
case E_PROBE:
fatal_error ("What?");
break;
case E_PROBEIN:
case E_PROBEOUT:
{
int off = getGlobalOffset (e->u.x.val, 2);
act_channel_state *c = _sc->getChan (off);
if ((c->fragmented & 0x1) && e->type == E_PROBEOUT) {
return 1;
}
else if ((c->fragmented & 0x2) && e->type == E_PROBEIN) {
return 1;
}
if (undo) {
if (c->probe) {
#ifdef DUMP_ALL
printf (" [clr %d]", off);
#endif
if (!_probe) {
_probe = c->probe;
}
else {
if (_probe != c->probe) {
fatal_error ("Weird!");
}
}
if (c->probe->isWaiting (this)) {
c->probe->DelObject (this);
}
c->probe = NULL;
}
if (e->type == E_PROBEIN) {
if (c->receiver_probe) {
c->recv_here = 0;
c->receiver_probe = 0;
}
}
else {
if (c->sender_probe) {
c->send_here = 0;
c->sender_probe = 0;
}
}
}
else {
if (e->type == E_PROBEIN && !WAITING_SENDER(c)) {
#ifdef DUMP_ALL
printf (" [add %d]", off);
#endif
if (!_probe) {
_probe = new WaitForOne (0);
}
if (c->probe && c->probe != _probe) {
fatal_error ("Channel is being probed by multiple processes!");
}
c->probe = _probe;
if (!c->probe->isWaiting (this)) {
c->probe->AddObject (this);
}
c->recv_here = (pc+1);
c->receiver_probe = 1;
}
else if (e->type == E_PROBEOUT && !WAITING_RECEIVER(c)) {
#ifdef DUMP_ALL
printf (" [add %d]", off);
#endif
if (!_probe) {
_probe = new WaitForOne (0);
}
if (c->probe && c->probe != _probe) {
fatal_error ("Channel is being probed by multiple processes!");
}
c->probe = _probe;
if (!c->probe->isWaiting (this)) {
c->probe->AddObject (this);
}
c->send_here = (pc+1);
c->sender_probe = 1;
}
}
}
break;
case E_FUNCTION:
{
Expr *tmp;
tmp = e->u.fn.r;
while (tmp) {
ret = ret | _collect_sharedvars (tmp->u.e.l, pc, undo);
tmp = tmp->u.e.r;
}
}
break;
case E_SELF:
case E_SELF_ACK:
default:
fatal_error ("Unknown expression type %d\n", e->type);
break;
}
return ret;
}
/*-- returns 1 if there's a shared variable in the guard --*/
int ChpSim::_add_waitcond (chpsimcond *gc, int pc, int undo)
{
int ret = 0;
#ifdef DUMP_ALL
if (undo) {
printf (" [del-waits]");
}
else {
printf (" [add-waits]");
}
#endif
_probe = NULL;
while (gc) {
if (gc->g) {
ret = ret | _collect_sharedvars (gc->g, pc, undo);
}
gc = gc->next;
}
if (undo) {
if (_probe) {
delete _probe;
}
}
#ifdef DUMP_ALL
printf (" sh-var:%d", ret);
#endif
return ret;
}
int ChpSim::computeOffset (const struct chpsimderef *d)
{
if (!d->range) {
return d->offset;
}
for (int i=0; i < d->range->nDims(); i++) {
BigInt res = exprEval (d->chp_idx[i]);
d->idx[i] = res.getVal(0);
}
int x = d->range->Offset (d->idx);
if (x == -1) {
fprintf (stderr, "In: ");
if (getName()) {
getName()->Print (stderr);
}
fprintf (stderr, " [ %s ]\n", _proc ? _proc->getName() : "-global-");
fprintf (stderr, "\tAccessing index ");
for (int i=0; i < d->range->nDims(); i++) {
fprintf (stderr, "[%d]", d->idx[i]);
}
fprintf (stderr, " from ");
d->cx->toid()->Print (stderr);
fprintf (stderr, "\n");
fatal_error ("Array out of bounds!");
}
return d->offset + x;
}
void ChpSimGraph::printStmt (FILE *fp, Process *p)
{
act_connection *c;
int dy;
if (!stmt) {
fprintf (fp, "(null)");
return;
}
switch (stmt->type) {
case CHPSIM_FORK:
fprintf (fp, "concur-fork:");
for (int i=0; i < stmt->u.fork; i++) {
if (all[i]) {
fprintf (fp, " ");
all[i]->printStmt (fp, p);
}
}
break;
case CHPSIM_ASSIGN:
fprintf (fp, "assign: ");
if (!p) break;
c = state->getConnFromOffset (p, stmt->u.assign.d.offset,
(stmt->u.assign.isint ? 1 : 0),
&dy);
if (c) {
ActId *t = c->toid();
t->Print (fp);
delete t;
if (dy != -1) { fprintf (fp, "[]"); }
}
else {
fprintf (fp, "-?-");
}
break;
case CHPSIM_SEND:
fprintf (fp, "send: ");
if (!p) break;
c = state->getConnFromOffset (p, stmt->u.sendrecv.chvar, 3, &dy);
if (c) {
ActId *t = c->toid();
t->Print (fp);
delete t;
if (dy != -1) { fprintf (fp, "[]"); }
}
else {
fprintf (fp, "-?-");
}
break;
case CHPSIM_RECV:
fprintf (fp, "recv: ");
if (!p) break;
c = state->getConnFromOffset (p, stmt->u.sendrecv.chvar, 2, &dy);
if (c) {
ActId *t = c->toid();
t->Print (fp);
delete t;
if (dy != -1) { fprintf (fp, "[]"); }
}
else {
fprintf (fp, "-?-");
}
break;
case CHPSIM_FUNC:
fprintf (fp, "log");
break;
case CHPSIM_COND:
fprintf (fp, "cond: ");
break;
case CHPSIM_CONDARB:
fprintf (fp, "cond-arb: ");
break;
case CHPSIM_LOOP:
fprintf (fp, "loop: ");
break;
case CHPSIM_NOP:
fprintf (fp, "nop ");
break;
default:
fatal_error ("What?");
break;
}
}
static const char *_process_string (const char *s,
int *is_zero,
int *type,
int *width)
{
const char *stmp = s;
*is_zero = 0;
*type = 0;
*width = -1;
if (*stmp == '%') {
int idx = 1;
while (stmp[idx] >= '0' && stmp[idx] <= '9' && stmp[idx]) {
if (*width == -1) {
*width = stmp[idx] - '0';
}
else {
*width *= 10;
*width += stmp[idx] - '0';
}
idx++;
}
if (idx != 1) {
if (stmp[1] == '0') {
*is_zero = 1;
}
else {
*is_zero = 0;
}
}
if (stmp[idx]) {
if (stmp[idx] == 'x') {
*type = 2; /* hex */
stmp = stmp + idx + 1;
}
else if (stmp[idx] == 'd') {
*type = 1; /* signed */
stmp = stmp + idx + 1;
}
else if (stmp[idx] == 'u') {
*type = 0; /* default */
stmp = stmp + idx + 1;
}
else if (stmp[idx] == 'b') {
*type = 3; /* bits */
stmp = stmp + idx + 1;
}
else {
*is_zero = 0;
*type = 0;
*width = -1;
}
}
else {
*is_zero = 0;
*type = 0;
*width = -1;
}
}
else {
*is_zero = 0;
*type = 0;
*width = -1;
}
return stmp;
}
static void _process_print_int (BigInt &v,
int int_is_zero,
int int_type,
int int_width)
{
if (int_width == -1) {
if (int_type == 0) {
v.decPrint (actsim_log_fp());
//actsim_log ("%" ACT_EXPR_RES_PRINTF "u", v.getVal (0));
}
else if (int_type == 1) {
actsim_log ("%" ACT_EXPR_RES_PRINTF "d", v.getVal (0));
}
else if (int_type == 2) {
v.hexPrint (actsim_log_fp ());
}
else if (int_type == 3) {
v.bitPrint (actsim_log_fp ());
}
}
else {
if (int_type == 0) {
v.decPrint (actsim_log_fp());
#if 0
if (int_is_zero) {
actsim_log ("%0" ACT_EXPR_RES_PRINTF "*u", int_width, v.getVal (0));
}
else {
actsim_log ("%" ACT_EXPR_RES_PRINTF "*u", int_width, v.getVal (0));
}
#endif
}
else if (int_type == 1) {
if (int_is_zero) {