Optimize x86-64 signbit{,f} a bit.
[glibc.git] / sunrpc / rpc_tblout.c
blob2d77c606caea2d40652e896709507b585d90e3eb
1 /*
2 * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
35 #include <stdio.h>
36 #include <string.h>
37 #include "rpc_parse.h"
38 #include "rpc_util.h"
39 #include "proto.h"
41 #define TABSIZE 8
42 #define TABCOUNT 5
43 #define TABSTOP (TABSIZE*TABCOUNT)
45 static const char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
47 static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
48 static const char tbl_end[] = "};\n";
50 static const char null_entry[] = "\n\t(char *(*)())0,\n\
51 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
52 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
55 static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
57 static void write_table (const definition * def);
58 static void printit (const char *prefix, const char *type);
60 void
61 write_tables (void)
63 list *l;
64 definition *def;
66 f_print (fout, "\n");
67 for (l = defined; l != NULL; l = l->next)
69 def = (definition *) l->val;
70 if (def->def_kind == DEF_PROGRAM)
72 write_table (def);
77 static void
78 write_table (const definition * def)
80 version_list *vp;
81 proc_list *proc;
82 int current;
83 int expected;
84 char progvers[100];
85 int warning;
87 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
89 warning = 0;
90 s_print (progvers, "%s_%s",
91 locase (def->def_name), vp->vers_num);
92 /* print the table header */
93 f_print (fout, tbl_hdr, progvers);
95 if (nullproc (vp->procs))
97 expected = 0;
99 else
101 expected = 1;
102 f_print (fout, null_entry);
104 for (proc = vp->procs; proc != NULL; proc = proc->next)
106 current = atoi (proc->proc_num);
107 if (current != expected++)
109 f_print (fout,
110 "\n/*\n * WARNING: table out of order\n */\n");
111 if (warning == 0)
113 f_print (stderr,
114 "WARNING %s table is out of order\n",
115 progvers);
116 warning = 1;
117 nonfatalerrors = 1;
119 expected = current + 1;
121 f_print (fout, "\n\t(char *(*)())RPCGEN_ACTION(");
123 /* routine to invoke */
124 if (Cflag && !newstyle)
125 pvname_svc (proc->proc_name, vp->vers_num);
126 else
128 if (newstyle)
129 f_print (fout, "_"); /* calls internal func */
130 pvname (proc->proc_name, vp->vers_num);
132 f_print (fout, "),\n");
134 /* argument info */
135 if (proc->arg_num > 1)
136 printit ((char *) NULL, proc->args.argname);
137 else
138 /* do we have to do something special for newstyle */
139 printit (proc->args.decls->decl.prefix,
140 proc->args.decls->decl.type);
141 /* result info */
142 printit (proc->res_prefix, proc->res_type);
145 /* print the table trailer */
146 f_print (fout, tbl_end);
147 f_print (fout, tbl_nproc, progvers, progvers, progvers);
151 static void
152 printit (const char *prefix, const char *type)
154 int len;
155 int tabs;
158 len = fprintf (fout, "\txdr_%s,", stringfix (type));
159 /* account for leading tab expansion */
160 len += TABSIZE - 1;
161 /* round up to tabs required */
162 tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
163 f_print (fout, "%s", &tabstr[TABCOUNT - tabs]);
165 if (streq (type, "void"))
167 f_print (fout, "0");
169 else
171 f_print (fout, "sizeof ( ");
172 /* XXX: should "follow" be 1 ??? */
173 ptype (prefix, type, 0);
174 f_print (fout, ")");
176 f_print (fout, ",\n");