下载

0下载券

加入VIP
  • 专属下载券
  • 上传内容扩展
  • 资料优先审核
  • 免费资料无限下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 毕业设计(论文)-基于LLVM的编译器的设计与实现.doc

毕业设计(论文)-基于LLVM的编译器的设计与实现.doc.doc

毕业设计(论文)-基于LLVM的编译器的设计与实现.d…

Ava霞
2018-02-05 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《毕业设计(论文)-基于LLVM的编译器的设计与实现.docdoc》,可适用于战略管理领域

毕业设计(论文)基于LLVM的编译器的设计与实现doc题目:基于LLVM的编译器的设计与实现设计人:指导教师:所属系部:计算机科学与技术学院专业班级:计算机班年月日太原科技大学毕业设计(论文)任务书学院:计算机科学与技术学院学生姓名梁关林学号专业班级计算机同组人无任务下发时间年月任务完成时间年月设计(论文)题目基于LLVM的编译器的设计与实现设计高质量应用软件的开发需要高效的编程语言和编译器的支持。目的为了加深学生对编程语言和编译器的理解要求学生设计一个类似C要求的小源语言然后利用LLVM实现该语言的编译器。在深刻理解编译原理掌握文法设计和编译器构造方法并且熟悉LLVM的基础上完成编程语言和编译器的设计。主要内容包括:设计()设计源语言要求包括变量声明基本赋值语句数组访问主要条件分支语句循环语句函数定义和函数调用等。内容()学习LLVM完成词法分析语法分析和语法制导翻译(翻译成LLVMIR)工作最后利用LLVM实现代码优化和代码生成功能。设计毕业论文提交外文资料翻译资料编译器软件学生签名指导教师签名系主任签名主管院长签名太原科技大学学士学位论文中文摘要开发高性能的应用软件除了一个良好的软件架构外还需要高效的编程语言和高质量的编译器的支持。现有语言的改动和新语言的创造都会带来编译器的开发需求。本文设计了一门新的编程语言leechee定义了此种语言的文法结构、词法规则并在linux环境下实现了leechee编程语言的编译器。具体实现方式为首先利用Flex完成词法分析而后使用Bison完成文法设计、语法分析和语法制导翻译把源代码翻译成LLVMIR最后利用LLVM实现代码优化和代码生成功能。关键字:编程语言编译器语法制导翻译LLVMIR代码优化太原科技大学学士学位论文TheDesignandImplementationofLLVMbasedCompilerAuthor:LiangGuanlinTutor:LiuAiqinABSTRACTInadditiontoagoodsoftwarearchitecture,thedevelopmentofhighperformanceapplicationsalsoneedsthesupportofanefficientprogramminglanguageandahighqualitycompilerChangestoexistin{TypeAST*tyAST=getType()switch(tyAST>getTypeId()){caseTypeAST::BOOLEAN:returnllvm::ConstantInt::get(tyAST>codeGen(context),ValueBoolValue)caseTypeAST::INT:returnllvm::ConstantInt::get(tyAST>codeGen(context),ValueIntValue)caseTypeAST::LONG:returnllvm::ConstantInt::get(tyAST>codeGen(context),ValueLongValue)caseTypeAST::FLOAT:returnllvm::ConstantFP::get(contextTheContext,llvm::APFloat(ValueFloatValue))caseTypeAST::DOUBLE:returnllvm::ConstantFP::get(contextTheContext,llvm::APFloat(ValueDoubleValue))default:break}printError("unknowntypeliteral")return}ConstantValueLiteralAST::getConstantValue(){ConstantValuecvswitch(getType()>getTypeId()){caseTypeAST::BOOLEAN:cvBoolValue=ValueBoolValuecaseTypeAST::INT:cvIntegerValue=ValueIntValuecaseTypeAST::LONG:cvIntegerValue=ValueLongValuecaseTypeAST::FLOAT:cvFloatingValue=ValueFloatValuecaseTypeAST::DOUBLE:cvFloatingValue=ValueDoubleValuedefault:break}returncv}太原科技大学学士学位论文===BinaryExprAST===llvm::Value*BinaryExprAST::codeGen(CodeGenContextcontext){llvm::Value*lhs=LHS>codeGen(context)llvm::Value*rhs=RHS>codeGen(context)if(lhs==||rhs==)returnswitch(Opcode){caseORL:returnhandleOrExpr(context,lhs,rhs)caseANDL:returnhandleAndExpr(context,lhs,rhs)caseINCLOR:caseEXCLOR:caseBINAND:caseEQ:returncontextTheBuilderCreateICmpEQ(lhs,rhs,"eqtmp")caseNE:returncontextTheBuilderCreateICmpNE(lhs,rhs,"netmp")caseLT:returncontextTheBuilderCreateICmpSLT(lhs,rhs,"lttmp")caseLE:returncontextTheBuilderCreateICmpSLE(lhs,rhs,"letmp")caseGT:returncontextTheBuilderCreateICmpSGT(lhs,rhs,"gttmp")caseGE:returncontextTheBuilderCreateICmpSGE(lhs,rhs,"getmp")caseSHLL:caseSHRL:caseSHRA:breakcaseADD:returncontextTheBuilderCreateAdd(lhs,rhs,"addtmp")caseSUB:returncontextTheBuilderCreateSub(lhs,rhs,"subtmp")caseMUL:returncontextTheBuilderCreateMul(lhs,rhs,"multmp")caseDIV:returncontextTheBuilderCreateSDiv(lhs,rhs,"divtmp")caseMOD:returncontextTheBuilderCreateSRem(lhs,rhs,"modtmp")default:break}太原科技大学学士学位论文printError("usednotexistentopcode")return}Handlelogicalorexpressionllvm::Value*BinaryExprAST::handleOrExpr(CodeGenContextcontext,llvm::Value*lhs,llvm::Value*rhs){llvm::Function*fun=contextTheBuilderGetInsertBlock()>getParent()Createblocksfororlexpressionllvm::BasicBlock*lhsFalseBB=llvm::BasicBlock::Create(contextTheContext,"orllhsfalse",fun)llvm::BasicBlock*trueBB=llvm::BasicBlock::Create(contextTheContext,"orltrue")llvm::BasicBlock*falseBB=llvm::BasicBlock::Create(contextTheContext,"orlfalse")llvm::BasicBlock*endBB=llvm::BasicBlock::Create(contextTheContext,"orlend")EmitlhscodecontextTheBuilderCreateCondBr(lhs,trueBB,lhsFalseBB)EmitlhsfalseblockcontextTheBuilderSetInsertPoint(lhsFalseBB)contextTheBuilderCreateCondBr(rhs,trueBB,falseBB)Emittrueblockfun>getBasicBlockList()pushback(trueBB)contextTheBuilderSetInsertPoint(trueBB)llvm::Value*trueV=llvm::ConstantInt::getTrue(contextTheContext)contextTheBuilderCreateBr(endBB)Emitfalseblockfun>getBasicBlockList()pushback(falseBB)contextTheBuilderSetInsertPoint(falseBB)llvm::Value*falseV=llvm::ConstantInt::getFalse(contextTheContext)contextTheBuilderCreateBr(endBB)Emitendblockfun>getBasicBlockList()pushback(endBB)contextTheBuilderSetInsertPoint(endBB)llvm::PHINode*PN=contextTheBuilderCreatePHI(llvm::Type::getIntTy(contextTheContext),,"orltmp")太原科技大学学士学位论文PN>addIncoming(trueV,trueBB)PN>addIncoming(falseV,falseBB)returnPN}Handlelogicalandexpressionllvm::Value*BinaryExprAST::handleAndExpr(CodeGenContextcontext,llvm::Value*lhs,llvm::Value*rhs){llvm::Function*fun=contextTheBuilderGetInsertBlock()>getParent()Createblocksforandlexpressionllvm::BasicBlock*lhsTrueBB=llvm::BasicBlock::Create(contextTheContext,"andllhstrue",fun)llvm::BasicBlock*trueBB=llvm::BasicBlock::Create(contextTheContext,"andltrue")llvm::BasicBlock*falseBB=llvm::BasicBlock::Create(contextTheContext,"andlfalse")llvm::BasicBlock*endBB=llvm::BasicBlock::Create(contextTheContext,"andlend")EmitlhscodecontextTheBuilderCreateCondBr(lhs,lhsTrueBB,falseBB)EmitlhstrueblockcontextTheBuilderSetInsertPoint(lhsTrueBB)contextTheBuilderCreateCondBr(rhs,trueBB,falseBB)Emittrueblockfun>getBasicBlockList()pushback(trueBB)contextTheBuilderSetInsertPoint(trueBB)llvm::Value*trueV=llvm::ConstantInt::getTrue(contextTheContext)contextTheBuilderCreateBr(endBB)Emitfalseblockfun>getBasicBlockList()pushback(falseBB)contextTheBuilderSetInsertPoint(falseBB)llvm::Value*falseV=llvm::ConstantInt::getFalse(contextTheContext)contextTheBuilderCreateBr(endBB)Emitendblockfun>getBasicBlockList()pushback(endBB)contextTheBuilderSetInsertPoint(endBB)llvm::PHINode*PN=contextTheBuilderCreatePHI(llvm::Type::getIntTy(contextTheContext),,"andltmp")太原科技大学学士学位论文PN>addIncoming(trueV,trueBB)PN>addIncoming(falseV,falseBB)returnPN}gettheexpression'sConstantValueConstantValueBinaryExprAST::getConstantValue(){ConstantValuevalswitch(Opcode){caseORL:valBoolValue=LHS>getConstantValue()BoolValue||RHS>getConstantValue()BoolValuereturnvalcaseANDL:valBoolValue=LHS>getConstantValue()BoolValueRHS>getConstantValue()BoolValuereturnval*caseINCLOR:caseEXCLOR:caseBINAND:returnval*caseEQ:valBoolValue=LHS>getConstantValue()BoolValue==RHS>getConstantValue()BoolValuereturnvalcaseNE:valBoolValue=LHS>getConstantValue()BoolValue!=RHS>getConstantValue()BoolValuereturnvalcaseLT:valBoolValue=LHS>getConstantValue()BoolValue<RHS>getConstantValue()BoolValuereturnvalcaseLE:valBoolValue=LHS>getConstantValue()BoolValue<=RHS>getConstantValue()BoolValuereturnvalcaseGT:valBoolValue=LHS>getConstantValue()BoolValue>RHS>getConstantValue()BoolValuereturnval太原科技大学学士学位论文caseGE:valBoolValue=LHS>getConstantValue()BoolValue>=RHS>getConstantValue()BoolValuereturnval*caseSHLL:caseSHRL:caseSHRA:returnval*caseADD:caseSUB:caseMUL:caseDIV:caseMOD:returncomputeConstantValue()default:break}returnval}ComputetheConstantvaluebaseonthetwoopandsConstantValueBinaryExprAST::computeConstantValue(){longlongintLHSValue=longlongintRHSValue=doublefloatLHSValue=doublefloatRHSValue=switch(LHS>getType()>getTypeId()){caseTypeAST::BYTE:caseTypeAST::SHORT:caseTypeAST::INT:caseTypeAST::LONG:intLHSValue=LHS>getConstantValue()IntegerValuebreakcaseTypeAST::FLOAT:caseTypeAST::DOUBLE:floatLHSValue=LHS>getConstantValue()FloatingValuebreak}switch(RHS>getType()>getTypeId()){caseTypeAST::BYTE:caseTypeAST::SHORT:caseTypeAST::INT:caseTypeAST::LONG:intRHSValue=RHS>getConstantValue()IntegerValue太原科技大学学士学位论文breakcaseTypeAST::FLOAT:caseTypeAST::DOUBLE:floatRHSValue=RHS>getConstantValue()FloatingValuebreak}boolisIntTy=trueswitch(getType()>getTypeId()){caseTypeAST::BYTE:caseTypeAST::SHORT:caseTypeAST::INT:caseTypeAST::LONG:isIntTy=truebreakcaseTypeAST::FLOAT:caseTypeAST::DOUBLE:isIntTy=falsebreakdefault:break}ConstantValueresultswitch(Opcode){caseADD:if(isIntTy)resultIntegerValue=intLHSValueintRHSValueelseresultFloatingValue=floatLHSValuefloatRHSValuereturnresultcaseSUB:if(isIntTy)resultIntegerValue=intLHSValueintRHSValueelseresultFloatingValue=floatLHSValuefloatRHSValuereturnresultcaseMUL:if(isIntTy)resultIntegerValue=intLHSValue*intRHSValueelseresultFloatingValue=floatLHSValue*floatRHSValuereturnresultcaseDIV:if(isIntTy)resultIntegerValue=intLHSValueintRHSValueelseresultFloatingValue=floatLHSValuefloatRHSValuereturnresultcaseMOD:if(isIntTy)resultIntegerValue=intLHSValueintRHSValueelseprintError("invalidoperandsoffloatingtypetobinaryoperator:")太原科技大学学士学位论文returnresult}returnresult}===IdentifierAST===llvm::Value*IdentifierAST::codeGen(CodeGenContextcontext){if(isConstant()){anamedconstant}Lookthisvariableupinthefunctionllvm::AllocaInst*V=contextTheEnvStackgetSymbol(Name)if(V==){printError("Unknownvariablename:"Name)return}LoadthevaluereturncontextTheBuilderCreateLoad(V,Namecstr())}===AssignExprAST===llvm::Value*AssignExprAST::codeGen(CodeGenContextcontext){ExprListTypepostExprListllvm::Value*val=Operand>codeGen(context)if(val==)returnif(Dest>getExprId()==ExprAST::IDENTIFIER){cout<<"assignstoidn"LookupthenameIdentifierAST*id=(IdentifierAST*)Destllvm::AllocaInst*variable=contextTheEnvStackgetSymbol(id>getName())if(variable==){printError("Unknownvariablename:"id>getName())return}contextTheBuilderCreateStore(val,variable)returnval}if(Dest>getExprId()==ExprAST::ARRAYELEM){ArrayElemAST*arrElem=(ArrayElemAST*)DestIdentifierAST*arrId=arrElem>getId()cout<<"assignstoarrayelement:"<<arrId>getName()<<'n'llvm::AllocaInst*arr=contextTheEnvStackgetSymbol(arrId>getName())if(arr==){太原科技大学学士学位论文printError("Unknownarray'selementname:"arrId>getName())return}std::vector<llvm::Value*>idxListllvm::Value*idx=contextgetIntConstant()idxListpushback(idx)OffsetExprTypeoffset=*(arrElem>getOffset())for(inti=i<offsetsize()i){llvm::Value*idx=offseti>codeGen(context)idxListpushback(idx)}llvm::GetElementPtrInst*gep=llvm::GetElementPtrInst::CreateInBounds(arr,idxList,"geptmp",contextTheBuilderGetInsertBlock())contextTheBuilderCreateStore(val,gep)returnval}return}===CallExprAST===llvm::Value*CallExprAST::codeGen(CodeGenContextcontext){Lookupthenameintheglobalmoduletablellvm::Function*calleeF=contextTheModule>getFunction(Id>getName())if(calleeF==){printError("Unknownfunctionreferenced")return}Ifargumentmismatcherrorif(calleeF>argsize()!=ArgList>size()){printError("Incorrect#argumentspassed")return}std::vector<llvm::Value*>argsVfor(unsignedi=,e=ArgList>size()i!=ei){argsVpushback((*ArgList)i>codeGen(context))if(argsVback()==){printError("cannotgeneratecallarguments")return}}returncontextTheBuilderCreateCall(calleeF,argsV,"calltmp")太原科技大学学士学位论文}语句的实现文件StatementASTcpp:======ThisfilecontainsimplementationofStatementAST======#include"StatementASThpp"usingnamespacemycompiler===CompoundStatementAST===llvm::BasicBlock*CompoundStatementAST::codeGen(CodeGenContextcontext){cout<<"basicblocksize="<<StatementList>size()<<"n"PushanewenvironmentcontextTheEnvStackpush()for(StatementListType::iteratori=StatementList>begin(),E=StatementList>end()i!=Ei){if((*i)>codeGen(context)==){printError("cannotgeneratecodeforcompoundstatement")return}}Poptheblock'senvironmentcontextTheEnvStackpop()returncontextTheBuilderGetInsertBlock()}===ExprStatementAST===llvm::Instruction*ExprStatementAST::codeGen(CodeGenContextcontext){for(ExprListType::iteratori=ExprList>begin(),E=ExprList>end()i!=Ei){if((*i)>codeGen(context)==){cout<<"exprId::"<<(int)(*i)>getExprId()<<'n'printError("cannotgeneratecodeforExprStatement")return}}return*(contextTheBuilderGetInsertPoint())}太原科技大学学士学位论文===ReturnStatementAST===llvm::Instruction*ReturnStatementAST::codeGen(CodeGenContextcontext){llvm::Value*val=RetExpr>codeGen(context)if(val==){printError("cannotgeneratecodeforreturnstatement'sexpression")return}returncontextTheBuilderCreateRet(val)}===IfStatementAST===llvm::Value*IfStatementAST::codeGen(CodeGenContextcontext){llvm::Value*condV=Cond>codeGen(context)if(condV==){printError("cannotgenerateifstatement'sCond'scode")return}llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()CreateblocksforthethenandelsecasesInsertthe'then'blockattheendofthefunctionllvm::BasicBlock*trueBB=llvm::BasicBlock::Create(contextTheContext,"iftrue",theFun)llvm::BasicBlock*endBB=llvm::BasicBlock::Create(contextTheContext,"ifend")contextTheBuilderCreateCondBr(condV,trueBB,endBB)EmittrueblockcontextTheBuilderSetInsertPoint(trueBB)llvm::Value*trueV=TrueStmt>codeGen(context)if(trueV==){printError("cannotgenerateifTrueStmtcode")return}contextTheBuilderCreateBr(endBB)EmitendblocktheFun>getBasicBlockList()pushback(endBB)contextTheBuilderSetInsertPoint(endBB)returntrueV}===ElseStatementAST===太原科技大学学士学位论文llvm::Value*ElseStatementAST::codeGen(CodeGenContextcontext){llvm::Value*condV=Cond>codeGen(context)if(condV==){printError("cannotgenerateifelseCondcode")return}llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()CreateblocksforthethenandelsecasesInsertthe'then'blockattheendofthefunctionllvm::BasicBlock*trueBB=llvm::BasicBlock::Create(contextTheContext,"ifelsetrue",theFun)llvm::BasicBlock*falseBB=llvm::BasicBlock::Create(contextTheContext,"ifelsefalse")llvm::BasicBlock*mergeBB=llvm::BasicBlock::Create(contextTheContext,"ifelsemerge")contextTheBuilderCreateCondBr(condV,trueBB,falseBB)EmittrueblockcontextTheBuilderSetInsertPoint(trueBB)llvm::Value*trueV=TrueStmt>codeGen(context)if(trueV==){printError("cannotgenerateifelseTrueStmtcode")return}contextTheBuilderCreateBr(mergeBB)Emitelse(false)blocktheFun>getBasicBlockList()pushback(falseBB)contextTheBuilderSetInsertPoint(falseBB)llvm::Value*falseV=FalseStmt>codeGen(context)if(falseV==){printError("cannotgenerateifelseFalseStmtcode")return}contextTheBuilderCreateBr(mergeBB)EmitmergeblocktheFun>getBasicBlockList()pushback(mergeBB)contextTheBuilderSetInsertPoint(mergeBB)returntrueV太原科技大学学士学位论文}===EmptyStatementAST===llvm::Value*EmptyStatementAST::codeGen(CodeGenContextcontext){return*(contextTheBuilderGetInsertPoint())}===ForStatementAST===llvm::Value*ForStatementAST::codeGen(CodeGenContextcontext){PushanewenvironmentcontextTheEnvStackpush()if(InitStmt>codeGen(context)==){printError("cannotgenerateforinitstatementcode")return}llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()SettheIterateStmtStackIterateBlocks*iterateBlks=newIterateBlocks()contextIterateStmtStackpush(iterateBlks)Createblocksforforstatementcond,body,stepandenditerateBlks>CondBB=llvm::BasicBlock::Create(contextTheContext,"forcond",theFun)iterateBlks>BodyBB=llvm::BasicBlock::Create(contextTheContext,"forbody")iterateBlks>BodyEndBB=llvm::BasicBlock::Create(contextTheContext,"forstep")iterateBlks>EndBB=llvm::BasicBlock::Create(contextTheContext,"forend")contextTheBuilderCreateBr(iterateBlks>CondBB)EmitcondblockcontextTheBuilderSetInsertPoint(iterateBlks>CondBB)llvm::Value*condV=Cond>codeGen(context)if(condV==){printError("cannotgenerateforCondexpressioncode")return}contextTheBuilderCreateCondBr(condV,iterateBlks>BodyBB,iterateBlks>EndBB)EmitboyblocktheFun>getBasicBlockList()pushback(iterateBlks>BodyBB)contextTheBuilderSetInsertPoint(iterateBlks>BodyBB)太原科技大学学士学位论文llvm::Value*bodyV=Body>codeGen(context)if(bodyV==){printError("cannotgenerateforbodycode")return}contextTheBuilderCreateBr(iterateBlks>BodyEndBB)EmitstepblocktheFun>getBasicBlockList()pushback(iterateBlks>BodyEndBB)contextTheBuilderSetInsertPoint(iterateBlks>BodyEndBB)if(Step!=){for(ExprListType::iteratori=Step>begin(),E=Step>end()i!=Ei){if((*i)>codeGen(context)==){printError("cannotgenerateforstepcode")return}}}contextTheBuilderCreateBr(iterateBlks>CondBB)DoapopontheIterateStmtStackcontextIterateStmtStackpop()Popthebodyforstatement'senvironmentcontextTheEnvStackpop()EmitendblocktheFun>getBasicBlockList()pushback(iterateBlks>EndBB)contextTheBuilderSetInsertPoint(iterateBlks>EndBB)returnbodyV}===ContinueStatementAST===llvm::Value*ContinueStatementAST::codeGen(CodeGenContextcontext){llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()IterateBlocks*iterateBlks=contextIterateStmtStacktop()llvm::BasicBlock*continueBB=llvm::BasicBlock::Create(contextTheContext,"continue")llvm::BasicBlock*bodyContinueBB=llvm::BasicBlock::Create(contextTheContext,"bodycontinue")contextTheBuilderCreateBr(continueBB)太原科技大学学士学位论文EmitcontinueblocktheFun>getBasicBlockList()pushback(continueBB)contextTheBuilderSetInsertPoint(continueBB)llvm::Value*continueV=contextTheBuilderCreateBr(iterateBlks>BodyEndBB)Changtheiteration'sbodyinsertpointtheFun>getBasicBlockList()pushback(bodyContinueBB)contextTheBuilderSetInsertPoint(bodyContinueBB)iterateBlks>BodyBB=bodyContinueBBreturncontinueV}===BreakStatementAST===llvm::Value*BreakStatementAST::codeGen(CodeGenContextcontext){llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()IterateBlocks*iterateBlks=contextIterateStmtStacktop()llvm::BasicBlock*breakBB=llvm::BasicBlock::Create(contextTheContext,"break")llvm::BasicBlock*bodyBreakBB=llvm::BasicBlock::Create(contextTheContext,"bodybreak")contextTheBuilderCreateBr(breakBB)EmitbreakblocktheFun>getBasicBlockList()pushback(breakBB)contextTheBuilderSetInsertPoint(breakBB)llvm::Value*breakV=contextTheBuilderCreateBr(iterateBlks>EndBB)Changetheiteration'sbodyinsertpointtheFun>getBasicBlockList()pushback(bodyBreakBB)contextTheBuilderSetInsertPoint(bodyBreakBB)iterateBlks>BodyBB=bodyBreakBBreturnbreakV}===WhileStatementAST===llvm::Value*WhileStatementAST::codeGen(CodeGenContextcontext){PushanewenvironmentcontextTheEnvStackpush()llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()SettheIterateStmtStack太原科技大学学士学位论文IterateBlocks*iterateBlks=newIterateBlocks()contextIterateStmtStackpush(iterateBlks)Createblocksforwhilestatementcond,bodyandenditerateBlks>CondBB=llvm::BasicBlock::Create(contextTheContext,"whilecond",theFun)iterateBlks>BodyBB=llvm::BasicBlock::Create(contextTheContext,"whilebody")iterateBlks>EndBB=llvm::BasicBlock::Create(contextTheContext,"whileend")iterateBlks>BodyEndBB=iterateBlks>CondBBcontextTheBuilderCreateBr(iterateBlks>CondBB)EmitcondblockcontextTheBuilderSetInsertPoint(iterateBlks>CondBB)llvm::Value*condV=Cond>codeGen(context)if(condV==){printError("cannotgeneratewhileCondexpressioncode")return}contextTheBuilderCreateCondBr(condV,iterateBlks>BodyBB,iterateBlks>EndBB)EmitboyblocktheFun>getBasicBlockList()pushback(iterateBlks>BodyBB)contextTheBuilderSetInsertPoint(iterateBlks>BodyBB)llvm::Value*bodyV=Body>codeGen(context)if(bodyV==){printError("cannotgeneratewhilebodycode")return}contextTheBuilderCreateBr(iterateBlks>CondBB)DoapopontheIterateStmtStackcontextIterateStmtStackpop()Popthebodyforstatement'senvironmentcontextTheEnvStackpop()EmitendblocktheFun>getBasicBlockList()pushback(iterateBlks>EndBB)contextTheBuilderSetInsertPoint(iterateBlks>EndBB)returnbodyV太原科技大学学士学位论文}===DoWhileStatementAST===llvm::Value*DoWhileStatementAST::codeGen(CodeGenContextcontext){PushanewenvironmentcontextTheEnvStackpush()llvm::Function*theFun=contextTheBuilderGetInsertBlock()>getParent()SettheIterateStmtStackIterateBlocks*iterateBlks=newIterateBlocks()contextIterateStmtStackpush(iterateBlks)Createblocksforwhilestatementcond,bodyandenditerateBlks>BodyBB=llvm::BasicBlock::Create(contextTheContext,"dowhilebody",theFun)iterateBlks>CondBB=llvm::BasicBlock::Create(contextTheContext,"dowhilecond")iterateBlks>EndBB=llvm::BasicBlock::Create(contextTheContext,"dowhileend")iterateBlks>BodyEndBB=iterateBlks>CondBBBackupthebodyblockpointer,becausethebodyblockmaybechangedbycontinueorbreakstatementllvm::BasicBlock*bodyBk=iterateBlks>BodyBBcontextTheBuilderCreateBr(iterateBlks>BodyBB)EmitboyblockcontextTheBuilderSetInsertPoint(iterateBlks>BodyBB)llvm::Value*bodyV=Body>codeGen(context)if(bodyV==){printError("cannotgeneratedowhilebodycode")return}contextTheBuilderCreateBr(iterateBlks>CondBB)EmitcondblocktheFun>getBasicBlockList()pushback(iterateBlks>CondBB)contextTheBuilderSetInsertPoint(iterateBlks>CondBB)llvm::Value*condV=Cond>codeGen(context)if(condV==){printError("cannotgeneratedowhileCondexpressioncode")return太原科技大学学士学位论文}contextTheBuilderCreateCondBr(condV,bodyBk,iterateBlks>EndBB)DoapopontheIterateStmtStackcontextIterateStmtStackpop()Popthebodyforstatement'senvironmentcontextTheEnvStackpop()EmitendblocktheFun>getBasicBlockList()pushback(iterateBlks>EndBB)contextTheBuilderSetInsertPoint(iterateBlks>EndBB)returnbodyV

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/149

VIP

意见
反馈

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利