ArkScript
A small, lisp-inspired, functional scripting language
Ark::internal::IR::Entity Class Reference

#include <Entity.hpp>

Collaboration diagram for Ark::internal::IR::Entity:
[legend]

Public Member Functions

 Entity (Kind kind)
 Create a new IR Entity.
 
 Entity (Instruction inst, uint16_t arg=0)
 Create a new IR Entity.
 
 Entity (Instruction inst, uint16_t primary_arg, uint16_t secondary_arg)
 Create a new IR Entity.
 
 Entity (Instruction inst, uint8_t inst2, uint8_t inst3, uint8_t inst4)
 Create a new IR Entity.
 
void replaceInstruction (Instruction replacement)
 
void replaceLabel (label_t replacement)
 
Word bytecode () const
 Return the bytecode representation of the IR Entity if it's an Opcode.
 
bool hasLabel () const
 Check if the Entity has a label attached.
 
label_t label () const
 Return the label of the IR Entity.
 
Kind kind () const
 Return the kind of IR Entity.
 
Instruction inst () const
 Return the underlying instruction of the IR Entity.
 
uint16_t primaryArg () const
 Return the primary argument of the IR Entity (can be 0 if the argument isn't used)
 
uint16_t secondaryArg () const
 Return the second argument of the IR Entity.
 
uint16_t tertiaryArg () const
 Return the third argument of the IR Entity.
 
void setSourceLocation (const std::string &filename, std::size_t line)
 Set the source location for an IR Entity, which is used to generate the file loc table.
 
void setRelatedResourceId (std::optional< uint16_t > id)
 
bool hasValidSourceLocation () const
 
const std::string & filename () const
 
std::size_t sourceLine () const
 
std::optional< uint16_t > relatedResourceId () const
 Return the related constant/symbol id an IR Entity refers to (only populated for LOAD_FAST_BY_INDEX, CALL_SYMBOL_BY_INDEX, CALL_SYMBOL, and CALL)
 

Static Public Member Functions

static Entity Label (label_t value)
 Create a new Label IR Entity.
 
static Entity Goto (const Entity &label, Instruction inst=Instruction::JUMP)
 Create a new Goto IR Entity.
 
static Entity GotoWithArg (const Entity &label, Instruction inst, uint16_t primary_arg)
 Create a new Goto IR Entity.
 
static Entity GotoIf (const Entity &label, bool cond)
 Create a new Goto IR Entity.
 

Private Attributes

Kind m_kind
 
label_t m_label { 0 }
 
Instruction m_inst { NOP }
 
uint16_t m_primary_arg { 0 }
 
uint16_t m_secondary_arg { 0 }
 
uint16_t m_tertiary_arg { 0 }
 
struct { 
 
   std::string   source_file 
 
   std::size_t   source_line { 0 } 
 
   std::optional< uint16_t >   related_res_id 
 Used by a few instructions to know the original symbol/constant id and deoptimize when necessary. More...
 
m_metadata 
 

Detailed Description

Definition at line 44 of file Entity.hpp.

Constructor & Destructor Documentation

◆ Entity() [1/4]

Ark::internal::IR::Entity::Entity ( Kind kind)
explicit

Create a new IR Entity.

Parameters
kindkind of entity (label, jump, instruction...)

Definition at line 5 of file Entity.cpp.

Referenced by Goto(), GotoWithArg(), and Label().

◆ Entity() [2/4]

Ark::internal::IR::Entity::Entity ( Instruction inst,
uint16_t arg = 0 )
explicit

Create a new IR Entity.

Parameters
instinstruction
argoptional argument, default to 0

Definition at line 10 of file Entity.cpp.

◆ Entity() [3/4]

Ark::internal::IR::Entity::Entity ( Instruction inst,
uint16_t primary_arg,
uint16_t secondary_arg )

Create a new IR Entity.

Parameters
instinstruction that takes two arguments
primary_argfirst argument on 12 bits
secondary_argsecond argument on 12 bits

Definition at line 15 of file Entity.cpp.

◆ Entity() [4/4]

Ark::internal::IR::Entity::Entity ( Instruction inst,
uint8_t inst2,
uint8_t inst3,
uint8_t inst4 )

Create a new IR Entity.

Parameters
instinstruction that takes three arguments
inst2first argument on 8 bits
inst3second argument on 8 bits
inst4third argument on 8 bits

Definition at line 20 of file Entity.cpp.

Member Function Documentation

◆ bytecode()

Word Ark::internal::IR::Entity::bytecode ( ) const
nodiscard

Return the bytecode representation of the IR Entity if it's an Opcode.

Returns
Word

Definition at line 67 of file Entity.cpp.

References m_inst, m_kind, m_primary_arg, m_secondary_arg, m_tertiary_arg, Ark::internal::IR::Opcode, Ark::internal::IR::Opcode2Args, and Ark::internal::IR::Opcode3Args.

◆ filename()

const std::string & Ark::internal::IR::Entity::filename ( ) const
inlinenodiscard

Definition at line 209 of file Entity.hpp.

References m_metadata.

Referenced by Ark::internal::IRInliner::inlineBlock(), and setSourceLocation().

◆ Goto()

Entity Ark::internal::IR::Entity::Goto ( const Entity & label,
Instruction inst = Instruction::JUMP )
static

Create a new Goto IR Entity.

Parameters
labellabel the goto relates to
instjump instruction to use, default to JUMP
Returns
Entity

Definition at line 43 of file Entity.cpp.

References Entity(), Ark::internal::IR::Goto, inst(), and label().

Referenced by Ark::internal::ASTLowerer::compileApplyInstruction(), Ark::internal::ASTLowerer::compileIf(), Ark::internal::ASTLowerer::compileWhile(), Ark::internal::ASTLowerer::handleFunctionCall(), and Ark::internal::ASTLowerer::handleShortcircuit().

◆ GotoIf()

Entity Ark::internal::IR::Entity::GotoIf ( const Entity & label,
bool cond )
static

Create a new Goto IR Entity.

Parameters
labellabel the goto relates to
condtrue to use POP_JUMP_IF_TRUE, false to use POP_JUMP_IF_FALSE
Returns
Entity

Definition at line 62 of file Entity.cpp.

References Ark::internal::IR::Goto, and label().

Referenced by Ark::internal::ASTLowerer::compileIf(), and Ark::internal::ASTLowerer::compileWhile().

◆ GotoWithArg()

Entity Ark::internal::IR::Entity::GotoWithArg ( const Entity & label,
Instruction inst,
uint16_t primary_arg )
static

Create a new Goto IR Entity.

Parameters
labellabel the goto relates to
instjump instruction to use
primary_argargument for the jump instruction
Returns
Entity

Definition at line 52 of file Entity.cpp.

References Entity(), Ark::internal::IR::GotoWithArg, inst(), and label().

Referenced by Ark::internal::IROptimizer::IROptimizer().

◆ hasLabel()

bool Ark::internal::IR::Entity::hasLabel ( ) const
inlinenodiscard

◆ hasValidSourceLocation()

bool Ark::internal::IR::Entity::hasValidSourceLocation ( ) const
inlinenodiscard

Definition at line 207 of file Entity.hpp.

References m_metadata.

◆ inst()

Instruction Ark::internal::IR::Entity::inst ( ) const
inlinenodiscard

Return the underlying instruction of the IR Entity.

Returns
Instruction

Definition at line 174 of file Entity.hpp.

References m_inst.

Referenced by Ark::internal::IRInliner::extractPagesMetadata(), Goto(), GotoWithArg(), and Ark::internal::IRInliner::inlineBlock().

◆ kind()

Kind Ark::internal::IR::Entity::kind ( ) const
inlinenodiscard

Return the kind of IR Entity.

See also
Kind
Returns
Kind

Definition at line 167 of file Entity.hpp.

References m_kind.

◆ Label()

◆ label()

label_t Ark::internal::IR::Entity::label ( ) const
inlinenodiscard

Return the label of the IR Entity.

Returns
label_t

Definition at line 160 of file Entity.hpp.

References m_label.

Referenced by Goto(), GotoIf(), GotoWithArg(), and Ark::internal::IRInliner::inlineBlock().

◆ primaryArg()

uint16_t Ark::internal::IR::Entity::primaryArg ( ) const
inlinenodiscard

Return the primary argument of the IR Entity (can be 0 if the argument isn't used)

The argument is on 16 bits for standard instructions ; for super instructions, only the first 12 bits are used

Returns
uint16_t

Definition at line 181 of file Entity.hpp.

References m_primary_arg.

Referenced by Ark::internal::IROptimizer::canBeOptimisedSafely(), and Ark::internal::IRInliner::extractPagesMetadata().

◆ relatedResourceId()

std::optional< uint16_t > Ark::internal::IR::Entity::relatedResourceId ( ) const
inlinenodiscard

Return the related constant/symbol id an IR Entity refers to (only populated for LOAD_FAST_BY_INDEX, CALL_SYMBOL_BY_INDEX, CALL_SYMBOL, and CALL)

Returns
std::optional<uint16_t>

Definition at line 218 of file Entity.hpp.

References m_metadata.

Referenced by Ark::internal::IRInliner::extractPagesMetadata(), and Ark::internal::IRInliner::inlineBlock().

◆ replaceInstruction()

void Ark::internal::IR::Entity::replaceInstruction ( Instruction replacement)

Definition at line 25 of file Entity.cpp.

References m_inst.

◆ replaceLabel()

void Ark::internal::IR::Entity::replaceLabel ( label_t replacement)

Definition at line 30 of file Entity.cpp.

References m_label.

Referenced by Ark::internal::IRInliner::inlineBlock().

◆ secondaryArg()

uint16_t Ark::internal::IR::Entity::secondaryArg ( ) const
inlinenodiscard

Return the second argument of the IR Entity.

The argument is for super instructions, where only the first 12 bits are used

Returns
uint16_t

Definition at line 188 of file Entity.hpp.

References m_secondary_arg.

Referenced by Ark::internal::IRInliner::inlineBlock().

◆ setRelatedResourceId()

void Ark::internal::IR::Entity::setRelatedResourceId ( std::optional< uint16_t > id)

Definition at line 88 of file Entity.cpp.

References m_metadata.

◆ setSourceLocation()

void Ark::internal::IR::Entity::setSourceLocation ( const std::string & filename,
std::size_t line )

Set the source location for an IR Entity, which is used to generate the file loc table.

Parameters
filename
line

Definition at line 82 of file Entity.cpp.

References filename(), and m_metadata.

◆ sourceLine()

std::size_t Ark::internal::IR::Entity::sourceLine ( ) const
inlinenodiscard

Definition at line 211 of file Entity.hpp.

References m_metadata.

Referenced by Ark::internal::IRInliner::inlineBlock().

◆ tertiaryArg()

uint16_t Ark::internal::IR::Entity::tertiaryArg ( ) const
inlinenodiscard

Return the third argument of the IR Entity.

The argument is for special super instructions, where only the first 8 bits are used (for all arguments)

Returns
uint16_t

Definition at line 195 of file Entity.hpp.

References m_tertiary_arg.

Member Data Documentation

◆ m_inst

Instruction Ark::internal::IR::Entity::m_inst { NOP }
private

Definition at line 224 of file Entity.hpp.

Referenced by bytecode(), inst(), and replaceInstruction().

◆ m_kind

Kind Ark::internal::IR::Entity::m_kind
private

Definition at line 221 of file Entity.hpp.

Referenced by bytecode(), hasLabel(), and kind().

◆ m_label

label_t Ark::internal::IR::Entity::m_label { 0 }
private

Definition at line 222 of file Entity.hpp.

Referenced by label(), and replaceLabel().

◆ [struct]

struct { ... } Ark::internal::IR::Entity::m_metadata

◆ m_primary_arg

uint16_t Ark::internal::IR::Entity::m_primary_arg { 0 }
private

Definition at line 225 of file Entity.hpp.

Referenced by bytecode(), and primaryArg().

◆ m_secondary_arg

uint16_t Ark::internal::IR::Entity::m_secondary_arg { 0 }
private

Definition at line 226 of file Entity.hpp.

Referenced by bytecode(), and secondaryArg().

◆ m_tertiary_arg

uint16_t Ark::internal::IR::Entity::m_tertiary_arg { 0 }
private

Definition at line 227 of file Entity.hpp.

Referenced by bytecode(), and tertiaryArg().

◆ related_res_id

std::optional<uint16_t> Ark::internal::IR::Entity::related_res_id

Used by a few instructions to know the original symbol/constant id and deoptimize when necessary.

Definition at line 233 of file Entity.hpp.

◆ source_file

std::string Ark::internal::IR::Entity::source_file

Definition at line 231 of file Entity.hpp.

◆ source_line

std::size_t Ark::internal::IR::Entity::source_line { 0 }

Definition at line 232 of file Entity.hpp.


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