Skip to content

Commit

Permalink
refactor usize
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik committed Nov 12, 2024
1 parent 8bc7c9b commit 3a06635
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 309 deletions.
19 changes: 10 additions & 9 deletions include/xsk/gsc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ class assembler
private:
auto assemble_function(function const& func) -> void;
auto assemble_instruction(instruction const& inst) -> void;
auto assemble_builtin_call(instruction const& inst, bool method, bool args) -> void;
auto assemble_local_call(instruction const& inst, bool thread) -> void;
auto assemble_far_call(instruction const& inst, bool thread) -> void;
auto assemble_switch(instruction const& inst) -> void;
auto assemble_end_switch(instruction const& inst) -> void;
auto assemble_field_variable(instruction const& inst) -> void;
auto assemble_formal_params(instruction const& inst) -> void;
auto assemble_field(instruction const& inst) -> void;
auto assemble_params(instruction const& inst) -> void;
auto assemble_call_far(instruction const& inst, bool thread) -> void;
auto assemble_call_far2(instruction const& inst, bool thread) -> void;
auto assemble_call_local(instruction const& inst, bool thread) -> void;
auto assemble_call_builtin(instruction const& inst, bool method, bool args) -> void;
auto assemble_jump(instruction const& inst, bool expr, bool back) -> void;
auto assemble_switch(instruction const& inst) -> void;
auto assemble_switch_table(instruction const& inst) -> void;
auto assemble_offset(i32 offs) -> void;
auto resolve_function(std::string const& name) -> i32;
auto resolve_label(std::string const& name) -> i32;
auto resolve_function(std::string const& name) -> usize;
auto resolve_label(std::string const& name) -> usize;
auto encrypt_string(std::string const& str) -> std::string;
};

Expand Down
10 changes: 5 additions & 5 deletions include/xsk/gsc/common/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ struct instruction
{
using ptr = std::unique_ptr<instruction>;

u32 index;
u32 size;
usize index;
usize size;
sourcepos pos;
opcode opcode;
std::vector<std::string> data;
Expand All @@ -246,12 +246,12 @@ struct function
{
using ptr = std::unique_ptr<function>;

u32 index;
u32 size;
usize index;
usize size;
u32 id;
std::string name;
std::vector<instruction::ptr> instructions;
std::unordered_map<u32, std::string> labels;
std::unordered_map<usize, std::string> labels;

static auto make() -> function::ptr
{
Expand Down
4 changes: 2 additions & 2 deletions include/xsk/gsc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class compiler
std::vector<scope*> continue_blks_;
std::string animname_;
sourcepos debug_pos_;
u32 index_;
u32 label_idx_;
usize index_;
usize label_idx_;
bool can_break_;
bool can_continue_;
bool developer_thread_;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class context

auto engine_name() const -> std::string_view;

auto opcode_size(opcode op) const -> u32;
auto opcode_size(opcode op) const -> usize;

auto opcode_id(opcode op) const -> u8;

Expand Down
2 changes: 1 addition & 1 deletion include/xsk/gsc/decompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class decompiler
context const* ctx_;
program::ptr program_;
decl_function::ptr func_;
std::unordered_map<u32, std::string> labels_;
std::unordered_map<usize, std::string> labels_;
std::vector<std::string> expr_labels_;
std::vector<std::string> tern_labels_;
std::stack<node::ptr> stack_;
Expand Down
8 changes: 4 additions & 4 deletions include/xsk/utils/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ struct reader
auto read() -> T;
auto read_i24() -> i32;
auto read_cstr() -> std::string;
auto read_bytes(u32 pos, u32 count) -> std::string;
auto read_bytes(usize pos, usize count) -> std::string;
auto is_avail() const -> bool;
auto seek(u32 size) -> void;
auto seek_neg(u32 size) -> void;
auto align(u32 size) -> u32;
auto seek(usize size) -> void;
auto seek_neg(usize size) -> void;
auto align(usize size) -> usize;
auto data() const -> u8 const*;
auto size() const -> usize;
auto pos() const -> usize;
Expand Down
21 changes: 11 additions & 10 deletions include/xsk/utils/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ struct writer
using error = std::runtime_error;

private:
static constexpr u32 default_size = 0x100000;
static constexpr usize default_size = 0x100000;
u8* data_;
u32 size_;
u32 pos_ = 0;
usize size_;
usize pos_ = 0;
bool swap_;

public:
Expand All @@ -26,21 +26,22 @@ struct writer
auto operator=(writer const&) -> writer& = delete;
auto operator=(writer&&) -> writer& = delete;
explicit writer(bool swap = false);
writer(u32 size, bool swap = false);
writer(usize size, bool swap = false);
~writer();
auto clear() -> void;
template <typename T>
auto write(T data) -> void;
auto write_i24(i32 data) -> void;
auto write_string(std::string const& data) -> void;
auto write_cstr(std::string const& data) -> void;
auto is_avail() const -> bool;
auto seek(u32 size) -> void;
auto seek_neg(u32 size) -> void;
auto align(u32 size) -> u32;
auto seek(usize size) -> void;
auto seek_neg(usize size) -> void;
auto align(usize size) -> usize;
auto data() const -> u8 const*;
auto size() const -> u32;
auto pos() const -> u32;
auto pos(u32 pos) -> void;
auto size() const -> usize;
auto pos() const -> usize;
auto pos(usize pos) -> void;
};

} // namespace xsk::utils
Loading

0 comments on commit 3a06635

Please sign in to comment.