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

This class is just a helper to. More...

#include <BytecodeReader.hpp>

Collaboration diagram for Ark::BytecodeReader:
[legend]

Public Member Functions

 BytecodeReader ()=default
 Construct a new Bytecode Reader object.
 
void feed (const std::string &file)
 Construct needed data before displaying information about a given file.
 
void feed (const bytecode_t &bytecode)
 Construct needed data before displaying information about a given bytecode.
 
bool checkMagic () const
 
Version version () const
 
unsigned long long timestamp () const
 Return the read timestamp from the bytecode file.
 
std::vector< unsigned char > sha256 () const
 
Symbols symbols () const
 
Values values (const Symbols &symbols) const
 
Filenames filenames (const Values &values) const
 
InstLocations instLocations (const Filenames &filenames) const
 
Code code (const InstLocations &instLocations) const
 
void display (BytecodeSegment segment=BytecodeSegment::All, std::optional< uint16_t > sStart=std::nullopt, std::optional< uint16_t > sEnd=std::nullopt, std::optional< uint16_t > cPage=std::nullopt) const
 Display the bytecode opcode in a human friendly way.
 

Private Member Functions

uint16_t readNumber (std::size_t &i) const
 Read a number from the bytecode, under the instruction pointer i.
 

Private Attributes

bytecode_t m_bytecode
 

Friends

class Ark::State
 

Detailed Description

This class is just a helper to.

  • check if a bytecode is valid
  • display it in a human readable way by using the opcode names

Definition at line 85 of file BytecodeReader.hpp.

Constructor & Destructor Documentation

◆ BytecodeReader()

Ark::BytecodeReader::BytecodeReader ( )
default

Construct a new Bytecode Reader object.

Member Function Documentation

◆ checkMagic()

bool Ark::BytecodeReader::checkMagic ( ) const
nodiscard

Check for the presence of the magic header

Returns
true if the magic 'ark\0' was found

Definition at line 40 of file BytecodeReader.cpp.

References m_bytecode, and Ark::internal::bytecode::Magic.

Referenced by code(), display(), Ark::State::doFile(), Ark::State::feed(), filenames(), instLocations(), main(), sha256(), symbols(), timestamp(), values(), and version().

◆ code()

Code Ark::BytecodeReader::code ( const InstLocations & instLocations) const
nodiscard

◆ display()

void Ark::BytecodeReader::display ( BytecodeSegment segment = BytecodeSegment::All,
std::optional< uint16_t > sStart = std::nullopt,
std::optional< uint16_t > sEnd = std::nullopt,
std::optional< uint16_t > cPage = std::nullopt ) const

◆ feed() [1/2]

void Ark::BytecodeReader::feed ( const bytecode_t & bytecode)

Construct needed data before displaying information about a given bytecode.

Parameters
bytecode

Definition at line 17 of file BytecodeReader.cpp.

References m_bytecode.

◆ feed() [2/2]

void Ark::BytecodeReader::feed ( const std::string & file)

Construct needed data before displaying information about a given file.

Parameters
filefilename of the bytecode file

Definition at line 22 of file BytecodeReader.cpp.

References m_bytecode.

Referenced by Ark::State::doFile(), Ark::State::feed(), and main().

◆ filenames()

Filenames Ark::BytecodeReader::filenames ( const Values & values) const
nodiscard

◆ instLocations()

◆ readNumber()

uint16_t Ark::BytecodeReader::readNumber ( std::size_t & i) const
nodiscardprivate

Read a number from the bytecode, under the instruction pointer i.

Parameters
ithis parameter is being modified to point to the next value
Returns
uint16_t the number we read (big endian)

Definition at line 559 of file BytecodeReader.cpp.

References m_bytecode.

Referenced by code(), filenames(), instLocations(), symbols(), and values().

◆ sha256()

std::vector< unsigned char > Ark::BytecodeReader::sha256 ( ) const
nodiscard
Returns
std::vector<unsigned char> bytecode sha

Definition at line 79 of file BytecodeReader.cpp.

References checkMagic(), Ark::internal::bytecode::HeaderSize, and m_bytecode.

Referenced by Ark::State::configure(), and display().

◆ symbols()

◆ timestamp()

unsigned long long Ark::BytecodeReader::timestamp ( ) const
nodiscard

Return the read timestamp from the bytecode file.

Returns
unsigned long long

Definition at line 61 of file BytecodeReader.cpp.

References checkMagic(), Ark::internal::bytecode::HeaderSize, and m_bytecode.

Referenced by display().

◆ values()

◆ version()

Version Ark::BytecodeReader::version ( ) const
nodiscard
Returns
Version compiler version used to create the given bytecode file

Definition at line 49 of file BytecodeReader.cpp.

References checkMagic(), m_bytecode, Ark::internal::bytecode::Magic, and Ark::internal::bytecode::Version.

Referenced by Ark::State::configure(), and display().

Friends And Related Symbol Documentation

◆ Ark::State

friend class Ark::State
friend

Definition at line 176 of file BytecodeReader.hpp.

Member Data Documentation

◆ m_bytecode

bytecode_t Ark::BytecodeReader::m_bytecode
private

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