1 /* $NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $ */
4 * Copyright (c) 1994, 1995 Jochen Pohl
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * $NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $
40 static void outtype __P((type_t *));
41 static void outdef __P((hte_t *, sym_t *));
42 static void dumpname __P((hte_t *));
45 * Write type into the output buffer.
56 if ((ts = tp->t_tspec) == INT && tp->t_isenum)
59 case CHAR: t = 'C'; s = '\0'; break;
60 case SCHAR: t = 'C'; s = 's'; break;
61 case UCHAR: t = 'C'; s = 'u'; break;
62 case SHORT: t = 'S'; s = '\0'; break;
63 case USHORT: t = 'S'; s = 'u'; break;
64 case INT: t = 'I'; s = '\0'; break;
65 case UINT: t = 'I'; s = 'u'; break;
66 case LONG: t = 'L'; s = '\0'; break;
67 case ULONG: t = 'L'; s = 'u'; break;
68 case QUAD: t = 'Q'; s = '\0'; break;
69 case UQUAD: t = 'Q'; s = 'u'; break;
70 case FLOAT: t = 'D'; s = 's'; break;
71 case DOUBLE: t = 'D'; s = '\0'; break;
72 case LDOUBLE: t = 'D'; s = 'l'; break;
73 case VOID: t = 'V'; s = '\0'; break;
74 case PTR: t = 'P'; s = '\0'; break;
75 case ARRAY: t = 'A'; s = '\0'; break;
76 case ENUM: t = 'T'; s = 'e'; break;
77 case STRUCT: t = 'T'; s = 's'; break;
78 case UNION: t = 'T'; s = 'u'; break;
80 if (tp->t_args != NULL && !tp->t_proto) {
88 errx(1, "internal error: outtype() 1");
99 } else if (ts == ENUM || ts == STRUCT || ts == UNION) {
102 outname(tp->t_tag->h_name);
103 } else if (tp->t_istynam) {
105 outname(tp->t_tynam->h_name);
109 } else if (ts == FUNC && tp->t_args != NULL) {
111 for (ap = tp->t_args; *ap != NULL; ap++)
116 for (ap = tp->t_args; *ap != NULL; ap++)
126 * Write a definition.
133 /* reset output buffer */
136 /* line number in C source file */
139 /* this is a definition */
142 /* index of file where symbol was defined and line number of def. */
149 outchar('v'); /* varargs */
153 outchar('S'); /* scanflike */
154 outint(sym->s_nscfl);
157 outchar('P'); /* printflike */
158 outint(sym->s_nprfl);
160 /* definition or tentative definition */
161 outchar(sym->s_def == DEF ? 'd' : 't');
162 if (TP(sym->s_type)->t_tspec == FUNC) {
164 outchar('r'); /* fkt. has return value */
166 outchar('o'); /* old style definition */
168 outchar('u'); /* used (no warning if not used) */
171 outname(hte->h_name);
174 outtype(TP(sym->s_type));
178 * Write the first definition of a name into the lint library.
186 /* static and undefined symbols are not written */
187 if (hte->h_static || !hte->h_def)
191 * If there is a definition, write it. Otherwise write a tentative
192 * definition. This is neccessary because more than one tentative
193 * definition is allowed (except with sflag).
196 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
197 if (sym->s_def == DEF) {
201 if (sym->s_def == TDEF && def == NULL)
205 errx(1, "internal error: dumpname() %s", hte->h_name);
211 * Write a new lint library.
217 /* Open of output file and initialisation of the output buffer */
220 /* write name of lint library */
223 /* name of lint lib has index 0 */
229 /* write all definitions with external linkage */
232 /* close the output */