ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::IRCompiler Class Referencefinal

#include <IRCompiler.hpp>

Collaboration diagram for Ark::internal::IRCompiler:
[legend]

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_tbytecode () 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::Blockm_ir
 
std::vector< std::string > m_filenames
 

Detailed Description

Definition at line 25 of file IRCompiler.hpp.

Constructor & Destructor Documentation

◆ IRCompiler()

Ark::internal::IRCompiler::IRCompiler ( unsigned debug)
explicit

Create a new IRCompiler.

Parameters
debugdebug level

Definition at line 20 of file IRCompiler.cpp.

Member Function Documentation

◆ bytecode()

const bytecode_t & Ark::internal::IRCompiler::bytecode ( ) const
nodiscardnoexcept

Return the constructed bytecode object.

Returns
const bytecode_t&

Definition at line 109 of file IRCompiler.cpp.

References m_bytecode.

Referenced by Ark::Welder::generateBytecode().

◆ compile()

◆ dumpToStream()

void Ark::internal::IRCompiler::dumpToStream ( std::ostream & stream) const

◆ process()

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.

Parameters
pageslist of lists of IR entities generated by the compiler
symbolssymbol table generated by the compiler
valuesvalue 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().

◆ pushFileHeader()

void Ark::internal::IRCompiler::pushFileHeader ( )
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().

◆ pushFilenameTable()

void Ark::internal::IRCompiler::pushFilenameTable ( )
private

◆ pushInstLocTable()

void Ark::internal::IRCompiler::pushInstLocTable ( const std::vector< IR::Block > & pages)
private

◆ pushSymbolTable()

void Ark::internal::IRCompiler::pushSymbolTable ( const std::vector< std::string > & symbols)
private

◆ pushValueTable()

◆ pushWord()

void Ark::internal::IRCompiler::pushWord ( const Word & word)
private

Push a word (4 bytes) to the m_bytecode.

Parameters
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().

Member Data Documentation

◆ m_bytecode

bytecode_t Ark::internal::IRCompiler::m_bytecode
private

◆ m_filenames

std::vector<std::string> Ark::internal::IRCompiler::m_filenames
private

Definition at line 62 of file IRCompiler.hpp.

Referenced by process(), pushFilenameTable(), and pushInstLocTable().

◆ m_ir

std::vector<IR::Block> Ark::internal::IRCompiler::m_ir
private

Definition at line 61 of file IRCompiler.hpp.

Referenced by compile(), dumpToStream(), and process().

◆ m_logger

Logger Ark::internal::IRCompiler::m_logger
private

Definition at line 59 of file IRCompiler.hpp.

Referenced by process().


The documentation for this class was generated from the following files: