Skip to contentSkip to conversation

Add annotation for inline function call.

PATCH New Christopher Li 1 participant 1 message Feb 10, 2007 Sparse checker

lore
Share & tools
lore

Christopher Li

author maintainer
#0 lore raw

PATCH 1/1 Add annotation for inline function call.

Sparse inline function body at evaluation. It very hard to find out the original function call. This change try to preserved the original call is preserved as annotation.

parse.h +2 -0
Index: sparse/parse.h
===================================================================
@@ -55,6 +55,8 @@ struct statement {
 		struct /* compound_struct */ {
 			struct statement_list *stmts;
 			struct symbol *ret;
+			struct symbol *inline_fn;
+			struct statement *args;
 		};
 		struct /* labeled_struct */ {
 			struct symbol *label_identifier;

Index: sparse/expression.h
===================================================================

evaluate.c +1 -1
Index: sparse/evaluate.c
===================================================================
@@ -2791,7 +2791,7 @@ struct symbol *evaluate_statement(struct
 		 * Then, evaluate each statement, making the type of the
 		 * compound statement be the type of the last statement
 		 */
-		type = NULL;
+		type = evaluate_statement(stmt->args);
 		FOR_EACH_PTR(stmt->stmts, s) {
 			type = evaluate_statement(s);
 		} END_FOR_EACH_PTR(s);
inline.c +7 -4
Index: sparse/inline.c
===================================================================
@@ -443,8 +443,9 @@ void copy_statement(struct statement *sr
 	FOR_EACH_PTR(src->stmts, stmt) {
 		add_statement(&dst->stmts, copy_one_statement(stmt));
 	} END_FOR_EACH_PTR(stmt);
-
+	dst->args = copy_one_statement(src->args);
 	dst->ret = copy_symbol(src->pos, src->ret);
+	dst->inline_fn = src->inline_fn;
 }
 
 static struct symbol *create_copy_symbol(struct symbol *orig)
@@ -489,6 +490,7 @@ int inline_function(struct expression *e
 	}
 	if (fn->expanding)
 		return 0;
+
 	fn->expanding = 1;
 
 	name_list = fn->arguments;
@@ -517,13 +519,14 @@ int inline_function(struct expression *e
 	} END_FOR_EACH_PTR(arg);
 	FINISH_PTR_LIST(name);
 
+	copy_statement(fn->inline_stmt, stmt);
+
 	if (arg_decl) {
 		struct statement *decl = alloc_statement(expr->pos, STMT_DECLARATION);
 		decl->declaration = arg_decl;
-		add_statement(&stmt->stmts, decl);
+		stmt->args = decl;
 	}
-
-	copy_statement(fn->inline_stmt, stmt);
+	stmt->inline_fn = sym;
 
 	unset_replace_list(fn_symbol_list);
 
expand.c +3 -3
Index: sparse/expand.c
===================================================================
@@ -1053,9 +1053,9 @@ static int expand_compound(struct statem
 	if (stmt->ret)
 		expand_symbol(stmt->ret);
 
-	cost = 0;
-	last = NULL;
-	statements = 0;
+	last = stmt->args;
+	cost = expand_statement(last);
+	statements = last != NULL;
 	FOR_EACH_PTR(stmt->stmts, s) {
 		statements++;
 		last = s;
show-parse.c +6 -0
Index: sparse/show-parse.c
===================================================================
@@ -485,6 +485,10 @@ int show_statement(struct statement *stm
 		struct statement *s;
 		int last = 0;
 
+		if (stmt->inline_fn) {
+			show_statement(stmt->args);
+			printf("\tbegin_inline \t%s\n", show_ident(stmt->inline_fn->ident));
+		}
 		FOR_EACH_PTR(stmt->stmts, s) {
 			last = show_statement(s);
 		} END_FOR_EACH_PTR(s);
@@ -496,6 +500,8 @@ int show_statement(struct statement *stm
 			last = new_pseudo();
 			printf("\tld.%d\t\tv%d,[v%d]\n", bits, last, addr);
 		}
+		if (stmt->inline_fn)
+			printf("\tend_inlined\t%s\n", show_ident(stmt->inline_fn->ident));
 		return last;
 	}
 
linearize.h +1 -0
Index: sparse/linearize.h
===================================================================
@@ -196,6 +196,7 @@ enum opcode {
 	OP_SCAST,
 	OP_FPCAST,
 	OP_PTRCAST,
+	OP_INLINED_CALL,
 	OP_CALL,
 	OP_VANEXT,
 	OP_VAARG,
linearize.c +37 -7

106 lines not on this page · raw message