cleanup t6 code

This commit is contained in:
xensik 2022-03-16 21:59:08 +01:00
parent 7a8184adfb
commit 9af726e690
8 changed files with 19 additions and 26 deletions

View File

@ -32,8 +32,11 @@ void assembler::assemble(const std::string& file, assembly::ptr& data)
filename_ = file;
assembly_ = std::move(data);
stringlist_.clear();
std::memset(&header_, 0 ,sizeof(header_));
exports_.clear();
imports_.clear();
animtrees_.clear();
stringtables_.clear();
std::memset(&header_, 0, sizeof(header_));
// skip header
script_->pos(64);
@ -638,7 +641,7 @@ void assembler::align_instruction(const instruction::ptr& inst)
case opcode::OP_SafeCreateLocalVariables:
script_->seek(1);
{
for (auto i = 0; i < inst->data.size(); i++)
for (auto i = 0u; i < inst->data.size(); i++)
{
inst->size += script_->align(2) + 2;
add_string_reference(inst->data[i], string_type::canonical, script_->pos());
@ -849,7 +852,7 @@ void assembler::add_import_reference(const std::vector<std::string>& data, std::
{
for (auto& entry : imports_)
{
if (entry.space == data[0] && entry.name == data[1] && entry.params == std::stoi(data[2]) && entry.params == std::stoi(data[3]))
if (entry.space == data[0] && entry.name == data[1] && entry.params == std::stoi(data[2]) && entry.flags == std::stoi(data[3]))
{
entry.refs.push_back(ref);
return;

View File

@ -16,7 +16,7 @@ auto compiler::output() -> assembly::ptr
return std::move(assembly_);
}
auto compiler::output_data() -> std::vector<std::uint8_t>
auto compiler::output_raw() -> std::vector<std::uint8_t>
{
output_ = std::make_unique<utils::byte_buffer>(0x100000);
@ -534,8 +534,6 @@ void compiler::emit_stmt_while(const ast::stmt_while::ptr& stmt)
auto break_loc = create_label();
auto continue_loc = insert_label();
auto begin_loc = continue_loc;
if (stmt->test == ast::kind::expr_not)
{
emit_expr(stmt->test.as_not->rvalue);
@ -1371,18 +1369,11 @@ void compiler::emit_expr_parameters(const ast::expr_parameters::ptr&)
{
if (local_stack_.size() == 0)
{
emit_opcode( opcode::OP_CheckClearParams);
emit_opcode(opcode::OP_CheckClearParams);
}
else
{
std::vector<std::string> data;
for (const auto& entry : local_stack_)
{
data.push_back(entry);
}
emit_opcode(opcode::OP_SafeCreateLocalVariables, data);
emit_opcode(opcode::OP_SafeCreateLocalVariables, local_stack_);
}
}
@ -2405,7 +2396,7 @@ void compiler::insert_label(const std::string& name)
}
else
{
function_->labels.insert({index_, name});
function_->labels.insert({ index_, name });
}
}

View File

@ -31,7 +31,7 @@ class compiler : public arc::compiler
public:
auto output() -> assembly::ptr;
auto output_data() -> std::vector<std::uint8_t>;
auto output_raw() -> std::vector<std::uint8_t>;
void compile(const std::string& file, std::vector<std::uint8_t>& data);
void mode(build mode);

View File

@ -14,7 +14,7 @@ auto disassembler::output() -> assembly::ptr
return std::move(assembly_);
}
auto disassembler::output_data() -> std::vector<std::uint8_t>
auto disassembler::output_raw() -> std::vector<std::uint8_t>
{
output_ = std::make_unique<utils::byte_buffer>(0x100000);
@ -39,8 +39,6 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
filename_ = file;
script_ = std::make_unique<utils::byte_buffer>(data);
assembly_ = std::make_unique<assembly>();
std::memset(&header_, 0, sizeof(header_));
exports_.clear();
imports_.clear();
strings_.clear();
@ -50,6 +48,7 @@ void disassembler::disassemble(const std::string& file, std::vector<std::uint8_t
anim_refs_.clear();
import_refs_.clear();
labels_.clear();
std::memset(&header_, 0, sizeof(header_));
// header
header_.magic = script_->read<std::uint64_t>();
@ -490,7 +489,7 @@ void disassembler::disassemble_localvars(const instruction::ptr& inst)
{
const auto count = script_->read<std::uint8_t>();
for (auto i = 0; i < count; i++)
for (auto i = 0u; i < count; i++)
{
disassemble_string(inst);
inst->size += 2;

View File

@ -27,7 +27,7 @@ class disassembler : public arc::disassembler
public:
auto output() -> assembly::ptr;
auto output_data() -> std::vector<std::uint8_t>;
auto output_raw() -> std::vector<std::uint8_t>;
void disassemble(const std::string& file, std::vector<std::uint8_t>& data);
private:

View File

@ -467,7 +467,7 @@ void disassemble_file(game game, const std::filesystem::path& file)
disassembler.disassemble(file.string(), data);
utils::file::save((std::filesystem::path("disassembled/t6") / next).string(), disassembler.output_data());
utils::file::save((std::filesystem::path("disassembled/t6") / next).string(), disassembler.output_raw());
std::cout << "disassembled " << path.replace_extension() << "\n";
}
catch (const std::exception& e)

View File

@ -15,7 +15,7 @@ public:
virtual ~compiler() = default;
virtual auto output() -> assembly::ptr = 0;
virtual auto output_data() -> std::vector<std::uint8_t> = 0;
virtual auto output_raw() -> std::vector<std::uint8_t> = 0;
virtual void compile(const std::string& file, std::vector<std::uint8_t>& data) = 0;
};

View File

@ -15,7 +15,7 @@ public:
virtual ~disassembler() = default;
virtual auto output() -> assembly::ptr = 0;
virtual auto output_data() -> std::vector<std::uint8_t> = 0;
virtual auto output_raw() -> std::vector<std::uint8_t> = 0;
virtual void disassemble(const std::string& file, std::vector<std::uint8_t>& data) = 0;
};