Skip to content

Commit

Permalink
operator test
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Sep 1, 2024
1 parent e6d64bd commit 6900c34
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/acts/compiler/gsc_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4583,6 +4583,20 @@ namespace acts::compiler {
return true;
}

if (obj.HasOpCode(OPCODE_IW_GetPositionRef)) {
auto itl = fobj.m_jumpLocs.find(varName);

if (itl != fobj.m_jumpLocs.end()) {
if (!itl->second.node) {
obj.info.PrintLineMessage(alogs::LVL_ERROR, exp, std::format("The jump location {} can't be referenced", varName));
return false;
}

fobj.AddNode(term, new AscmNodeJump(itl->second.node, OPCODE_IW_GetPositionRef));
return true;
}
}

auto gvarIt = fobj.m_vmInfo->globalvars.find(obj.vmInfo->HashField(varName));

if (gvarIt != fobj.m_vmInfo->globalvars.end()) {
Expand Down
3 changes: 2 additions & 1 deletion src/acts/tools/gsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ namespace tool::gsc {
TYPE_SELF,
TYPE_GET_UNDEFINED,

TYPE_JUMP_STACK_TOP
TYPE_JUMP_STACK_TOP,
TYPE_GET_CODE_REF,
};

inline bool IsJumpType(ASMContextNodeType type) {
Expand Down
17 changes: 17 additions & 0 deletions src/acts/tools/gsc_opcode_nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,23 @@ namespace tool::gsc::opcode {
}
};

class ASMContextNodeCodeRef : public ASMContextNode {
public:
int64_t m_location;

ASMContextNodeCodeRef(int64_t location) :
ASMContextNode(PRIORITY_VALUE, TYPE_VALUE), m_location(location) {
}

ASMContextNode* Clone() const override {
return new ASMContextNodeCodeRef(m_location);
}

void Dump(std::ostream& out, DecompContext& ctx) const override {
out << "LOC_" << std::hex << std::setfill('0') << std::setw(sizeof(int32_t) << 1) << m_location;
}
};

bool IsJumpConditionForceReversed(const ASMContextNodeJumpOperator* op);
ASMContextNode* JumpCondition(ASMContextNodeJumpOperator* op, bool reversed);

Expand Down
43 changes: 42 additions & 1 deletion src/acts/tools/gsc_opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ class OPCodeInfoJumpExpr : public OPCodeInfo {
using OPCodeInfo::OPCodeInfo;

int Dump(std::ostream& out, uint16_t value, ASMContext& context, tool::gsc::T8GSCOBJContext& objctx) const override {
int32_t m_jumpLocation = context.FunctionRelativeLocation(context.m_bcl - 2);
int32_t m_jumpLocation = context.FunctionRelativeLocation(context.m_bcl - ((objctx.m_vmInfo->HasFlag(VmFlags::VMF_OPCODE_U16)) ? 2 : 1));
// get the jump opcode location

if (objctx.m_vmInfo->HasFlag(VmFlags::VMF_ALIGN)) {
Expand Down Expand Up @@ -4119,6 +4119,46 @@ class OPCodeInfoSwitch : public OPCodeInfo {
}
};

class OPCodeInfoGetPositionRef : public OPCodeInfo {
public:
OPCodeInfoGetPositionRef() : OPCodeInfo(OPCODE_IW_GetPositionRef, "GetPositionRef") {}

int Dump(std::ostream& out, uint16_t v, ASMContext& context, tool::gsc::T8GSCOBJContext& objctx) const override {
int32_t opcodeLocation = context.FunctionRelativeLocation(context.m_bcl - ((objctx.m_vmInfo->HasFlag(VmFlags::VMF_OPCODE_U16)) ? 2 : 1));
if (objctx.m_vmInfo->HasFlag(VmFlags::VMF_ALIGN)) {
context.Aligned<int16_t>();
}
auto& bytecode = context.m_bcl;

int16_t delta = *(int16_t*)bytecode;

bytecode += 2;

// push a location and mark it as referenced
byte* refLocation = &context.m_bcl[delta];

out << "." << std::hex << std::setfill('0') << std::setw(sizeof(int32_t) << 1)
<< context.FunctionRelativeLocation(refLocation) << "\n";

tool::gsc::opcode::asmcontextlocation& loc = context.PushLocation(refLocation);

// add ref so this code can be handled
loc.refs.insert(opcodeLocation);

if (context.m_runDecompiler) {
// push location
context.PushASMCNode(new ASMContextNodeCodeRef(loc.rloc));
}


return 0;
}

int Skip(uint16_t value, ASMSkipContext& ctx) const override {
throw std::runtime_error("not impl");
}
};

class OPCodeInfoIWSwitch : public OPCodeInfo {
public:
OPCodeInfoIWSwitch() : OPCodeInfo(OPCODE_IW_Switch, "Switch") {}
Expand Down Expand Up @@ -5263,6 +5303,7 @@ namespace tool::gsc::opcode {
RegisterOpCodeHandler(new OPCodeInfoSingle(OPCODE_IW_WaitTillMatch, "WaitTillMatch", "waittillmatch", true, 2, 2));
// scripts\asm\asm::asm_getanim()'s assertmsg lol
RegisterOpCodeHandler(new OPCodeInfoSingle(OPCODE_T10_FlatArgs, "FlatArgs", "flat_args", true, 2, 0, false));
RegisterOpCodeHandler(new OPCodeInfoGetPositionRef());

RegisterOpCodeHandler(new OPCodeInfoIWNotify(OPCODE_IW_Notify, "Notify"));

Expand Down
2 changes: 2 additions & 0 deletions src/acts/tools/gsc_opcodes_load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ namespace tool::gsc::opcode {
OPCODE_T10_LowerThanOrSuperEqualTo,
OPCODE_IW_GetResourceHash2,

OPCODE_IW_GetPositionRef,

OPCODE_COUNT,
};
void RegisterOpCodesMap();
Expand Down
9 changes: 8 additions & 1 deletion test/gsc-compiler/acts_cer_test.gsc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function autoexec test_ev() {
#c: { #d: "bye", #e: "bye" }
};
test3 = "hello";
test = 42 >== 23 <== 64 === 22 !== false;
test = 2;
//test = 42 >== 23 <== 64 === 22 !== false;
test2 = test ?? 23;
test3 = getthread();
test3 = istrue(true);
Expand Down Expand Up @@ -53,4 +54,10 @@ function test() {

self iprintln("hello: " + v1 + v2 + v3);
}


code_loc:
i++;

return code_loc;
}

0 comments on commit 6900c34

Please sign in to comment.