![]() |
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 (4 bytes) to the m_bytecode. | |
void | pushFileHeader () noexcept |
Push the file headers (magic, version used, timestamp) | |
void | pushSymbolTable (const std::vector< std::string > &symbols) |
void | pushValueTable (const std::vector< ValTableElem > &values) |
void | pushFilenameTable () |
void | pushInstLocTable (const std::vector< IR::Block > &pages) |
Private Attributes | |
Logger | m_logger |
bytecode_t | m_bytecode |
std::vector< IR::Block > | m_ir |
std::vector< std::string > | m_filenames |
Definition at line 25 of file IRCompiler.hpp.
|
explicit |
|
nodiscardnoexcept |
Return the constructed bytecode object.
Definition at line 109 of file IRCompiler.cpp.
References m_bytecode.
Referenced by Ark::Welder::generateBytecode().
|
private |
Definition at line 114 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, pushWord(), and Ark::internal::serializeOn2BytesToVecBE().
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 68 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 24 of file IRCompiler.cpp.
References Ark::internal::CODE_SEGMENT_START, compile(), Ark::internal::HALT, Ark::internal::bytecode::HeaderSize, m_bytecode, m_filenames, m_ir, m_logger, pushFileHeader(), pushFilenameTable(), pushInstLocTable(), pushSymbolTable(), pushValueTable(), 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 187 of file IRCompiler.cpp.
References ARK_VERSION_MAJOR, ARK_VERSION_MINOR, ARK_VERSION_PATCH, m_bytecode, and Ark::internal::serializeOn2BytesToVecBE().
Referenced by process().
|
private |
Definition at line 283 of file IRCompiler.cpp.
References Ark::internal::FILENAMES_TABLE_START, m_bytecode, m_filenames, and Ark::internal::serializeOn2BytesToVecBE().
Referenced by process().
|
private |
Definition at line 301 of file IRCompiler.cpp.
References Ark::internal::INST_LOC_TABLE_START, Ark::internal::IR::Label, m_bytecode, m_filenames, Ark::internal::serializeOn2BytesToVecBE(), and Ark::internal::serializeToVecBE().
Referenced by process().
|
private |
Definition at line 218 of file IRCompiler.cpp.
References m_bytecode, Ark::internal::serializeOn2BytesToVecBE(), and Ark::internal::SYM_TABLE_START.
Referenced by process().
|
private |
Definition at line 237 of file IRCompiler.cpp.
References Ark::internal::FUNC_TYPE, m_bytecode, Ark::internal::Number, Ark::internal::NUMBER_TYPE, Ark::internal::PageAddr, Ark::internal::ieee754::serialize(), Ark::internal::serializeOn2BytesToVecBE(), Ark::internal::serializeToVecLE(), Ark::internal::String, Ark::internal::STRING_TYPE, and Ark::internal::VAL_TABLE_START.
Referenced by process().
|
private |
Push a word (4 bytes) to the m_bytecode.
word |
Definition at line 179 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 60 of file IRCompiler.hpp.
Referenced by bytecode(), compile(), process(), pushFileHeader(), pushFilenameTable(), pushInstLocTable(), pushSymbolTable(), pushValueTable(), and pushWord().
|
private |
Definition at line 62 of file IRCompiler.hpp.
Referenced by process(), pushFilenameTable(), and pushInstLocTable().
|
private |
Definition at line 61 of file IRCompiler.hpp.
Referenced by compile(), dumpToStream(), and process().
|
private |
Definition at line 59 of file IRCompiler.hpp.
Referenced by process().