Exemplo n.º 1
0
static void
dump_scope(scope_t *scope)
{
	scope_t *cur_scope;

	/*
	 * Emit the first patch for this scope
	 */
	emit_patch(scope, 0);

	/*
	 * Dump each scope within this one.
	 */
	cur_scope = TAILQ_FIRST(&scope->inner_scope);

	while (cur_scope != NULL) {

		dump_scope(cur_scope);

		cur_scope = TAILQ_NEXT(cur_scope, scope_links);
	}

	/*
	 * Emit the second, closing, patch for this scope
	 */
	emit_patch(scope, 1);
}
Exemplo n.º 2
0
INT main(INT argcc, CHAR * argvc[])
{    
	CHAR * argv[] = {
		"xoc.exe",
		"..\\..\\test\\test_ansic.c",
	    "-dump","cfe.tmp",
	};
	INT argc = sizeof(argv)/sizeof(argv[0]);
#else
INT main(INT argc, CHAR * argv[])
{
#endif
	if (!process_cmd(argc, argv)) return 1;
	init_parser();
	g_fe_sym_tab = new SYM_TAB(64); 
	fe_process();

	//Show you all info that generated by CfrontEnd.
	dump_scope(get_global_scope(), 0xFFFFFFFF);	
	show_err();
	show_warn();
	fprintf(stdout, "\n%s - (%d) error(s), (%d) warnging(s)\n",
					g_source_file_name, 
					g_err_msg_list.get_elem_count(),
					g_warn_msg_list.get_elem_count());
	fini_parser();
	finidump();
	return 0;
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
	int  ch;
	int  retval;
	char *inputfilename;
	scope_t *sentinal;

	STAILQ_INIT(&patches);
	SLIST_INIT(&search_path);
	STAILQ_INIT(&seq_program);
	TAILQ_INIT(&cs_tailq);
	SLIST_INIT(&scope_stack);

	/* Set Sentinal scope node */
	sentinal = scope_alloc();
	sentinal->type = SCOPE_ROOT;
	
	includes_search_curdir = 1;
	appname = *argv;
	regfile = NULL;
	listfile = NULL;
#if DEBUG
	yy_flex_debug = 0;
	mm_flex_debug = 0;
	yydebug = 0;
	mmdebug = 0;
#endif
	while ((ch = getopt(argc, argv, "d:i:l:n:o:p:r:I:X")) != -1) {
		switch(ch) {
		case 'd':
#if DEBUG
			if (strcmp(optarg, "s") == 0) {
				yy_flex_debug = 1;
				mm_flex_debug = 1;
			} else if (strcmp(optarg, "p") == 0) {
				yydebug = 1;
				mmdebug = 1;
			} else {
				fprintf(stderr, "%s: -d Requires either an "
					"'s' or 'p' argument\n", appname);
				usage();
			}
#else
			stop("-d: Assembler not built with debugging "
			     "information", EX_SOFTWARE);
#endif
			break;
		case 'i':
			stock_include_file = optarg;
			break;
		case 'l':
			/* Create a program listing */
			if ((listfile = fopen(optarg, "w")) == NULL) {
				perror(optarg);
				stop(NULL, EX_CANTCREAT);
			}
			listfilename = optarg;
			break;
		case 'n':
			/* Don't complain about the -nostdinc directrive */
			if (strcmp(optarg, "ostdinc")) {
				fprintf(stderr, "%s: Unknown option -%c%s\n",
					appname, ch, optarg);
				usage();
				/* NOTREACHED */
			}
			break;
		case 'o':
			if ((ofile = fopen(optarg, "w")) == NULL) {
				perror(optarg);
				stop(NULL, EX_CANTCREAT);
			}
			ofilename = optarg;
			break;
		case 'p':
			/* Create Register Diagnostic "printing" Functions */
			if ((regdiagfile = fopen(optarg, "w")) == NULL) {
				perror(optarg);
				stop(NULL, EX_CANTCREAT);
			}
			regdiagfilename = optarg;
			break;
		case 'r':
			if ((regfile = fopen(optarg, "w")) == NULL) {
				perror(optarg);
				stop(NULL, EX_CANTCREAT);
			}
			regfilename = optarg;
			break;
		case 'I':
		{
			path_entry_t include_dir;

			if (strcmp(optarg, "-") == 0) {
				if (includes_search_curdir == 0) {
					fprintf(stderr, "%s: Warning - '-I-' "
							"specified multiple "
							"times\n", appname);
				}
				includes_search_curdir = 0;
				for (include_dir = SLIST_FIRST(&search_path);
				     include_dir != NULL;
				     include_dir = SLIST_NEXT(include_dir,
							      links))
					/*
					 * All entries before a '-I-' only
					 * apply to includes specified with
					 * quotes instead of "<>".
					 */
					include_dir->quoted_includes_only = 1;
			} else {
				include_dir =
				    (path_entry_t)malloc(sizeof(*include_dir));
				if (include_dir == NULL) {
					perror(optarg);
					stop(NULL, EX_OSERR);
				}
				include_dir->directory = strdup(optarg);
				if (include_dir->directory == NULL) {
					perror(optarg);
					stop(NULL, EX_OSERR);
				}
				include_dir->quoted_includes_only = 0;
				SLIST_INSERT_HEAD(&search_path, include_dir,
						  links);
			}
			break;
		}
		case 'X':
			/* icc version of -nostdinc */
			break;
		case '?':
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 1) {
		fprintf(stderr, "%s: No input file specifiled\n", appname);
		usage();
		/* NOTREACHED */
	}

	if (regdiagfile != NULL
	 && (regfile == NULL || stock_include_file == NULL)) {
		fprintf(stderr,
			"%s: The -p option requires the -r and -i options.\n",
			appname);
		usage();
		/* NOTREACHED */
	}
	symtable_open();
	inputfilename = *argv;
	include_file(*argv, SOURCE_FILE);
	retval = yyparse();
	if (retval == 0) {
		if (SLIST_FIRST(&scope_stack) == NULL
		 || SLIST_FIRST(&scope_stack)->type != SCOPE_ROOT) {
			stop("Unterminated conditional expression", EX_DATAERR);
			/* NOTREACHED */
		}

		/* Process outmost scope */
		process_scope(SLIST_FIRST(&scope_stack));
		/*
		 * Decend the tree of scopes and insert/emit
		 * patches as appropriate.  We perform a depth first
		 * tranversal, recursively handling each scope.
		 */
		/* start at the root scope */
		dump_scope(SLIST_FIRST(&scope_stack));

		/* Patch up forward jump addresses */
		back_patch();

		if (ofile != NULL)
			output_code();
		if (regfile != NULL)
			symtable_dump(regfile, regdiagfile);
		if (listfile != NULL)
			output_listing(inputfilename);
	}

	stop(NULL, 0);
	/* NOTREACHED */
	return (0);
}
Exemplo n.º 4
0
//Recusively dumping SCOPE trees.
void dump_scope(SCOPE * s, UINT flag)
{
	if (g_tfile == NULL) return;
	static CHAR buf[8192];
	buf[0] = 0;
	note("\nSCOPE(id:%d, level:%d)", SCOPE_id(s), SCOPE_level(s));
	g_indent++;
	
	//symbols
	SYM_LIST * sym_list = SCOPE_sym_tab_list(s);
	if (sym_list != NULL) {
		note("\nSYMBAL:");
		g_indent++;
		note("\n");
		while (sym_list != NULL) {
			note("%s\n", SYM_name(SYM_LIST_sym(sym_list)));
			sym_list = SYM_LIST_next(sym_list);
		}
		g_indent--;
	}

	//all of defined customer label in code
	LABEL_INFO * li = SCOPE_label_list(s).get_head(); 
	if (li != NULL) {
		note("\nDEFINED LABEL:");		
		g_indent++;
		note("\n");
		for (; li != NULL; li = SCOPE_label_list(s).get_next()) { 
			IS_TRUE0(map_lab2lineno(li) != 0);
			note("%s (def in line:%d)\n",
				 SYM_name(LABEL_INFO_name(li)),
				 map_lab2lineno(li));
		}
		g_indent--;
	}

	//refered customer label in code
	li = SCOPE_ref_label_list(s).get_head(); 
	if (li != NULL) {
		note("\nREFED LABEL:");
		g_indent++;		
		note("\n");
		for (; li != NULL; li = SCOPE_ref_label_list(s).get_next()) { 
			note("%s (use in line:%d)\n", 
				 SYM_name(LABEL_INFO_name(li)),
				 map_lab2lineno(li));
		}
		g_indent--;
	}

	//enums
	ENUM_LIST * el = SCOPE_enum_list(s);
	if (el != NULL) {
		note("\nENUM LIST:");
		g_indent++;
		note("\n");
		while (el != NULL) {
			buf[0] = 0;
			format_enum_complete(buf, ENUM_LIST_enum(el));
			note("%s\n", buf);
			el = ENUM_LIST_next(el);
		}
		g_indent--;
	}

	//user defined type, by 'typedef'
	USER_TYPE_LIST * utl = SCOPE_user_type_list(s);
	if (utl != NULL) {
		note("\nUSER TYPE:");
		g_indent++;	
		note("\n");
		while (utl != NULL) {
			buf[0] = 0;
			format_user_type_spec(buf, USER_TYPE_LIST_utype(utl));
			note("%s\n", buf);
			utl = USER_TYPE_LIST_next(utl);
		}
		g_indent--;
	}

	//structs
	STRUCT * st = SCOPE_struct_list(s);
	if (st != NULL) {
		note("\nSTRUCT:");
		g_indent++;	
		note("\n");
		while (st != NULL) {
			buf[0] = 0;
			format_struct_complete(buf, st);
			note("%s\n", buf);
			st = USER_TYPE_LIST_next(st);
		}
		g_indent--;
	}

	//unions
	UNION * un = SCOPE_union_list(s);
	if (un != NULL) {
		note("\nUNION:");
		g_indent++;
		note("\n");
		while (un != NULL) {
			buf[0] = 0;
			format_union_complete(buf, un);
			note("%s\n", buf);
			un = USER_TYPE_LIST_next(un);
		}
		g_indent--;
	}

	//declarations
	DECL * dcl = SCOPE_decl_list(s);
	if (dcl != NULL) {
		note("\nDECLARATIONS:");
		note("\n");
		g_indent++;
		while (dcl != NULL) {
			buf[0] = 0;
			format_declaration(buf, dcl);
			note("%s", buf);
			dump_decl(dcl);

			//Dump function body
			if (DECL_is_fun_def(dcl) && HAVE_FLAG(flag, DUMP_SCOPE_FUNC_BODY)) {
				g_indent += 2;
				dump_scope(DECL_fun_body(dcl), flag);
				g_indent -= 2;
			}

			//Dump initializing value/expression.
			if (DECL_is_init(DECL_decl_list(dcl))) {
				note("= ");
				g_indent += 2;
				dump_tree(DECL_init_tree(DECL_decl_list(dcl)));
				g_indent -= 2;
			}
			
			note("\n");
			dcl = DECL_next(dcl);
		}
		g_indent--;
	}
	fflush(g_tfile);

	if (HAVE_FLAG(flag, DUMP_SCOPE_STMT_TREE)) {
		TREE * t = SCOPE_stmt_list(s);
		if (t != NULL) {
			note("\nSTATEMENT:");
			g_indent++;	
			note("\n");
			dump_trees(t);	
			g_indent--;
		}
	}
	g_indent--;
}