// Copyright 2021 xensik. All rights reserved. // // Use of this source code is governed by a GNU GPLv3 license // that can be found in the LICENSE file. #pragma once namespace xsk::gsc::iw5 { class assembler : public gsc::assembler { std::string filename_; utils::byte_buffer_ptr script_; utils::byte_buffer_ptr stack_; std::vector functions_; std::unordered_map labels_; public: auto output_script() -> std::vector; auto output_stack() -> std::vector; void assemble(const std::string& file, std::vector& data); void assemble(const std::string& file, std::vector& functions); private: void assemble_function(const gsc::function_ptr& func); void assemble_instruction(const gsc::instruction_ptr& inst); void assemble_builtin_call(const gsc::instruction_ptr& inst, bool method, bool arg_num); void assemble_local_call(const gsc::instruction_ptr& inst, bool thread); void assemble_far_call(const gsc::instruction_ptr& inst, bool thread); void assemble_switch(const gsc::instruction_ptr& inst); void assemble_end_switch(const gsc::instruction_ptr& inst); void assemble_field_variable(const gsc::instruction_ptr& inst); void assemble_jump(const gsc::instruction_ptr& inst, bool expr, bool back); void assemble_offset(std::int32_t offset); auto resolve_function(const std::string& name) -> std::uint32_t; auto resolve_label(const std::string& name) -> std::uint32_t; }; } // namespace xsk::gsc::iw5