-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslice.c
1919 lines (1809 loc) · 53.3 KB
/
slice.c
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 software was developed by employees of the National Institute
of Standards and Technology (NIST), an agency of the Federal
Government and is being made available as a public service. Pursuant
to title 17 United States Code Section 105, works of NIST employees
are not subject to copyright protection in the United States. This
software may be subject to foreign copyright. Permission in the
United States and in foreign countries, to the extent that NIST may
hold copyright, to use, copy, modify, create derivative works, and
distribute this software and its documentation without fee is hereby
granted on a non-exclusive basis, provided that this notice and
disclaimer of warranty appears in all copies.
THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND,
EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED
TO, ANY WARRANTY THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS,
ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, AND FREEDOM FROM INFRINGEMENT, AND ANY WARRANTY THAT THE
DOCUMENTATION WILL CONFORM TO THE SOFTWARE, OR ANY WARRANTY THAT THE
SOFTWARE WILL BE ERROR FREE. IN NO EVENT SHALL NIST BE LIABLE FOR
ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL
OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN ANY
WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY
PERSONS OR PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS
SUSTAINED FROM, OR AROSE OUT OF THE RESULTS OF, OR USE OF, THE
SOFTWARE OR SERVICES PROVIDED HEREUNDER.
*/
#include "slice.h"
#include "lif.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
static char sccsid[] = "@(#)slice.c 1.7 8/16/95";
static char *sccs_h_id = SLICE_SCCS_ID;
*/
extern int v_opt;
static bit_set dont_descend;
void (*slice_hook)() = NULL;
void (*slice_pass_hook)() = NULL;
void *QQQ;
void slice_proc(bit_set final_slice_sets[], bit_set slice_sets[], int proc, bit_set active);
void union_bit_set(bit_set to, bit_set from);
void bit_on(bit_set b, int at);
void clear_id_set(id_set_ptr head);
int add_to_id_set(id_set_ptr *head, int pid, int id);
int bit_set_equal(bit_set a, bit_set b);
void bit_off(bit_set b, int at);
void print_proc_defs(int nc, int proc);
int
stmt_to_proc(int file, int stmt)
{
int i;
for (i = 1; i <= n_procs; i++)
{
if (procs[i].file_id == file)
if ((stmt >= procs[i].entry) && (stmt <= procs[i].exit))
return i;
}
return 0; /* no proc found */
}
int
is_id_valid(int pid, int id)
{
if ((pid < 0) || (pid > n_procs))
{
fprintf(stderr, "proc %d out of range %d\n", pid, n_procs);
fflush(stderr);
return 0;
}
if (pid)
{
if ((id < 0) || (id > procs[pid].n_locals))
{
fprintf(stderr, "local id %d out of range %d\n", id, procs[pid].n_locals);
fflush(stderr);
return 0;
}
}
else
{
if ((id < 0) || (id > n_globals))
{
fprintf(stderr, "global id %d out of range %d\n", id, n_globals);
fflush(stderr);
return 0;
}
}
return 1;
}
void
set_criteria(int file, int stmt_proc, int stmt, int var_proc, int var)
{
int var_max, var_n;
if (var_proc)
{ /* get all members of a structure */
var_n = procs[var_proc].n_locals;
var_max = procs[var_proc].locals[var].offset + var;
}
else
{
var_n = n_globals;
var_max = globals[var].offset + var;
}
for (; var <= var_max; var++)
{
is_id_valid(var_proc, var);
if (var_proc)
{
if (stmt_proc == var_proc)
bit_on(files[file].stmts[stmt].active_local, var);
else
{
add_to_id_set(&files[file].stmts[stmt].active_other, var_proc, var);
}
}
else
bit_on(files[file].stmts[stmt].active_global, var);
}
}
void
clear_active_proc(int proc)
{
int file, stmt;
file = procs[proc].file_id;
for (stmt = procs[proc].entry; stmt <= procs[proc].exit; stmt++)
{
clear_bit_set(files[file].stmts[stmt].active_global);
clear_bit_set(files[file].stmts[stmt].active_local);
clear_id_set(files[file].stmts[stmt].active_other);
files[file].stmts[stmt].active_other = NULL;
}
}
void
clear_active(void)
{
int file, stmt;
for (file = 0; file < n_files; file++)
for (stmt = 1; stmt <= files[file].n_stmts; stmt++)
{
clear_bit_set(files[file].stmts[stmt].active_global);
clear_bit_set(files[file].stmts[stmt].active_local);
clear_id_set(files[file].stmts[stmt].active_other);
files[file].stmts[stmt].active_other = NULL;
}
}
int
lib_defs(stmt_ptr stmt, int id, int is_local)
{
call_ptr calls;
var_ptr var;
actual_ptr act;
int cx, ax;
calls = stmt->calls;
while (calls)
{
cx = calls->pid;
if (v_opt)
printf("call to %s\n", procs[cx].proc_name);
act = calls->actuals;
while (act)
{
var = act->actuals;
while (var)
{
if (var->code == LIF_AREF)
{
ax = var->id;
if ((addrs[ax].id == id) &&
((is_local && addrs[ax].pid) || (!is_local && !addrs[ax].pid)))
return 1;
}
var = var->next;
}
act = act->next;
}
calls = calls->next_this_stmt;
}
return 0;
}
int
is_var_defed(stmt_ptr stmt, int id, int is_local)
{
var_ptr defs;
int result;
defs = stmt->defs;
while (defs)
{
if (defs->level == 0)
switch (defs->code)
{
case LIF_DEF:
if (!is_local)
break;
if (id == defs->id)
return 1;
break;
case LIF_GDEF:
if (is_local)
break;
if (id == defs->id)
return 1;
break;
default:;
}
defs = defs->next;
}
result = lib_defs(stmt, id, is_local);
if (v_opt)
printf("is %d defed %d\n", result); /* KS Missing variable */
return result;
/*
if (is_local) return is_bit_on (stmt->active_local,id);
return is_bit_on (stmt->active_global,id);
*/
}
void
print_addr(set_ptr addr_set)
{
int addr, id, pid;
if (addr_set)
{
addr = addr_set->id;
id = addrs[addr].id;
pid = addrs[addr].pid;
}
}
static int base_id, base_pid, base_ptr, base_level, base_done = 1;
static var_ptr base;
static set_ptr base_addrs[200];
static int base_off[200];
int
offset_check(int pid, int id, int off)
{
id_ptr ids;
int n;
static id_set_ptr trouble = NULL;
if (pid)
{
ids = procs[pid].locals;
n = procs[pid].n_locals;
}
else
{
n = n_globals;
ids = globals;
}
if (id > n)
{
if (add_to_id_set(&trouble, pid, id))
fprintf(stderr, "id %d out of range (%d)\n", id, n);
return 0;
}
if ((off > ids[id].offset) || (off + id > n))
{
if (add_to_id_set(&trouble, pid, id))
fprintf(stderr,
"offset on %s is too large %d (%d)\n",
var_name(pid, id),
off,
ids[id].offset);
return 0;
}
return 1;
}
void
print_field_resolve(int ptr, field_ptr f)
{
set_ptr addr;
int id, pid, p;
if (!f)
return;
addr = ptr_points_to(ptr);
while (addr)
{
print_addr(addr);
printf(" ");
printf("field %d %s +%d: ", f->fid, f->name, f->offset);
id = addrs[addr->id].id;
pid = addrs[addr->id].pid;
id += f->offset;
p = pid ? procs[pid].locals[id].ptr_id : globals[id].ptr_id;
printf("[[%s]]", pid ? procs[pid].locals[id].name : globals[id].name);
printf("\n");
print_field_resolve(p, f->next);
addr = addr->next;
}
}
void
chain_resolve_set(int def, int proc)
{
int chain_id, head_id, head_pid, ptr;
int id, pid;
set_ptr addr;
id_ptr head;
field_ptr f;
if (v_opt)
printf("proc %s\n", procs[proc].proc_name);
chain_id = def;
head_id = chains[chain_id].id;
head_pid = chains[chain_id].pid;
f = chains[chain_id].fields;
if (v_opt)
printf("Set chain %d on %s->%s\n",
def,
var_name(head_pid, head_id),
f ? f->name : "<No field>");
head = head_pid ? procs[head_pid].locals : globals;
ptr = head[head_id].ptr_id;
addr = ptr_points_to(ptr);
base_level = 0;
base_addrs[base_level] = addr;
while (f)
{
base_off[base_level] = f->offset;
base_level++;
if (addr)
{
id = addrs[addr->id].id;
pid = addrs[addr->id].pid;
if (offset_check(pid, id, f->offset))
{
id += f->offset;
ptr = pid ? procs[pid].locals[id].ptr_id : globals[id].ptr_id;
addr = ptr_points_to(ptr);
base_addrs[base_level] = addr;
}
else
{
base_addrs[base_level] = NULL;
}
}
else
base_addrs[base_level] = NULL;
f = f->next;
}
if (v_opt)
{
printf("base level %d\n", base_level);
printf("base off %d %d %d %d\n", base_off[0], base_off[1], base_off[2], base_off[3]);
/* KS Added ->id field as this is a linked list */
printf("base addrs %d %d %d %d\n",
base_addrs[0]->id,
base_addrs[1]->id,
base_addrs[2]->id,
base_addrs[3]->id);
}
}
int
chain_resolve_get(int *id, int *pid)
{
int level, addr;
int idx, pidx, ptr;
set_ptr objs;
/*
level = base_level - 1;
if (level < 0) return 0;
printf ("get level %d\n",level); fflush(stdout);
objs = base_addrs[level];
while ((!objs) && (level >= 0)){
if(v_opt)printf ("level %d\n",level);
if (base_addrs[level]){
base_addrs[level] = base_addrs[level]->next;
objs = base_addrs[level];
if (objs)while ((level >= 0) && (level < (base_level - 1))){
if(v_opt)printf ("\tlevel %d\n",level);
if (base_addrs[level]){
addr = base_addrs[level]->id;
idx = addrs[addr].id;
pidx = addrs[addr].pid;
if (offset_check(pidx,idx,base_off[level])){
idx += base_off[level];
ptr = pidx?procs[pidx].locals[idx].ptr_id:
globals[idx].ptr_id;
base_addrs[level] = base_addrs[level]->next;
level++;
if (ptr) base_addrs[level] = ptr_points_to(ptr);
else {
level--;
}
}
else {
base_addrs[level] = base_addrs[level]->next;
}
}
else {
level--;
}
}
else {
level--;
}
}
else level--;
if (level == (base_level - 1))objs = base_addrs[level];
else objs = NULL;
}
*/
level = base_level - 1;
if (level < 0)
return 0;
objs = base_addrs[level];
if (!objs)
level--;
while ((level >= 0) && (level < (base_level - 1)))
{
if (v_opt)
printf("level %d\n", level);
if (base_addrs[level])
{
base_addrs[level] = base_addrs[level]->next;
objs = base_addrs[level];
if (v_opt)
printf("\tlevel %d\n", level);
if (base_addrs[level])
{
addr = base_addrs[level]->id;
idx = addrs[addr].id;
pidx = addrs[addr].pid;
if (offset_check(pidx, idx, base_off[level]))
{
idx += base_off[level];
ptr = pidx ? procs[pidx].locals[idx].ptr_id : globals[idx].ptr_id;
level++;
if (ptr)
base_addrs[level] = ptr_points_to(ptr);
else
{
level--;
}
}
else
{
base_addrs[level] = base_addrs[level]->next;
}
}
else
{
level--;
}
}
else
level--;
}
if (base_addrs[level] && (level == (base_level - 1)))
{
addr = base_addrs[level]->id;
if (offset_check(addrs[addr].pid, addrs[addr].id, base_off[level]))
{
*id = addrs[addr].id + base_off[level];
*pid = addrs[addr].pid;
base_addrs[level] = base_addrs[level]->next;
return 1;
}
}
return 0;
}
void
var_resolve_set(var_ptr def, int proc)
{
int i, id, pid, ptr, addr;
base = def;
base_done = 0;
base_level = def->level;
base_id = def->id;
if ((def->code == LIF_GDEF) || (def->code == LIF_GREF))
base_pid = 0;
else
base_pid = proc;
base_ptr = base_pid ? procs[proc].locals[base_id].ptr_id : globals[base_id].ptr_id;
base_addrs[0] = ptr_points_to(base_ptr);
for (i = 1; i < base_level; i++)
{
if (base_addrs[i - 1] != NULL)
{
addr = base_addrs[i - 1]->id;
pid = addrs[addr].pid;
id = addrs[addr].id;
ptr = pid ? procs[pid].locals[id].ptr_id : globals[id].ptr_id;
if (ptr)
base_addrs[i] = ptr_points_to(ptr);
else
base_addrs[i] = NULL;
}
else
base_addrs[i] = NULL;
}
}
void
print_base_state(void)
{
int i;
set_ptr objs;
printf("resolve %s at level %d\n",
base_pid ? procs[base_pid].locals[base_id].name : globals[base_id].name,
base_level);
for (i = 0; i < base_level; i++)
{
if (base_addrs[i])
{
printf("level %d is:", i);
objs = base_addrs[i];
while (objs)
{
printf(" %d", objs->id);
objs = objs->next;
}
printf("\n");
}
}
}
/********************************************************************/
/* */
/* var_resolve_get does a depth first traversal of the pointer state*/
/* */
/********************************************************************/
int
var_resolve_get(int *id, int *pid)
{
int top;
int ptr, addr;
set_ptr objs;
top = base_level - 1;
objs = base_addrs[top];
while ((!objs) && (top >= 0))
{
/* top--; */
if (base_addrs[top])
{
base_addrs[top] = base_addrs[top]->next;
objs = base_addrs[top];
if (objs)
while (((top < (base_level - 1)) && (top >= 0)))
{
if (base_addrs[top])
{
int id, pid; /* D E C L */
addr = base_addrs[top]->id;
top++;
pid = addrs[addr].pid;
id = addrs[addr].id;
ptr = pid ? procs[pid].locals[id].ptr_id : globals[id].ptr_id;
if (ptr)
base_addrs[top] = ptr_points_to(ptr);
else
{
top--;
base_addrs[top] = base_addrs[top]->next;
}
}
else
{
top--;
}
}
}
else
top--;
if (top == (base_level - 1))
objs = base_addrs[top];
else
objs = NULL;
}
if (objs)
{
base_addrs[top] = base_addrs[top]->next;
addr = objs->id;
if ((addr > 0) && (addr <= n_addrs))
{
*id = addrs[addr].id;
*pid = addrs[addr].pid;
return 1;
}
}
return 0;
}
void
chain_resolve_path(int f, int n, int proc)
{
int i, id, pid, addr;
if (base_level < 2)
return;
for (i = 0; i < (base_level - 1); i++)
if (base_addrs[i])
{
addr = base_addrs[i]->id;
if (offset_check(addrs[addr].pid, addrs[addr].id, base_off[i]))
{
id = addrs[addr].id + base_off[i];
pid = addrs[addr].pid;
if ((pid == 0) || (pid == proc))
{
bit_on(
pid ? files[f].stmts[n].active_local : files[f].stmts[n].active_global, id);
}
else
add_to_id_set(&files[f].stmts[n].active_other, pid, id);
}
}
}
void
var_resolve_path(int f, int n, int proc)
{
int i, id, pid, addr;
if (base_level < 2)
return;
for (i = 0; i < (base_level - 1); i++)
if (base_addrs[i])
{
addr = base_addrs[i]->id;
id = addrs[addr].id;
pid = addrs[addr].pid;
if ((pid == 0) || (pid == proc))
{
bit_on(pid ? files[f].stmts[n].active_local : files[f].stmts[n].active_global, id);
}
else
add_to_id_set(&files[f].stmts[n].active_other, pid, id);
}
}
int
is_other_active(id_set_ptr set, int pid, int id)
{
while (set)
{
if ((set->id == id) && (set->pid == pid))
return 1;
set = set->next;
}
return 0;
}
int
active_defed(int f, int n, int succ, int proc)
{
int match = 0;
if (!files[f].stmts[n].defs)
return 0;
if (files[f].stmts[n].defs->level == 0)
{
switch (files[f].stmts[n].defs->code)
{
case LIF_DEF:
if (is_bit_on(files[f].stmts[succ].active_local, files[f].stmts[n].defs->id))
{
return 1;
}
break;
case LIF_GDEF:
if (is_bit_on(files[f].stmts[succ].active_global, files[f].stmts[n].defs->id))
{
return 1;
}
break;
case LIF_CDEF:
{
int id, pid;
if (v_opt)
printf("\ndef to chain %d\n", files[f].stmts[n].defs->id);
chain_resolve_set(files[f].stmts[n].defs->id, proc);
while (chain_resolve_get(&id, &pid))
{
if (v_opt)
printf("chain resolves to: %s\n",
pid ? procs[pid].locals[id].name : globals[id].name);
if (!pid || (pid == proc))
{
if (is_bit_on(pid ? files[f].stmts[succ].active_local
: files[f].stmts[succ].active_global,
id))
{
match = 1;
chain_resolve_path(f, n, proc);
}
}
else
{
if (is_other_active(files[f].stmts[succ].active_other, pid, id))
{
match += add_to_id_set(&files[f].stmts[n].active_other, pid, id);
chain_resolve_path(f, n, proc);
}
}
}
if (match)
{
id = chains[files[f].stmts[n].defs->id].id;
pid = chains[files[f].stmts[n].defs->id].pid;
if (pid == 0)
bit_on(files[f].stmts[n].active_global, id);
else if (pid == proc)
bit_on(files[f].stmts[n].active_local, id);
}
else
{
if (is_other_active(files[f].stmts[succ].active_other, pid, id))
{
match += add_to_id_set(&files[f].stmts[n].active_other, pid, id);
return match;
}
}
}
break;
default:;
}
}
else
{
int id, pid;
if (v_opt)
print_base_state();
var_resolve_set(files[f].stmts[n].defs, proc);
while (var_resolve_get(&id, &pid))
{
/*
printf ("resolves to: %s\n",pid?
procs[proc].locals[id].name: globals[id].name);
*/
if ((pid == 0) || (pid == proc))
{
if (is_bit_on(pid ? files[f].stmts[succ].active_local
: files[f].stmts[succ].active_global,
id))
{
var_resolve_path(f, n, proc);
match = 1;
}
}
else
{
if (is_other_active(files[f].stmts[succ].active_other, pid, id))
{
match += add_to_id_set(&files[f].stmts[n].active_other, pid, id);
return match;
}
}
}
if (match)
if (files[f].stmts[n].defs->code == LIF_GDEF)
bit_on(files[f].stmts[n].active_global, files[f].stmts[n].defs->id);
else if (files[f].stmts[n].defs->code == LIF_DEF)
bit_on(files[f].stmts[n].active_local, files[f].stmts[n].defs->id);
}
return match;
}
void
add_to_active(int f, int n, int pid, int id, int proc_id)
{
bit_set active;
is_id_valid(pid, id);
if (v_opt)
printf("add %s to active %d (L %d) of %s\n",
var_name(pid, id),
n,
files[f].stmts[n].froml,
procs[proc_id].proc_name);
if (proc_id == pid)
active = files[f].stmts[n].active_local;
else if (pid)
{
add_to_id_set(&files[f].stmts[n].active_other, pid, id);
return;
}
else
active = files[f].stmts[n].active_global;
bit_on(active, id);
}
void
de_ref_chain(int f, int pid, var_ptr refs, int n)
{
int id, proc_id;
stmt_ptr stmt;
int chain_id;
stmt = &files[f].stmts[n];
chain_resolve_set(refs->id, pid);
chain_id = refs->id;
add_to_active(f, n, pid, chains[chain_id].id, chains[chain_id].pid);
while (chain_resolve_get(&id, &proc_id))
{
if (v_opt)
printf("chain resolve to %d %d %s \n", id, proc_id, var_name(proc_id, id));
if (v_opt)
fflush(stdout);
chain_resolve_path(f, n, pid);
add_to_active(f, n, proc_id, id, pid);
}
}
void
de_ref_ref(int f, int pid, var_ptr refs, int n)
{
int id, proc_id;
stmt_ptr stmt;
stmt = &files[f].stmts[n];
if (v_opt)
printf("de ref %s %s in %s at %d\n",
refs->code == LIF_REF ? "local" : (refs->code == LIF_GREF ? "global" : "???"),
refs->code == LIF_REF ? procs[pid].locals[refs->id].name
: (refs->code == LIF_GREF ? globals[refs->id].name : "???"),
procs[pid].proc_name,
stmt->froml);
if (v_opt)
fflush(stdout);
var_resolve_set(refs, pid);
while (var_resolve_get(&id, &proc_id))
{
if (v_opt)
printf("resolve to %d %d %s \n", id, proc_id, var_name(proc_id, id));
fflush(stdout);
var_resolve_path(f, n, pid);
add_to_active(f, n, proc_id, id, pid);
}
}
int
add_stmt_to_slice(int pid, int f, int stmt, bit_set slice, stmt_ptr succ)
{
int already_in_slice = 0;
int change = 0;
id_set_ptr others;
int at;
var_ptr refs;
set_ptr control;
if (v_opt)
printf("add stmt %d to slice ", stmt);
if (is_bit_on(slice, stmt))
already_in_slice = 1;
else
bit_on(slice, stmt);
if (already_in_slice)
if (v_opt)
printf("already in ");
if (v_opt)
printf("\n");
if (!already_in_slice)
{
refs = files[f].stmts[stmt].refs;
while (refs)
{
switch (refs->code)
{
case LIF_REF:
bit_on(files[f].stmts[stmt].active_local, refs->id);
if (refs->level != 0)
de_ref_ref(f, pid, refs, stmt);
break;
case LIF_GREF:
bit_on(files[f].stmts[stmt].active_global, refs->id);
if (refs->level != 0)
de_ref_ref(f, pid, refs, stmt);
break;
case LIF_CREF:
de_ref_chain(f, pid, refs, stmt);
break;
default:;
}
refs = refs->next;
}
control = files[f].stmts[stmt].requires;
while (control)
{
if (!is_bit_on(slice, control->id))
{
add_stmt_to_slice(pid, f, control->id, slice, (stmt_ptr)NULL);
if (v_opt)
printf("add %d required by %d\n", control->id, stmt);
}
control = control->next;
}
}
if (succ)
{
at = -1;
while ((at = get_next_member(succ->active_local, at)) >= 0)
{
if (!is_var_defed(&files[f].stmts[stmt], at, 1))
{
if (!is_bit_on(files[f].stmts[stmt].active_local, at))
{
bit_on(files[f].stmts[stmt].active_local, at);
change += 1;
}
}
}
at = -1;
while ((at = get_next_member(succ->active_global, at)) >= 0)
{
if (!is_var_defed(&files[f].stmts[stmt], at, 0))
{
if (!is_bit_on(files[f].stmts[stmt].active_global, at))
{
bit_on(files[f].stmts[stmt].active_global, at);
change += 1;
}
}
}
others = succ->active_other;
while (others)
{
change += add_to_id_set(&files[f].stmts[stmt].active_other, others->pid, others->id);
others = others->next;
}
}
return change + 1 - already_in_slice;
}
int
pass_criteria(int f, int stmt, int succ)
{
int change, c;
id_set_ptr active;
change = 0;
if (!bit_set_equal(files[f].stmts[stmt].active_global, files[f].stmts[succ].active_global))
{
change =
cunion_bit_set(files[f].stmts[stmt].active_global, files[f].stmts[succ].active_global);
}
if (!bit_set_equal(files[f].stmts[stmt].active_local, files[f].stmts[succ].active_local))
{
c = cunion_bit_set(files[f].stmts[stmt].active_local, files[f].stmts[succ].active_local);
change += c;
}
active = files[f].stmts[succ].active_other;
while (active)
{
change += add_to_id_set(&files[f].stmts[stmt].active_other, active->pid, active->id);
active = active->next;
}
return change;
}
#define LINE 60
void
print_active_stmt(int f, int proc, int stmt, int mark)
{
stmt_ptr s;
int k, var, n;
char buff[100];
id_set_ptr active;
s = &files[f].stmts[stmt];
var = -1;