sourcepawn/decompiler/code_analyzer.h
changeset 2320 88550c031d23
child 2322 2125ced692ac
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcepawn/decompiler/code_analyzer.h	Tue Sep 23 21:20:40 2008 -0700
     1.3 @@ -0,0 +1,141 @@
     1.4 +#ifndef _INCLUDE_SP_DECOMP_CODE_ANALYZER_H_
     1.5 +#define _INCLUDE_SP_DECOMP_CODE_ANALYZER_H_
     1.6 +
     1.7 +#include <sp_vm_types.h>
     1.8 +
     1.9 +enum Opcode
    1.10 +{
    1.11 +	_OP_VAR		= -1,
    1.12 +	_OP_STMT	= -2,
    1.13 +	_OP_CONST	= -3,
    1.14 +	_OP_STORE	= -4,
    1.15 +	_OP_NEW		= -5,
    1.16 +	_OP_MODULO	= -6,
    1.17 +	_OP_EMPTY	= -7,
    1.18 +#define OPDEF(num,name,str,params) \
    1.19 +	OP_##name = num,
    1.20 +#include "opcodes.tbl"
    1.21 +#undef OPDEF
    1.22 +};
    1.23 +
    1.24 +struct sp_opdef_t
    1.25 +{
    1.26 +	const char *name;
    1.27 +	int params;
    1.28 +};
    1.29 +
    1.30 +struct FuncVar;
    1.31 +
    1.32 +struct BaseNode
    1.33 +{
    1.34 +	BaseNode(cell_t _op) : op(_op)
    1.35 +	{
    1.36 +	}
    1.37 +	cell_t op;
    1.38 +};
    1.39 +
    1.40 +struct ConstNode : public BaseNode
    1.41 +{
    1.42 +	ConstNode(cell_t _val) : BaseNode(_OP_CONST), val(_val)
    1.43 +	{
    1.44 +	}
    1.45 +	cell_t val;
    1.46 +};
    1.47 +
    1.48 +struct StmtNode : public BaseNode
    1.49 +{
    1.50 +	StmtNode(cell_t _op, BaseNode *_node, StmtNode *_next) : BaseNode(_op)
    1.51 +		, node(_node)
    1.52 +		, next(_next)
    1.53 +	{
    1.54 +	}
    1.55 +	BaseNode *node;
    1.56 +	StmtNode *next;
    1.57 +};
    1.58 +
    1.59 +struct FunctionInfo;
    1.60 +
    1.61 +struct CallNode : public BaseNode
    1.62 +{
    1.63 +	CallNode(FunctionInfo *f, BaseNode **t, unsigned int c) : BaseNode(OP_CALL)
    1.64 +		, func(f)
    1.65 +		, args(t)
    1.66 +		, argc(c)
    1.67 +	{
    1.68 +	}
    1.69 +	FunctionInfo *func;
    1.70 +	BaseNode **args;
    1.71 +	unsigned int argc;
    1.72 +};
    1.73 +
    1.74 +struct DefineNode : public BaseNode
    1.75 +{
    1.76 +	TempNode(const char *name
    1.77 +	char name[32];
    1.78 +};
    1.79 +
    1.80 +struct UnaryNode : public BaseNode
    1.81 +{
    1.82 +	UnaryNode(cell_t _op, BaseNode *_node) : BaseNode(_op), node(_node)
    1.83 +	{
    1.84 +	}
    1.85 +	BaseNode *node;
    1.86 +};
    1.87 +
    1.88 +struct VarNode : public BaseNode
    1.89 +{
    1.90 +	VarNode(FuncVar *_var) : BaseNode(_OP_VAR), var(_var)
    1.91 +	{
    1.92 +	}
    1.93 +	FuncVar *var;
    1.94 +};
    1.95 +
    1.96 +struct BinOpNode : public BaseNode
    1.97 +{
    1.98 +	BinOpNode(cell_t _op, BaseNode *_left, BaseNode *_right) : BaseNode(_op)
    1.99 +		,left(_left)
   1.100 +		,right(_right)
   1.101 +	{
   1.102 +	}
   1.103 +	BaseNode *left;
   1.104 +	BaseNode *right;
   1.105 +};
   1.106 +
   1.107 +struct DeclNode : public BaseNode
   1.108 +{
   1.109 +	DeclNode(VarNode *_var, BaseNode *_expr) : BaseNode(_OP_NEW), var(_var), expr(_expr)
   1.110 +	{
   1.111 +	}
   1.112 +	VarNode *var;
   1.113 +	BaseNode *expr;
   1.114 +};
   1.115 +
   1.116 +struct FuncVar
   1.117 +{
   1.118 +	sp_fdbg_symbol_t *sym;
   1.119 +	sp_fdbg_arraydim_t *dims;
   1.120 +	sp_tag_t *tag;
   1.121 +	const char *name;
   1.122 +	DeclNode *new_stmt;
   1.123 +};
   1.124 +
   1.125 +struct FunctionInfo
   1.126 +{
   1.127 +	char name[64];
   1.128 +	sp_fdbg_symbol_t *sym;
   1.129 +	FuncVar known_args[SP_MAX_EXEC_PARAMS];
   1.130 +	unsigned int num_known_args;
   1.131 +	sp_tag_t *tag;
   1.132 +	uint32_t code_addr;
   1.133 +	uint32_t code_end;
   1.134 +	bool is_public;
   1.135 +	FunctionInfo *next;
   1.136 +	FuncVar *known_vars;
   1.137 +	unsigned int num_known_vars;
   1.138 +};
   1.139 +
   1.140 +struct sp_decomp_t;
   1.141 +
   1.142 +int Sp_DecompFunction(sp_decomp_t *dc, uint32_t code_addr, bool is_public);
   1.143 +
   1.144 +#endif //_INCLUDE_SP_DECOMP_CODE_ANALYZER_H_