Debian Codegraph @

arch/pdp10/code.c

raw symbols SCIP
1 /* $Id: code.c,v 1.44 2022/03/30 14:11:59 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 #ifdef LANG_CXX
33 #define p1listf listf
34 #define p1tfree tfree
35 #else
36 #define NODE P1ND
37 #define talloc p1alloc
38 #endif
39
40 /*
41 * Print out assembler segment name.
42 */
43 void
44 setseg(int seg, char *name)
45 {
46 switch (seg) {
47 case PROG: name = ".text"; break;
48 case DATA:
49 case LDATA: name = ".data"; break;
50 case UDATA: break;
51 case STRNG:
52 case RDATA: name = ".section .rodata"; break;
53 case NMSEG:
54 printf(PRTPREF "\t.section %s,\"a%c\",@progbits\n", name,
55 cftnsp ? 'x' : 'w');
56 return;
57 default:
58 cerror("bad seg %d", seg);
59 }
60 printf(PRTPREF "\t%s\n", name);
61 }
62
63 /*
64 * Define everything needed to print out some data (or text).
65 * This means segment, alignment, visibility, etc.
66 */
67 void
68 defloc(struct symtab *sp)
69 {
70
71 if (sp->sclass == EXTDEF)
72 printf(" .globl %s\n", getexname(sp));
73 if (sp->slevel == 0)
74 printf("%s:\n", getexname(sp));
75 else
76 printf(LABFMT ":\n", sp->soffset);
77 }
78
79 /*
80 * code for the end of a function
81 */
82 void
83 efcode(void)
84 {
85 }
86
87 /*
88 * code for the beginning of a function; a is an array of
89 * indices in stab for the arguments; n is the number
90 */
91 void
92 bfcode(struct symtab **sp, int cnt)
93 {
94 NODE *p, *q;
95 int i, n;
96
97 if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) {
98 uerror("no struct return yet");
99 }
100 /* recalculate the arg offset and create TEMP moves */
101 for (n = 1, i = 0; i < cnt; i++) {
102 if (n < 8) {
103 p = tempnode(0, sp[i]->stype, sp[i]->sdf, sp[i]->sap);
104 q = block(REG, NIL, NIL,
105 sp[i]->stype, sp[i]->sdf, sp[i]->sap);
106 q->n_rval = n;
107 p = buildtree(ASSIGN, p, q);
108 sp[i]->soffset = regno(p->n_left);
109 sp[i]->sflags |= STNODE;
110 ecomp(p);
111 } else {
112 sp[i]->soffset += SZINT * n;
113 if (xtemps) {
114 /* put stack args in temps if optimizing */
115 p = tempnode(0, sp[i]->stype,
116 sp[i]->sdf, sp[i]->sap);
117 p = buildtree(ASSIGN, p, nametree(sp[i]));
118 sp[i]->soffset = regno(p->n_left);
119 sp[i]->sflags |= STNODE;
120 ecomp(p);
121 }
122 }
123 n += szty(sp[i]->stype);
124 }
125 }
126
127
128 void
129 bjobcode(void)
130 {
131 }
132
133 /* called just before final exit */
134 /* flag is 1 if errors, 0 if none */
135 void
136 ejobcode(int flag)
137 {
138 }
139
140 /*
141 * Make a register node, helper for funcode.
142 */
143 static NODE *
144 mkreg(NODE *p, int n)
145 {
146 NODE *r;
147
148 r = block(REG, NIL, NIL, p->n_type, p->n_df, p->n_ap);
149 if (szty(p->n_type) == 2)
150 n += 16;
151 r->n_rval = n;
152 return r;
153 }
154
155 static int regnum;
156 /*
157 * Move args to registers and emit expressions bottom-up.
158 */
159 static void
160 fixargs(NODE *p)
161 {
162 NODE *r;
163
164 if (p->n_op == CM) {
165 fixargs(p->n_left);
166 r = p->n_right;
167 if (r->n_op == STARG)
168 regnum = 9; /* end of register list */
169 else if (regnum + szty(r->n_type) > 8)
170 p->n_right = block(FUNARG, r, NIL, r->n_type,
171 r->n_df, r->n_ap);
172 else
173 p->n_right = buildtree(ASSIGN, mkreg(r, regnum), r);
174 } else {
175 if (p->n_op == STARG) {
176 regnum = 9; /* end of register list */
177 } else {
178 r = talloc();
179 *r = *p;
180 r = buildtree(ASSIGN, mkreg(r, regnum), r);
181 *p = *r;
182 p1nfree(r);
183 }
184 r = p;
185 }
186 regnum += szty(r->n_type);
187 }
188
189
190 /*
191 * Called with a function call with arguments as argument.
192 * This is done early in buildtree() and only done once.
193 */
194 NODE *
195 funcode(NODE *p)
196 {
197
198 regnum = 1;
199
200 fixargs(p->n_right);
201 return p;
202 }
203
204 /* fix up type of field p */
205 void
206 fldty(struct symtab *p)
207 {
208 }
209
210 /*
211 * XXX - fix genswitch.
212 */
213 int
214 mygenswitch(int num, TWORD type, struct swents **p, int n)
215 {
216 return 0;
217 }
218
219 /*
220 * Return "canonical frame address".
221 */
222 NODE *
223 builtin_cfa(const struct bitable *bt, NODE *a)
224 {
225 uerror(__func__);
226 return bcon(0);
227 }
228
229 NODE *
230 builtin_return_address(const struct bitable *bt, NODE *a)
231 {
232 uerror(__func__);
233 return bcon(0);
234 }
235
236 NODE *
237 builtin_frame_address(const struct bitable *bt, NODE *a)
238 {
239 uerror(__func__);
240 return bcon(0);
241 }
242