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 pathtree.cc
1152 lines (926 loc) · 28.6 KB
/
tree.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
*****************************************************************************/
#define TREE_C
#include <stdio.h>
#include <stdlib.h>
//#if !defined(THINK_C) && !defined(__MWERKS__)
//#include <varargs.h>
//#endif // THINK_C
#include <stdarg.h>
#include <string.h>
#include "vtypes.h"
#include "tree.h"
//#ifndef __GNUC__
#include "obstack.h"
//#else
//#include <obstack.h>
//#endif
#include "decl.h"
#include "glue.h"
#include "scope.h"
#include "veriwell.h"
#include "timescal.h"
#if VDEBUG != 0
#include "flags.h"
#endif
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
tree resolve_hierarchical_name(tree);
//extern void * xmalloc ();
/* Tree nodes of permanent duration are allocated in this obstack.
They are the identifier nodes, declaration nodes, and
block nodes. */
struct obstack permanent_obstack;
/* Each module has its own stack for its statements so that they
can be deallocated on a per-module basis after its code has been
generated. These are initialized dynamically. */
struct obstack *module_obstack;
/* Scaffolding (information needed between phases) are put in the linkage
stack. */
struct obstack linkage_obstack;
/* Low-level code that is generated from syntax trees is put on the
code stack. */
struct obstack code_obstack;
/* Expressions are put on the temporary stack while they are being
processed. They are copied to the permanent stack after being
folded and converted, where necessary. */
struct obstack temporary_obstack;
/* This usually points to permanent obstack. */
struct obstack *saveable_obstack;
/* This points at either permanent_obstack or temporary_obstack. */
struct obstack *current_obstack;
/* This points to either permanent, temporary, or momentary obstack. */
struct obstack *expression_obstack;
/* Addresses of first objects in some obstacks.
This is for freeing their entire contents. */
char *temporary_firstobj;
/* Table indexed by tree code giving a string containing a character
classifying the tree code. Possibilities are
d, s, c, r and e. See tree.def for details. */
#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
char *tree_code_type[] = {
#include "tree.def"
};
#undef DEFTREECODE
/* Table indexed by tree code giving number of expression
operands beyond the fixed part of the node structure.
Not used for types or decls. */
#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
int tree_code_length[] = {
#include "tree.def"
};
#undef DEFTREECODE
#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) NAME,
char *tree_code_name[] = {
#include "tree.def"
};
#undef DEFTREECODE
/* Hash table for uniquizing IDENTIFIER_NODEs by name. */
#define MAX_HASH_TABLE 1009
static tree hash_table[MAX_HASH_TABLE]; /* id hash buckets */
/* 0 while creating built-in identifiers. */
static int do_identifier_warnings;
/* Used to pass lsb and msb expression pointers during parsing. */
tree range_handle;
/* Points to the toplevel of the tree */
tree top_level = NULL_TREE;
/* List of continuous assignments */
tree continuous_assignments = NULL_TREE;
/* Init data for node creation, at the beginning of compilation. */
tree build_decl(enum tree_code code, tree name, enum tree_type type);
void init_tree()
{
obstack_init(&permanent_obstack);
obstack_init(&linkage_obstack);
obstack_init(&temporary_obstack);
temporary_firstobj = (char *) obstack_alloc(&temporary_obstack, 0);
current_obstack = &permanent_obstack;
// expression_obstack = &momentary_obstack;
expression_obstack = &permanent_obstack;
range_handle = make_node(RANGE_HANDLE);
integer_zero_node = build_int_cst((unsigned_32_t) 0);
integer_one_node = build_int_cst((unsigned_32_t) 1);
error_mark_node = make_node(ERROR_MARK);
TREE_NBITS(error_mark_node) = 0;
}
/* Allocate SIZE bytes in the current obstack
and return a pointer to them.
In practice the current obstack is always the temporary one. */
char *oballoc(long size)
{
return (char *) obstack_alloc(current_obstack, size);
}
/* Free the object PTR in the current obstack
as well as everything allocated since PTR.
In practice the current obstack is always the temporary one. */
void obfree(char *ptr)
{
obstack_free(current_obstack, ptr);
}
/* Allocate SIZE bytes in the permanent obstack
and return a pointer to them. */
char *permalloc(long size)
{
char *tmp = (char *) obstack_alloc(&permanent_obstack, size);
return tmp;
}
/* Allocate SIZE bytes in the linkage obstack
and return a pointer to them. */
char *linkalloc(long size)
{
return (char *) obstack_alloc(&linkage_obstack, size);
}
/* clear everything out of the temporary obstack */
void clear_temporary()
{
obstack_free(&temporary_obstack, temporary_firstobj);
}
tree build_int_cst(signed_32_t i)
{
tree t = make_node(INTEGER_CST);
// INT_CST_HIGH (t) = HIGH_INT (i);
// INT_CST_LOW (t) = LOW_INT (i);
INT_CST_DATA(t) = i;
TREE_CONSTANT_ATTR(t) = 1;
TREE_INTEGER_ATTR(t) = 1;
TREE_NBITS(t) = 32;
return t;
}
tree build_real_cst(char *real_string)
{
tree t = make_node(REAL_CST);
REAL_CST_DATA(t) = atof(real_string);
TREE_CONSTANT_ATTR(t) = 1;
TREE_REAL_ATTR(t) = 1;
TREE_NBITS(t) = 32;
return t;
}
void switch_to_linkage_obstack()
{
current_obstack = &linkage_obstack;
}
void switch_to_permanent_obstack()
{
current_obstack = &permanent_obstack;
}
/* Return a newly allocated node of code CODE.
Initialize the node's unique id and its TREE_PERMANENT flag.
For decl and type nodes, some other fields are initialized.
The rest of the node is initialized to zero.
Achoo! I got a code in the node. */
int num_nodes = 0;
int num_nodes_g = 0;
int num_nodes_e = 0;
int num_nodes_b = 0;
int num_nodes_s = 0;
int num_nodes_r = 0;
int num_nodes_c = 0;
int num_nodes_d = 0;
int num_nodes_x = 0;
tree make_node(enum tree_code code)
{
register tree t;
register int type = *tree_code_type[(int) code];
register int length;
register struct obstack *obstack = current_obstack;
num_nodes++;
//HEAPTEST ("Heap corrupted (in make_node)");
switch (type) {
case 'b': /* A block node */
num_nodes_b++;
length = sizeof(struct tree_block_common)
+ tree_code_length[(int) code] * sizeof(char *);
obstack = &permanent_obstack;
break;
case 'd': /* A decl node */
num_nodes_d++;
length = sizeof(struct tree_decl_common)
+ tree_code_length[(int) code] * sizeof(char *);
obstack = &permanent_obstack;
break;
case 'g': /* a gate node */
num_nodes_g++;
length = sizeof(struct tree_gate_instance)
+ (tree_code_length[(int) code]) * sizeof(char *);
/* All gates are put where we can preserve them if nec. */
if (obstack != &permanent_obstack)
obstack = module_obstack;
break;
case 's': /* a stmt node */
num_nodes_s++;
length = sizeof(struct tree_stmt)
+ (tree_code_length[(int) code] - 1) * sizeof(char *);
/* All stmts are put where we can preserve them if nec. */
if (obstack != &permanent_obstack)
obstack = module_obstack;
break;
case 'r': /* a reference */
num_nodes_r++;
goto e;
case 'e': /* an expression */
num_nodes_e++;
e:
obstack = expression_obstack;
length = sizeof(struct tree_exp)
+ (tree_code_length[(int) code] - 1) * sizeof(char *);
break;
case 'c': /* a constant */
num_nodes_c++;
obstack = expression_obstack;
goto x;
case 'x': /* something random, like an identifier. */
num_nodes_x++;
x:length = sizeof(struct tree_common)
+ tree_code_length[(int) code] * sizeof(char *);
/* Identifier nodes are always permanent since they are
unique in a compiler run. */
if (code == IDENTIFIER_NODE)
obstack = &permanent_obstack;
}
//HEAPTEST ("In make_node, before alloc");
t = (tree) obstack_alloc(obstack, length);
memset(t, 0, length);
TREE_SET_TYPE(t, 0);
TREE_CHAIN(t) = 0;
TREE_SET_CODE(t, code);
TREE_LABEL(t) = 0;
TREE_SUB_LABEL(t) = 0;
if (type == 's' || type == 'd' || type == 'b') {
STMT_SOURCE_LINE(t) = (type == 's'
|| type == 'b') ? stmt_lineno : lineno;
#if VDEBUG != 0
if (vdebug)
printf_V("Line %d\n", STMT_SOURCE_LINE(t));
#endif
STMT_SOURCE_FILE(t) = input_filename;
if (type == 'd')
DECL_EVENT_NOCAST(t) = NULL;
else if (type == 's')
STMT_SCOPE(t) = current_scope;
}
if (code == REAL_DECL)
TREE_REAL_ATTR(t) = 1;
#if VDEBUG != 0
if (vdebug) {
extern unsigned long mem;
unsigned long mem_left = mem_avail();
printf_V("Made node '%s', at %p, size %d\n", tree_code_name[code],
t, length);
printf_V("Memory used: %lu\n", mem - mem_left);
printf_V("Memory left: %lu\n", mem_left);
}
#endif
//HEAPTEST ("Heap corrupted (make_node)");
return t;
}
/* Return a new node with the same contents as NODE
except that its TREE_CHAIN is zero and it has a fresh uid. */
tree copy_node(tree node)
{
register tree t;
register enum tree_code code = TREE_CODE(node);
register int length;
HEAPTEST("In copy_node");
switch (*tree_code_type[(int) code]) {
case 'b': /* A block node */
length = sizeof(struct tree_block_common)
+ tree_code_length[(int) code] * sizeof(char *);
break;
case 'd': /* A decl node */
length = sizeof(struct tree_decl_common)
+ tree_code_length[(int) code] * sizeof(char *);
break;
case 's': /* a stmt node */
length = sizeof(struct tree_stmt)
+ (tree_code_length[(int) code] - 1) * sizeof(char *);
break;
case 'g': /* a gate node */
length = sizeof(struct tree_gate_instance)
+ (tree_code_length[(int) code]) * sizeof(char *);
break;
case 'r': /* a reference */
case 'e': /* an expression */
length = sizeof(struct tree_exp)
+ (tree_code_length[(int) code] - 1) * sizeof(char *);
break;
case 'c': /* a constant */
case 'x': /* something random, like an identifier. */
length = sizeof(struct tree_common)
+ tree_code_length[(int) code] * sizeof(char *);
}
HEAPTEST("In copy_node, before alloc");
//printf ("next free = %p, limit = %p\n", current_obstack->next_free, current_obstack->chunk_limit);
//printf ("length is %d\n", length);
// t = (tree) obstack_alloc (current_obstack, length);
t = (tree) obstack_copy(current_obstack, node, length);
HEAPTEST("In copy_node, after alloc");
//printf ("Allocated node %p, length %d\n", t, length);
//printf ("alignment %d, base %p, limit %p\n",
//current_obstack->alignment_mask, current_obstack->object_base, current_obstack->chunk_limit);
// for (i = ((length + sizeof (int) - 1) / sizeof (int)) - 1;
// i >= 0;
// i--)
// ((int *) t)[i] = ((int *) node)[i];
HEAPTEST("In copy_node, after alloc and init");
TREE_CHAIN(t) = 0;
return t;
}
#define HASHBITS 30
/* Return an IDENTIFIER_NODE whose name is TEXT (a null-terminated string).
If an identifier with that name has previously been referred to,
the same node is returned this time. */
tree get_identifier(char *text)
{
register unsigned hi;
register int i;
register tree idp;
register int len, hash_len;
/* Compute length of text in len. */
for (len = 0; text[len]; len++);
/* Decide how much of that length to hash on */
hash_len = len;
/* if (warn_id_clash && len > id_clash_len)
* hash_len = id_clash_len;
*/
/* Compute hash code */
hi = hash_len;
for (i = 0; i < hash_len; i++)
hi = ((hi * 613) + (unsigned) (text[i]));
hi &= (1 << HASHBITS) - 1;
hi %= MAX_HASH_TABLE;
/* Search table for identifier */
for (idp = hash_table[hi]; idp; idp = TREE_CHAIN(idp))
if (IDENTIFIER_LENGTH(idp) == len
&& !strcmp(IDENTIFIER_POINTER(idp), text))
return idp; /* <-- return if found */
/* Not found; optionally warn about a similar identifier */
/*
if (warn_id_clash && do_identifier_warnings && len >= id_clash_len)
for (idp = hash_table[hi]; idp; idp = TREE_CHAIN (idp))
if (!strncmp (IDENTIFIER_POINTER (idp), text, id_clash_len))
{
warning ("`%s' and `%s' identical in first n characters",
IDENTIFIER_POINTER (idp), text);
break;
}
*/
/* Not found, create one, add to chain */
idp = make_node(IDENTIFIER_NODE);
IDENTIFIER_LENGTH(idp) = len;
IDENTIFIER_POINTER(idp) =
(char *) obstack_copy0(&permanent_obstack, text, len);
TREE_CHAIN(idp) = hash_table[hi];
hash_table[hi] = idp;
TREE_NBITS(idp) = 32; /* A default number for hierarchical names */
return idp; /* <-- return if created */
}
/* Enable warnings on similar identifiers (if requested).
Done after the built-in identifiers are created. */
void start_identifier_warnings()
{
do_identifier_warnings = 1;
}
/* Return a node that points to a bit constant. */
tree build_bit_cst(nbits_t length, enum radii radix)
{
register tree t = make_node(BIT_CST);
Group *g =
(Group *) permalloc((bits_to_groups(length) + 1) * sizeof(Group));
BIT_CST_GROUP(t) = g;
BIT_CST_NBITS(t) = length;
BIT_CST_SET_RADIX(t, radix);
TREE_TYPE(t) = REG_TYPE;
TREE_CONSTANT_ATTR(t) = 1;
TREE_NBITS(t) = length; /* default to this; this may be changed at pass 2 */
return t;
}
/* Return a newly constructed STRING_CST node whose value is
the LEN characters at STR.
The TREE_TYPE is not initialized. */
tree build_string(int len, char *str)
{
register tree s = make_node(STRING_CST);
TREE_STRING_LENGTH(s) = len;
TREE_STRING_POINTER(s) =
(char *) obstack_copy0(current_obstack, str, len);
return s;
}
/* Return the length of a chain of nodes chained through TREE_CHAIN.
We expect a null pointer to mark the end of the chain.
This is the Lisp primitive `length'. */
int list_length(tree t)
{
register tree tail;
register int len = 0;
for (tail = t; tail; tail = TREE_CHAIN(tail))
len++;
return len;
}
/* Concatenate two chains of nodes (chained through TREE_CHAIN)
by modifying the last node in chain 1 to point to chain 2.
This is the Lisp primitive `nconc'. */
tree chainon(tree op1, tree op2)
{
tree t;
if (op1) {
for (t = op1; TREE_CHAIN(t); t = TREE_CHAIN(t))
if (t == op2) {
printf("Fatal: Circularity during compilation\n");
// printf ("%lu\n", coreleft ());
shell_abort(); /* Circularity being created */
}
TREE_CHAIN(t) = op2;
return op1;
} else
return op2;
}
/* Return a newly created TREE_LIST node whose
purpose and value fields are PARM and VALUE. */
tree build_tree_list(tree parm, tree value)
{
register tree t = make_node(TREE_LIST);
TREE_PURPOSE(t) = parm;
TREE_VALUE(t) = value;
TREE_3RD(t) = NULL_TREE;
return t;
}
/* Return a newly created TREE_LIST node whose
purpose and value fields are PARM and VALUE
and whose TREE_CHAIN is CHAIN. */
tree tree_cons(tree purpose, tree value, tree chain)
{
register tree node = make_node(TREE_LIST);
TREE_CHAIN(node) = chain;
TREE_PURPOSE(node) = purpose;
TREE_VALUE(node) = value;
TREE_3RD(node) = NULL_TREE;
return node;
}
/* Same as `tree_cons' but make a permanent object. */
tree perm_tree_cons(tree purpose, tree value, tree chain)
{
register tree node;
register struct obstack *ambient_obstack = current_obstack;
current_obstack = &permanent_obstack;
node = make_node(TREE_LIST);
TREE_CHAIN(node) = chain;
TREE_PURPOSE(node) = purpose;
TREE_VALUE(node) = value;
TREE_3RD(node) = NULL_TREE;
current_obstack = ambient_obstack;
return node;
}
tree free_link = NULL_TREE;
/* Same as `tree_cons' but make a linkage object. */
tree link_tree_cons(tree purpose, tree value, tree chain)
{
register tree node;
register struct obstack *ambient_obstack = current_obstack;
current_obstack = &permanent_obstack;
if (!free_link)
node = make_node(TREE_LIST);
else {
node = free_link;
free_link = TREE_CHAIN(free_link);
}
TREE_CHAIN(node) = chain;
TREE_PURPOSE(node) = purpose;
TREE_VALUE(node) = value;
TREE_3RD(node) = NULL_TREE;
current_obstack = ambient_obstack;
return node;
}
void free_link_list(tree node)
{
TREE_CHAIN(node) = free_link;
free_link = node;
}
/* Reverse the order of elements in the chain T,
and return the new head of the chain (old last element). */
tree nreverse(tree t)
{
register tree prev = 0, decl, next;
for (decl = t; decl; decl = next) {
next = TREE_CHAIN(decl);
TREE_CHAIN(decl) = prev;
prev = decl;
}
return prev;
}
void set_all_list_values(tree list, tree value)
{
tree t;
for (t = list; t; t = TREE_CHAIN(t))
TREE_VALUE(t) = value;
}
/* Return non-zero if node is a vector net or scalar net */
int is_net_code(enum tree_code code)
{
/* Return nonzero if node is a net or a reference to a net or any entry
of a concat is a net. */
if (code == NET_VECTOR_DECL || code == NET_SCALAR_DECL)
return 1;
else
return 0;
}
int is_all_net(tree node)
{
enum tree_code code = TREE_CODE(node);
tree t;
if (code == BIT_REF)
code = TREE_CODE(BIT_REF_DECL(node));
else if (code == PART_REF)
code = TREE_CODE(PART_DECL(node));
if (is_net_code(code))
return 1;
if (code == CONCAT_REF) {
for (t = CONCAT_LIST(node); t; t = TREE_CHAIN(t))
if (!is_all_net(TREE_EXPR(t)))
return 0;
return 1;
}
return 0;
}
/* Return nonzero if REF is a reference to an array */
int is_array(tree ref)
{
if (ref)
return (TREE_CODE(ref) == ARRAY_REF);
else
return 0;
}
/* Return nonzero if REF is a string */
int is_string(tree ref)
{
if (ref)
if (TREE_CODE(ref) == BIT_CST)
return (BIT_CST_RADIX(ref) == STRING_);
return 0;
}
/* Return non-zero if pure decl (used for $dumpvar, currently) as well
as the actual decl node. */
int is_var(tree node, tree * decl)
{
enum tree_code code = TREE_CODE(node);
/* Hierarchical name; get decl node then check again */
if (code == IDENTIFIER_NODE && HIERARCHICAL_ATTR(node)) {
*decl = resolve_hierarchical_name(node);
return is_var(*decl, decl);
}
/* Must be a DECL and not array nor parameter (for dumpvars) */
if (*tree_code_type[code] == 'd')
if (code != ARRAY_DECL && code != PARAM_DECL && code != BLOCK_DECL) {
*decl = node;
return 1;
}
return 0;
}
/* Return nonzero if var or hierarchical ref is a block as well as actual
BLOCK node. */
int is_block(tree node, tree * scope)
{
enum tree_code code = TREE_CODE(node);
/* Hierarchical scope, get actual BLOCK node */
if (code == IDENTIFIER_NODE && HIERARCHICAL_ATTR(node)) {
*scope = search_scope(IDENT(node), 0);
return is_block(*scope, scope);
}
/* This could be either a pointer to a block (if called recursively)... */
if (*tree_code_type[code] == 'b') {
*scope = node;
return 1;
}
/* ...or a pointer to a BLOCK_DECL */
else if (code == BLOCK_DECL) {
*scope = DECL_CONTEXT(node);
return 1;
}
return 0;
}
/* return non-zero if node is a legal procedural lvalue. */
int is_proc_lval(tree node)
{
enum tree_code code = TREE_CODE(node);
if (*tree_code_type[code] == 'c' || *tree_code_type[code] == 'e')
return 0;
if (is_all_net(node))
return 0;
if (code == FUNCTION_REF)
return 0;
return 1;
}
/* Return name of identifier, be it hierarchical or otherwise */
char *ident_name(tree node)
{
enum tree_code code = TREE_CODE(node);
if (code == IDENTIFIER_NODE)
return IDENT(node);
else
return IDENT(DECL_NAME(node));
}
/* Given an lval, check if it is a "SHADOW_LVAL_REF". If so, return the
lval that it is shadowing (a hierarchical reference). */
tree the_lval(tree lval_arg)
{
tree lval;
if (TREE_CODE(lval_arg) != SHADOW_LVAL_REF)
return lval_arg;
lval = TREE_CHAIN(lval_arg); /* This points to the actual decl */
return lval;
}
/* Return the string of the type, suitable for printing */
char *decl_type(tree node)
{
enum tree_code code = TREE_CODE(node);
switch (code) {
case EVENT_DECL:
return "event";
case INTEGER_DECL:
return "integer";
case REG_SCALAR_DECL:
return "reg";
case REG_VECTOR_DECL:
return "reg";
case TIME_DECL:
return "time";
case REAL_DECL:
return "real";
case NET_SCALAR_DECL:
case NET_VECTOR_DECL:
switch (TREE_TYPE(node)) {
case NET_WIRE_TYPE:
return "wire";
case NET_TRI_TYPE:
return "tri";
case NET_WAND_TYPE:
return "wand";
case NET_TRIAND_TYPE:
return "triand";
case NET_WOR_TYPE:
return "wor";
case NET_TRIOR_TYPE:
return "trior";
case NET_TRI0_TYPE:
return "tri0";
case NET_TRI1_TYPE:
return "tri1";
case NET_SUPPLY0_TYPE:
return "supply0";
case NET_SUPPLY1_TYPE:
return "supply1";
}
}
return "";
}
/* Low-level constructors for expressions. */
/* Build an expression of code CODE, data type TYPE,
and operands as specified by the arguments ARG1 and following arguments.
Expressions and reference nodes can be created this way.
Constants, decls, types and misc nodes cannot be. */
tree build(enum tree_code code, enum tree_type type, ...)
{
/*register */ va_list p;
register tree t;
register int length;
register int i;
va_start(p, type);
// code = va_arg (p, enum tree_code);
t = make_node(code);
length = tree_code_length[(int) code];
TREE_TYPE(t) = type;
// TREE_TYPE (t) = va_arg (p, enum tree_type);
if (length == 2) {
/* This is equivalent to the loop below, but faster. */
register tree arg0 = va_arg(p, tree);
register tree arg1 = va_arg(p, tree);
TREE_OPERAND(t, 0) = arg0;
TREE_OPERAND(t, 1) = arg1;
} else {
for (i = 0; i < length; i++) {
register tree operand = va_arg(p, tree);
TREE_OPERAND(t, i) = operand;
}
}
va_end(p);
return t;
}
/* Similar except don't specify the TREE_TYPE
and leave the TREE_VOLATILE as 0.
It is permissible for arguments to be null,
or even garbage if their values do not matter. */
tree build_nt(enum tree_code code, ...)
{
/*register */ va_list p;
register tree t;
register int length;
register int i;
va_start(p, code);
t = make_node(code);
length = tree_code_length[(int) code];
for (i = 0; i < length; i++)
TREE_OPERAND(t, i) = va_arg(p, tree);
va_end(p);
return t;
}
/* Create a DECL_... node of code CODE, name NAME and data type TYPE.
We do NOT enter this node in any sort of symbol table.
layout_decl is used to set up the decl's storage layout.
Other slots are initialized to 0 or null pointers. */
tree build_decl(enum tree_code code, tree name, enum tree_type type)
{
register tree t;
t = make_node(code);
/* if (type == error_mark_node)
type = integer_type_node; */
/* That is not done, deliberately, so that having error_mark_node
as the type can suppress useless errors in the use of this variable. */
DECL_NAME(t) = name;
TREE_TYPE(t) = type;
return t;
}
/* Build an array node */
tree build_array(tree ident, tree decl, tree lobounds, tree hibounds)
{
tree node = make_node(ARRAY_DECL);
// ARRAY_DECL (node) = decl;
ARRAY_CODE(node) = TREE_CODE(decl);
ARRAY_HI_EXPR(node) = hibounds;
ARRAY_LO_EXPR(node) = lobounds;
DECL_NAME(node) = ident;
DECL_MSB(node) = DECL_MSB(decl);
DECL_LSB(node) = DECL_LSB(decl);
if (TREE_CODE(decl) == INTEGER_DECL)
TREE_INTEGER_ATTR(node) = 1;
if (TREE_CODE(decl) == REAL_DECL)
TREE_REAL_ATTR(node) = 1;
return node;
}
/* Build a module block */
tree build_module(tree ident)
{
tree tmp = make_node(MODULE_BLOCK);
#if VDEBUG != 0
if (vdebug)
printf_error_V("Building module %s\n", IDENTIFIER_POINTER(ident));
#endif
BLOCK_NAME(tmp) = ident;
MODULE_NAME(tmp) = IDENTIFIER_POINTER(ident);
BLOCK_UP(tmp) = BLOCK_DECL(tmp) = BLOCK_PORTS(tmp) = NULL_TREE;
BLOCK_DOWN(tmp) = BLOCK_ARGS(tmp) = NULL_TREE;
MODULE_DEFPARAMS(tmp) = NULL_TREE;
MODULE_SPECDEFS(tmp) = NULL_TREE;
MODULE_SPECINST(tmp) = NULL_TREE;
/* Module names have their own namespace, so the following remains comment out */
/* IDENT_CURRENT_DECL (ident) = tmp; *//* make ident point to mod */
set_decl(ident, tmp);
module_timescale(tmp);
return tmp;
}
/* Clean up at end of module parse */
void end_module(tree node)
{
tree t, t1, t2;
char *name;