Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 1 | //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the parser class for .ll files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_ASMPARSER_LLPARSER_H |
| 15 | #define LLVM_ASMPARSER_LLPARSER_H |
| 16 | |
| 17 | #include "LLLexer.h" |
Kostya Serebryany | 164b86b | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 18 | #include "llvm/Attributes.h" |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 19 | #include "llvm/Instructions.h" |
Owen Anderson | fba933c | 2009-07-01 23:57:11 +0000 | [diff] [blame] | 20 | #include "llvm/Module.h" |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 21 | #include "llvm/Type.h" |
Chris Lattner | b45218f | 2010-04-01 05:20:21 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseMap.h" |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | 5660846 | 2009-12-28 08:20:46 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | e80250e | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 25 | #include <map> |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
| 28 | class Module; |
| 29 | class OpaqueType; |
| 30 | class Function; |
| 31 | class Value; |
| 32 | class BasicBlock; |
| 33 | class Instruction; |
| 34 | class Constant; |
| 35 | class GlobalValue; |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 36 | class MDString; |
| 37 | class MDNode; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 38 | class StructType; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 40 | /// ValID - Represents a reference of a definition of some sort with no type. |
| 41 | /// There are several cases where we have to parse the value but where the |
| 42 | /// type can depend on later context. This may either be a numeric reference |
| 43 | /// or a symbolic (%var) reference. This is just a discriminated union. |
| 44 | struct ValID { |
| 45 | enum { |
| 46 | t_LocalID, t_GlobalID, // ID in UIntVal. |
| 47 | t_LocalName, t_GlobalName, // Name in StrVal. |
| 48 | t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal. |
| 49 | t_Null, t_Undef, t_Zero, // No value. |
| 50 | t_EmptyArray, // No value: [] |
| 51 | t_Constant, // Value in ConstantVal. |
| 52 | t_InlineAsm, // Value in StrVal/StrVal2/UIntVal. |
Chris Lattner | 287881d | 2009-12-30 02:11:14 +0000 | [diff] [blame] | 53 | t_MDNode, // Value in MDNodeVal. |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 54 | t_MDString, // Value in MDStringVal. |
| 55 | t_ConstantStruct, // Value in ConstantStructElts. |
| 56 | t_PackedConstantStruct // Value in ConstantStructElts. |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 57 | } Kind; |
| 58 | |
| 59 | LLLexer::LocTy Loc; |
| 60 | unsigned UIntVal; |
| 61 | std::string StrVal, StrVal2; |
| 62 | APSInt APSIntVal; |
| 63 | APFloat APFloatVal; |
| 64 | Constant *ConstantVal; |
Chris Lattner | 287881d | 2009-12-30 02:11:14 +0000 | [diff] [blame] | 65 | MDNode *MDNodeVal; |
| 66 | MDString *MDStringVal; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 67 | Constant **ConstantStructElts; |
| 68 | |
| 69 | ValID() : Kind(t_LocalID), APFloatVal(0.0) {} |
| 70 | ~ValID() { |
| 71 | if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) |
| 72 | delete [] ConstantStructElts; |
| 73 | } |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 74 | |
| 75 | bool operator<(const ValID &RHS) const { |
| 76 | if (Kind == t_LocalID || Kind == t_GlobalID) |
| 77 | return UIntVal < RHS.UIntVal; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 78 | assert((Kind == t_LocalName || Kind == t_GlobalName || |
| 79 | Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) && |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 80 | "Ordering not defined for this ValID kind yet"); |
| 81 | return StrVal < RHS.StrVal; |
| 82 | } |
| 83 | }; |
| 84 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 85 | class LLParser { |
| 86 | public: |
| 87 | typedef LLLexer::LocTy LocTy; |
| 88 | private: |
Chris Lattner | 4ba9d9b | 2010-04-07 04:08:57 +0000 | [diff] [blame] | 89 | LLVMContext &Context; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 90 | LLLexer Lex; |
| 91 | Module *M; |
Chris Lattner | 449c310 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 92 | |
| 93 | // Instruction metadata resolution. Each instruction can have a list of |
| 94 | // MDRef info associated with them. |
Dan Gohman | 41d6ab4 | 2010-08-24 14:31:06 +0000 | [diff] [blame] | 95 | // |
| 96 | // The simpler approach of just creating temporary MDNodes and then calling |
| 97 | // RAUW on them when the definition is processed doesn't work because some |
| 98 | // instruction metadata kinds, such as dbg, get stored in the IR in an |
| 99 | // "optimized" format which doesn't participate in the normal value use |
| 100 | // lists. This means that RAUW doesn't work, even on temporary MDNodes |
| 101 | // which otherwise support RAUW. Instead, we defer resolving MDNode |
| 102 | // references until the definitions have been processed. |
Chris Lattner | 449c310 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 103 | struct MDRef { |
| 104 | SMLoc Loc; |
| 105 | unsigned MDKind, MDSlot; |
| 106 | }; |
| 107 | DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 108 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 109 | // Type resolution handling data structures. The location is set when we |
| 110 | // have processed a use of the type but not a definition yet. |
| 111 | StringMap<std::pair<Type*, LocTy> > NamedTypes; |
| 112 | std::vector<std::pair<Type*, LocTy> > NumberedTypes; |
| 113 | |
Chris Lattner | 0834e6a | 2009-12-30 04:51:58 +0000 | [diff] [blame] | 114 | std::vector<TrackingVH<MDNode> > NumberedMetadata; |
Chris Lattner | e80250e | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 115 | std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 116 | |
| 117 | // Global Value reference information. |
| 118 | std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals; |
| 119 | std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs; |
| 120 | std::vector<GlobalValue*> NumberedVals; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 121 | |
| 122 | // References to blockaddress. The key is the function ValID, the value is |
| 123 | // a list of references to blocks in that function. |
| 124 | std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > > |
| 125 | ForwardRefBlockAddresses; |
| 126 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 127 | public: |
Chris Lattner | eeb4a84 | 2009-07-02 23:08:13 +0000 | [diff] [blame] | 128 | LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) : |
Victor Hernandez | 13ad5aa | 2009-10-17 00:00:19 +0000 | [diff] [blame] | 129 | Context(m->getContext()), Lex(F, SM, Err, m->getContext()), |
Chris Lattner | f3a789d | 2011-06-17 03:16:47 +0000 | [diff] [blame] | 130 | M(m) {} |
Chris Lattner | ad7d1e2 | 2009-01-04 20:44:11 +0000 | [diff] [blame] | 131 | bool Run(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 133 | LLVMContext &getContext() { return Context; } |
Owen Anderson | b43eae7 | 2009-07-02 17:04:01 +0000 | [diff] [blame] | 134 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 135 | private: |
| 136 | |
Benjamin Kramer | d1e1703 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 137 | bool Error(LocTy L, const Twine &Msg) const { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 138 | return Lex.Error(L, Msg); |
| 139 | } |
Benjamin Kramer | d1e1703 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 140 | bool TokError(const Twine &Msg) const { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 141 | return Error(Lex.getLoc(), Msg); |
| 142 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 143 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 144 | /// GetGlobalVal - Get a value with the specified name or ID, creating a |
| 145 | /// forward reference record if needed. This can return null if the value |
| 146 | /// exists but does not have the right type. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 147 | GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc); |
| 148 | GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 149 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 150 | // Helper Routines. |
| 151 | bool ParseToken(lltok::Kind T, const char *ErrMsg); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 152 | bool EatIfPresent(lltok::Kind T) { |
| 153 | if (Lex.getKind() != T) return false; |
| 154 | Lex.Lex(); |
| 155 | return true; |
| 156 | } |
Rafael Espindola | d72479c | 2011-01-13 01:30:30 +0000 | [diff] [blame] | 157 | bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 158 | if (Lex.getKind() != T) { |
| 159 | Present = false; |
| 160 | } else { |
Rafael Espindola | d72479c | 2011-01-13 01:30:30 +0000 | [diff] [blame] | 161 | if (Loc) |
| 162 | *Loc = Lex.getLoc(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 163 | Lex.Lex(); |
| 164 | Present = true; |
| 165 | } |
| 166 | return false; |
| 167 | } |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 168 | bool ParseStringConstant(std::string &Result); |
| 169 | bool ParseUInt32(unsigned &Val); |
| 170 | bool ParseUInt32(unsigned &Val, LocTy &Loc) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 171 | Loc = Lex.getLoc(); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 172 | return ParseUInt32(Val); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 173 | } |
Hans Wennborg | ce718ff | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 174 | |
| 175 | bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM); |
| 176 | bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 177 | bool ParseOptionalAddrSpace(unsigned &AddrSpace); |
Kostya Serebryany | 164b86b | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 178 | bool ParseOptionalAttrs(Attributes &Attrs, unsigned AttrKind); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 179 | bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage); |
| 180 | bool ParseOptionalLinkage(unsigned &Linkage) { |
| 181 | bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage); |
| 182 | } |
| 183 | bool ParseOptionalVisibility(unsigned &Visibility); |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 184 | bool ParseOptionalCallingConv(CallingConv::ID &CC); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 185 | bool ParseOptionalAlignment(unsigned &Alignment); |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 186 | bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, |
| 187 | AtomicOrdering &Ordering); |
Charles Davis | 1e063d1 | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 188 | bool ParseOptionalStackAlignment(unsigned &Alignment); |
Chris Lattner | c3a6c5c | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 189 | bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); |
Chris Lattner | 628c13a | 2009-12-30 05:14:00 +0000 | [diff] [blame] | 190 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma); |
| 191 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) { |
| 192 | bool AteExtraComma; |
| 193 | if (ParseIndexList(Indices, AteExtraComma)) return true; |
| 194 | if (AteExtraComma) |
| 195 | return TokError("expected index"); |
| 196 | return false; |
| 197 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 198 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 199 | // Top-Level Entities |
| 200 | bool ParseTopLevelEntities(); |
| 201 | bool ValidateEndOfModule(); |
| 202 | bool ParseTargetDefinition(); |
| 203 | bool ParseDepLibs(); |
| 204 | bool ParseModuleAsm(); |
| 205 | bool ParseUnnamedType(); |
| 206 | bool ParseNamedType(); |
| 207 | bool ParseDeclare(); |
| 208 | bool ParseDefine(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 209 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 210 | bool ParseGlobalType(bool &IsConstant); |
Dan Gohman | 3845e50 | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 211 | bool ParseUnnamedGlobal(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 212 | bool ParseNamedGlobal(); |
| 213 | bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, |
| 214 | bool HasLinkage, unsigned Visibility); |
| 215 | bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility); |
Devang Patel | 923078c | 2009-07-01 19:21:12 +0000 | [diff] [blame] | 216 | bool ParseStandaloneMetadata(); |
Devang Patel | eff2ab6 | 2009-07-29 00:34:02 +0000 | [diff] [blame] | 217 | bool ParseNamedMetadata(); |
Chris Lattner | 442ffa1 | 2009-12-29 21:53:55 +0000 | [diff] [blame] | 218 | bool ParseMDString(MDString *&Result); |
Chris Lattner | 4a72efc | 2009-12-30 04:15:23 +0000 | [diff] [blame] | 219 | bool ParseMDNodeID(MDNode *&Result); |
Chris Lattner | 449c310 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 220 | bool ParseMDNodeID(MDNode *&Result, unsigned &SlotNo); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 221 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 222 | // Type Parsing. |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 223 | bool ParseType(Type *&Result, bool AllowVoid = false); |
| 224 | bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 225 | Loc = Lex.getLoc(); |
Chris Lattner | a9a9e07 | 2009-03-09 04:49:14 +0000 | [diff] [blame] | 226 | return ParseType(Result, AllowVoid); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 227 | } |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 228 | bool ParseAnonStructType(Type *&Result, bool Packed); |
| 229 | bool ParseStructBody(SmallVectorImpl<Type*> &Body); |
| 230 | bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name, |
| 231 | std::pair<Type*, LocTy> &Entry, |
| 232 | Type *&ResultTy); |
| 233 | |
| 234 | bool ParseArrayVectorType(Type *&Result, bool isVector); |
| 235 | bool ParseFunctionType(Type *&Result); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 236 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 237 | // Function Semantic Analysis. |
| 238 | class PerFunctionState { |
| 239 | LLParser &P; |
| 240 | Function &F; |
| 241 | std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals; |
| 242 | std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs; |
| 243 | std::vector<Value*> NumberedVals; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 244 | |
| 245 | /// FunctionNumber - If this is an unnamed function, this is the slot |
| 246 | /// number of it, otherwise it is -1. |
| 247 | int FunctionNumber; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 248 | public: |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 249 | PerFunctionState(LLParser &p, Function &f, int FunctionNumber); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 250 | ~PerFunctionState(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 251 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 252 | Function &getFunction() const { return F; } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 253 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 254 | bool FinishFunction(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 255 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 256 | /// GetVal - Get a value with the specified name or ID, creating a |
| 257 | /// forward reference record if needed. This can return null if the value |
| 258 | /// exists but does not have the right type. |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 259 | Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc); |
| 260 | Value *GetVal(unsigned ID, Type *Ty, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 261 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 262 | /// SetInstName - After an instruction is parsed and inserted into its |
| 263 | /// basic block, this installs its name. |
| 264 | bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, |
| 265 | Instruction *Inst); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 266 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 267 | /// GetBB - Get a basic block with the specified name or ID, creating a |
| 268 | /// forward reference record if needed. This can return null if the value |
| 269 | /// is not a BasicBlock. |
| 270 | BasicBlock *GetBB(const std::string &Name, LocTy Loc); |
| 271 | BasicBlock *GetBB(unsigned ID, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 272 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 273 | /// DefineBB - Define the specified basic block, which is either named or |
| 274 | /// unnamed. If there is an error, this returns null otherwise it returns |
| 275 | /// the block being defined. |
| 276 | BasicBlock *DefineBB(const std::string &Name, LocTy Loc); |
| 277 | }; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 278 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 279 | bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V, |
Victor Hernandez | 92f238d | 2010-01-11 22:31:58 +0000 | [diff] [blame] | 280 | PerFunctionState *PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 281 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 282 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS); |
| 283 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) { |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 284 | return ParseValue(Ty, V, &PFS); |
| 285 | } |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 286 | bool ParseValue(Type *Ty, Value *&V, LocTy &Loc, |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 287 | PerFunctionState &PFS) { |
| 288 | Loc = Lex.getLoc(); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 289 | return ParseValue(Ty, V, &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 290 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 291 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 292 | bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS); |
| 293 | bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) { |
| 294 | return ParseTypeAndValue(V, &PFS); |
| 295 | } |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 296 | bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) { |
| 297 | Loc = Lex.getLoc(); |
| 298 | return ParseTypeAndValue(V, PFS); |
| 299 | } |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 300 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc, |
| 301 | PerFunctionState &PFS); |
| 302 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) { |
| 303 | LocTy Loc; |
| 304 | return ParseTypeAndBasicBlock(BB, Loc, PFS); |
| 305 | } |
Victor Hernandez | 1971556 | 2009-12-03 23:40:58 +0000 | [diff] [blame] | 306 | |
Chris Lattner | fdfeb69 | 2010-02-12 20:49:41 +0000 | [diff] [blame] | 307 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 308 | struct ParamInfo { |
| 309 | LocTy Loc; |
| 310 | Value *V; |
Kostya Serebryany | 164b86b | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 311 | Attributes Attrs; |
| 312 | ParamInfo(LocTy loc, Value *v, Attributes attrs) |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 313 | : Loc(loc), V(v), Attrs(attrs) {} |
| 314 | }; |
| 315 | bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, |
| 316 | PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 317 | |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 318 | // Constant Parsing. |
| 319 | bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 320 | bool ParseGlobalValue(Type *Ty, Constant *&V); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 321 | bool ParseGlobalTypeAndValue(Constant *&V); |
| 322 | bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts); |
Dan Gohman | 309b3af | 2010-08-24 02:24:03 +0000 | [diff] [blame] | 323 | bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS); |
Dan Gohman | 8344803 | 2010-07-14 18:26:50 +0000 | [diff] [blame] | 324 | bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS); |
Victor Hernandez | 24e64df | 2010-01-10 07:14:18 +0000 | [diff] [blame] | 325 | bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS); |
Dan Gohman | 9d072f5 | 2010-08-24 02:05:17 +0000 | [diff] [blame] | 326 | bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 327 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 328 | // Function Parsing. |
| 329 | struct ArgInfo { |
| 330 | LocTy Loc; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 331 | Type *Ty; |
Kostya Serebryany | 164b86b | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 332 | Attributes Attrs; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 333 | std::string Name; |
Kostya Serebryany | 164b86b | 2012-01-20 17:56:17 +0000 | [diff] [blame] | 334 | ArgInfo(LocTy L, Type *ty, Attributes Attr, const std::string &N) |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 335 | : Loc(L), Ty(ty), Attrs(Attr), Name(N) {} |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 336 | }; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 337 | bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 338 | bool ParseFunctionHeader(Function *&Fn, bool isDefine); |
| 339 | bool ParseFunctionBody(Function &Fn); |
| 340 | bool ParseBasicBlock(PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 341 | |
Chris Lattner | f1bc7ce | 2009-12-30 05:23:43 +0000 | [diff] [blame] | 342 | // Instruction Parsing. Each instruction parsing routine can return with a |
| 343 | // normal result, an error result, or return having eaten an extra comma. |
| 344 | enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; |
| 345 | int ParseInstruction(Instruction *&Inst, BasicBlock *BB, |
| 346 | PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 347 | bool ParseCmpPredicate(unsigned &Pred, unsigned Opc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 348 | |
Chris Lattner | 437544f | 2011-06-17 06:49:41 +0000 | [diff] [blame] | 349 | bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 350 | bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); |
| 351 | bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 352 | bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 353 | bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); |
Bill Wendling | dccc03b | 2011-07-31 06:30:59 +0000 | [diff] [blame] | 354 | bool ParseResume(Instruction *&Inst, PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 355 | |
Chris Lattner | e914b59 | 2009-01-05 08:24:46 +0000 | [diff] [blame] | 356 | bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, |
| 357 | unsigned OperandType); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 358 | bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 359 | bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 360 | bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 361 | bool ParseSelect(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | 0088a5c | 2009-01-05 08:18:44 +0000 | [diff] [blame] | 362 | bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 363 | bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS); |
| 364 | bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS); |
| 365 | bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | a7d7f2c | 2009-12-30 05:27:33 +0000 | [diff] [blame] | 366 | int ParsePHI(Instruction *&I, PerFunctionState &PFS); |
Bill Wendling | e6e8826 | 2011-08-12 20:24:12 +0000 | [diff] [blame] | 367 | bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 368 | bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail); |
Chris Lattner | f3a789d | 2011-06-17 03:16:47 +0000 | [diff] [blame] | 369 | int ParseAlloc(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | fbe910e | 2011-11-27 06:56:53 +0000 | [diff] [blame] | 370 | int ParseLoad(Instruction *&I, PerFunctionState &PFS); |
| 371 | int ParseStore(Instruction *&I, PerFunctionState &PFS); |
Eli Friedman | f03bb26 | 2011-08-12 22:50:01 +0000 | [diff] [blame] | 372 | int ParseCmpXchg(Instruction *&I, PerFunctionState &PFS); |
| 373 | int ParseAtomicRMW(Instruction *&I, PerFunctionState &PFS); |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 374 | int ParseFence(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | a7d7f2c | 2009-12-30 05:27:33 +0000 | [diff] [blame] | 375 | int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS); |
| 376 | int ParseExtractValue(Instruction *&I, PerFunctionState &PFS); |
| 377 | int ParseInsertValue(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 378 | |
| 379 | bool ResolveForwardRefBlockAddresses(Function *TheFn, |
| 380 | std::vector<std::pair<ValID, GlobalValue*> > &Refs, |
| 381 | PerFunctionState *PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 382 | }; |
| 383 | } // End llvm namespace |
| 384 | |
| 385 | #endif |