Debian Codegraph @

arch/pdp7/code.c

raw symbols SCIP
1 /* $Id: code.c,v 1.7 2017/02/16 18:55:31 ragge Exp $ */
2 /*
3 * Copyright (c) 2017 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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27
28 # include "pass1.h"
29
30 #ifdef LANG_CXX
31 #define p1listf listf
32 #define p1tfree tfree
33 #define P1ND NODE
34 #else
35 #define NODE P1ND
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 #if 0
46 switch (seg) {
47 case PROG: name = ".text"; break;
48 case DATA:
49 case LDATA: name = ".data"; break;
50 case UDATA: break;
51 case PICLDATA: name = ".section .data.rel.local,\"aw\",@progbits";break;
52 case PICDATA: name = ".section .data.rel.rw,\"aw\",@progbits"; break;
53 case PICRDATA: name = ".section .data.rel.ro,\"aw\",@progbits"; break;
54 case STRNG:
55 case RDATA: name = ".data"; break;
56 case TLSDATA: name = ".section .tdata,\"awT\",@progbits"; break;
57 case TLSUDATA: name = ".section .tbss,\"awT\",@nobits"; break;
58 case CTORS: name = ".section\t.ctors,\"aw\",@progbits"; break;
59 case DTORS: name = ".section\t.dtors,\"aw\",@progbits"; break;
60 case NMSEG:
61 printf(PRTPREF "\t.section %s,\"a%c\",@progbits\n", name,
62 cftnsp ? 'x' : 'w');
63 return;
64 }
65 printf(PRTPREF "\t%s\n", name);
66 #endif
67 }
68
69 /* nothing on pdp7 */
70 void
71 defalign(int al)
72 {
73 }
74
75 /*
76 * Define everything needed to print out some data (or text).
77 * This means segment, alignment, visibility, etc.
78 */
79 void
80 defloc(struct symtab *sp)
81 {
82 extern void dellab(int);
83 char *name;
84
85 name = getexname(sp);
86 if (sp->slevel == 0) {
87 if (sp->sclass == STATIC)
88 printf(PRTPREF "\t.local %s\n", name);
89 printf(PRTPREF "%s:\t", name);
90 } else {
91 dellab(sp->soffset);
92 printf(PRTPREF LABFMT ":\t", sp->soffset);
93 }
94 }
95
96 /*
97 * code for the end of a function
98 * deals with struct return here
99 */
100 void
101 efcode(void)
102 {
103 if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
104 return;
105 }
106
107 /*
108 * code for the beginning of a function; a is an array of
109 * indices in symtab for the arguments; n is the number
110 * pdp7 has its arguments after the function call, must
111 * put them aside directly.
112 */
113 void
114 bfcode(struct symtab **sp, int cnt)
115 {
116 P1ND *p, *p2;
117 char *c;
118 int i, l;
119
120 /* handcraft isz */
121 l = strlen(cftnsp->sname)+10;
122 c = tmpalloc(l);
123 snprintf(c, l, " isz %s\n", exname(cftnsp->sname));
124
125 /* Convert param symtab entries to NAMEs */
126 for (i = 0; i < cnt; i++) {
127 sp[i]->sclass = STATIC;
128 sp[i]->soffset = getlab();
129 p2 = cast(buildtree(ADDROF,
130 nametree(cftnsp), 0), INCREF(INCREF(sp[i]->stype)), 0);
131 p = buildtree(ASSIGN, nametree(sp[i]),
132 buildtree(UMUL, buildtree(UMUL, p2, 0), 0));
133 ecomp(p);
134 send_passt(IP_ASM, c);
135 printf(LABFMT ": 0\n", sp[i]->soffset);
136 }
137 }
138
139 /* called just before final exit */
140 /* flag is 1 if errors, 0 if none */
141 void
142 ejobcode(int flag)
143 {
144 extern void printlab(void);
145 printlab();
146 }
147
148 void
149 bjobcode(void)
150 {
151 astypnames[INT] = astypnames[UNSIGNED] = "";
152 }
153
154 /*
155 * Called with a function call with arguments as argument.
156 * This is done early in buildtree() and only done once.
157 * Returns p.
158 */
159 NODE *
160 funcode(NODE *p)
161 {
162 extern int gotnr;
163 NODE *r, *l;
164 TWORD t = DECREF(DECREF(p->n_left->n_type));
165 int stcall;
166
167 stcall = ISSOU(t);
168 /*
169 * We may have to prepend:
170 * - Hidden arg0 for struct return (in reg or on stack).
171 * - ebx in case of PIC code.
172 */
173
174 /* Fix function call arguments. On x86, just add funarg */
175 for (r = p->n_right; r->n_op == CM; r = r->n_left) {
176 if (r->n_right->n_op != STARG)
177 r->n_right = block(FUNARG, r->n_right, NIL,
178 r->n_right->n_type, r->n_right->n_df,
179 r->n_right->n_ap);
180 }
181 if (r->n_op != STARG) {
182 l = talloc();
183 *l = *r;
184 r->n_op = FUNARG;
185 r->n_left = l;
186 r->n_type = l->n_type;
187 }
188 return p;
189 }
190
191 /* fix up type of field p */
192 void
193 fldty(struct symtab *p)
194 {
195 }
196
197 /*
198 * XXX - fix genswitch.
199 */
200 int
201 mygenswitch(int num, TWORD type, struct swents **p, int n)
202 {
203 return 0;
204 }
205
206 NODE *
207 builtin_return_address(const struct bitable *bt, NODE *a)
208 {
209 uerror("missing builtin_return_address");
210 return bcon(0);
211 }
212
213 NODE *
214 builtin_frame_address(const struct bitable *bt, NODE *a)
215 {
216 uerror("missing __builtin_frame_address");
217 return bcon(0);
218 }
219
220 /*
221 * Return "canonical frame address".
222 */
223 NODE *
224 builtin_cfa(const struct bitable *bt, NODE *a)
225 {
226 uerror("missing builtin_cfa");
227 return bcon(0);
228 }
229