mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 20:02:40 +01:00
rwengine: remove unused ScriptDisassembly
This commit is contained in:
parent
deb7db5faf
commit
6142e0bf80
@ -127,8 +127,6 @@ set(RWENGINE_SOURCES
|
||||
|
||||
src/script/SCMFile.cpp
|
||||
src/script/SCMFile.hpp
|
||||
src/script/ScriptDisassembly.cpp
|
||||
src/script/ScriptDisassembly.hpp
|
||||
src/script/ScriptFunctions.cpp
|
||||
src/script/ScriptFunctions.hpp
|
||||
src/script/ScriptMachine.cpp
|
||||
|
@ -1,93 +0,0 @@
|
||||
#include <script/SCMFile.hpp>
|
||||
#include <script/ScriptDisassembly.hpp>
|
||||
#include <script/ScriptMachine.hpp>
|
||||
#include <script/ScriptModule.hpp>
|
||||
|
||||
ScriptDisassembly::ScriptDisassembly(ScriptModule* _codes, SCMFile* _scm)
|
||||
: codes(_codes), scm(_scm) {
|
||||
}
|
||||
|
||||
void ScriptDisassembly::disassemble(SCMAddress startAddress) {
|
||||
for (SCMAddress a = startAddress; a < scm->getMainSize();) {
|
||||
auto opcode = scm->read<SCMOpcode>(a);
|
||||
uint8_t flags = 0;
|
||||
|
||||
bool isNegatedConditional = ((opcode & SCM_NEGATE_CONDITIONAL_MASK) ==
|
||||
SCM_NEGATE_CONDITIONAL_MASK);
|
||||
opcode = opcode & ~SCM_NEGATE_CONDITIONAL_MASK;
|
||||
|
||||
if (isNegatedConditional) {
|
||||
flags |= OpcodeFlagNegatedConditional;
|
||||
}
|
||||
|
||||
ScriptFunctionMeta* foundcode;
|
||||
if (!codes->findOpcode(opcode, &foundcode)) {
|
||||
throw IllegalInstruction(opcode, a, "Disassembler");
|
||||
}
|
||||
ScriptFunctionMeta& code = *foundcode;
|
||||
|
||||
SCMParams parameters;
|
||||
auto instructionAddress = a;
|
||||
a += sizeof(SCMOpcode);
|
||||
|
||||
bool hasExtraParameters = code.arguments < 0;
|
||||
auto requiredParams = std::abs(code.arguments);
|
||||
|
||||
for (int p = 0; p < requiredParams || hasExtraParameters; ++p) {
|
||||
auto type_r = scm->read<SCMByte>(a);
|
||||
auto type = static_cast<SCMType>(type_r);
|
||||
|
||||
if (type_r > 42) {
|
||||
// for implicit strings, we need the byte we just read.
|
||||
type = TString;
|
||||
} else {
|
||||
a += sizeof(SCMByte);
|
||||
}
|
||||
|
||||
parameters.push_back(SCMOpcodeParameter{type, {0}});
|
||||
switch (type) {
|
||||
case EndOfArgList:
|
||||
hasExtraParameters = false;
|
||||
break;
|
||||
case TInt8:
|
||||
parameters.back().integer = scm->read<std::uint8_t>(a);
|
||||
a += sizeof(SCMByte);
|
||||
break;
|
||||
case TInt16:
|
||||
parameters.back().integer = scm->read<std::int16_t>(a);
|
||||
a += sizeof(SCMByte) * 2;
|
||||
break;
|
||||
case TGlobal: {
|
||||
auto v = scm->read<std::uint16_t>(a);
|
||||
parameters.back().globalPtr =
|
||||
reinterpret_cast<void*>(v); //* SCM_VARIABLE_SIZE;
|
||||
a += sizeof(SCMByte) * 2;
|
||||
} break;
|
||||
case TLocal: {
|
||||
auto v = scm->read<std::uint16_t>(a);
|
||||
parameters.back().globalPtr =
|
||||
reinterpret_cast<void*>(v * SCM_VARIABLE_SIZE);
|
||||
a += sizeof(SCMByte) * 2;
|
||||
} break;
|
||||
case TInt32:
|
||||
parameters.back().integer = scm->read<std::uint32_t>(a);
|
||||
a += sizeof(SCMByte) * 4;
|
||||
break;
|
||||
case TString:
|
||||
std::copy(scm->data() + a, scm->data() + a + 8,
|
||||
parameters.back().string);
|
||||
a += sizeof(SCMByte) * 8;
|
||||
break;
|
||||
case TFloat16:
|
||||
parameters.back().real = scm->read<std::int16_t>(a) / 16.f;
|
||||
a += sizeof(SCMByte) * 2;
|
||||
break;
|
||||
default:
|
||||
throw UnknownType(type, a, "Disassembler");
|
||||
break;
|
||||
};
|
||||
}
|
||||
instructions[instructionAddress] =
|
||||
InstructionInfo{opcode, parameters, flags};
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef _SCRIPTDISASSEMBLY_HPP_
|
||||
#define _SCRIPTDISASSEMBLY_HPP_
|
||||
#include <script/ScriptTypes.hpp>
|
||||
|
||||
class SCMFile;
|
||||
|
||||
/**
|
||||
* Extracts instruction level information from a SCM file
|
||||
*/
|
||||
class ScriptDisassembly {
|
||||
public:
|
||||
enum {
|
||||
/// The opcode's conditional is negated
|
||||
OpcodeFlagNegatedConditional = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Information about a single call to a single opcode and
|
||||
* it's parameters
|
||||
*/
|
||||
struct InstructionInfo {
|
||||
/// Numeric Opcode ID
|
||||
SCMOpcode opcode;
|
||||
/// Parameter information
|
||||
SCMParams parameters;
|
||||
uint8_t flags;
|
||||
};
|
||||
|
||||
ScriptDisassembly(ScriptModule* codes, SCMFile* scm);
|
||||
|
||||
/**
|
||||
* Execute the disassembly routine.
|
||||
*
|
||||
* If there is an error during disassembly, an exeption will be
|
||||
* thrown
|
||||
*/
|
||||
void disassemble(SCMAddress startAddress);
|
||||
|
||||
std::map<SCMAddress, InstructionInfo>& getInstructions() {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
private:
|
||||
ScriptModule* codes;
|
||||
SCMFile* scm;
|
||||
|
||||
std::map<SCMAddress, InstructionInfo> instructions;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user