freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于llvm的編譯器的設(shè)計與實現(xiàn)畢業(yè)論文-資料下載頁

2025-06-18 15:49本頁面
  

【正文】 R的輔助模板類——IRBuilder,方便前端生成中間代碼。在遍歷抽象語法樹生成LLVM IR時可以利用這一個模板。 第五章 編譯器的實現(xiàn)上一章完成了leechee語言及其編譯器的設(shè)計工作,這一章給出leechee編譯器的現(xiàn)實,包括抽象語法樹、符號表、分析棧、中間代碼生成等的實現(xiàn)。 抽象語法樹的實現(xiàn)在設(shè)計一章中已經(jīng)完成了抽象語法樹的設(shè)計,所以這里需要做的就是設(shè)計實現(xiàn)各種語法樹節(jié)點的類,完整地描述整棵語法樹。 NodeASTNodeAST表示一個語法樹節(jié)點,它有兩個數(shù)據(jù)域,一個整型的NodeValue,用來表示節(jié)點的信息。一個是節(jié)點在源碼中的位置信息,包括所在文件、首行、首列、末行、末列,用一個結(jié)構(gòu)體表示。NodeAST是所有其它節(jié)點類的公共基類,除了它外,其它節(jié)點類都有一個codeGen()方法,來生成LLVM IR。struct SymbolLocationType { std::string contain_file。 int first_line。 int first_column。 int last_line。 int last_column。}。struct NodeAST { int NodeValue。 SymbolLocationType SymbolLocation。 NodeAST(int val = 11111, SymbolLocationType amp。loc = CurrentLocation)。 virtual ~NodeAST() {}}。 類型1. TypeASTTypeAST表示一個類型,它有一個類型域,即類型標(biāo)識的枚舉類型,表示具體的類型。使用類型標(biāo)識可以快速區(qū)分不同的類型。除了類型標(biāo)識外,它還有兩個數(shù)據(jù)域,類型名稱和所需存儲空間的大小。它的方法包括,虛析構(gòu)函數(shù)(因為它可以被派生),構(gòu)造函數(shù),中間代碼生成函數(shù),和一些訪問函數(shù)。class TypeAST : public NodeAST {public: enum TypeIdTy { VOID, BOOLEAN, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, ARRAY, FUNCTION }。private: TypeIdTy TypeId。 std::string Name。 int Size。public: virtual ~TypeAST() {} TypeAST(TypeIdTy typeId, const std::string amp。name, int size)。 virtual llvm::Type *codeGen(CodeGenContext amp。context)。 // Accessor methods. TypeIdTy getTypeId()。 std::string getName()。 int getSize()。 // The basic types. static TypeAST Void, Bool, Byte, Short, Int, Long, Float, Double。protected: // Needed by array type. int setSize(int size)。}。2. ArrayTypeASTArrayType表示一個數(shù)組類型,它有兩個數(shù)據(jù)域,一個是它的元素類型,一個是各個維度的大小,用一個vecorint變量表示。它的方法包括,構(gòu)造函數(shù),中間代碼生成函數(shù),和一些訪問函數(shù)。class ArrayTypeAST : public TypeAST { TypeAST *ElemType。 std::vectorint Dimensions。public: ArrayTypeAST(TypeAST *elemType, int elemNum)。 virtual llvm::ArrayType *codeGen(CodeGenContext amp。context)。 // Accessor methods. void expand(int factor) 。 TypeAST *getElemType()。 std::vectorint amp。getDimensions()。}。3. FunctionTypeASTFunctionTypeAST表示一個函數(shù)類型,它有三個數(shù)據(jù)域,一個是返回類型,一個函數(shù)名稱,一個是形參列表。它的方法包括,構(gòu)造函數(shù),中間代碼生成函數(shù),和一些訪問函數(shù)。class FunctionTypeAST : public TypeAST { TypeAST *RetType。 std::string Name。 ParameterListType *ParamList。public: FunctionTypeAST(TypeAST *retTy, const std::string amp。name, ParameterListType *paramList)。 virtual llvm::FunctionType *codeGen(CodeGenContext amp。context)。 // Accessor methods. TypeAST *getRetType()。 std::string getName()。 ParameterListType *getParameterList()。}。struct ParameterAST : public NodeAST { TypeAST *Type。 std::string Name。 ParameterAST(TypeAST *type, const std::string amp。name = )。 TypeAST *getType()。 std::string getName()。}。 表達(dá)式1. ExprASTExprAST是所有表達(dá)式的公共基類,它是一個虛基類,只能夠通過它的子類實例化。它有一個枚舉類型域,表示不同類型的表達(dá)式,即表達(dá)式標(biāo)識。它還有三個數(shù)據(jù)域,一個是表達(dá)式標(biāo)識,一個是表達(dá)式的類型,一個表示是否為常量(添加這個域,是為了支持常量數(shù)據(jù)的聲明)。ExprAST也有一個虛析構(gòu)函數(shù),因為它是所有表達(dá)式類的父類。class ExprAST : public NodeAST {public: enum ExprIdTy { LITERAL, IDENTIFIER, ARRAY_ELEM, CALL, SELF_AFFECT, UNARY, CAST, BINARY, ASSIGN, ARRAY_INITIALIZER, CONSTANT, LOCATION }。private: ExprIdTy ExprId。 TypeAST *Type。 bool IsConstant。public: ExprAST(ExprIdTy exprId, TypeAST *type, bool isConst = false); virtual ~ExprAST() {} virtual llvm::Value *codeGen(CodeGenContext amp。context) = 0。 // Accessor methods. ExprIdTy getExprId()。 TypeAST *getType()。 bool isConstant()。 void setConst()。 virtual ConstantValue getConstantValue()。 static ConstantValue LiteralValueToConstantValue(TypeAST *ty, LiteralValue lv)。}。2. LiteralASTLiteralAST表示字面值常量,它有一個數(shù)據(jù)表,存儲對應(yīng)的字面值。class LiteralAST : public ExprAST { LiteralValue Value。public: LiteralAST(TypeAST *ty, LiteralValue val); // Generate LLVM IR virtual llvm::Constant *codeGen(CodeGenContext amp。context)。 // Accessor methods. LiteralValue getLiteralValue(); virtual ConstantValue getConstantValue()。 // Create a Literal from a basic value. static LiteralAST *createLiteral(bool val)。 static LiteralAST *createLiteral(long long val, bool isLong)。 static LiteralAST *createLiteral(double val, bool isLong)。}。union LiteralValue { bool BoolValue。 int IntValue。 long long LongValue。 float FloatValue。 double DoubleValue。}。3. IdentifierASTIdentifierAST表示一個標(biāo)識符,可以一個變量,可以是命名的常量,也可以是函數(shù)。它有兩個數(shù)據(jù)域,一個是它的名字,一個是它常量值(僅當(dāng)它是命名常量時有效)。class IdentifierAST : public ExprAST { std::string Name。 // This value is only valid when the Id is constant itself. ConstantValue Value。public: // Constructor. IdentifierAST(TypeAST *ty, const std::string amp。name, bool isConst = false)。 // Accessor methods. std::string getName() const { return Name。 } void setValue(ConstantValue val)。 virtual ConstantValue getConstantValue()。 virtual llvm::Value *codeGen(CodeGenContext amp。context)。}。4. ArrayElementASTArrayElemAST表示一個數(shù)組元素,它有兩個數(shù)據(jù)域,一個對應(yīng)數(shù)組變量的標(biāo)識符,一個是數(shù)組下標(biāo),用一個表達(dá)式序列表示(OffsetExprType是vectorExprAST*的typedef)。class ArrayElemAST : public ExprAST { IdentifierAST *Id。 OffsetExprType *Offset。 // Transform the OffsetExpr to Expr. static ExprAST *offsetExpr2Expr(OffsetExprType *offset)。public: // Constructor ArrayElemAST(IdentifierAST *id, OffsetExprType *offset)。 ArrayElemAST(IdentifierAST *id, ExprAST *offset)。 virtual llvm::Value *codeGen(CodeGenContext amp。context)。 // Accessor methods. IdentifierAST *getId() { return Id。 } OffsetExprType *getOffset() { return Offset。 } virtual ConstantValue getConstantValue()。}。5. SelfAffectExprASTSelfAffectExprAST表示一個作用在自身的表達(dá)式,現(xiàn)在只有前增、前減、后增、后減。它有一個枚舉類型的類型域,表示運算的操作碼。它有兩個數(shù)據(jù)域,一個操作碼,一個是操作數(shù)。之所以把這種表達(dá)式和單目運算表達(dá)式區(qū)分開,是因為這種表達(dá)式的操作數(shù)必須是可賦值的,而且這種表達(dá)自身也是可賦值的。class SelfAffectExprAST : public ExprAST {public: enum OpcodeTy { PRE_INC, PRE_DEC, POST_INC, POST_DEC }。private: OpcodeTy Opcode。 ExprAST *Operand。public: SelfAffectExprAST(OpcodeTy opcode, ExprAST *operand)。 virtual llvm::Value *co
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1