![]() |
ArkScript
A small, fast, functional and scripting language for video games
|
#include <IRCompiler.hpp>
Public Member Functions | |
IRCompiler (unsigned debug) | |
Create a new IRCompiler. | |
void | process (const std::vector< IR::Block > &pages, const std::vector< std::string > &symbols, const std::vector< ValTableElem > &values) |
Turn a given IR into bytecode. | |
void | dumpToStream (std::ostream &stream) const |
Dump the IR given to process to an output stream. | |
const bytecode_t & | bytecode () const noexcept |
Return the constructed bytecode object. | |
Private Member Functions | |
void | compile () |
void | pushWord (const Word &word) |
Push a word to the m_bytecode. | |
void | pushFileHeader () noexcept |
Push the file headers (magic, version used, timestamp) | |
void | pushSymAndValTables (const std::vector< std::string > &symbols, const std::vector< ValTableElem > &values) |
Push the symbols and values tables. | |
Private Attributes | |
Logger | m_logger |
bytecode_t | m_bytecode |
std::vector< IR::Block > | m_ir |
Definition at line 26 of file IRCompiler.hpp.
|
explicit |
|
nodiscardnoexcept |
Return the constructed bytecode object.
Definition at line 93 of file IRCompiler.cpp.
References m_bytecode.
Referenced by Ark::Welder::generateBytecode().
|
private |
Definition at line 98 of file IRCompiler.cpp.
References Ark::internal::CODE_SEGMENT_START, Ark::internal::IR::Goto, Ark::internal::IR::GotoIfFalse, Ark::internal::IR::GotoIfTrue, Ark::internal::HALT, Ark::internal::JUMP, Ark::internal::IR::Label, m_bytecode, m_ir, Ark::internal::IR::Opcode, Ark::internal::IR::Opcode2Args, Ark::internal::POP_JUMP_IF_FALSE, Ark::internal::POP_JUMP_IF_TRUE, and pushWord().
Referenced by process().
void Ark::internal::IRCompiler::dumpToStream | ( | std::ostream & | stream | ) | const |
Dump the IR given to process
to an output stream.
stream | output stream |
Definition at line 52 of file IRCompiler.cpp.
References Ark::internal::IR::Goto, Ark::internal::IR::GotoIfFalse, Ark::internal::IR::GotoIfTrue, Ark::internal::InstructionNames, Ark::internal::IR::Label, m_ir, Ark::internal::IR::Opcode, and Ark::internal::IR::Opcode2Args.
Referenced by Ark::Welder::dumpIRToFile(), and Ark::Welder::textualIR().
void Ark::internal::IRCompiler::process | ( | const std::vector< IR::Block > & | pages, |
const std::vector< std::string > & | symbols, | ||
const std::vector< ValTableElem > & | values ) |
Turn a given IR into bytecode.
pages | list of lists of IR entities generated by the compiler |
symbols | symbol table generated by the compiler |
values | value table generated by the compiler |
Definition at line 20 of file IRCompiler.cpp.
References Ark::internal::CODE_SEGMENT_START, compile(), Ark::internal::HALT, m_bytecode, m_ir, m_logger, pushFileHeader(), pushSymAndValTables(), Ark::internal::Logger::traceEnd(), and Ark::internal::Logger::traceStart().
Referenced by Ark::Welder::generateBytecode().
|
privatenoexcept |
Push the file headers (magic, version used, timestamp)
Definition at line 172 of file IRCompiler.cpp.
References ARK_VERSION_MAJOR, ARK_VERSION_MINOR, ARK_VERSION_PATCH, and m_bytecode.
Referenced by process().
|
private |
Push the symbols and values tables.
Definition at line 206 of file IRCompiler.cpp.
References Ark::internal::FUNC_TYPE, m_bytecode, Ark::internal::Number, Ark::internal::NUMBER_TYPE, Ark::internal::PageAddr, Ark::internal::String, Ark::internal::STRING_TYPE, Ark::internal::SYM_TABLE_START, and Ark::internal::VAL_TABLE_START.
Referenced by process().
|
private |
Push a word to the m_bytecode.
word |
Definition at line 164 of file IRCompiler.cpp.
References Ark::internal::Word::byte_1, Ark::internal::Word::byte_2, Ark::internal::Word::byte_3, m_bytecode, and Ark::internal::Word::opcode.
Referenced by compile().
|
private |
Definition at line 61 of file IRCompiler.hpp.
Referenced by bytecode(), compile(), process(), pushFileHeader(), pushSymAndValTables(), and pushWord().
|
private |
Definition at line 62 of file IRCompiler.hpp.
Referenced by compile(), dumpToStream(), and process().
|
private |
Definition at line 60 of file IRCompiler.hpp.
Referenced by process().