Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * Hypervisor Software File: aschk_main.c | |
5 | * | |
6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
7 | * | |
8 | * - Do no alter or remove copyright notices | |
9 | * | |
10 | * - Redistribution and use of this software in source and binary forms, with | |
11 | * or without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistribution of source code must retain the above copyright notice, | |
15 | * this list of conditions and the following disclaimer. | |
16 | * | |
17 | * - Redistribution in binary form must reproduce the above copyright notice, | |
18 | * this list of conditions and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * | |
21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors | |
22 | * may be used to endorse or promote products derived from this software | |
23 | * without specific prior written permission. | |
24 | * | |
25 | * This software is provided "AS IS," without a warranty of any kind. | |
26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
37 | * | |
38 | * You acknowledge that this software is not designed, licensed or | |
39 | * intended for use in the design, construction, operation or maintenance of | |
40 | * any nuclear facility. | |
41 | * | |
42 | * ========== Copyright Header End ============================================ | |
43 | */ | |
44 | /* | |
45 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
46 | * Use is subject to license terms. | |
47 | */ | |
48 | ||
49 | #pragma ident "@(#)aschk_main.c 1.3 07/06/07 SMI" | |
50 | ||
51 | #include <stdio.h> | |
52 | #include <stdlib.h> | |
53 | #include <stdarg.h> | |
54 | #include <unistd.h> | |
55 | #include <fcntl.h> | |
56 | #include <errno.h> | |
57 | #include <string.h> | |
58 | ||
59 | #include "basics.h" | |
60 | #include "internal.h" | |
61 | #include "parser.h" | |
62 | ||
63 | extern void lex_only(); | |
64 | ||
65 | static void usage(); | |
66 | static void check_file(char *fnamep); | |
67 | static void add_name_file(char *fnamep); | |
68 | ||
69 | bool_t flag_suppress_unknowns; | |
70 | int warning_count; | |
71 | ||
72 | int | |
73 | main(int argc, char **argv) | |
74 | { | |
75 | int i; | |
76 | bool_t flag_strict_mode; | |
77 | ||
78 | init_symbols(); | |
79 | flag_suppress_unknowns = false; | |
80 | flag_strict_mode = false; | |
81 | ||
82 | for (i = 1; i < argc && argv[i][0] == '-'; i++) { | |
83 | switch (argv[i][1]) { | |
84 | case 'n': | |
85 | add_name_file(argv[++i]); | |
86 | break; | |
87 | case 'u': | |
88 | flag_suppress_unknowns = true; | |
89 | break; | |
90 | case 's': | |
91 | flag_strict_mode = true; | |
92 | break; | |
93 | default: | |
94 | usage(); | |
95 | } | |
96 | } | |
97 | ||
98 | warning_count = 0; | |
99 | ||
100 | for (; i < argc; i++) { | |
101 | check_file(argv[i]); | |
102 | } | |
103 | ||
104 | if (warning_count > 0) { | |
105 | fprintf(stderr, "Completed with %d warnings\n", warning_count); | |
106 | } | |
107 | ||
108 | if (!flag_strict_mode) | |
109 | return (0); | |
110 | ||
111 | return ((warning_count != 0) ? 1 : 0); | |
112 | } | |
113 | ||
114 | ||
115 | static void | |
116 | check_file(char *fnamep) | |
117 | { | |
118 | FILE *fp; | |
119 | ||
120 | fp = fopen(fnamep, "r"); | |
121 | ||
122 | aslexin = fp; | |
123 | yyloc.fnamep = fnamep; | |
124 | yy_line_num = 1; | |
125 | lex_only(); | |
126 | ||
127 | fclose(fp); | |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | static void | |
133 | usage(void) | |
134 | { | |
135 | fprintf(stderr, "aschk [-s] [-u] [-n <chk file>] <testfile.s>" | |
136 | " [<others.s>]*\n" | |
137 | "\t-u = suppress warnings for unknowns\n" | |
138 | "\t-s = strict mode; non-zero exit if warning count >0\n" | |
139 | "\t-n = specify name table file\n"); | |
140 | exit(1); | |
141 | } | |
142 | ||
143 | ||
144 | ||
145 | #define MAXLINE 2048 | |
146 | ||
147 | static void | |
148 | add_name_file(char *fnamep) | |
149 | { | |
150 | FILE *fp; | |
151 | char linebuf[MAXLINE]; | |
152 | char typestr[4]; | |
153 | char symname[MAXLINE]; | |
154 | int offset, size; | |
155 | int linenum; | |
156 | sym_flags_t flags; | |
157 | symbol_t *symp; | |
158 | ||
159 | fp = fopen(fnamep, "r"); | |
160 | if (fp == NULL) { | |
161 | fprintf(stderr, "Opening: %s : %s\n", fnamep, strerror(errno)); | |
162 | exit(1); | |
163 | } | |
164 | ||
165 | linenum = 0; | |
166 | while (fgets(linebuf, MAXLINE, fp) != NULL) { | |
167 | /* skip comments and directives */ | |
168 | linenum++; | |
169 | if (linebuf[0] == '!' || linebuf[0] == '#') | |
170 | continue; | |
171 | ||
172 | if (sscanf(linebuf, "%4s %x %x %s\n", typestr, | |
173 | &offset, &size, symname) != 4) | |
174 | continue; | |
175 | DBG(printf("Sym: %s\t@ 0x%x\tsize=0x%x\ttype=%s\n", | |
176 | symname, offset, size, typestr)); | |
177 | ||
178 | flags = Sym_unknown; | |
179 | switch (typestr[0]) { | |
180 | case 'p': flags |= Sym_pointer; break; | |
181 | case 'u': flags |= Sym_unsigned; break; | |
182 | case 's': flags |= Sym_signed; break; | |
183 | default: | |
184 | fprintf(stderr, "Unknown check type for line %d\n", | |
185 | linenum); | |
186 | exit(1); | |
187 | } | |
188 | if (typestr[1] == 'c') flags |= Sym_char; | |
189 | ||
190 | symp = new_sym(flags, symname, offset, size); | |
191 | sym_hash_insert(symp); | |
192 | } | |
193 | ||
194 | fclose(fp); | |
195 | } |