]>
git.cameronkatri.com Git - apple_cmds.git/blob - bootstrap_cmds/migcom.tproj/mig.c
2 * Copyright (c) 1999-2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Mach Operating System
25 * Copyright (c) 1991,1990 Carnegie Mellon University
26 * All Rights Reserved.
28 * Permission to use, copy, modify and distribute this software and its
29 * documentation is hereby granted, provided that both the copyright
30 * notice and this permission notice appear in all copies of the
31 * software, derivative works or modified versions, and any portions
32 * thereof, and that both notices appear in supporting documentation.
34 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
35 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
36 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
38 * Carnegie Mellon requests users of this software to return to
40 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
41 * School of Computer Science
42 * Carnegie Mellon University
43 * Pittsburgh PA 15213-3890
45 * any improvements or extensions that they make and grant Carnegie the
46 * rights to redistribute these changes.
51 * -[v,Q] verbose or not quiet: prints out type
52 * and routine information as mig runs.
53 * -[V,q] not verbose or quiet : don't print
54 * information during compilation
55 * (this is the default)
56 * -[r,R] do or don't use rpc calls instead of
57 * send/receive pairs. Default is -r.
58 * -[s,S] generate symbol table or not: generate a
59 * table of rpc-name, number, routine triplets
60 * as an external data structure -- main use is
61 * for protection system's specification of rights
62 * and for protection dispatch code. Default is -s.
63 * -[l,L] -L generate code that insert code for logging
64 * the most important events that happen at the
65 * stub level (message conception, target routine
66 * calls). Default is -l.
67 * -[k,K] -K enforces MIG to generate K&R C language, with the
68 * addition of ANSI C syntax under #ifdef __STDC__.
70 * -[n,N] -n enforces NDR checking and conversion logic generation.
71 * Default is -N (no checking).
73 * Put each user routine in its own file. The
74 * file is named <prefix><routine-name>.c.
76 * Name the user-side file <name>
78 * Name the server-side file <name>
80 * Name the user-side header file <name>
82 * Name the user-side internal header file <name>
84 * Name the server-side header file <name>
86 * Name the defines (msgh_ids) header file <name>
89 * Mig uses a lexxer module created by lex from lexxer.l and
90 * a parser module created by yacc from parser.y to parse an
91 * interface definitions module for a mach server.
92 * The parser module calls routines in statement.c
93 * and routines.c to build a list of statement structures.
94 * The most interesting statements are the routine definitions
95 * which contain information about the name, type, characteristics
96 * of the routine, an argument list containing information for
97 * each argument type, and a list of special arguments. The
98 * argument type structures are build by routines in type.c
99 * Once parsing is completed, the three code generation modules:
100 * header.c user.c and server.c are called sequentially. These
101 * do some code generation directly and also call the routines
102 * in utils.c for common (parameterized) code generation.
114 extern int yyparse(void);
115 static FILE *myfopen(const char *name
, const char *mode
);
118 parseArgs(int argc
,char *argv
[])
120 if (argc
== 2 && streql(argv
[1], "-version")) {
126 if ((++argv
)[0][0] == '-') {
127 switch (argv
[0][1]) {
154 UseEventLogger
= FALSE
;
158 UseEventLogger
= TRUE
;
170 if (streql(argv
[0], "-novouchers")) {
171 IsVoucherCodeAllowed
= FALSE
;
182 if (streql(argv
[0], "-server")) {
185 fatal("missing name for -server option");
186 ServerFileName
= strmake(argv
[0]);
188 else if (streql(argv
[0], "-sheader")) {
191 fatal ("missing name for -sheader option");
192 ServerHeaderFileName
= strmake(argv
[0]);
194 else if (streql(argv
[0], "-split"))
195 UseSplitHeaders
= TRUE
;
205 warn("Mach RPC traps not fully supported");
215 if (streql(argv
[0], "-iheader")) {
218 fatal("missing name for -iheader option");
219 InternalHeaderFileName
= strmake(argv
[0]);
224 fatal("missing prefix for -i option");
225 UserFilePrefix
= strmake(argv
[0]);
230 if (streql(argv
[0], "-user")) {
233 fatal("missing name for -user option");
234 UserFileName
= strmake(argv
[0]);
237 fatal("unknown flag: '%s'", argv
[0]);
241 if (streql(argv
[0], "-header")) {
244 fatal("missing name for -header option");
245 UserHeaderFileName
= strmake(argv
[0]);
248 fatal("unknown flag: '%s'", argv
[0]);
252 if (streql(argv
[0], "-dheader")) {
255 fatal("missing name for -dheader option");
256 DefinesHeaderFileName
= strmake(argv
[0]);
259 fatal("unknown flag: '%s'", argv
[0]);
263 if (streql(argv
[0], "-maxonstack")) {
266 fatal("missing size for -maxonstack option");
267 MaxMessSizeOnStack
= atoi(argv
[0]);
270 fatal("unknown flag: '%s'", argv
[0]);
274 ShortCircuit
= FALSE
;
279 /* fall thru - no longer supported */
282 fatal("unknown/unsupported flag: '%s'", argv
[0]);
287 fatal("bad argument: '%s'", *argv
);
290 FILE *uheader
, *server
, *user
;
293 main(int argc
, char *argv
[])
299 extern string_t GenerationDate
;
301 set_program_name("mig");
302 parseArgs(argc
, argv
);
304 printf("%s\n", MIG_VERSION
);
310 loc
= time((time_t *)0);
311 GenerationDate
= ctime(&loc
);
317 fatal("%d errors found. Abort.\n", mig_errors
);
321 uheader
= myfopen(UserHeaderFileName
, "w");
323 user
= myfopen(UserFileName
, "w");
324 server
= myfopen(ServerFileName
, "w");
325 if (ServerHeaderFileName
)
326 sheader
= myfopen(ServerHeaderFileName
, "w");
327 if (IsKernelServer
) {
328 iheader
= myfopen(InternalHeaderFileName
, "w");
330 if (DefinesHeaderFileName
)
331 dheader
= myfopen(DefinesHeaderFileName
, "w");
333 printf("Writing %s ... ", UserHeaderFileName
);
336 WriteUserHeader(uheader
, stats
);
338 if (ServerHeaderFileName
) {
340 printf ("done.\nWriting %s ...", ServerHeaderFileName
);
343 WriteServerHeader(sheader
, stats
);
346 if (IsKernelServer
) {
348 printf("done.\nWriting %s ... ", InternalHeaderFileName
);
351 WriteInternalHeader(iheader
, stats
);
354 if (DefinesHeaderFileName
) {
356 printf ("done.\nWriting %s ...", DefinesHeaderFileName
);
359 WriteDefinesHeader(dheader
, stats
);
362 if (UserFilePrefix
) {
364 printf("done.\nWriting individual user files ... ");
367 WriteUserIndividual(stats
);
371 printf("done.\nWriting %s ... ", UserFileName
);
374 WriteUser(user
, stats
);
378 printf("done.\nWriting %s ... ", ServerFileName
);
381 WriteServer(server
, stats
);
390 myfopen(const char *name
, const char *mode
)
392 const char *realname
;
396 realname
= "/dev/null";
400 file
= fopen(realname
, mode
);
402 fatal("fopen(%s): %s", realname
, strerror(errno
));