1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Example trivial client program that uses the sparse library 3f08c3bdfSopenharmony_ci * to tokenize, preprocess and parse a C file, and prints out 4f08c3bdfSopenharmony_ci * the results. 5f08c3bdfSopenharmony_ci * 6f08c3bdfSopenharmony_ci * Copyright (C) 2003 Transmeta Corp. 7f08c3bdfSopenharmony_ci * 2003-2004 Linus Torvalds 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#include <stdarg.h> 28f08c3bdfSopenharmony_ci#include <stdlib.h> 29f08c3bdfSopenharmony_ci#include <stdio.h> 30f08c3bdfSopenharmony_ci#include <string.h> 31f08c3bdfSopenharmony_ci#include <ctype.h> 32f08c3bdfSopenharmony_ci#include <unistd.h> 33f08c3bdfSopenharmony_ci#include <fcntl.h> 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci#include "lib.h" 36f08c3bdfSopenharmony_ci#include "allocate.h" 37f08c3bdfSopenharmony_ci#include "token.h" 38f08c3bdfSopenharmony_ci#include "parse.h" 39f08c3bdfSopenharmony_ci#include "symbol.h" 40f08c3bdfSopenharmony_ci#include "expression.h" 41f08c3bdfSopenharmony_ci#include "linearize.h" 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_cistatic void emit_entrypoint(struct entrypoint *ep) 44f08c3bdfSopenharmony_ci{ 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci} 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_cistatic void emit_symbol(struct symbol *sym) 49f08c3bdfSopenharmony_ci{ 50f08c3bdfSopenharmony_ci struct entrypoint *ep; 51f08c3bdfSopenharmony_ci ep = linearize_symbol(sym); 52f08c3bdfSopenharmony_ci if (ep) 53f08c3bdfSopenharmony_ci emit_entrypoint(ep); 54f08c3bdfSopenharmony_ci} 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_cistatic void emit_symbol_list(struct symbol_list *list) 57f08c3bdfSopenharmony_ci{ 58f08c3bdfSopenharmony_ci struct symbol *sym; 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci FOR_EACH_PTR(list, sym) { 61f08c3bdfSopenharmony_ci expand_symbol(sym); 62f08c3bdfSopenharmony_ci emit_symbol(sym); 63f08c3bdfSopenharmony_ci } END_FOR_EACH_PTR(sym); 64f08c3bdfSopenharmony_ci} 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ciint main(int argc, char **argv) 67f08c3bdfSopenharmony_ci{ 68f08c3bdfSopenharmony_ci struct string_list *filelist = NULL; 69f08c3bdfSopenharmony_ci char *file; 70f08c3bdfSopenharmony_ci 71f08c3bdfSopenharmony_ci emit_symbol_list(sparse_initialize(argc, argv, &filelist)); 72f08c3bdfSopenharmony_ci FOR_EACH_PTR(filelist, file) { 73f08c3bdfSopenharmony_ci emit_symbol_list(sparse(file)); 74f08c3bdfSopenharmony_ci } END_FOR_EACH_PTR(file); 75f08c3bdfSopenharmony_ci return 0; 76f08c3bdfSopenharmony_ci} 77