![]() |
ArkScript
A small, lisp-inspired, functional scripting language
|
#include <Entity.hpp>
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 | |
Definition at line 44 of file Entity.hpp.
|
explicit |
| kind | kind of entity (label, jump, instruction...) |
Definition at line 5 of file Entity.cpp.
Referenced by Goto(), GotoWithArg(), and Label().
|
explicit |
| inst | instruction |
| arg | optional argument, default to 0 |
Definition at line 10 of file Entity.cpp.
| Ark::internal::IR::Entity::Entity | ( | Instruction | inst, |
| uint16_t | primary_arg, | ||
| uint16_t | secondary_arg ) |
| inst | instruction that takes two arguments |
| primary_arg | first argument on 12 bits |
| secondary_arg | second argument on 12 bits |
Definition at line 15 of file Entity.cpp.
| Ark::internal::IR::Entity::Entity | ( | Instruction | inst, |
| uint8_t | inst2, | ||
| uint8_t | inst3, | ||
| uint8_t | inst4 ) |
| inst | instruction that takes three arguments |
| inst2 | first argument on 8 bits |
| inst3 | second argument on 8 bits |
| inst4 | third argument on 8 bits |
Definition at line 20 of file Entity.cpp.
|
nodiscard |
Return the bytecode representation of the IR Entity if it's an Opcode.
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.
|
inlinenodiscard |
Definition at line 209 of file Entity.hpp.
References m_metadata.
Referenced by Ark::internal::IRInliner::inlineBlock(), and setSourceLocation().
|
static |
| label | label the goto relates to |
| inst | jump instruction to use, default to JUMP |
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().
| label | label the goto relates to |
| cond | true to use POP_JUMP_IF_TRUE, false to use POP_JUMP_IF_FALSE |
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().
|
static |
| label | label the goto relates to |
| inst | jump instruction to use |
| primary_arg | argument for the jump instruction |
Definition at line 52 of file Entity.cpp.
References Entity(), Ark::internal::IR::GotoWithArg, inst(), and label().
Referenced by Ark::internal::IROptimizer::IROptimizer().
|
inlinenodiscard |
Check if the Entity has a label attached.
Definition at line 133 of file Entity.hpp.
References Ark::internal::IR::Goto, Ark::internal::IR::GotoWithArg, Ark::internal::IR::Label, m_kind, Ark::internal::IR::Opcode, Ark::internal::IR::Opcode2Args, and Ark::internal::IR::Opcode3Args.
Referenced by Ark::internal::IROptimizer::canBeOptimisedSafely(), and Ark::internal::IRInliner::inlineBlock().
|
inlinenodiscard |
Definition at line 207 of file Entity.hpp.
References m_metadata.
|
inlinenodiscard |
Return the underlying instruction of the IR Entity.
Definition at line 174 of file Entity.hpp.
References m_inst.
Referenced by Ark::internal::IRInliner::extractPagesMetadata(), Goto(), GotoWithArg(), and Ark::internal::IRInliner::inlineBlock().
|
inlinenodiscard |
| value | value for the label |
Definition at line 35 of file Entity.cpp.
References Entity(), and Ark::internal::IR::Label.
Referenced by Ark::internal::ASTLowerer::compileApplyInstruction(), Ark::internal::ASTLowerer::compileIf(), Ark::internal::ASTLowerer::compileWhile(), Ark::internal::ASTLowerer::handleFunctionCall(), and Ark::internal::ASTLowerer::handleShortcircuit().
|
inlinenodiscard |
Return the label of the IR Entity.
Definition at line 160 of file Entity.hpp.
References m_label.
Referenced by Goto(), GotoIf(), GotoWithArg(), and Ark::internal::IRInliner::inlineBlock().
|
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
Definition at line 181 of file Entity.hpp.
References m_primary_arg.
Referenced by Ark::internal::IROptimizer::canBeOptimisedSafely(), and Ark::internal::IRInliner::extractPagesMetadata().
|
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)
Definition at line 218 of file Entity.hpp.
References m_metadata.
Referenced by Ark::internal::IRInliner::extractPagesMetadata(), and Ark::internal::IRInliner::inlineBlock().
| void Ark::internal::IR::Entity::replaceInstruction | ( | Instruction | replacement | ) |
Definition at line 25 of file Entity.cpp.
References m_inst.
| 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().
|
inlinenodiscard |
Return the second argument of the IR Entity.
The argument is for super instructions, where only the first 12 bits are used
Definition at line 188 of file Entity.hpp.
References m_secondary_arg.
Referenced by Ark::internal::IRInliner::inlineBlock().
| void Ark::internal::IR::Entity::setRelatedResourceId | ( | std::optional< uint16_t > | id | ) |
Definition at line 88 of file Entity.cpp.
References m_metadata.
| 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.
| filename | |
| line |
Definition at line 82 of file Entity.cpp.
References filename(), and m_metadata.
|
inlinenodiscard |
Definition at line 211 of file Entity.hpp.
References m_metadata.
Referenced by Ark::internal::IRInliner::inlineBlock().
|
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)
Definition at line 195 of file Entity.hpp.
References m_tertiary_arg.
|
private |
Definition at line 224 of file Entity.hpp.
Referenced by bytecode(), inst(), and replaceInstruction().
|
private |
Definition at line 221 of file Entity.hpp.
Referenced by bytecode(), hasLabel(), and kind().
|
private |
Definition at line 222 of file Entity.hpp.
Referenced by label(), and replaceLabel().
| struct { ... } Ark::internal::IR::Entity::m_metadata |
Referenced by filename(), hasValidSourceLocation(), relatedResourceId(), setRelatedResourceId(), setSourceLocation(), and sourceLine().
|
private |
Definition at line 225 of file Entity.hpp.
Referenced by bytecode(), and primaryArg().
|
private |
Definition at line 226 of file Entity.hpp.
Referenced by bytecode(), and secondaryArg().
|
private |
Definition at line 227 of file Entity.hpp.
Referenced by bytecode(), and tertiaryArg().
| 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.
| std::string Ark::internal::IR::Entity::source_file |
Definition at line 231 of file Entity.hpp.
| std::size_t Ark::internal::IR::Entity::source_line { 0 } |
Definition at line 232 of file Entity.hpp.