ArkScript
A small, fast, functional and scripting language for video games
BytecodeReader.hpp
Go to the documentation of this file.
1/**
2 * @file BytecodeReader.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief A bytecode disassembler for ArkScript
5 * @version 0.3
6 * @date 2020-10-27
7 *
8 * @copyright Copyright (c) 2020-2021
9 *
10 */
11
12#ifndef ARK_COMPILER_BYTECODEREADER_HPP
13#define ARK_COMPILER_BYTECODEREADER_HPP
14
15#include <vector>
16#include <fstream>
17#include <iostream>
18#include <string>
19#include <cinttypes>
20#include <optional>
21
22#include <Ark/Platform.hpp>
24
25namespace Ark
26{
27 enum class BytecodeSegment
28 {
29 All,
30 Symbols,
31 Values,
32 Code,
34 };
35
36 /**
37 * @brief This class is just a helper to
38 * - check if a bytecode is valid
39 * - display it in a human readable way by using the opcode names
40 *
41 */
43 {
44 public:
45 /**
46 * @brief Construct a new Bytecode Reader object
47 *
48 */
49 BytecodeReader() = default;
50
51 /**
52 * @brief Construct needed data before displaying information about a given file
53 *
54 * @param file filename of the bytecode file
55 */
56 void feed(const std::string& file);
57
58 /**
59 * @brief Return the bytecode object constructed
60 *
61 * @return const bytecode_t&
62 */
63 const bytecode_t& bytecode() noexcept;
64
65 /**
66 * @brief Return the read timestamp from the bytecode file
67 *
68 * @return unsigned long long
69 */
70 unsigned long long timestamp();
71
72 /**
73 * @brief Display the bytecode opcode in a human friendly way.
74 *
75 * @param segment selected bytecode segment that will be displayed
76 * @param sStart start of the segment slice to display (Ignored in code segment if no page is available)
77 * @param sEnd end of the segment slice to display (Ignored in code segment if no page is available)
78 * @param cPage selected page of the code segment (Used only for the code segment)
79 */
80 void display(BytecodeSegment segment = BytecodeSegment::All,
81 std::optional<uint16_t> sStart = std::nullopt,
82 std::optional<uint16_t> sEnd = std::nullopt,
83 std::optional<uint16_t> cPage = std::nullopt);
84
85 private:
86 bytecode_t m_bytecode;
87
88 /**
89 * @brief Read a number from the bytecode, under the instruction pointer i
90 *
91 * @param i this parameter is being modified to point to the next value
92 * @return uint16_t the number we read (big endian)
93 */
94 uint16_t readNumber(std::size_t& i);
95 };
96}
97
98#endif
Common code for the compiler.
#define ARK_API
Definition: Module.hpp:29
ArkScript configuration macros.
This class is just a helper to.
BytecodeReader()=default
Construct a new Bytecode Reader object.
Definition: Builtins.hpp:21
std::vector< uint8_t > bytecode_t
Definition: Common.hpp:22