1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Example trivial client program that uses the sparse library 3f08c3bdfSopenharmony_ci * and x86 backend. 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * Copyright (C) 2003 Transmeta Corp. 6f08c3bdfSopenharmony_ci * 2003 Linus Torvalds 7f08c3bdfSopenharmony_ci * Copyright 2003 Jeff Garzik 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 10f08c3bdfSopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 11f08c3bdfSopenharmony_ci * in the Software without restriction, including without limitation the rights 12f08c3bdfSopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13f08c3bdfSopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 14f08c3bdfSopenharmony_ci * furnished to do so, subject to the following conditions: 15f08c3bdfSopenharmony_ci * 16f08c3bdfSopenharmony_ci * The above copyright notice and this permission notice shall be included in 17f08c3bdfSopenharmony_ci * all copies or substantial portions of the Software. 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20f08c3bdfSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21f08c3bdfSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22f08c3bdfSopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23f08c3bdfSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24f08c3bdfSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25f08c3bdfSopenharmony_ci * THE SOFTWARE. 26f08c3bdfSopenharmony_ci * 27f08c3bdfSopenharmony_ci */ 28f08c3bdfSopenharmony_ci#include <stdarg.h> 29f08c3bdfSopenharmony_ci#include <stdlib.h> 30f08c3bdfSopenharmony_ci#include <stdio.h> 31f08c3bdfSopenharmony_ci#include <string.h> 32f08c3bdfSopenharmony_ci#include <ctype.h> 33f08c3bdfSopenharmony_ci#include <unistd.h> 34f08c3bdfSopenharmony_ci#include <fcntl.h> 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci#include "lib.h" 37f08c3bdfSopenharmony_ci#include "allocate.h" 38f08c3bdfSopenharmony_ci#include "token.h" 39f08c3bdfSopenharmony_ci#include "parse.h" 40f08c3bdfSopenharmony_ci#include "symbol.h" 41f08c3bdfSopenharmony_ci#include "expression.h" 42f08c3bdfSopenharmony_ci#include "compile.h" 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_cistatic void clean_up_symbols(struct symbol_list *list) 45f08c3bdfSopenharmony_ci{ 46f08c3bdfSopenharmony_ci struct symbol *sym; 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci FOR_EACH_PTR(list, sym) { 49f08c3bdfSopenharmony_ci expand_symbol(sym); 50f08c3bdfSopenharmony_ci emit_one_symbol(sym); 51f08c3bdfSopenharmony_ci } END_FOR_EACH_PTR(sym); 52f08c3bdfSopenharmony_ci} 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ciint main(int argc, char **argv) 55f08c3bdfSopenharmony_ci{ 56f08c3bdfSopenharmony_ci char *file; 57f08c3bdfSopenharmony_ci struct string_list *filelist = NULL; 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_ci bits_in_bool = 8; 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci clean_up_symbols(sparse_initialize(argc, argv, &filelist)); 62f08c3bdfSopenharmony_ci FOR_EACH_PTR(filelist, file) { 63f08c3bdfSopenharmony_ci struct symbol_list *list; 64f08c3bdfSopenharmony_ci const char *basename = strrchr(file, '/'); 65f08c3bdfSopenharmony_ci basename = basename ? basename+1 : file; 66f08c3bdfSopenharmony_ci 67f08c3bdfSopenharmony_ci list = sparse(file); 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ci // Do type evaluation and simplification 70f08c3bdfSopenharmony_ci emit_unit_begin(basename); 71f08c3bdfSopenharmony_ci clean_up_symbols(list); 72f08c3bdfSopenharmony_ci emit_unit_end(); 73f08c3bdfSopenharmony_ci } END_FOR_EACH_PTR(file); 74f08c3bdfSopenharmony_ci 75f08c3bdfSopenharmony_ci#if 0 76f08c3bdfSopenharmony_ci // And show the allocation statistics 77f08c3bdfSopenharmony_ci show_ident_alloc(); 78f08c3bdfSopenharmony_ci show_token_alloc(); 79f08c3bdfSopenharmony_ci show_symbol_alloc(); 80f08c3bdfSopenharmony_ci show_expression_alloc(); 81f08c3bdfSopenharmony_ci show_statement_alloc(); 82f08c3bdfSopenharmony_ci show_string_alloc(); 83f08c3bdfSopenharmony_ci show_bytes_alloc(); 84f08c3bdfSopenharmony_ci#endif 85f08c3bdfSopenharmony_ci return 0; 86f08c3bdfSopenharmony_ci} 87