sourcepawn/decompiler/code_analyzer.cpp
changeset 2322 2125ced692ac
parent 2320 88550c031d23
child 2325 7a24ee5557fb
     1.1 --- a/sourcepawn/decompiler/code_analyzer.cpp	Tue Sep 23 21:21:03 2008 -0700
     1.2 +++ b/sourcepawn/decompiler/code_analyzer.cpp	Tue Sep 23 22:00:47 2008 -0700
     1.3 @@ -43,6 +43,15 @@
     1.4  	FunctionInfo *func;
     1.5  };
     1.6  
     1.7 +DefineNode::DefineNode(BaseNode *o, const char *fmt, ...) : BaseNode(_OP_DEFINE), other(o)
     1.8 +{
     1.9 +	va_list ap;
    1.10 +	
    1.11 +	va_start(ap, fmt);
    1.12 +	Sp_FormatArgs(name, sizeof(name), fmt, ap);
    1.13 +	va_end(ap);
    1.14 +}
    1.15 +
    1.16  static FunctionInfo *sp_InferFuncPrototype(sp_decomp_t *dc, uint32_t code_addr, bool is_public)
    1.17  {
    1.18  	sp_tag_t *pTag;
    1.19 @@ -333,6 +342,14 @@
    1.20  {
    1.21  	switch (node->op)
    1.22  	{
    1.23 +	case _OP_DEFINE:
    1.24 +		{
    1.25 +			DefineNode *def = (DefineNode *)node;
    1.26 +
    1.27 +			buffer->Append("new %s = ", def->name);
    1.28 +			sp_DebugExprTree(buffer, def->other, is_stmt);
    1.29 +			break;
    1.30 +		}
    1.31  	case OP_CALL:
    1.32  		{
    1.33  			CallNode *call = (CallNode *)node;
    1.34 @@ -345,6 +362,13 @@
    1.35  			buffer->Append(")");
    1.36  			break;
    1.37  		}
    1.38 +	case _OP_USE:
    1.39 +		{
    1.40 +			UseNode *unode = (UseNode *)node;
    1.41 +
    1.42 +			buffer->Append("%s", unode->def->name);
    1.43 +			break;
    1.44 +		}
    1.45  	case _OP_VAR:
    1.46  		{
    1.47  			VarNode *var_node = (VarNode *)node;
    1.48 @@ -577,6 +601,7 @@
    1.49  	FunctionInfo *func, *tfunc;
    1.50  	cell_t p1, p2, op;
    1.51  	FuncVar *v1, *v2;
    1.52 +	unsigned int callnumber = 0;
    1.53  	unsigned int stack_entries = 0;
    1.54  	StackEntry eval_stack[MAX_STACK_ENTRIES];
    1.55  
    1.56 @@ -637,6 +662,11 @@
    1.57  				assert(sp <= 0);
    1.58  
    1.59  				pri = new (graph) CallNode(tfunc, nodes, cnode->val);
    1.60 +				pri = new (graph) DefineNode(pri, "call%03x", ++callnumber);
    1.61 +				rtemp = new (graph) StmtNode(_OP_STMT, pri, NULL);
    1.62 +				root_tail->next = rtemp;
    1.63 +				root_tail = rtemp;
    1.64 +				pri = new (graph) UseNode((DefineNode *)pri);
    1.65  				
    1.66  				break;
    1.67  			}