2023-03-02 10:41:32 -05:00
|
|
|
// Copyright 2023 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
|
|
|
|
|
2023-05-13 13:24:57 -04:00
|
|
|
#include "xsk/arc/common/types.hpp"
|
|
|
|
#include "xsk/arc/source.hpp"
|
|
|
|
#include "xsk/arc/assembler.hpp"
|
|
|
|
#include "xsk/arc/disassembler.hpp"
|
|
|
|
#include "xsk/arc/compiler.hpp"
|
|
|
|
#include "xsk/arc/decompiler.hpp"
|
2023-03-02 10:41:32 -05:00
|
|
|
|
|
|
|
namespace xsk::arc
|
|
|
|
{
|
|
|
|
|
|
|
|
class context
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using fs_callback = std::function<std::vector<u8>(std::string const&)>;
|
|
|
|
|
|
|
|
context(props props, engine engine, endian endian, system system, u64 magic);
|
|
|
|
|
|
|
|
auto props() const -> props { return props_; }
|
|
|
|
auto build() const -> build { return build_; }
|
|
|
|
auto engine() const -> engine { return engine_; }
|
|
|
|
auto endian() const -> endian { return endian_; }
|
|
|
|
auto system() const -> system { return system_; }
|
|
|
|
auto instance() const -> instance { return instance_; }
|
|
|
|
auto magic() const -> u64 { return magic_; }
|
|
|
|
auto source() -> source& { return source_; }
|
2023-05-13 13:24:57 -04:00
|
|
|
auto assembler() -> assembler& { return assembler_; }
|
2023-03-02 10:41:32 -05:00
|
|
|
auto disassembler() -> disassembler& { return disassembler_; }
|
2023-05-13 13:24:57 -04:00
|
|
|
auto compiler() -> compiler& { return compiler_; }
|
2023-03-02 10:41:32 -05:00
|
|
|
auto decompiler() -> decompiler& { return decompiler_; }
|
|
|
|
|
|
|
|
auto init(arc::build build, fs_callback callback) -> void;
|
|
|
|
auto cleanup() -> void;
|
|
|
|
auto engine_name() const -> std::string_view;
|
|
|
|
|
|
|
|
auto opcode_size(opcode op) const -> u32;
|
2023-05-13 13:24:57 -04:00
|
|
|
auto opcode_id(opcode op) const -> u16;
|
2023-03-02 10:41:32 -05:00
|
|
|
auto opcode_name(opcode op) const -> std::string;
|
|
|
|
auto opcode_enum(std::string const& name) const -> opcode;
|
|
|
|
auto opcode_enum(u16 id) const -> opcode;
|
|
|
|
auto hash_id(std::string const& name) const -> u32;
|
|
|
|
auto hash_name(u32 id) const -> std::string;
|
2023-05-13 13:24:57 -04:00
|
|
|
auto make_token(std::string_view str) const -> std::string;
|
|
|
|
auto load_header(std::string const& name) -> std::tuple<std::string const*, char const*, usize>;
|
2023-03-02 10:41:32 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
arc::props props_;
|
|
|
|
arc::build build_;
|
|
|
|
arc::engine engine_;
|
|
|
|
arc::endian endian_;
|
|
|
|
arc::system system_;
|
|
|
|
arc::instance instance_;
|
|
|
|
u64 magic_;
|
|
|
|
arc::source source_;
|
2023-05-13 13:24:57 -04:00
|
|
|
arc::assembler assembler_;
|
2023-03-02 10:41:32 -05:00
|
|
|
arc::disassembler disassembler_;
|
2023-05-13 13:24:57 -04:00
|
|
|
arc::compiler compiler_;
|
2023-03-02 10:41:32 -05:00
|
|
|
arc::decompiler decompiler_;
|
|
|
|
|
|
|
|
fs_callback fs_callback_;
|
|
|
|
std::unordered_map<opcode, std::string_view> opcode_map_;
|
|
|
|
std::unordered_map<std::string_view, opcode> opcode_map_rev_;
|
|
|
|
std::unordered_map<u16, opcode> code_map_;
|
2023-05-13 13:24:57 -04:00
|
|
|
std::unordered_map<opcode, u16> code_map_rev_;
|
2023-03-02 10:41:32 -05:00
|
|
|
std::unordered_map<u32, std::string_view> hash_map_;
|
2023-05-13 13:24:57 -04:00
|
|
|
std::unordered_map<std::string, std::vector<u8>> header_files_;
|
2023-03-02 10:41:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xsk::arc
|