4 #include <llvm/IR/IntrinsicInst.h> 5 #include <llvm/IR/Module.h> 20 static llvm::StructType*
type =
nullptr;
33 type = llvm::StructType::create(elems,
"RuntimeData");
40 static llvm::StructType*
type =
nullptr;
49 type = llvm::StructType::create(elems,
"Runtime");
86 auto mallocFunc = llvm::Function::Create(llvm::FunctionType::get(
Type::WordPtr, {
Type::Size},
false), llvm::Function::ExternalLinkage,
"malloc",
getModule());
87 mallocFunc->setDoesNotThrow();
88 mallocFunc->setDoesNotAlias(0);
95 for (
unsigned i = 0; i <
m_dataElts.size(); ++i)
105 auto freeFunc =
getModule()->getFunction(
"free");
109 freeFunc->setDoesNotThrow();
110 freeFunc->setDoesNotCapture(1);
121 auto func =
m_builder.GetInsertBlock()->getParent();
122 auto rtPtr = &func->getArgumentList().front();
158 auto ptr =
getPtr(_index);
159 assert(ptr->getType() == _value->getType()->getPointerTo());
166 auto mem =
m_builder.CreateLoad(memPtr,
"memory");
167 auto returnDataPtr =
m_builder.CreateGEP(mem, _offset);
177 auto retPhi = llvm::cast<llvm::PHINode>(&
m_exitBB->front());
183 auto longjmp = llvm::Intrinsic::getDeclaration(
getModule(), llvm::Intrinsic::eh_sjlj_longjmp);
184 m_builder.CreateCall(longjmp, {_jmpBuf});
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void setGas(llvm::Value *_gas)
llvm::Module * getModule()
Reference to the IR module being compiled.
Return data pointer (set only in case of RETURN)
void set(RuntimeData::Index _index, llvm::Value *_value)
llvm::Value * getGasPtr()
llvm::Value * getDataPtr()
void registerReturnData(llvm::Value *_index, llvm::Value *_size)
static llvm::PointerType * RuntimePtr
assert(len-trim+(2 *lenIndices)<=WIDTH)
llvm::Value * m_stackBase
static llvm::Type * getType()
static llvm::PointerType * WordPtr
llvm::Value * getPtr(RuntimeData::Index _index)
Return data size (set only in case of RETURN)
byte const * code_iterator
static llvm::StructType * getRuntimeType()
Base class for compiler helpers like Memory, GasMeter, etc.
RuntimeManager(IRBuilder &_builder, code_iterator _codeBegin, code_iterator _codeEnd)
static llvm::PointerType * BytePtr
static llvm::StructType * getRuntimeDataType()
llvm::Value * getCallDataSize()
static llvm::IntegerType * Word
static llvm::ConstantInt * get(int64_t _n)
Returns word-size constant.
llvm::Value * getEnvPtr()
static llvm::IntegerType * MainReturn
Main function return type.
void exit(ReturnCode _returnCode)
llvm::Function * getMainFunction()
Reference to the main module function.
static llvm::PointerType * RuntimeDataPtr
void abort(llvm::Value *_jmpBuf)
static const size_t stackSizeLimit
PlatformStyle::TableColorType type
llvm::Value * getCodeSize()
std::array< llvm::Value *, RuntimeData::numElements > m_dataElts
llvm::Value * m_stackSize
static llvm::IntegerType * Size
IRBuilder & m_builder
Reference to parent compiler IR builder.
llvm::Value * getCallData()
llvm::IRBuilder<> IRBuilder
code_iterator m_codeBegin
static llvm::IntegerType * Gas
static llvm::PointerType * EnvPtr
llvm::BasicBlock * m_exitBB
llvm::Value * getRuntimePtr()