本文整理汇总了C++中PrototypeAST类的典型用法代码示例。如果您正苦于以下问题:C++ PrototypeAST类的具体用法?C++ PrototypeAST怎么用?C++ PrototypeAST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PrototypeAST类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visitPrototype
FunctionAST *Parser::visitFuncttionDefinition() {
int bkup = Tokens->getCurIndex();
PrototypeAST *proto = visitPrototype();
if (!proto) {
return NULL;
} else if ((PrototypeTable.find(proto->getName()) != PrototypeTable.end() &&
PrototypeTable[proto->getName()] != proto->getParamNum()) ||
FunctionTable.find(proto->getName()) != FunctionTable.end()) {
fprintf(stderr, "Function: %s is redefined", proto->getName().c_str());
SAFE_DELETE(proto);
return NULL;
}
VariableTable.clear();
FunctionStmtAST *func_stmt = visitFunctionStatement(proto);
if (func_stmt) {
FunctionTable[proto->getName()] = proto->getParamNum();
return new FunctionAST(proto, func_stmt);
} else {
SAFE_DELETE(proto);
Tokens->applyTokenIndex(bkup);
return NULL;
}
}
示例2:
//! Compares two function prototypes to see if they have the same signature
bool PrototypeAST::operator==( const PrototypeAST& rhs ) const {
if( GetName() != rhs.GetName() ) return false;
if( m_pReturnType != rhs.m_pReturnType ) return false;
if( m_pArgs.size() != rhs.m_pArgs.size() ) return false;
for( uint iArg=0; iArg<m_pArgs.size(); ++iArg ) {
if( m_pArgs[iArg]->GetType() != rhs.m_pArgs[iArg]->GetType() ) return false;
} // end for arg
return true;
} // end PrototypeAST::operator==()
示例3: verifyFunction
Function *FunctionAST::Codegen() {
NamedValues.clear();
Function *TheFunction = Proto->Codegen();
if (TheFunction == 0)
return 0;
// Create a new basic block to start insertion into.
BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
Builder.SetInsertPoint(BB);
if (Value *RetVal = Body->Codegen()) {
// Finish off the function.
Builder.CreateRet(RetVal);
// Validate the generated code, checking for consistency.
verifyFunction(*TheFunction);
// Optimize the function.
TheFPM->run(*TheFunction);
return TheFunction;
}
// Error reading body, remove function.
TheFunction->eraseFromParent();
return 0;
}
示例4: verifyFunction
Function *FunctionAST::Codegen() {
NamedValues.clear();
Function *TheFunction = Proto->Codegen();
if (TheFunction == 0)
return 0;
// If this is an operator, install it.
if (Proto->isBinaryOp())
BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
// Create a new basic block to start insertion into.
BasicBlock *BB = BasicBlock::Create(TheContext, "entry", TheFunction);
Builder.SetInsertPoint(BB);
// Add all arguments to the symbol table and create their allocas.
Proto->CreateArgumentAllocas(TheFunction);
if (Value *RetVal = Body->Codegen()) {
// Finish off the function.
Builder.CreateRet(RetVal);
// Validate the generated code, checking for consistency.
verifyFunction(*TheFunction);
return TheFunction;
}
// Error reading body, remove function.
TheFunction->eraseFromParent();
if (Proto->isBinaryOp())
BinopPrecedence.erase(Proto->getOperatorName());
return 0;
}