Skip to content

Commit

Permalink
use tuple/pair for dev_map
Browse files Browse the repository at this point in the history
  • Loading branch information
ineed bots committed Dec 29, 2023
1 parent 7f777b5 commit ed91463
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 40 deletions.
3 changes: 1 addition & 2 deletions include/xsk/arc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class assembler

public:
assembler(context const* ctx);
auto assemble(assembly const& data, std::string const& name = {}) -> buffer;
auto get_dev_map() -> buffer;
auto assemble(assembly const& data, std::string const& name = {}) -> std::pair<buffer, buffer>;

private:
auto assemble_function(function& func) -> void;
Expand Down
3 changes: 1 addition & 2 deletions include/xsk/gsc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class assembler

public:
assembler(context const* ctx);
auto assemble(assembly const& data) -> std::pair<buffer, buffer>;
auto get_dev_map() -> buffer;
auto assemble(assembly const& data) -> std::tuple<buffer, buffer, buffer>;

private:
auto assemble_function(function const& func) -> void;
Expand Down
9 changes: 2 additions & 7 deletions src/arc/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ assembler::assembler(context const* ctx) : ctx_{ ctx }, script_{ ctx->endian() =
{
}

auto assembler::assemble(assembly const& data, std::string const& name) -> buffer
auto assembler::assemble(assembly const& data, std::string const& name) -> std::pair<buffer, buffer>
{
assembly_ = &data;
script_.clear();
Expand Down Expand Up @@ -224,12 +224,7 @@ auto assembler::assemble(assembly const& data, std::string const& name) -> buffe
script_.write<u8>(head.flags);
script_.pos(endpos);

return buffer{ script_.data(), script_.pos() };
}

auto assembler::get_dev_map() -> buffer
{
return buffer{ dev_map_.data(), dev_map_.pos() };
return { buffer{ script_.data(), script_.pos() }, buffer{ dev_map_.data(), dev_map_.pos() } };
}

auto assembler::assemble_function(function& func) -> void
Expand Down
1 change: 1 addition & 0 deletions src/arc/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ auto compiler::emit_program(program const& prog) -> void
developer_thread_ = false;
animtree_ = {};
index_ = 0;
debug_pos_ = {};

for (auto const& include : prog.includes)
{
Expand Down
9 changes: 2 additions & 7 deletions src/gsc/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ assembler::assembler(context const* ctx) : ctx_{ ctx }, script_{ ctx->endian() =
{
}

auto assembler::assemble(assembly const& data) -> std::pair<buffer, buffer>
auto assembler::assemble(assembly const& data) -> std::tuple<buffer, buffer, buffer>
{
assembly_ = &data;
script_.clear();
Expand All @@ -28,12 +28,7 @@ auto assembler::assemble(assembly const& data) -> std::pair<buffer, buffer>
assemble_function(*func);
}

return { buffer{ script_.data(), script_.pos() }, buffer{ stack_.data(), stack_.pos() } };
}

auto assembler::get_dev_map() -> buffer
{
return buffer{ dev_map_.data(), dev_map_.pos() };
return { buffer{ script_.data(), script_.pos() }, buffer{ stack_.data(), stack_.pos() }, buffer{ dev_map_.data(), dev_map_.pos() } };
}

auto assembler::assemble_function(function const& func) -> void
Expand Down
1 change: 1 addition & 0 deletions src/gsc/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ auto compiler::emit_program(program const& prog) -> void
animload_ = false;
animname_ = {};
index_ = 1;
debug_pos_ = {};

ctx_->init_includes();

Expand Down
42 changes: 20 additions & 22 deletions src/tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ auto assemble_file(game game, mach mach, fs::path file, fs::path rel) -> void
if (zonetool)
{
auto path = fs::path{ "assembled" } / rel;
utils::file::save(path, outbin.first.data, outbin.first.size);
utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size);
utils::file::save(path, std::get<0>(outbin).data, std::get<0>(outbin).size);
utils::file::save(path.replace_extension(".cgsc.stack"), std::get<1>(outbin).data, std::get<1>(outbin).size);
std::cout << fmt::format("assembled {}\n", rel.generic_string());
}
else
{
asset script;
script.name = "GSC"s;

script.bytecode.resize(outbin.first.size);
std::memcpy(script.bytecode.data(), outbin.first.data, script.bytecode.size());
script.bytecode.resize(std::get<0>(outbin).size);
std::memcpy(script.bytecode.data(), std::get<0>(outbin).data, script.bytecode.size());

script.buffer.resize(outbin.second.size);
std::memcpy(script.buffer.data(), outbin.second.data, script.buffer.size());
script.buffer.resize(std::get<1>(outbin).size);
std::memcpy(script.buffer.data(), std::get<1>(outbin).data, script.buffer.size());
script.buffer = utils::zlib::compress(script.buffer);

script.len = static_cast<std::uint32_t>(outbin.second.size);
script.len = static_cast<std::uint32_t>(std::get<1>(outbin).size);
script.compressedLen = static_cast<std::uint32_t>(script.buffer.size());
script.bytecodeLen = static_cast<std::uint32_t>(script.bytecode.size());

Expand Down Expand Up @@ -263,34 +263,33 @@ auto compile_file(game game, mach mach, fs::path file, fs::path rel) -> void
if (zonetool)
{
auto path = fs::path{ "compiled" } / rel;
utils::file::save(path, outbin.first.data, outbin.first.size);
utils::file::save(path.replace_extension(".cgsc.stack"), outbin.second.data, outbin.second.size);
utils::file::save(path, std::get<0>(outbin).data, std::get<0>(outbin).size);
utils::file::save(path.replace_extension(".cgsc.stack"), std::get<1>(outbin).data, std::get<1>(outbin).size);
std::cout << fmt::format("compiled {}\n", rel.generic_string());
}
else
{
asset script;
script.name = "GSC"s;

script.bytecode.resize(outbin.first.size);
std::memcpy(script.bytecode.data(), outbin.first.data, script.bytecode.size());
script.bytecode.resize(std::get<0>(outbin).size);
std::memcpy(script.bytecode.data(), std::get<0>(outbin).data, script.bytecode.size());

script.buffer.resize(outbin.second.size);
std::memcpy(script.buffer.data(), outbin.second.data, script.buffer.size());
script.buffer.resize(std::get<1>(outbin).size);
std::memcpy(script.buffer.data(), std::get<1>(outbin).data, script.buffer.size());
script.buffer = utils::zlib::compress(script.buffer);

script.len = static_cast<std::uint32_t>(outbin.second.size);
script.len = static_cast<std::uint32_t>(std::get<1>(outbin).size);
script.compressedLen = static_cast<std::uint32_t>(script.buffer.size());
script.bytecodeLen = static_cast<std::uint32_t>(script.bytecode.size());

auto result = script.serialize();
utils::file::save(fs::path{ "compiled" } / rel, result);
std::cout << fmt::format("compiled {}\n", rel.generic_string());

auto dev_map = contexts[game][mach]->assembler().get_dev_map();
if (dev_map.size > 0)
if (std::get<2>(outbin).size > 0)
{
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel, dev_map.data, dev_map.size);
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel, std::get<2>(outbin).data, std::get<2>(outbin).size);
std::cout << fmt::format("wrote developer map {}\n", rel.generic_string());
}
}
Expand Down Expand Up @@ -711,7 +710,7 @@ void assemble_file(game game, mach mach, fs::path const& file, fs::path rel)
auto outasm = contexts[game][mach]->source().parse_assembly(data);
auto outbin = contexts[game][mach]->assembler().assemble(*outasm);

utils::file::save(fs::path{ "assembled" } / rel, outbin.data, outbin.size);
utils::file::save(fs::path{ "assembled" } / rel, outbin.first.data, outbin.first.size);
std::cout << fmt::format("assembled {}\n", rel.generic_string());
}
catch (std::exception const& e)
Expand Down Expand Up @@ -758,13 +757,12 @@ void compile_file(game game, mach mach, fs::path const& file, fs::path rel)
auto outasm = contexts[game][mach]->compiler().compile(file.string(), data);
auto outbin = contexts[game][mach]->assembler().assemble(*outasm);

utils::file::save(fs::path{ "compiled" } / rel, outbin.data, outbin.size);
utils::file::save(fs::path{ "compiled" } / rel, outbin.first.data, outbin.first.size);
std::cout << fmt::format("compiled {}\n", rel.generic_string());

auto dev_map = contexts[game][mach]->assembler().get_dev_map();
if (dev_map.size > 0)
if (outbin.second.size > 0)
{
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel, dev_map.data, dev_map.size);
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel, outbin.second.data, outbin.second.size);
std::cout << fmt::format("wrote developer map {}\n", rel.generic_string());
}
}
Expand Down

0 comments on commit ed91463

Please sign in to comment.