11f5207bJohn Levon/*
21f5207bJohn Levon * Example trivial client program that uses the sparse library
31f5207bJohn Levon * and x86 backend.
41f5207bJohn Levon *
51f5207bJohn Levon * Copyright (C) 2003 Transmeta Corp.
61f5207bJohn Levon *               2003 Linus Torvalds
71f5207bJohn Levon * Copyright 2003 Jeff Garzik
81f5207bJohn Levon *
91f5207bJohn Levon * Permission is hereby granted, free of charge, to any person obtaining a copy
101f5207bJohn Levon * of this software and associated documentation files (the "Software"), to deal
111f5207bJohn Levon * in the Software without restriction, including without limitation the rights
121f5207bJohn Levon * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
131f5207bJohn Levon * copies of the Software, and to permit persons to whom the Software is
141f5207bJohn Levon * furnished to do so, subject to the following conditions:
151f5207bJohn Levon *
161f5207bJohn Levon * The above copyright notice and this permission notice shall be included in
171f5207bJohn Levon * all copies or substantial portions of the Software.
181f5207bJohn Levon *
191f5207bJohn Levon * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
201f5207bJohn Levon * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211f5207bJohn Levon * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
221f5207bJohn Levon * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
231f5207bJohn Levon * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
241f5207bJohn Levon * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
251f5207bJohn Levon * THE SOFTWARE.
261f5207bJohn Levon *
271f5207bJohn Levon */
281f5207bJohn Levon#include <stdarg.h>
291f5207bJohn Levon#include <stdlib.h>
301f5207bJohn Levon#include <stdio.h>
311f5207bJohn Levon#include <string.h>
321f5207bJohn Levon#include <ctype.h>
331f5207bJohn Levon#include <unistd.h>
341f5207bJohn Levon#include <fcntl.h>
351f5207bJohn Levon
361f5207bJohn Levon#include "lib.h"
371f5207bJohn Levon#include "allocate.h"
381f5207bJohn Levon#include "token.h"
391f5207bJohn Levon#include "parse.h"
401f5207bJohn Levon#include "symbol.h"
411f5207bJohn Levon#include "expression.h"
421f5207bJohn Levon#include "compile.h"
431f5207bJohn Levon
441f5207bJohn Levonstatic void clean_up_symbols(struct symbol_list *list)
451f5207bJohn Levon{
461f5207bJohn Levon	struct symbol *sym;
471f5207bJohn Levon
481f5207bJohn Levon	FOR_EACH_PTR(list, sym) {
491f5207bJohn Levon		expand_symbol(sym);
501f5207bJohn Levon		emit_one_symbol(sym);
511f5207bJohn Levon	} END_FOR_EACH_PTR(sym);
521f5207bJohn Levon}
531f5207bJohn Levon
541f5207bJohn Levonint main(int argc, char **argv)
551f5207bJohn Levon{
561f5207bJohn Levon	char *file;
571f5207bJohn Levon	struct string_list *filelist = NULL;
581f5207bJohn Levon
591f5207bJohn Levon	bits_in_bool = 8;
601f5207bJohn Levon
611f5207bJohn Levon	clean_up_symbols(sparse_initialize(argc, argv, &filelist));
62c85f09cJohn Levon	FOR_EACH_PTR(filelist, file) {
631f5207bJohn Levon		struct symbol_list *list;
641f5207bJohn Levon		const char *basename = strrchr(file, '/');
651f5207bJohn Levon		basename = basename ?  basename+1 : file;
661f5207bJohn Levon
671f5207bJohn Levon		list = sparse(file);
681f5207bJohn Levon
691f5207bJohn Levon		// Do type evaluation and simplification
701f5207bJohn Levon		emit_unit_begin(basename);
711f5207bJohn Levon		clean_up_symbols(list);
721f5207bJohn Levon		emit_unit_end();
73c85f09cJohn Levon	} END_FOR_EACH_PTR(file);
741f5207bJohn Levon
751f5207bJohn Levon#if 0
761f5207bJohn Levon	// And show the allocation statistics
771f5207bJohn Levon	show_ident_alloc();
781f5207bJohn Levon	show_token_alloc();
791f5207bJohn Levon	show_symbol_alloc();
801f5207bJohn Levon	show_expression_alloc();
811f5207bJohn Levon	show_statement_alloc();
821f5207bJohn Levon	show_string_alloc();
831f5207bJohn Levon	show_bytes_alloc();
841f5207bJohn Levon#endif
851f5207bJohn Levon	return 0;
861f5207bJohn Levon}
87