ArkScript
A small, fast, functional and scripting language for video games
IROptimizer.hpp
Go to the documentation of this file.
1/**
2 * @file IROptimizer.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief Optimize IR based on IR entity grouped by 2 (or more)
5 * @version 0.2
6 * @date 2024-10-11
7 *
8 * @copyright Copyright (c) 2024
9 *
10 */
11#ifndef ARK_COMPILER_INTERMEDIATEREPRESENTATION_IROPTIMIZER_HPP
12#define ARK_COMPILER_INTERMEDIATEREPRESENTATION_IROPTIMIZER_HPP
13
14#include <Ark/Platform.hpp>
15#include <Ark/Logger.hpp>
18
19#include <optional>
20
21namespace Ark::internal
22{
23 class ARK_API IROptimizer final
24 {
25 public:
26 /**
27 * @brief Create a new IROptimizer
28 *
29 * @param debug debug level
30 */
31 explicit IROptimizer(unsigned debug);
32
33 /**
34 * @brief Turn a given IR into bytecode
35 *
36 * @param pages list of lists of IR entities generated by the compiler
37 * @param symbols symbol table generated by the compiler
38 * @param values value table generated by the compiler
39 */
40 void process(const std::vector<IR::Block>& pages, const std::vector<std::string>& symbols, const std::vector<ValTableElem>& values);
41
42 /**
43 * @brief Return the IR blocks (one per scope)
44 *
45 * @return const std::vector<Block>&
46 */
47 [[nodiscard]] const std::vector<IR::Block>& intermediateRepresentation() const noexcept;
48
49 private:
51 std::vector<IR::Block> m_ir;
52 std::vector<std::string> m_symbols;
53 std::vector<ValTableElem> m_values;
54
55 [[nodiscard]] std::optional<IR::Entity> compactEntities(const IR::Entity& first, const IR::Entity& second);
56 [[nodiscard]] std::optional<IR::Entity> compactEntities(const IR::Entity& first, const IR::Entity& second, const IR::Entity& third);
57
58 [[nodiscard]] bool isPositiveNumberInlinable(uint16_t id) const;
59 };
60}
61
62#endif // ARK_COMPILER_INTERMEDIATEREPRESENTATION_IROPTIMIZER_HPP
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< ValTableElem > m_values
std::vector< IR::Block > m_ir
std::vector< std::string > m_symbols