ArkScript
A small, fast, functional and scripting language for video games
IRCompiler.hpp
Go to the documentation of this file.
1/**
2 * @file IRCompiler.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief Compile the intermediate representation to bytecode
5 * @version 0.1
6 * @date 2024-10-05
7 *
8 * @copyright Copyright (c) 2024
9 *
10 */
11
12#ifndef ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
13#define ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
14
15#include <vector>
16#include <string>
17
18#include <Ark/Platform.hpp>
19#include <Ark/Logger.hpp>
23
24namespace Ark::internal
25{
26 class ARK_API IRCompiler final
27 {
28 public:
29 /**
30 * @brief Create a new IRCompiler
31 *
32 * @param debug debug level
33 */
34 explicit IRCompiler(unsigned debug);
35
36 /**
37 * @brief Turn a given IR into bytecode
38 *
39 * @param pages list of lists of IR entities generated by the compiler
40 * @param symbols symbol table generated by the compiler
41 * @param values value table generated by the compiler
42 */
43 void process(const std::vector<IR::Block>& pages, const std::vector<std::string>& symbols, const std::vector<ValTableElem>& values);
44
45 /**
46 * @brief Dump the IR given to `process` to an output stream
47 *
48 * @param stream output stream
49 */
50 void dumpToStream(std::ostream& stream) const;
51
52 /**
53 * @brief Return the constructed bytecode object
54 *
55 * @return const bytecode_t&
56 */
57 [[nodiscard]] const bytecode_t& bytecode() const noexcept;
58
59 private:
62 std::vector<IR::Block> m_ir;
63
64 void compile();
65
66 /**
67 * @brief Push a word to the m_bytecode
68 * @param word
69 */
70 void pushWord(const Word& word);
71
72 /**
73 * @brief Push the file headers (magic, version used, timestamp)
74 *
75 */
76 void pushFileHeader() noexcept;
77
78 /**
79 * @brief Push the symbols and values tables
80 *
81 */
82 void pushSymAndValTables(const std::vector<std::string>& symbols, const std::vector<ValTableElem>& values);
83 };
84}
85
86#endif // ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
Common code for the compiler.
An entity in the IR is a bundle of information.
Internal logger.
#define ARK_API
Definition Module.hpp:28
ArkScript configuration macros.
The basic value type handled by the compiler.
std::vector< IR::Block > m_ir
std::vector< uint8_t > bytecode_t
Definition Common.hpp:22
A Compiler Value class helper to handle multiple types.