declreps.c
3.15 KB
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
/*====================================================================
* declreps.c
*
* Copyright 1993, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
* Inc.; the contents of this file may not be disclosed to third
* parties, copied or duplicated in any form, in whole or in part,
* without the prior written permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights
* in Technical Data and Computer Software clause at DFARS
* 252.227-7013, and/or in similar or successor clauses in the FAR,
* DOD or NASA FAR Supplement. Unpublished - rights reserved under the
* Copyright Laws of the United States.
*====================================================================*/
#include <assert.h>
#include "ic.h"
#include "y.tab.h"
List *objectList = 0;
int objectID = 0;
void declInit()
{
objectList = calloc(1,sizeof(List));
assert(objectList);
listNew(objectList);
makebankfiledecl();
}
int declSize(Decl *d)
{
return (d->size + 7) & ~7;
}
void declPrint(Decl *d)
{
printf("\tId:\t\t%d\n", d->id);
printf("\tOffset:\t\t0x%x\n",d->offset);
printf("\tSize:\t\t%d\n", d->size);
printf("\tClass:\t\t%d\n",d->declclass);
}
/* Allocate a new decl and fill in decltype field. */
struct decl *makedecl(int declclass)
{
struct decl *declptr = (struct decl *) calloc(1, sizeof(struct decl));
declptr->declclass = declclass;
return declptr;
}
/*
* Make a constant decl for an enumerated type.
*/
struct decl *makeenumconstdecl(int value)
{
struct decl *declptr = makedecl(CONST);
declptr->value = value;
return declptr;
}
struct decl *maketypedecl()
{
struct decl *declptr = makedecl(TYPE);
return declptr;
}
struct decl *makebankfiledecl()
{
ICBankFile *b = calloc(1,sizeof(ICBankFile));
assert(b);
bankfNew(b);
listAppend(objectList, b);
curBankFile = b; /* ### temp kludge */
return (Decl *)b;
}
struct decl *makebankdecl()
{
ICBank *b = calloc(1,sizeof(ICBank));
assert(b);
bankNew(b);
listAppend(objectList, b);
/*
* ### kludge, should put bank in the grammar
*/
bankfAddBank(curBankFile, b, 0);
return (Decl *)b;
}
struct decl *makeinstdecl()
{
ICInst *i = calloc(1, sizeof(ICInst));
assert(i);
instNew(i);
listAppend(objectList, i);
return (Decl *)i;
}
struct decl *makesounddecl()
{
ICSound *s = calloc(1, sizeof(ICSound));
assert(s);
soundNew(s);
listAppend(objectList, s);
return (Decl *)s;
}
struct decl *makekeydecl()
{
ICKeyMap *k = calloc(1, sizeof(ICKeyMap));
assert(k);
keyNew(k);
listAppend(objectList, k);
return (Decl *)k;
}
struct decl *makeenvdecl()
{
ICEnvelope *env = calloc(1, sizeof(ICEnvelope));
assert(env);
envNew(env);
listAppend(objectList, env);
return (Decl *)env;
}
struct decl *makefiledecl(char *s)
{
struct decl *declptr = makedecl(SFILE);
return declptr;
}