hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
IRBuilder Class Reference

#include <IR.h>

Collaboration diagram for IRBuilder:

Classes

struct  LoopContext
 

Public Types

enum class  ExtractType { All , First , Last }
 

Public Member Functions

 IRBuilder ()=delete
 
 IRBuilder (std::shared_ptr< compilerContext > compilerCtx, std::shared_ptr< IRModule > currentModule, std::shared_ptr< IRFunctionDefinition > currentFunction)
 
void setDebugInfo (const IRDebugInfo &debugInfo)
 
const IRDebugInfogetCurrentDebugInfo ()
 
void pushLoopContext (yoi::indexT breakTarget, yoi::indexT continueTarget)
 
void popLoopContext ()
 
yoi::indexT saveState ()
 
void discardState ()
 
void restoreState ()
 
void restoreStateTemporarily ()
 
void commitState ()
 
void discardStateUntil (yoi::indexT stateIndex)
 
void pushTempVar (const std::shared_ptr< IRValueType > &type)
 
yoi::indexT createCodeBlock ()
 
std::shared_ptr< IRFunctionDefinitionirFuncDefinition ()
 
IRCodeBlockgetCurrentCodeBlock ()
 
yoi::indexT getCurrentCodeBlockIndex ()
 
yoi::indexT switchCodeBlock (yoi::indexT index)
 
IRCodeBlockgetCodeBlock (yoi::indexT index)
 
void yield ()
 
void insert (const IR &ir, yoi::indexT insertionPoint=0xffffffff)
 
yoi::IROperand createLocalVar (const yoi::wstr &varName, const std::shared_ptr< IRValueType > &type)
 
IRValueType getLocalVar (yoi::indexT index)
 
std::shared_ptr< IRValueType > & getLhsFromTempVarStack ()
 
std::shared_ptr< IRValueType > & getRhsFromTempVarStack ()
 
void basicCast (const std::shared_ptr< IRValueType > &valType, yoi::indexT insertionPoint, bool lhs=false)
 
void popOp ()
 
void uniqueArithmeticOp (IR::Opcode op)
 
void arithmeticOp (IR::Opcode op)
 
bool hasTerminated ()
 
void jumpOp (yoi::indexT target)
 
void jumpIfOp (IR::Opcode op, yoi::indexT target)
 
void pushOp (IR::Opcode op, const yoi::IROperand &constV)
 
void loadOp (IR::Opcode op, const yoi::IROperand &source, const std::shared_ptr< IRValueType > &expectedType, yoi::indexT moduleIndex=-1)
 
void loadFieldOp (yoi::vec< yoi::IROperand > &accessors, const std::shared_ptr< IRValueType > &expectedType)
 
void loadMemberOp (const yoi::IROperand &memberIndex, const std::shared_ptr< IRValueType > &memberType)
 
void storeOp (IR::Opcode op, const yoi::IROperand &operand, yoi::indexT moduleIndex=-1)
 
void storeMemberOp (const yoi::IROperand &memberIndex)
 
void storeFieldOp (yoi::vec< yoi::IROperand > &accessors)
 
void invokeOp (yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
 Invoke a function with the given arguments.
 
void invokeDanglingOp (yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
 invoke a function with the given arguments, but the last param will be taken as the first param.
 
void invokeMethodOp (yoi::indexT funcIndex, yoi::indexT methodArgsCount, const std::shared_ptr< IRValueType > &returnType, bool isStatic, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
 
void invokeVirtualOp (yoi::indexT funcIndex, yoi::indexT interfaceIndex, yoi::indexT methodArgsCount, const std::shared_ptr< IRValueType > &returnType, bool externalInvocation=false, yoi::indexT moduleIndex=-1)
 
void invokeImportedOp (yoi::indexT libIndex, yoi::indexT funcIndex, yoi::indexT funcArgsCount, const std::shared_ptr< IRValueType > &returnType)
 
void retOp (bool returnWithNone=false)
 
void newStructOp (yoi::indexT structIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
 
void newDataStructOp (yoi::indexT structIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
 
void initializeFieldsOp (yoi::indexT parameterCount)
 
void newInterfaceOp (yoi::indexT interfaceIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
 
void constructInterfaceImplOp (const std::pair< yoi::indexT, yoi::indexT > &interfaceId, yoi::indexT interfaceImplIndex, bool isExternal=false, yoi::indexT moduleIndex=-1)
 
void newArrayOp (const std::shared_ptr< IRValueType > &elementType, const yoi::vec< yoi::indexT > &dimensions, yoi::indexT onstackElementCount)
 
void newDynamicArrayOp (const std::shared_ptr< IRValueType > &elementType, yoi::indexT initializerSize=0)
 
void arrayLengthOp ()
 
void interfaceOfOp ()
 
void typeIdOp (const std::shared_ptr< IRValueType > &type)
 
void typeIdOp ()
 
void dynCastOp (const std::shared_ptr< IRValueType > &type)
 
void pointerCastOp ()
 
void breakOp ()
 
void continueOp ()
 
void bindElementsOp (yoi::indexT extractElementCount, ExtractType extractType)
 
void bindFieldsOp (yoi::indexT extractFieldCount, ExtractType extractType)
 
void yieldOp (bool yieldNone=false)
 
void resumeOp ()
 
yoi::indexT getCurrentInsertionPoint ()
 
void popFromTempVarStack ()
 

Private Attributes

std::shared_ptr< compilerContextcompilerCtx
 
std::shared_ptr< IRModulecurrentModule
 
std::shared_ptr< IRFunctionDefinitioncurrentFunction
 
std::vector< std::shared_ptr< IRCodeBlock > > codeBlocks
 
std::vector< std::shared_ptr< yoi::IRValueType > > tempVarStack
 
yoi::indexT currentCodeBlockIndex
 
yoi::vec< std::tuple< yoi::indexT, yoi::indexT, yoi::indexT > > codeBlockInsertionStates
 
yoi::vec< IRtempStateCodeBlock
 
yoi::vec< std::shared_ptr< yoi::IRValueType > > tempStateTempVarStack
 
IRDebugInfo currentDebugInfo
 
yoi::vec< LoopContextloopContext
 

Detailed Description

Definition at line 873 of file IR.h.

Member Enumeration Documentation

◆ ExtractType

enum class ExtractType
strong
Enumerator
All 
First 
Last 

Definition at line 1055 of file IR.h.

Constructor & Destructor Documentation

◆ IRBuilder() [1/2]

IRBuilder ( )
delete

◆ IRBuilder() [2/2]

IRBuilder ( std::shared_ptr< compilerContext compilerCtx,
std::shared_ptr< IRModule currentModule,
std::shared_ptr< IRFunctionDefinition currentFunction 
)

Definition at line 118 of file IR.cpp.

Member Function Documentation

◆ arithmeticOp()

◆ arrayLengthOp()

void arrayLengthOp ( )

Definition at line 1339 of file IR.cpp.

References IR::array_length.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ basicCast()

◆ bindElementsOp()

void bindElementsOp ( yoi::indexT  extractElementCount,
ExtractType  extractType 
)

Extract elements from an array or a dynamic array, push them to the temp var stack, and dereference the array object.

Parameters
extractElementCountThe number of elements to extract.
extractTypeThe type of extraction, either all, first, or last.

Definition at line 1499 of file IR.cpp.

References IR::bind_elements_post, IR::bind_elements_pred, IROperand::index, and yoi::managedPtr().

Referenced by visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindFieldsOp()

void bindFieldsOp ( yoi::indexT  extractFieldCount,
ExtractType  extractType 
)

Extract fields from a struct, push them to the temp var stack, and dereference the struct object.

Parameters
extractFieldCountThe number of fields to extract.
extractTypeThe type of extraction, either all, first, or last.

Definition at line 1511 of file IR.cpp.

References IR::bind_fields_post, IR::bind_fields_pred, and IROperand::index.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ breakOp()

void breakOp ( )

Definition at line 1489 of file IR.cpp.

References yoi::yoi_assert().

Referenced by visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commitState()

void commitState ( )

Definition at line 1444 of file IR.cpp.

References IROperand::type.

Referenced by visitor::handleSubscript(), and visitor::visit().

Here is the caller graph for this function:

◆ constructInterfaceImplOp()

void constructInterfaceImplOp ( const std::pair< yoi::indexT, yoi::indexT > &  interfaceId,
yoi::indexT  interfaceImplIndex,
bool  isExternal = false,
yoi::indexT  moduleIndex = -1 
)

◆ continueOp()

void continueOp ( )

Definition at line 1494 of file IR.cpp.

References yoi::yoi_assert().

Referenced by visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createCodeBlock()

◆ createLocalVar()

yoi::IROperand createLocalVar ( const yoi::wstr varName,
const std::shared_ptr< IRValueType > &  type 
)

Definition at line 142 of file IR.cpp.

References IRBuilder::currentFunction, and IROperand::localVar.

◆ discardState()

◆ discardStateUntil()

void discardStateUntil ( yoi::indexT  stateIndex)

Definition at line 1456 of file IR.cpp.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ dynCastOp()

void dynCastOp ( const std::shared_ptr< IRValueType > &  type)

Definition at line 1247 of file IR.cpp.

References IR::dyn_cast_any, and IROperand::index.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ getCodeBlock()

IRCodeBlock & getCodeBlock ( yoi::indexT  index)

Definition at line 128 of file IR.cpp.

References IRBuilder::codeBlocks.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ getCurrentCodeBlock()

IRCodeBlock & getCurrentCodeBlock ( )

Definition at line 138 of file IR.cpp.

References IRBuilder::codeBlocks, and IRBuilder::currentCodeBlockIndex.

Referenced by IRBuilder::getCurrentInsertionPoint(), and IRBuilder::insert().

Here is the caller graph for this function:

◆ getCurrentCodeBlockIndex()

yoi::indexT getCurrentCodeBlockIndex ( )

Definition at line 498 of file IR.cpp.

References IRBuilder::currentCodeBlockIndex.

◆ getCurrentDebugInfo()

◆ getCurrentInsertionPoint()

◆ getLhsFromTempVarStack()

◆ getLocalVar()

IRValueType getLocalVar ( yoi::indexT  index)

◆ getRhsFromTempVarStack()

◆ hasTerminated()

bool hasTerminated ( )

Definition at line 1462 of file IR.cpp.

References IR::jump, IR::ret, and IR::ret_none.

Referenced by IRBuilder::jumpIfOp(), IRBuilder::jumpOp(), and IRBuilder::retOp().

Here is the caller graph for this function:

◆ initializeFieldsOp()

void initializeFieldsOp ( yoi::indexT  parameterCount)

Definition at line 1673 of file IR.cpp.

References IROperand::index, and IR::initialize_field.

Referenced by visitor::constructDataStruct().

Here is the caller graph for this function:

◆ insert()

◆ interfaceOfOp()

void interfaceOfOp ( )

Definition at line 1345 of file IR.cpp.

References IR::interfaceof.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ invokeDanglingOp()

void invokeDanglingOp ( yoi::indexT  funcIndex,
yoi::indexT  funcArgsCount,
const std::shared_ptr< IRValueType > &  returnType,
bool  externalInvocation = false,
yoi::indexT  moduleIndex = -1 
)

invoke a function with the given arguments, but the last param will be taken as the first param.

Parameters
funcIndexThe index of function in irModule->functionTable
funcArgsCountThe number of arguments of invocation.
returnTypeThe return type of the function. Need for push the return value type to tempVarStack.
externalInvocationIf true, the function is invoked from an external module.
moduleIndexThe index of the module that the function is imported from.

Definition at line 1530 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::currentModule, IROperand::index, IRBuilder::insert(), IR::invoke_dangling, and IRBuilder::tempVarStack.

Referenced by visitor::createCallableInstanceForFunction(), and visitor::tryCastTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeImportedOp()

void invokeImportedOp ( yoi::indexT  libIndex,
yoi::indexT  funcIndex,
yoi::indexT  funcArgsCount,
const std::shared_ptr< IRValueType > &  returnType 
)

Definition at line 1070 of file IR.cpp.

References IROperand::index, IR::invoke_imported, and yoi::managedPtr().

Referenced by visitor::visit(), and visitor::visitExtern().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeMethodOp()

void invokeMethodOp ( yoi::indexT  funcIndex,
yoi::indexT  methodArgsCount,
const std::shared_ptr< IRValueType > &  returnType,
bool  isStatic,
bool  externalInvocation = false,
yoi::indexT  moduleIndex = -1 
)

◆ invokeOp()

void invokeOp ( yoi::indexT  funcIndex,
yoi::indexT  funcArgsCount,
const std::shared_ptr< IRValueType > &  returnType,
bool  externalInvocation = false,
yoi::indexT  moduleIndex = -1 
)

Invoke a function with the given arguments.

Parameters
funcIndexThe index of function in irModule->functionTable
funcArgsCountThe number of arguments of invocation.
returnTypeThe return type of the function. Need for push the return value type to tempVarStack.
externalInvocationIf true, the function is invoked from an external module.

Definition at line 382 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::currentModule, IROperand::index, IRBuilder::insert(), IR::invoke, and IRBuilder::tempVarStack.

Referenced by visitor::createCallableImplementationForFunction(), IRLinker::createEntryFunction(), and visitor::handleInvocationExtern().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeVirtualOp()

void invokeVirtualOp ( yoi::indexT  funcIndex,
yoi::indexT  interfaceIndex,
yoi::indexT  methodArgsCount,
const std::shared_ptr< IRValueType > &  returnType,
bool  externalInvocation = false,
yoi::indexT  moduleIndex = -1 
)

Definition at line 420 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::currentModule, IROperand::index, IRBuilder::insert(), IR::invoke_virtual, and IRBuilder::tempVarStack.

Referenced by visitor::handleBinaryOperatorOverload(), visitor::handleInvocationExtern(), and visitor::handleUnaryOperatorOverload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ irFuncDefinition()

std::shared_ptr< IRFunctionDefinition > irFuncDefinition ( )

Definition at line 502 of file IR.cpp.

References IRBuilder::currentFunction.

Referenced by visitor::isVisitingGlobalScope(), visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), and visitor::visit().

Here is the caller graph for this function:

◆ jumpIfOp()

void jumpIfOp ( IR::Opcode  op,
yoi::indexT  target 
)

Definition at line 292 of file IR.cpp.

References IRValueType::booleanObject, IROperand::codeBlock, IRBuilder::currentDebugInfo, IRBuilder::hasTerminated(), IRBuilder::insert(), IRBuilder::tempVarStack, and yoi::yoi_assert().

Referenced by visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ jumpOp()

void jumpOp ( yoi::indexT  target)

Definition at line 286 of file IR.cpp.

References IROperand::codeBlock, IRBuilder::currentDebugInfo, IRBuilder::hasTerminated(), IRBuilder::insert(), and IR::jump.

Referenced by visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), visitor::visit(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFieldOp()

void loadFieldOp ( yoi::vec< yoi::IROperand > &  accessors,
const std::shared_ptr< IRValueType > &  expectedType 
)

Definition at line 1680 of file IR.cpp.

References IR::load_field.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ loadMemberOp()

void loadMemberOp ( const yoi::IROperand memberIndex,
const std::shared_ptr< IRValueType > &  memberType 
)

Definition at line 344 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::insert(), IR::load_member, and IRBuilder::tempVarStack.

Referenced by visitor::getGeneratorContext(), visitor::visit(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadOp()

void loadOp ( IR::Opcode  op,
const yoi::IROperand source,
const std::shared_ptr< IRValueType > &  expectedType,
yoi::indexT  moduleIndex = -1 
)

◆ newArrayOp()

◆ newDataStructOp()

void newDataStructOp ( yoi::indexT  structIndex,
bool  isExternal = false,
yoi::indexT  moduleIndex = -1 
)

Definition at line 462 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::currentModule, IRValueType::datastructObject, IROperand::index, IRBuilder::insert(), yoi::managedPtr(), IR::new_datastruct, and IRBuilder::tempVarStack.

Referenced by visitor::constructDataStruct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ newDynamicArrayOp()

◆ newInterfaceOp()

void newInterfaceOp ( yoi::indexT  interfaceIndex,
bool  isExternal = false,
yoi::indexT  moduleIndex = -1 
)

◆ newStructOp()

void newStructOp ( yoi::indexT  structIndex,
bool  isExternal = false,
yoi::indexT  moduleIndex = -1 
)

◆ pointerCastOp()

void pointerCastOp ( )

Definition at line 1276 of file IR.cpp.

References yoi::managedPtr(), IR::pointer_cast, and IRValueType::pointerObject.

Here is the call graph for this function:

◆ popFromTempVarStack()

void popFromTempVarStack ( )

Definition at line 488 of file IR.cpp.

References IRBuilder::tempVarStack.

Referenced by visitor::tryCastTo(), visitor::visit(), visitor::visit(), and visitor::visitExtern().

Here is the caller graph for this function:

◆ popLoopContext()

void popLoopContext ( )

Definition at line 1485 of file IR.cpp.

Referenced by visitor::visit(), and visitor::visit().

Here is the caller graph for this function:

◆ popOp()

void popOp ( )

Definition at line 1189 of file IR.cpp.

References IRValueType::bracedInitalizerList, IRBuilder::currentDebugInfo, IRBuilder::insert(), IR::pop, and IRBuilder::tempVarStack.

Referenced by visitor::handleSubscript(), visitor::visit(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pushLoopContext()

void pushLoopContext ( yoi::indexT  breakTarget,
yoi::indexT  continueTarget 
)

Definition at line 1524 of file IR.cpp.

Referenced by visitor::visit(), and visitor::visit().

Here is the caller graph for this function:

◆ pushOp()

◆ pushTempVar()

void pushTempVar ( const std::shared_ptr< IRValueType > &  type)

Definition at line 1185 of file IR.cpp.

References IRBuilder::tempVarStack.

Referenced by visitor::visit(), visitor::visit(), visitor::visit(), and visitor::visit().

Here is the caller graph for this function:

◆ restoreState()

◆ restoreStateTemporarily()

void restoreStateTemporarily ( )

Definition at line 1433 of file IR.cpp.

References yoi::yoi_assert().

Referenced by visitor::handleSubscript(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resumeOp()

void resumeOp ( )

Takes the raw LLVM context pointer and resume the control flow from the yield point.

Definition at line 1693 of file IR.cpp.

References IR::resume.

Referenced by visitor::getGeneratorContext().

Here is the caller graph for this function:

◆ retOp()

void retOp ( bool  returnWithNone = false)

◆ saveState()

◆ setDebugInfo()

◆ storeFieldOp()

void storeFieldOp ( yoi::vec< yoi::IROperand > &  accessors)

Definition at line 1687 of file IR.cpp.

References IR::store_field.

Referenced by visitor::visit().

Here is the caller graph for this function:

◆ storeMemberOp()

void storeMemberOp ( const yoi::IROperand memberIndex)

Definition at line 375 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::insert(), IR::store_member, and IRBuilder::tempVarStack.

Referenced by visitor::createLambdaUnnamedStruct(), visitor::getGeneratorContext(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storeOp()

◆ switchCodeBlock()

◆ typeIdOp() [1/2]

void typeIdOp ( )

Definition at line 1216 of file IR.cpp.

◆ typeIdOp() [2/2]

void typeIdOp ( const std::shared_ptr< IRValueType > &  type)

Definition at line 1222 of file IR.cpp.

References IROperand::index, IRValueType::integerObject, yoi::managedPtr(), and IR::typeid_object_non_stack.

Referenced by visitor::visit(), and visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uniqueArithmeticOp()

void uniqueArithmeticOp ( IR::Opcode  op)

Definition at line 233 of file IR.cpp.

References IRBuilder::currentDebugInfo, IRBuilder::insert(), and IRBuilder::tempVarStack.

Referenced by visitor::visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yield()

◆ yieldOp()

void yieldOp ( bool  yieldNone = false)

Takes the value from the temp var stack and also the raw LLVM context pointer and return the control flow to the caller.

Parameters
yieldNoneIf true, yield None instead of the value from the temp var stack.

Definition at line 1698 of file IR.cpp.

References IR::yield.

Referenced by visitor::visit().

Here is the caller graph for this function:

Member Data Documentation

◆ codeBlockInsertionStates

yoi::vec<std::tuple<yoi::indexT, yoi::indexT, yoi::indexT> > codeBlockInsertionStates
private

Definition at line 884 of file IR.h.

Referenced by IRBuilder::discardState(), IRBuilder::restoreState(), and IRBuilder::saveState().

◆ codeBlocks

std::vector<std::shared_ptr<IRCodeBlock> > codeBlocks
private

◆ compilerCtx

std::shared_ptr<compilerContext> compilerCtx
private

Definition at line 878 of file IR.h.

Referenced by IRBuilder::arithmeticOp(), IRBuilder::basicCast(), and IRBuilder::pushOp().

◆ currentCodeBlockIndex

◆ currentDebugInfo

◆ currentFunction

std::shared_ptr<IRFunctionDefinition> currentFunction
private

Definition at line 880 of file IR.h.

Referenced by IRBuilder::createLocalVar(), IRBuilder::irFuncDefinition(), and IRBuilder::yield().

◆ currentModule

◆ loopContext

yoi::vec<LoopContext> loopContext
private

Definition at line 888 of file IR.h.

◆ tempStateCodeBlock

yoi::vec<IR> tempStateCodeBlock
private

Definition at line 885 of file IR.h.

◆ tempStateTempVarStack

yoi::vec<std::shared_ptr<yoi::IRValueType> > tempStateTempVarStack
private

Definition at line 886 of file IR.h.

◆ tempVarStack


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