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
>
20
#include <
Ark/Compiler/Common.hpp
>
21
#include <
Ark/Compiler/ValTableElem.hpp
>
22
#include <
Ark/Compiler/IntermediateRepresentation/Entity.hpp
>
23
24
namespace
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
:
60
Logger
m_logger
;
61
bytecode_t
m_bytecode
;
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.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:27
Ark::internal::IRCompiler::m_bytecode
bytecode_t m_bytecode
Definition
IRCompiler.hpp:61
Ark::internal::IRCompiler::m_ir
std::vector< IR::Block > m_ir
Definition
IRCompiler.hpp:62
Ark::internal::IRCompiler::m_logger
Logger m_logger
Definition
IRCompiler.hpp:60
Ark::internal::Logger
Definition
Logger.hpp:25
Ark::internal
Definition
Builtins.hpp:26
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:38
Ark::internal::Word
Definition
Word.hpp:18
include
Ark
Compiler
IntermediateRepresentation
IRCompiler.hpp
Generated on Wed Jan 15 2025 19:51:44 for ArkScript by
1.12.0