xref: /illumos-gate/usr/src/tools/smatch/src/test-linearize.c (revision c85f09cc92abd00c84e58ec9f0f5d942906cb713)
11f5207b7SJohn Levon /*
21f5207b7SJohn Levon  * Parse and linearize the tree for testing.
31f5207b7SJohn Levon  *
41f5207b7SJohn Levon  * Copyright (C) 2003 Transmeta Corp.
51f5207b7SJohn Levon  *               2003-2004 Linus Torvalds
61f5207b7SJohn Levon  *
71f5207b7SJohn Levon  * Permission is hereby granted, free of charge, to any person obtaining a copy
81f5207b7SJohn Levon  * of this software and associated documentation files (the "Software"), to deal
91f5207b7SJohn Levon  * in the Software without restriction, including without limitation the rights
101f5207b7SJohn Levon  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111f5207b7SJohn Levon  * copies of the Software, and to permit persons to whom the Software is
121f5207b7SJohn Levon  * furnished to do so, subject to the following conditions:
131f5207b7SJohn Levon  *
141f5207b7SJohn Levon  * The above copyright notice and this permission notice shall be included in
151f5207b7SJohn Levon  * all copies or substantial portions of the Software.
161f5207b7SJohn Levon  *
171f5207b7SJohn Levon  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181f5207b7SJohn Levon  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191f5207b7SJohn Levon  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201f5207b7SJohn Levon  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211f5207b7SJohn Levon  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
221f5207b7SJohn Levon  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
231f5207b7SJohn Levon  * THE SOFTWARE.
241f5207b7SJohn Levon  */
251f5207b7SJohn Levon #include <stdarg.h>
261f5207b7SJohn Levon #include <stdlib.h>
271f5207b7SJohn Levon #include <stdio.h>
281f5207b7SJohn Levon #include <string.h>
291f5207b7SJohn Levon #include <ctype.h>
301f5207b7SJohn Levon #include <unistd.h>
311f5207b7SJohn Levon #include <fcntl.h>
321f5207b7SJohn Levon 
331f5207b7SJohn Levon #include "lib.h"
341f5207b7SJohn Levon #include "allocate.h"
351f5207b7SJohn Levon #include "token.h"
361f5207b7SJohn Levon #include "parse.h"
371f5207b7SJohn Levon #include "symbol.h"
381f5207b7SJohn Levon #include "expression.h"
391f5207b7SJohn Levon #include "linearize.h"
401f5207b7SJohn Levon 
clean_up_symbols(struct symbol_list * list)411f5207b7SJohn Levon static void clean_up_symbols(struct symbol_list *list)
421f5207b7SJohn Levon {
431f5207b7SJohn Levon 	struct symbol *sym;
441f5207b7SJohn Levon 
451f5207b7SJohn Levon 	FOR_EACH_PTR(list, sym) {
461f5207b7SJohn Levon 		struct entrypoint *ep;
471f5207b7SJohn Levon 
481f5207b7SJohn Levon 		expand_symbol(sym);
491f5207b7SJohn Levon 		ep = linearize_symbol(sym);
50*c85f09ccSJohn Levon 		if (!(fdump_ir & PASS_FINAL))
51*c85f09ccSJohn Levon 			continue;
521f5207b7SJohn Levon 		if (ep)
531f5207b7SJohn Levon 			show_entry(ep);
541f5207b7SJohn Levon 	} END_FOR_EACH_PTR(sym);
551f5207b7SJohn Levon }
561f5207b7SJohn Levon 
main(int argc,char ** argv)571f5207b7SJohn Levon int main(int argc, char **argv)
581f5207b7SJohn Levon {
591f5207b7SJohn Levon 	struct string_list *filelist = NULL;
601f5207b7SJohn Levon 	char *file;
611f5207b7SJohn Levon 
621f5207b7SJohn Levon 	clean_up_symbols(sparse_initialize(argc, argv, &filelist));
63*c85f09ccSJohn Levon 	FOR_EACH_PTR(filelist, file) {
641f5207b7SJohn Levon 		clean_up_symbols(sparse(file));
65*c85f09ccSJohn Levon 	} END_FOR_EACH_PTR(file);
661f5207b7SJohn Levon 
671f5207b7SJohn Levon 	report_stats();
681f5207b7SJohn Levon 	return 0;
691f5207b7SJohn Levon }
70