Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik committed Jan 7, 2024
1 parent 6068941 commit e8ff89b
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions include/xsk/arc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class assembler
function const* func_;
assembly const* assembly_;
utils::writer script_;
utils::writer dev_map_;
u32 dev_map_inst_count_;
utils::writer devmap_;
std::unordered_map<std::string, u16> strpool_;
std::vector<export_ref> exports_;
std::vector<import_ref> imports_;
std::vector<string_ref> strings_;
std::vector<animtree_ref> anims_;
u32 devmap_count_;

public:
assembler(context const* ctx);
Expand Down
8 changes: 7 additions & 1 deletion include/xsk/arc/common/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ enum class opcode : u8
OP_Count,
};

struct sourcepos
{
u16 line;
u16 column;
};

struct instruction
{
using ptr = std::unique_ptr<instruction>;

u32 index;
u32 size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;
std::pair<position::counter_type, position::counter_type> pos;

static auto make() -> instruction::ptr
{
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/common/location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class position
{
public:
typedef const std::string filename_type;
typedef int counter_type;
typedef u16 counter_type;

filename_type *filename;
counter_type line;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#pragma once

#include "xsk/arc/common/asset.hpp"
#include "xsk/arc/common/location.hpp"
#include "xsk/arc/common/assembly.hpp"
#include "xsk/arc/common/buffer.hpp"
#include "xsk/arc/common/location.hpp"
#include "xsk/arc/common/exception.hpp"
#include "xsk/arc/common/lookahead.hpp"
#include "xsk/arc/common/directive.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class compiler
std::vector<scope> scopes_;
std::unordered_map<std::string, expr const*> constants_;
std::string animtree_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
bool can_break_;
bool can_continue_;
bool developer_thread_;
std::pair<position::counter_type, position::counter_type> debug_pos_;

public:
compiler(context* ctx);
Expand Down
4 changes: 2 additions & 2 deletions include/xsk/gsc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class assembler
assembly const* assembly_;
utils::writer script_;
utils::writer stack_;
utils::writer dev_map_;
u32 dev_map_inst_count_;
utils::writer devmap_;
u32 devmap_count_;

public:
assembler(context const* ctx);
Expand Down
8 changes: 7 additions & 1 deletion include/xsk/gsc/common/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,21 @@ enum class opcode : u8
OP_count,
};

struct sourcepos
{
u16 line;
u16 column;
};

struct instruction
{
using ptr = std::unique_ptr<instruction>;

u32 index;
u32 size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;
std::pair<position::counter_type, position::counter_type> pos;

static auto make() -> instruction::ptr
{
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/common/location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class position
{
public:
typedef const std::string filename_type;
typedef int counter_type;
typedef u16 counter_type;

filename_type *filename;
counter_type line;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "xsk/gsc/common/asset.hpp"
#include "xsk/gsc/common/scope.hpp"
#include "xsk/gsc/common/buffer.hpp"
#include "xsk/gsc/common/location.hpp"
#include "xsk/gsc/common/assembly.hpp"
#include "xsk/gsc/common/location.hpp"
#include "xsk/gsc/common/exception.hpp"
#include "xsk/gsc/common/lookahead.hpp"
#include "xsk/gsc/common/directive.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class compiler
std::vector<scope*> break_blks_;
std::vector<scope*> continue_blks_;
std::string animname_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
bool can_break_;
bool can_continue_;
bool developer_thread_;
bool animload_;
std::pair<position::counter_type, position::counter_type> debug_pos_;

public:
compiler(context* ctx);
Expand Down
1 change: 0 additions & 1 deletion include/xsk/stdinc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <queue>
#include <regex>
#include <set>
Expand Down
27 changes: 13 additions & 14 deletions src/arc/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ auto assembler::assemble(assembly const& data, std::string const& name) -> std::
{
assembly_ = &data;
script_.clear();
dev_map_.clear();
devmap_.clear();
strpool_.clear();
exports_.clear();
imports_.clear();
strings_.clear();
anims_.clear();
dev_map_inst_count_ = 0;
devmap_count_ = 0;
auto head = header{};

dev_map_.pos(sizeof(u32));
devmap_.pos(sizeof(u32));
script_.pos((ctx_->props() & props::headerxx) ? 0 : (ctx_->props() & props::header72) ? 72 : 64);
process_string(name);

Expand Down Expand Up @@ -188,7 +188,7 @@ auto assembler::assemble(assembly const& data, std::string const& name) -> std::
head.flags = 0;
head.name = resolve_string(name);

auto endpos = script_.pos();
auto const endpos = script_.pos();

script_.pos(0);
script_.write<u64>(ctx_->magic());
Expand Down Expand Up @@ -226,12 +226,12 @@ auto assembler::assemble(assembly const& data, std::string const& name) -> std::
script_.write<u8>(head.flags);
script_.pos(endpos);

auto const dev_endpos = dev_map_.pos();
dev_map_.pos(0);
dev_map_.write<u32>(dev_map_inst_count_);
dev_map_.pos(dev_endpos);
auto const dev_endpos = devmap_.pos();
devmap_.pos(0);
devmap_.write<u32>(devmap_count_);
devmap_.pos(dev_endpos);

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

auto assembler::assemble_function(function& func) -> void
Expand Down Expand Up @@ -278,11 +278,10 @@ auto assembler::assemble_function(function& func) -> void

auto assembler::assemble_instruction(instruction const& inst) -> void
{
dev_map_inst_count_++;
dev_map_.write<u32>(script_.pos());
dev_map_.write<position::counter_type>(inst.pos.first);
dev_map_.write<position::counter_type>(inst.pos.second);

devmap_count_++;
devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line);
devmap_.write<u16>(inst.pos.column);
script_.write<u8>(static_cast<u8>(ctx_->opcode_id(inst.opcode)));

switch (inst.opcode)
Expand Down
25 changes: 12 additions & 13 deletions src/gsc/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ auto assembler::assemble(assembly const& data) -> std::tuple<buffer, buffer, buf
assembly_ = &data;
script_.clear();
stack_.clear();
dev_map_.clear();
dev_map_inst_count_ = 0;
devmap_.clear();
devmap_count_ = 0;

dev_map_.pos(sizeof(u32));
devmap_.pos(sizeof(u32));
script_.write<u8>(ctx_->opcode_id(opcode::OP_End));

for (auto const& func : data.functions)
{
assemble_function(*func);
}

auto const dev_endpos = dev_map_.pos();
dev_map_.pos(0);
dev_map_.write<u32>(dev_map_inst_count_);
dev_map_.pos(dev_endpos);
auto const dev_endpos = devmap_.pos();
devmap_.pos(0);
devmap_.write<u32>(devmap_count_);
devmap_.pos(dev_endpos);

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

auto assembler::assemble_function(function const& func) -> void
Expand Down Expand Up @@ -69,11 +69,10 @@ auto assembler::assemble_function(function const& func) -> void

auto assembler::assemble_instruction(instruction const& inst) -> void
{
dev_map_inst_count_++;
dev_map_.write<u32>(script_.pos());
dev_map_.write<position::counter_type>(inst.pos.first);
dev_map_.write<position::counter_type>(inst.pos.second);

devmap_count_++;
devmap_.write<u32>(script_.pos());
devmap_.write<u16>(inst.pos.line);
devmap_.write<u16>(inst.pos.column);
script_.write<u8>(ctx_->opcode_id(inst.opcode));

switch (inst.opcode)
Expand Down
8 changes: 4 additions & 4 deletions src/tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ auto compile_file(game game, mach mach, fs::path file, fs::path rel) -> result
utils::file::save(fs::path{ "compiled" } / rel, result);
std::cout << fmt::format("compiled {}\n", rel.generic_string());

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());
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension(".gscmap"), std::get<2>(outbin).data, std::get<2>(outbin).size);
std::cout << fmt::format("saved developer map {}\n", rel.generic_string());
}
}

Expand Down Expand Up @@ -799,8 +799,8 @@ auto compile_file(game game, mach mach, fs::path const& file, fs::path rel) -> r
utils::file::save(fs::path{ "compiled" } / rel, outbin.first.data, outbin.first.size);
std::cout << fmt::format("compiled {}\n", rel.generic_string());

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());
utils::file::save(fs::path{ "compiled" } / fs::path{ "developer_maps" } / rel.replace_extension(".gscmap"), outbin.second.data, outbin.second.size);
std::cout << fmt::format("saved developer map {}\n", rel.generic_string());

return result::success;
}
Expand Down

0 comments on commit e8ff89b

Please sign in to comment.