Debian Codegraph @

arch/pdp11/code.c

raw symbols SCIP
1 /* $Id: code.c,v 1.17 2019/04/25 17:39:23 ragge Exp $ */
2 /*
3 * Copyright (c) 2003 Anders Magnusson ([email protected]).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30 # include "pass1.h"
31
32 #ifndef LANG_CXX
33 #define NODE P1ND
34 #undef NIL
35 #define NIL NULL
36 #define talloc p1alloc
37 #endif
38
39 /*
40 * Print out assembler segment name.
41 */
42 void
43 setseg(int seg, char *name)
44 {
45 switch (seg) {
46 case PROG: name = ".text"; break;
47 case STRNG:
48 case RDATA:
49 case DATA:
50 case LDATA: name = ".data"; break;
51 case UDATA: break;
52 default:
53 cerror("setseg");
54 }
55 printf("\t%s\n", name);
56 }
57
58 void
59 defalign(int al)
60 {
61 if (al > ALCHAR)
62 printf(".even\n");
63 }
64
65 /*
66 * Define everything needed to print out some data (or text).
67 * This means segment, alignment, visibility, etc.
68 */
69 void
70 defloc(struct symtab *sp)
71 {
72 static char *loctbl[] = { "text", "data", "data" };
73 TWORD t;
74 char *n;
75 int s;
76
77 t = sp->stype;
78 s = ISFTN(t) ? PROG : ISCON(cqual(t, sp->squal)) ? RDATA : DATA;
79 if (s != lastloc)
80 printf(" .%s\n", loctbl[s]);
81 lastloc = s;
82 n = getexname(sp);
83 if (sp->sclass == EXTDEF)
84 printf(" .globl %s\n", n);
85 if (sp->slevel == 0) {
86 printf("%s:\n", n);
87 printf("~~%s:\n", n+1);
88 } else {
89 printf(LABFMT ":\n", sp->soffset);
90 }
91 }
92
93 /*
94 * Code for the end of a function. Deals with struct return here.
95 * On pdp11 we use a static bounce-buffer for struct return,
96 * which address is returned in r0.
97 */
98 void
99 efcode(void)
100 {
101 struct symtab *sp;
102 NODE *p, *q;
103
104 if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
105 return;
106
107 /* Handcraft a static buffer */
108 sp = getsymtab("007", SSTMT);
109 sp->stype = DECREF(cftnsp->stype);
110 sp->sdf = cftnsp->sdf;
111 sp->sap = cftnsp->sap;
112 sp->sclass = STATIC;
113 sp->soffset = getlab();
114 sp->slevel = 1;
115 defzero(sp);
116
117 /* create struct assignment */
118 q = nametree(sp);
119 p = block(REG, NIL, NIL, PTR+STRTY, 0, cftnsp->sap);
120 p = buildtree(UMUL, p, NIL);
121 p = buildtree(ASSIGN, q, p);
122 ecomp(p);
123
124 /* return address of buffer */
125 q = buildtree(ADDROF, nametree(sp), NIL);
126 p = block(REG, NIL, NIL, PTR+STRTY, 0, cftnsp->sap);
127 p = buildtree(ASSIGN, p, q);
128 ecomp(p);
129 }
130
131 /*
132 * code for the beginning of a function; a is an array of
133 * indices in symtab for the arguments; n is the number
134 */
135 void
136 bfcode(struct symtab **sp, int cnt)
137 {
138 struct symtab *sp2;
139 NODE *n;
140 int i;
141
142 if (xtemps == 0)
143 return;
144
145 /* put arguments in temporaries */
146 for (i = 0; i < cnt; i++) {
147 if (sp[i]->stype == STRTY || sp[i]->stype == UNIONTY ||
148 cisreg(sp[i]->stype) == 0)
149 continue;
150 sp2 = sp[i];
151 n = tempnode(0, sp[i]->stype, sp[i]->sdf, sp[i]->sap);
152 n = buildtree(ASSIGN, n, nametree(sp2));
153 sp[i]->soffset = regno(n->n_left);
154 sp[i]->sflags |= STNODE;
155 ecomp(n);
156 }
157 }
158
159
160 /* called just before final exit */
161 /* flag is 1 if errors, 0 if none */
162 void
163 ejobcode(int flag)
164 {
165 }
166
167 void
168 bjobcode(void)
169 {
170 extern char *asspace;
171 /* ".word" is not printed out for pdp11 as */
172 astypnames[INT] = astypnames[UNSIGNED] = "";
173 asspace = ".=.+"; /* advance counter, not .space */
174 }
175
176 /*
177 * Called with a function call with arguments as argument.
178 * This is done early in buildtree() and only done once.
179 * Returns p.
180 */
181 NODE *
182 funcode(NODE *p)
183 {
184 NODE *r, *l;
185
186 /* Fix function call arguments. On x86, just add funarg */
187 for (r = p->n_right; r->n_op == CM; r = r->n_left) {
188 if (r->n_right->n_op != STARG)
189 r->n_right = block(FUNARG, r->n_right, NIL,
190 r->n_right->n_type, r->n_right->n_df,
191 r->n_right->n_ap);
192 }
193 if (r->n_op != STARG) {
194 l = talloc();
195 *l = *r;
196 r->n_op = FUNARG;
197 r->n_left = l;
198 r->n_type = l->n_type;
199 }
200 return p;
201 }
202
203 /* fix up type of field p */
204 void
205 fldty(struct symtab *p)
206 {
207 }
208
209 /*
210 * XXX - fix genswitch.
211 */
212 int
213 mygenswitch(int num, TWORD type, struct swents **p, int n)
214 {
215 return 0;
216 }
217
218 /*
219 * Return "canonical frame address".
220 */
221 NODE *
222 builtin_cfa(const struct bitable *bt, NODE *a)
223 {
224 uerror(__func__);
225 return bcon(0);
226 }
227
228 NODE *
229 builtin_return_address(const struct bitable *bt, NODE *a)
230 {
231 uerror(__func__);
232 return bcon(0);
233 }
234
235 NODE *
236 builtin_frame_address(const struct bitable *bt, NODE *a)
237 {
238 uerror(__func__);
239 return bcon(0);
240 }