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 $
34 * $DragonFly: src/usr.bin/xlint/lint2/emit2.c,v 1.4 2003/11/03 19:31:34 eirikn Exp $
41 static void outtype(type_t *);
42 static void outdef(hte_t *, sym_t *);
43 static void dumpname(hte_t *);
46 * Write type into the output buffer.
57 if ((ts = tp->t_tspec) == INT && tp->t_isenum)
60 case CHAR: t = 'C'; s = '\0'; break;
61 case SCHAR: t = 'C'; s = 's'; break;
62 case UCHAR: t = 'C'; s = 'u'; break;
63 case SHORT: t = 'S'; s = '\0'; break;
64 case USHORT: t = 'S'; s = 'u'; break;
65 case INT: t = 'I'; s = '\0'; break;
66 case UINT: t = 'I'; s = 'u'; break;
67 case LONG: t = 'L'; s = '\0'; break;
68 case ULONG: t = 'L'; s = 'u'; break;
69 case QUAD: t = 'Q'; s = '\0'; break;
70 case UQUAD: t = 'Q'; s = 'u'; break;
71 case FLOAT: t = 'D'; s = 's'; break;
72 case DOUBLE: t = 'D'; s = '\0'; break;
73 case LDOUBLE: t = 'D'; s = 'l'; break;
74 case VOID: t = 'V'; s = '\0'; break;
75 case PTR: t = 'P'; s = '\0'; break;
76 case ARRAY: t = 'A'; s = '\0'; break;
77 case ENUM: t = 'T'; s = 'e'; break;
78 case STRUCT: t = 'T'; s = 's'; break;
79 case UNION: t = 'T'; s = 'u'; break;
81 if (tp->t_args != NULL && !tp->t_proto) {
89 errx(1, "internal error: outtype() 1");
100 } else if (ts == ENUM || ts == STRUCT || ts == UNION) {
103 outname(tp->t_tag->h_name);
104 } else if (tp->t_istynam) {
106 outname(tp->t_tynam->h_name);
110 } else if (ts == FUNC && tp->t_args != NULL) {
112 for (ap = tp->t_args; *ap != NULL; ap++)
117 for (ap = tp->t_args; *ap != NULL; ap++)
127 * Write a definition.
134 /* reset output buffer */
137 /* line number in C source file */
140 /* this is a definition */
143 /* index of file where symbol was defined and line number of def. */
150 outchar('v'); /* varargs */
154 outchar('S'); /* scanflike */
155 outint(sym->s_nscfl);
158 outchar('P'); /* printflike */
159 outint(sym->s_nprfl);
161 /* definition or tentative definition */
162 outchar(sym->s_def == DEF ? 'd' : 't');
163 if (TP(sym->s_type)->t_tspec == FUNC) {
165 outchar('r'); /* fkt. has return value */
167 outchar('o'); /* old style definition */
169 outchar('u'); /* used (no warning if not used) */
172 outname(hte->h_name);
175 outtype(TP(sym->s_type));
179 * Write the first definition of a name into the lint library.
187 /* static and undefined symbols are not written */
188 if (hte->h_static || !hte->h_def)
192 * If there is a definition, write it. Otherwise write a tentative
193 * definition. This is neccessary because more than one tentative
194 * definition is allowed (except with sflag).
197 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
198 if (sym->s_def == DEF) {
202 if (sym->s_def == TDEF && def == NULL)
206 errx(1, "internal error: dumpname() %s", hte->h_name);
212 * Write a new lint library.
218 /* Open of output file and initialisation of the output buffer */
221 /* write name of lint library */
224 /* name of lint lib has index 0 */
230 /* write all definitions with external linkage */
233 /* close the output */