1 /*        Id: flocal.c,v 1.17 2012/04/22 21:07:40 plunky Exp          */
2 /*        $NetBSD: flocal.c,v 1.1.1.4 2014/07/24 19:16:54 plunky Exp $          */
3 /*
4  * Copyright(C) Caldera International Inc. 2001-2002. 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  *
10  * Redistributions of source code and documentation must retain the above
11  * copyright notice, this list of conditions and the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditionsand the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * All advertising materials mentioning features or use of this software
16  * must display the following acknowledgement:
17  *        This product includes software developed or owned by Caldera
18  *        International, Inc.
19  * Neither the name of Caldera International, Inc. nor the names of other
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
24  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
28  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 #include <stdio.h>
37 
38 #include "defines.h"
39 #include "defs.h"
40 
41 void
prchars(int * s)42 prchars(int *s)
43 {
44           printf("\t.byte 0%o,0%o\n", s[0], s[1]);
45 }
46 
47 void
setloc(int l)48 setloc(int l)
49 {
50           static int lastloc = -1;
51           static char *loctbl[] =
52               { "text", "data", "section .rodata", "section .rodata", "bss" };
53           if (l == lastloc)
54                     return;
55           printf("\t.%s\n", loctbl[l]);
56           lastloc = l;
57 }
58 
59 #ifdef FCOM
60 
61 
62 /*
63           PDP11-780/VAX - SPECIFIC PRINTING ROUTINES
64 */
65 
66 /*
67  * Called just before return from a subroutine.
68  */
69 void
goret(int type)70 goret(int type)
71 {
72 }
73 
74 /*
75  * Print out a label.
76  */
77 void
prlabel(int k)78 prlabel(int k)
79 {
80           printf(LABFMT ":\n", k);
81 }
82 
83 /*
84  * Print naming for location.
85  * name[0] is location type.
86  */
87 void
prnloc(char * name)88 prnloc(char *name)
89 {
90           if (*name == '0')
91                     setloc(DATA);
92           else
93                     fatal("unhandled prnloc %c", *name);
94           printf("%s:\n", name+1);
95 }
96 
97 /*
98  * Print integer constant.
99  */
100 void
prconi(FILE * fp,int type,ftnint n)101 prconi(FILE *fp, int type, ftnint n)
102 {
103           fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n);
104 }
105 
106 /*
107  * Print address constant, given as a label number.
108  */
109 void
prcona(ftnint a)110 prcona(ftnint a)
111 {
112           printf("\t.long\t" LABFMT "\n", (int)a);
113 }
114 
115 /*
116  * Print out a floating constant.
117  */
118 void
prconr(FILE * fp,int type,double x)119 prconr(FILE *fp, int type, double x)
120 {
121           fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x);
122 }
123 
124 void
preven(int k)125 preven(int k)
126 {
127           if (k > 1)
128                     printf("\t.align\t%d\n", k);
129 }
130 
131 /*
132  * Convert a tag and offset into the symtab table to a string.
133  * An external string is never longer than XL bytes.
134  */
135 char *
memname(int stg,int mem)136 memname(int stg, int mem)
137 {
138 #define   MLEN      (XL + 10)
139           char *s = malloc(MLEN);
140 
141           switch(stg) {
142           case STGCOMMON:
143           case STGEXT:
144                     snprintf(s, MLEN, "%s", varstr(XL, extsymtab[mem].extname));
145                     break;
146 
147           case STGBSS:
148           case STGINIT:
149                     snprintf(s, MLEN, "v.%d", mem);
150                     break;
151 
152           case STGCONST:
153                     snprintf(s, MLEN, ".L%d", mem);
154                     break;
155 
156           case STGEQUIV:
157                     snprintf(s, MLEN, "q.%d", mem);
158                     break;
159 
160           default:
161                     fatal1("memname: invalid vstg %d", stg);
162           }
163           return(s);
164 }
165 
166 void
prlocvar(char * s,ftnint len)167 prlocvar(char *s, ftnint len)
168 {
169           printf("\t.lcomm\t%s,%ld\n", s, len);
170 }
171 
172 
173 void
prext(char * name,ftnint leng,int init)174 prext(char *name, ftnint leng, int init)
175 {
176           if(leng == 0)
177                     printf("\t.globl\t%s\n", name);
178           else
179                     printf("\t.comm\t%s,%ld\n", name, leng);
180 }
181 
182 void
prendproc(void)183 prendproc(void)
184 {
185 }
186 
187 void
prtail(void)188 prtail(void)
189 {
190 }
191 
192 void
prolog(struct entrypoint * ep,struct bigblock * argvec)193 prolog(struct entrypoint *ep, struct bigblock *argvec)
194 {
195           /* Ignore for now.  ENTRY is not supported */
196 }
197 
198 void
prdbginfo(void)199 prdbginfo(void)
200 {
201 }
202 
203 static void
fcheck(NODE * p,void * arg)204 fcheck(NODE *p, void *arg)
205 {
206           NODE *r, *l;
207 
208           switch (p->n_op) {
209           case CALL: /* fix arguments */
210                     for (r = p->n_right; r->n_op == CM; r = r->n_left) {
211                               r->n_right = mkunode(FUNARG, r->n_right, 0,
212                                   r->n_right->n_type);
213                     }
214                     l = talloc();
215                     *l = *r;
216                     r->n_op = FUNARG;
217                     r->n_left = l;
218                     r->n_type = l->n_type;
219                     break;
220           }
221 }
222 
223 /*
224  * Called just before the tree is written out to pass2.
225  */
226 void p2tree(NODE *p);
227 void
p2tree(NODE * p)228 p2tree(NODE *p)
229 {
230           walkf(p, fcheck, 0);
231 }
232 #endif /* FCOM */
233