Add compiler decomp

This commit is contained in:
ineed bots
2023-09-15 16:35:58 -06:00
parent bd25b6429b
commit 15309fc2c0
8 changed files with 5813 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include "cscr_compiler.hpp"
#include "cscr_main.hpp"
#include "cscr_memorytree.hpp"
#include "cscr_parser.hpp"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,202 @@
#pragma once
namespace codsrc
{
void RemoveRefToValue(game::scriptInstance_t inst, game::VariableValue* value);
void Scr_CompileRemoveRefToString(game::scriptInstance_t inst, unsigned int stringVal);
void EmitCanonicalString(game::scriptInstance_t inst, unsigned int stringVal);
void CompileTransferRefToString(unsigned int stringValue, game::scriptInstance_t inst, unsigned int user);
void EmitOpcode(game::scriptInstance_t inst, game::OpcodeVM op, int offset, int callType);
void EmitEnd(game::scriptInstance_t inst);
void EmitReturn(game::scriptInstance_t inst);
void EmitCodepos(game::scriptInstance_t inst, int codepos);
void EmitShort(game::scriptInstance_t inst, int value);
void EmitByte(game::scriptInstance_t inst, int value);
void EmitGetInteger(game::scriptInstance_t inst, int value, game::sval_u sourcePos);
void EmitGetFloat(game::scriptInstance_t inst, float value, game::sval_u sourcePos);
void EmitAnimTree(game::scriptInstance_t inst, game::sval_u sourcePos);
int Scr_FindLocalVarIndex(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos, int create, game::scr_block_s* block);
void EmitCreateLocalVars(game::scriptInstance_t inst, game::scr_block_s* block);
void EmitRemoveLocalVars(game::scriptInstance_t inst, game::scr_block_s* outerBlock, game::scr_block_s* block);
void EmitNOP2(game::scr_block_s* block, game::scriptInstance_t inst, int lastStatement, unsigned int endSourcePos);
void Scr_InitFromChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block);
void Scr_AppendChildBlocks(game::scr_block_s* block, game::scr_block_s** childBlocks, int childCount);
void Scr_MergeChildBlocks(game::scr_block_s** childBlocks, int childCount, game::scr_block_s* block);
void Scr_TransferBlock(game::scr_block_s* to, game::scr_block_s* from);
void EmitSafeSetVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitSafeSetWaittillVariableField(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitGetString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitGetIString(unsigned int value, game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitGetVector(const float* value, game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue);
void Scr_PushValue(game::scriptInstance_t inst, game::VariableCompileValue* constValue);
void EmitCastBool(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitBoolNot(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitBoolComplement(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitSize(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitSelf(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitLevel(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitGame(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitAnim(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitSelfObject(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitLevelObject(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitAnimObject(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitLocalVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitLocalVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void Scr_RegisterLocalVar(unsigned int name, game::sval_u sourcePos, game::scr_block_s* block);
void EmitGameRef(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitClearArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos);
void EmitEmptyArray(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitAnimation(game::scriptInstance_t inst, game::sval_u anim, game::sval_u sourcePos);
void EmitFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos);
void EmitClearFieldVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::sval_u rhsSourcePos);
void EmitObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitDecTop(game::scriptInstance_t inst);
void EmitCastFieldObject(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos);
void EmitArrayVariableRef(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos);
void EmitClearArrayVariable(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u index, game::sval_u sourcePos, game::sval_u indexSourcePos);
void EmitVariableExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block);
int EmitExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::scr_block_s* block);
void AddExpressionListOpcodePos(game::scriptInstance_t inst, game::sval_u exprlist);
void AddFilePrecache(game::scriptInstance_t inst, unsigned int filename, unsigned int sourcePos, bool include, unsigned int* filePosId, unsigned int* fileCountId);
void EmitFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos);
void EmitGetFunction(game::scriptInstance_t inst, game::sval_u func, game::sval_u sourcePos);
int AddFunction(game::scriptInstance_t inst, int func);
void EmitPostScriptFunction(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u nameSourcePos);
void EmitPostScriptFunctionPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u nameSourcePos, game::sval_u sourcePos);
void EmitPostScriptThread(game::scriptInstance_t inst, game::sval_u func, int param_count, int bMethod, game::sval_u sourcePos);
void EmitPostScriptThreadPointer(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, int param_count, int bMethod, game::sval_u sourcePos);
void EmitPostScriptFunctionCall(game::scriptInstance_t inst, int bMethod, int param_count, game::sval_u func_name, game::sval_u nameSourcePos, game::scr_block_s* block);
void EmitPostScriptThreadCall(game::scriptInstance_t inst, int isMethod, int param_count, game::sval_u func_name, game::sval_u sourcePos, game::sval_u nameSourcePos, game::scr_block_s* block);
void EmitPreFunctionCall(game::scriptInstance_t inst);
void EmitPostFunctionCall(game::scriptInstance_t inst, int bMethod, game::sval_u func_name, int param_count, game::scr_block_s* block);
void Scr_BeginDevScript(game::scriptInstance_t isnt, int* type, char** savedPos);
void Scr_EndDevScript(game::scriptInstance_t inst, char** savedPos);
void EmitCallBuiltinOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos);
void EmitCallBuiltinMethodOpcode(game::scriptInstance_t inst, int param_count, game::sval_u sourcePos);
void EmitCall(game::scriptInstance_t inst, game::sval_u func_name, game::sval_u params, int bStatement, game::scr_block_s* block);
void EmitMethod(game::scriptInstance_t inst, game::sval_u expr, game::sval_u func_name, game::sval_u params, game::sval_u methodSourcePos, int bStatement, game::scr_block_s* block);
void LinkThread(game::scriptInstance_t inst, unsigned int threadCountId, game::VariableValue* pos, int allowFarCall);
void LinkFile(game::scriptInstance_t inst, unsigned int filePosId, unsigned int fileCountId);
void CheckThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos);
void EmitCallExpression(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr, int bStatement);
void EmitCallExpressionFieldObject(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr);
void Scr_CreateVector(game::scriptInstance_t inst, game::VariableCompileValue* constValue, game::VariableValue* value);
bool EvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue);
bool EmitOrEvalPrimitiveExpressionList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a5);
void EmitExpressionListFieldObject(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block);
bool EvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue);
bool EmitOrEvalPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block);
void EmitBoolOrExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* block);
void EmitBoolAndExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u expr1sourcePos, game::sval_u expr2sourcePos, game::scr_block_s* a6);
bool EvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue);
bool EmitOrEvalBinaryOperatorExpression(game::scriptInstance_t inst, game::sval_u expr1, game::sval_u expr2, game::sval_u opcode, game::sval_u sourcePos, game::VariableCompileValue* constValue, game::scr_block_s* a8);
void EmitBinaryEqualsOperatorExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u opcode, game::sval_u sourcePos);
void Scr_CalcLocalVarsVariableExpressionRef(game::scr_block_s* block, game::sval_u expr);
bool EvalExpression(game::VariableCompileValue* constValue, game::scriptInstance_t inst, game::sval_u expr);
bool EmitOrEvalExpression(game::scriptInstance_t inst, game::sval_u expr, game::VariableCompileValue* constValue, game::scr_block_s* block);
void EmitExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block);
void EmitVariableExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block);
void EmitArrayPrimitiveExpressionRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsArrayVariableRef(game::sval_u expr, game::scr_block_s* block);
void EmitPrimitiveExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block);
void ConnectBreakStatements(game::scriptInstance_t inst);
void ConnectContinueStatements(game::scriptInstance_t inst);
bool EmitClearVariableExpression(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u rhsSourcePos);
void EmitAssignmentStatement(game::scriptInstance_t inst, game::sval_u lhs, game::sval_u rhs, game::sval_u sourcePos, game::sval_u rhsSourcePos, game::scr_block_s* block);
void EmitCallExpressionStatement(game::scriptInstance_t inst, game::scr_block_s* block, game::sval_u expr);
void EmitReturnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitWaitStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::sval_u waitSourcePos);
void EmitWaittillFrameEnd(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitIfStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock);
void Scr_CalcLocalVarsIfStatement(game::scriptInstance_t inst, game::sval_u stmt, game::scr_block_s* block, game::sval_u* ifStatBlock);
void EmitIfElseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt1, game::sval_u stmt2, game::sval_u sourcePos, game::sval_u elseSourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock);
void Scr_CalcLocalVarsIfElseStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u stmt2, game::scr_block_s* block, game::sval_u* ifStatBlock, game::sval_u* elseStatBlock);
void Scr_AddBreakBlock(game::scriptInstance_t inst, game::scr_block_s* block);
void Scr_AddContinueBlock(game::scriptInstance_t inst, game::scr_block_s* block);
void EmitWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::sval_u sourcePos, game::sval_u whileSourcePos, game::scr_block_s* block, game::sval_u* whileStatBlock);
void Scr_CalcLocalVarsWhileStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmt, game::scr_block_s* block, game::sval_u* whileStatBlock);
void EmitForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::sval_u sourcePos, game::sval_u forSourcePos, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock);
void Scr_CalcLocalVarsForStatement(game::scriptInstance_t inst, game::sval_u stmt1, game::sval_u expr, game::sval_u stmt2, game::sval_u stmt, game::scr_block_s* block, game::sval_u* forStatBlock, game::sval_u* forStatPostBlock);
void EmitIncStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitDecStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void Scr_CalcLocalVarsFormalParameterListInternal(game::sval_u* node, game::scr_block_s* block);
void EmitWaittillStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block);
void EmitWaittillmatchStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u waitSourcePos, game::scr_block_s* block);
void EmitNotifyStatement(game::scriptInstance_t inst, game::sval_u obj, game::sval_u exprlist, game::sval_u sourcePos, game::sval_u notifySourcePos, game::scr_block_s* block);
void EmitEndOnStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u obj, game::sval_u expr, game::sval_u sourcePos, game::sval_u exprSourcePos);
int CompareCaseInfo(const void* elem1, const void* elem2);
void EmitCaseStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos);
void EmitSwitchStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsSwitchStatement(game::scriptInstance_t inst, game::sval_u stmtlist, game::scr_block_s* block);
void EmitSwitchStatement(game::scriptInstance_t inst, game::sval_u expr, game::sval_u stmtlist, game::sval_u sourcePos, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block);
void EmitCaseStatementInfo(game::scriptInstance_t inst, unsigned int name, game::sval_u sourcePos);
void EmitBreakStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitContinueStatement(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitProfStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos, game::OpcodeVM op);
void EmitStatement(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsStatement(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block);
void EmitStatementList(game::scriptInstance_t inst, game::sval_u val, int lastStatement, unsigned int endSourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsStatementList(game::scr_block_s* block, game::scriptInstance_t inst, game::sval_u val);
void Scr_CalcLocalVarsDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::scr_block_s* block, game::sval_u* devStatBlock);
void EmitDeveloperStatementList(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::scr_block_s* block, game::sval_u* devStatBlock);
void EmitFormalParameterList(game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u sourcePos, game::scr_block_s* block);
void SpecifyThread(game::scriptInstance_t inst, game::sval_u val);
void EmitThreadInternal(game::scriptInstance_t inst, game::sval_u val, game::sval_u sourcePos, game::sval_u endSourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsThread(game::sval_u* stmttblock, game::scriptInstance_t inst, game::sval_u exprlist, game::sval_u stmtlist);
void InitThread(int type, game::scriptInstance_t inst);
void EmitNormalThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock);
void EmitDeveloperThread(game::scriptInstance_t inst, game::sval_u val, game::sval_u* stmttblock);
void EmitThread(game::scriptInstance_t inst, game::sval_u val);
void EmitThreadList(game::scriptInstance_t inst, game::sval_u val);
void EmitInclude(game::scriptInstance_t inst, game::sval_u val);
void ScriptCompile(game::scriptInstance_t inst, game::sval_u val, unsigned int filePosId, unsigned int fileCountId, unsigned int scriptId, game::PrecacheEntry* entries, int entriesCount);
void EmitFloat(game::scriptInstance_t inst, float value);
void EmitCanonicalStringConst(game::scriptInstance_t inst, unsigned int stringValue);
int Scr_FindLocalVar(game::scr_block_s* block, int startIndex, unsigned int name);
void Scr_CheckLocalVarsCount(int localVarsCount);
void EmitGetUndefined(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitPrimitiveExpression(game::scriptInstance_t inst, game::sval_u expr, game::scr_block_s* block);
void Scr_EmitAnimation(game::scriptInstance_t inst, char* pos, unsigned int animName, unsigned int sourcePos);
void EmitEvalArray(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos);
void EmitEvalArrayRef(game::scriptInstance_t inst, game::sval_u sourcePos, game::sval_u indexSourcePos);
unsigned int Scr_GetBuiltin(game::scriptInstance_t inst, game::sval_u func_name);
int Scr_GetUncacheType(int type);
int Scr_GetCacheType(int type);
game::BuiltinFunction Scr_GetFunction(const char** pName, int* type);
game::BuiltinFunction GetFunction(game::scriptInstance_t inst, const char** pName, int* type);
game::BuiltinMethod GetMethod(game::scriptInstance_t inst, const char** pName, int* type);
unsigned int GetVariableName(game::scriptInstance_t inst, unsigned int id);
int GetExpressionCount(game::sval_u exprlist);
game::sval_u* GetSingleParameter(game::sval_u exprlist);
void EmitExpressionFieldObject(game::scriptInstance_t inst, game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block);
void EvalInteger(int value, game::sval_u sourcePos, game::VariableCompileValue* constValue);
void EvalFloat(float value, game::sval_u sourcePos, game::VariableCompileValue* constValue);
void EvalString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue* constValue);
void EvalIString(unsigned int value, game::sval_u sourcePos, game::VariableCompileValue* constValue);
void EvalUndefined(game::sval_u sourcePos, game::VariableCompileValue* constValue);
void Scr_PopValue(game::scriptInstance_t inst);
void EmitSetVariableField(game::scriptInstance_t inst, game::sval_u sourcePos);
void EmitFieldVariableRef(game::scriptInstance_t inst, game::sval_u expr, game::sval_u field, game::sval_u sourcePos, game::scr_block_s* block);
void Scr_CalcLocalVarsArrayPrimitiveExpressionRef(game::sval_u expr, game::scr_block_s* block);
BOOL IsUndefinedPrimitiveExpression(game::sval_u expr);
bool IsUndefinedExpression(game::sval_u expr);
void Scr_CopyBlock(game::scr_block_s* from, game::scr_block_s** to);
void Scr_CheckMaxSwitchCases(int count);
void Scr_CalcLocalVarsSafeSetVariableField(game::sval_u expr, game::sval_u sourcePos, game::scr_block_s* block);
void EmitFormalWaittillParameterListRefInternal(game::scriptInstance_t inst, game::sval_u* node, game::scr_block_s* block);
void EmitDefaultStatement(game::scriptInstance_t inst, game::sval_u sourcePos);
char Scr_IsLastStatement(game::scriptInstance_t inst, game::sval_u* node);
void EmitEndStatement(game::scriptInstance_t inst, game::sval_u sourcePos, game::scr_block_s* block);
void EmitProfBeginStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos);
void EmitProfEndStatement(game::scriptInstance_t inst, game::sval_u profileName, game::sval_u sourcePos);
void Scr_CalcLocalVarsIncStatement(game::sval_u expr, game::scr_block_s* block);
void Scr_CalcLocalVarsWaittillStatement(game::sval_u exprlist, game::scr_block_s* block);
void EmitFormalParameterListInternal(game::scriptInstance_t inst, game::sval_u* node, game::scr_block_s* block);
unsigned int SpecifyThreadPosition(game::scriptInstance_t inst, unsigned int posId, unsigned int name, unsigned int sourcePos, int type);
void Scr_CalcLocalVarsFormalParameterList(game::sval_u exprlist, game::scr_block_s* block);
void SetThreadPosition(game::scriptInstance_t inst, unsigned int posId);
void EmitIncludeList(game::scriptInstance_t inst, game::sval_u val);
}