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
* @date 2024-10-05
6
*
7
* @copyright Copyright (c) 2024-2025
8
*
9
*/
10
11
#ifndef ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
12
#define ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
13
14
#include <vector>
15
#include <string>
16
17
#include <
Ark/Platform.hpp
>
18
#include <
Ark/Logger.hpp
>
19
#include <
Ark/Compiler/Common.hpp
>
20
#include <
Ark/Compiler/ValTableElem.hpp
>
21
#include <
Ark/Compiler/IntermediateRepresentation/Entity.hpp
>
22
23
namespace
Ark::internal
24
{
25
class
ARK_API
IRCompiler
final
26
{
27
public
:
28
/**
29
* @brief Create a new IRCompiler
30
*
31
* @param debug debug level
32
*/
33
explicit
IRCompiler
(
unsigned
debug);
34
35
/**
36
* @brief Turn a given IR into bytecode
37
*
38
* @param pages list of lists of IR entities generated by the compiler
39
* @param symbols symbol table generated by the compiler
40
* @param values value table generated by the compiler
41
*/
42
void
process(
const
std::vector<IR::Block>& pages,
const
std::vector<std::string>& symbols,
const
std::vector<ValTableElem>& values);
43
44
/**
45
* @brief Dump the IR given to `process` to an output stream
46
*
47
* @param stream output stream
48
*/
49
void
dumpToStream(std::ostream& stream)
const
;
50
51
/**
52
* @brief Return the constructed bytecode object
53
*
54
* @return const bytecode_t&
55
*/
56
[[nodiscard]]
const
bytecode_t
& bytecode()
const
noexcept
;
57
58
private
:
59
Logger
m_logger
;
60
bytecode_t
m_bytecode
;
61
std::vector<IR::Block>
m_ir
;
62
std::vector<std::string>
m_filenames
;
63
64
void
compile();
65
66
/**
67
* @brief Push a word (4 bytes) 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
void
pushSymbolTable(const std::vector<std::
string
>& symbols);
79
void
pushValueTable(const std::vector<
ValTableElem
>& values);
80
void
pushFilenameTable();
81
void
pushInstLocTable(const std::vector<IR::Block>& pages);
82
};
83
}
84
85
#endif
// ARK_COMPILER_INTERMEDIATEREPRESENTATION_IRCOMPILER_HPP
Common.hpp
Common code for the compiler.
Entity.hpp
An entity in the IR is a bundle of information.
Logger.hpp
Internal logger.
ARK_API
#define ARK_API
Definition
Module.hpp:28
Platform.hpp
ArkScript configuration macros.
ValTableElem.hpp
The basic value type handled by the compiler.
Ark::internal::IRCompiler
Definition
IRCompiler.hpp:26
Ark::internal::IRCompiler::m_filenames
std::vector< std::string > m_filenames
Definition
IRCompiler.hpp:62
Ark::internal::IRCompiler::m_bytecode
bytecode_t m_bytecode
Definition
IRCompiler.hpp:60
Ark::internal::IRCompiler::m_ir
std::vector< IR::Block > m_ir
Definition
IRCompiler.hpp:61
Ark::internal::IRCompiler::m_logger
Logger m_logger
Definition
IRCompiler.hpp:59
Ark::internal::Logger
Definition
Logger.hpp:24
Ark::internal
Definition
Builtins.hpp:25
Ark::bytecode_t
std::vector< uint8_t > bytecode_t
Definition
Common.hpp:22
Ark::internal::ValTableElem
A Compiler Value class helper to handle multiple types.
Definition
ValTableElem.hpp:37
Ark::internal::Word
Definition
Word.hpp:17
include
Ark
Compiler
IntermediateRepresentation
IRCompiler.hpp
Generated on Wed May 21 2025 18:40:52 for ArkScript by
1.12.0