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" |
Owen Anderson | fba933c | 2009-07-01 23:57:11 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 19 | #include "llvm/Type.h" |
Chris Lattner | 5660846 | 2009-12-28 08:20:46 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | e80250e | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 21 | #include <map> |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | class Module; |
| 25 | class OpaqueType; |
| 26 | class Function; |
| 27 | class Value; |
| 28 | class BasicBlock; |
| 29 | class Instruction; |
| 30 | class Constant; |
| 31 | class GlobalValue; |
Devang Patel | e54abc9 | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 32 | class MetadataBase; |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 33 | class MDString; |
| 34 | class MDNode; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 36 | /// ValID - Represents a reference of a definition of some sort with no type. |
| 37 | /// There are several cases where we have to parse the value but where the |
| 38 | /// type can depend on later context. This may either be a numeric reference |
| 39 | /// or a symbolic (%var) reference. This is just a discriminated union. |
| 40 | struct ValID { |
| 41 | enum { |
| 42 | t_LocalID, t_GlobalID, // ID in UIntVal. |
| 43 | t_LocalName, t_GlobalName, // Name in StrVal. |
| 44 | t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal. |
| 45 | t_Null, t_Undef, t_Zero, // No value. |
| 46 | t_EmptyArray, // No value: [] |
| 47 | t_Constant, // Value in ConstantVal. |
| 48 | t_InlineAsm, // Value in StrVal/StrVal2/UIntVal. |
Chris Lattner | 287881d | 2009-12-30 02:11:14 +0000 | [diff] [blame] | 49 | t_MDNode, // Value in MDNodeVal. |
| 50 | t_MDString // Value in MDStringVal. |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 51 | } Kind; |
| 52 | |
| 53 | LLLexer::LocTy Loc; |
| 54 | unsigned UIntVal; |
| 55 | std::string StrVal, StrVal2; |
| 56 | APSInt APSIntVal; |
| 57 | APFloat APFloatVal; |
| 58 | Constant *ConstantVal; |
Chris Lattner | 287881d | 2009-12-30 02:11:14 +0000 | [diff] [blame] | 59 | MDNode *MDNodeVal; |
| 60 | MDString *MDStringVal; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 61 | ValID() : APFloatVal(0.0) {} |
| 62 | |
| 63 | bool operator<(const ValID &RHS) const { |
| 64 | if (Kind == t_LocalID || Kind == t_GlobalID) |
| 65 | return UIntVal < RHS.UIntVal; |
| 66 | assert((Kind == t_LocalName || Kind == t_GlobalName) && |
| 67 | "Ordering not defined for this ValID kind yet"); |
| 68 | return StrVal < RHS.StrVal; |
| 69 | } |
| 70 | }; |
| 71 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 72 | class LLParser { |
| 73 | public: |
| 74 | typedef LLLexer::LocTy LocTy; |
| 75 | private: |
Owen Anderson | fba933c | 2009-07-01 23:57:11 +0000 | [diff] [blame] | 76 | LLVMContext& Context; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 77 | LLLexer Lex; |
| 78 | Module *M; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 79 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 80 | // Type resolution handling data structures. |
| 81 | std::map<std::string, std::pair<PATypeHolder, LocTy> > ForwardRefTypes; |
| 82 | std::map<unsigned, std::pair<PATypeHolder, LocTy> > ForwardRefTypeIDs; |
| 83 | std::vector<PATypeHolder> NumberedTypes; |
Chris Lattner | 0834e6a | 2009-12-30 04:51:58 +0000 | [diff] [blame] | 84 | std::vector<TrackingVH<MDNode> > NumberedMetadata; |
Chris Lattner | e80250e | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 85 | std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 86 | struct UpRefRecord { |
| 87 | /// Loc - This is the location of the upref. |
| 88 | LocTy Loc; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 89 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 90 | /// NestingLevel - The number of nesting levels that need to be popped |
| 91 | /// before this type is resolved. |
| 92 | unsigned NestingLevel; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 93 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 94 | /// LastContainedTy - This is the type at the current binding level for |
| 95 | /// the type. Every time we reduce the nesting level, this gets updated. |
| 96 | const Type *LastContainedTy; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 97 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 98 | /// UpRefTy - This is the actual opaque type that the upreference is |
| 99 | /// represented with. |
| 100 | OpaqueType *UpRefTy; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 101 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 102 | UpRefRecord(LocTy L, unsigned NL, OpaqueType *URTy) |
| 103 | : Loc(L), NestingLevel(NL), LastContainedTy((Type*)URTy), |
| 104 | UpRefTy(URTy) {} |
| 105 | }; |
| 106 | std::vector<UpRefRecord> UpRefs; |
| 107 | |
| 108 | // Global Value reference information. |
| 109 | std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals; |
| 110 | std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs; |
| 111 | std::vector<GlobalValue*> NumberedVals; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 112 | |
| 113 | // References to blockaddress. The key is the function ValID, the value is |
| 114 | // a list of references to blocks in that function. |
| 115 | std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > > |
| 116 | ForwardRefBlockAddresses; |
| 117 | |
| 118 | Function *MallocF; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 119 | public: |
Chris Lattner | eeb4a84 | 2009-07-02 23:08:13 +0000 | [diff] [blame] | 120 | LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) : |
Victor Hernandez | 13ad5aa | 2009-10-17 00:00:19 +0000 | [diff] [blame] | 121 | Context(m->getContext()), Lex(F, SM, Err, m->getContext()), |
| 122 | M(m), MallocF(NULL) {} |
Chris Lattner | ad7d1e2 | 2009-01-04 20:44:11 +0000 | [diff] [blame] | 123 | bool Run(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 124 | |
Owen Anderson | b43eae7 | 2009-07-02 17:04:01 +0000 | [diff] [blame] | 125 | LLVMContext& getContext() { return Context; } |
| 126 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 127 | private: |
| 128 | |
| 129 | bool Error(LocTy L, const std::string &Msg) const { |
| 130 | return Lex.Error(L, Msg); |
| 131 | } |
| 132 | bool TokError(const std::string &Msg) const { |
| 133 | return Error(Lex.getLoc(), Msg); |
| 134 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 135 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 136 | /// GetGlobalVal - Get a value with the specified name or ID, creating a |
| 137 | /// forward reference record if needed. This can return null if the value |
| 138 | /// exists but does not have the right type. |
| 139 | GlobalValue *GetGlobalVal(const std::string &N, const Type *Ty, LocTy Loc); |
| 140 | GlobalValue *GetGlobalVal(unsigned ID, const Type *Ty, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 141 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 142 | // Helper Routines. |
| 143 | bool ParseToken(lltok::Kind T, const char *ErrMsg); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 144 | bool EatIfPresent(lltok::Kind T) { |
| 145 | if (Lex.getKind() != T) return false; |
| 146 | Lex.Lex(); |
| 147 | return true; |
| 148 | } |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 149 | bool ParseOptionalToken(lltok::Kind T, bool &Present) { |
| 150 | if (Lex.getKind() != T) { |
| 151 | Present = false; |
| 152 | } else { |
| 153 | Lex.Lex(); |
| 154 | Present = true; |
| 155 | } |
| 156 | return false; |
| 157 | } |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 158 | bool ParseStringConstant(std::string &Result); |
| 159 | bool ParseUInt32(unsigned &Val); |
| 160 | bool ParseUInt32(unsigned &Val, LocTy &Loc) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 161 | Loc = Lex.getLoc(); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 162 | return ParseUInt32(Val); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 163 | } |
| 164 | bool ParseOptionalAddrSpace(unsigned &AddrSpace); |
| 165 | bool ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind); |
| 166 | bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage); |
| 167 | bool ParseOptionalLinkage(unsigned &Linkage) { |
| 168 | bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage); |
| 169 | } |
| 170 | bool ParseOptionalVisibility(unsigned &Visibility); |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 171 | bool ParseOptionalCallingConv(CallingConv::ID &CC); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 172 | bool ParseOptionalAlignment(unsigned &Alignment); |
Chris Lattner | 1340dd3 | 2009-12-30 05:48:36 +0000 | [diff] [blame] | 173 | bool ParseInstructionMetadata(SmallVectorImpl<std::pair<unsigned, |
| 174 | MDNode *> > &); |
Chris Lattner | c3a6c5c | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 175 | bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); |
Chris Lattner | 628c13a | 2009-12-30 05:14:00 +0000 | [diff] [blame] | 176 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma); |
| 177 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) { |
| 178 | bool AteExtraComma; |
| 179 | if (ParseIndexList(Indices, AteExtraComma)) return true; |
| 180 | if (AteExtraComma) |
| 181 | return TokError("expected index"); |
| 182 | return false; |
| 183 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 184 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 185 | // Top-Level Entities |
| 186 | bool ParseTopLevelEntities(); |
| 187 | bool ValidateEndOfModule(); |
| 188 | bool ParseTargetDefinition(); |
| 189 | bool ParseDepLibs(); |
| 190 | bool ParseModuleAsm(); |
| 191 | bool ParseUnnamedType(); |
| 192 | bool ParseNamedType(); |
| 193 | bool ParseDeclare(); |
| 194 | bool ParseDefine(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 195 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 196 | bool ParseGlobalType(bool &IsConstant); |
Dan Gohman | 3845e50 | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 197 | bool ParseUnnamedGlobal(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 198 | bool ParseNamedGlobal(); |
| 199 | bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, |
| 200 | bool HasLinkage, unsigned Visibility); |
| 201 | bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility); |
Devang Patel | 923078c | 2009-07-01 19:21:12 +0000 | [diff] [blame] | 202 | bool ParseStandaloneMetadata(); |
Devang Patel | eff2ab6 | 2009-07-29 00:34:02 +0000 | [diff] [blame] | 203 | bool ParseNamedMetadata(); |
Chris Lattner | 442ffa1 | 2009-12-29 21:53:55 +0000 | [diff] [blame] | 204 | bool ParseMDString(MDString *&Result); |
Chris Lattner | 4a72efc | 2009-12-30 04:15:23 +0000 | [diff] [blame] | 205 | bool ParseMDNodeID(MDNode *&Result); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 206 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 207 | // Type Parsing. |
Chris Lattner | a9a9e07 | 2009-03-09 04:49:14 +0000 | [diff] [blame] | 208 | bool ParseType(PATypeHolder &Result, bool AllowVoid = false); |
| 209 | bool ParseType(PATypeHolder &Result, LocTy &Loc, bool AllowVoid = false) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 210 | Loc = Lex.getLoc(); |
Chris Lattner | a9a9e07 | 2009-03-09 04:49:14 +0000 | [diff] [blame] | 211 | return ParseType(Result, AllowVoid); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 212 | } |
| 213 | bool ParseTypeRec(PATypeHolder &H); |
| 214 | bool ParseStructType(PATypeHolder &H, bool Packed); |
| 215 | bool ParseArrayVectorType(PATypeHolder &H, bool isVector); |
| 216 | bool ParseFunctionType(PATypeHolder &Result); |
| 217 | PATypeHolder HandleUpRefs(const Type *Ty); |
| 218 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 219 | // Function Semantic Analysis. |
| 220 | class PerFunctionState { |
| 221 | LLParser &P; |
| 222 | Function &F; |
| 223 | std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals; |
| 224 | std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs; |
| 225 | std::vector<Value*> NumberedVals; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 226 | |
| 227 | /// FunctionNumber - If this is an unnamed function, this is the slot |
| 228 | /// number of it, otherwise it is -1. |
| 229 | int FunctionNumber; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 230 | public: |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 231 | PerFunctionState(LLParser &p, Function &f, int FunctionNumber); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 232 | ~PerFunctionState(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 233 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 234 | Function &getFunction() const { return F; } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 235 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 236 | bool FinishFunction(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 237 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 238 | /// GetVal - Get a value with the specified name or ID, creating a |
| 239 | /// forward reference record if needed. This can return null if the value |
| 240 | /// exists but does not have the right type. |
| 241 | Value *GetVal(const std::string &Name, const Type *Ty, LocTy Loc); |
| 242 | Value *GetVal(unsigned ID, const Type *Ty, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 243 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 244 | /// SetInstName - After an instruction is parsed and inserted into its |
| 245 | /// basic block, this installs its name. |
| 246 | bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, |
| 247 | Instruction *Inst); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 248 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 249 | /// GetBB - Get a basic block with the specified name or ID, creating a |
| 250 | /// forward reference record if needed. This can return null if the value |
| 251 | /// is not a BasicBlock. |
| 252 | BasicBlock *GetBB(const std::string &Name, LocTy Loc); |
| 253 | BasicBlock *GetBB(unsigned ID, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 254 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 255 | /// DefineBB - Define the specified basic block, which is either named or |
| 256 | /// unnamed. If there is an error, this returns null otherwise it returns |
| 257 | /// the block being defined. |
| 258 | BasicBlock *DefineBB(const std::string &Name, LocTy Loc); |
| 259 | }; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 260 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 261 | bool ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V, |
| 262 | PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 263 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 264 | bool ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS); |
| 265 | bool ParseValue(const Type *Ty, Value *&V, LocTy &Loc, |
| 266 | PerFunctionState &PFS) { |
| 267 | Loc = Lex.getLoc(); |
| 268 | return ParseValue(Ty, V, PFS); |
| 269 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 270 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 271 | bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS); |
| 272 | bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) { |
| 273 | Loc = Lex.getLoc(); |
| 274 | return ParseTypeAndValue(V, PFS); |
| 275 | } |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 276 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc, |
| 277 | PerFunctionState &PFS); |
| 278 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) { |
| 279 | LocTy Loc; |
| 280 | return ParseTypeAndBasicBlock(BB, Loc, PFS); |
| 281 | } |
Victor Hernandez | 1971556 | 2009-12-03 23:40:58 +0000 | [diff] [blame] | 282 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 283 | struct ParamInfo { |
| 284 | LocTy Loc; |
| 285 | Value *V; |
| 286 | unsigned Attrs; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 287 | ParamInfo(LocTy loc, Value *v, unsigned attrs) |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 288 | : Loc(loc), V(v), Attrs(attrs) {} |
| 289 | }; |
| 290 | bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, |
| 291 | PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 292 | |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 293 | // Constant Parsing. |
| 294 | bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL); |
| 295 | bool ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, Constant *&V); |
| 296 | bool ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID, |
Victor Hernandez | 24e64df | 2010-01-10 07:14:18 +0000 | [diff] [blame^] | 297 | Value *&V, PerFunctionState *PFS); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 298 | bool ParseGlobalValue(const Type *Ty, Constant *&V); |
| 299 | bool ParseGlobalTypeAndValue(Constant *&V); |
| 300 | bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts); |
Victor Hernandez | 24e64df | 2010-01-10 07:14:18 +0000 | [diff] [blame^] | 301 | bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 302 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 303 | // Function Parsing. |
| 304 | struct ArgInfo { |
| 305 | LocTy Loc; |
| 306 | PATypeHolder Type; |
| 307 | unsigned Attrs; |
| 308 | std::string Name; |
| 309 | ArgInfo(LocTy L, PATypeHolder Ty, unsigned Attr, const std::string &N) |
| 310 | : Loc(L), Type(Ty), Attrs(Attr), Name(N) {} |
| 311 | }; |
| 312 | bool ParseArgumentList(std::vector<ArgInfo> &ArgList, |
Chris Lattner | dfd19dd | 2009-01-05 18:34:07 +0000 | [diff] [blame] | 313 | bool &isVarArg, bool inType); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 314 | bool ParseFunctionHeader(Function *&Fn, bool isDefine); |
| 315 | bool ParseFunctionBody(Function &Fn); |
| 316 | bool ParseBasicBlock(PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 317 | |
Chris Lattner | f1bc7ce | 2009-12-30 05:23:43 +0000 | [diff] [blame] | 318 | // Instruction Parsing. Each instruction parsing routine can return with a |
| 319 | // normal result, an error result, or return having eaten an extra comma. |
| 320 | enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; |
| 321 | int ParseInstruction(Instruction *&Inst, BasicBlock *BB, |
| 322 | PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 323 | bool ParseCmpPredicate(unsigned &Pred, unsigned Opc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 324 | |
Chris Lattner | f1bc7ce | 2009-12-30 05:23:43 +0000 | [diff] [blame] | 325 | int ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 326 | bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); |
| 327 | bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 328 | bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 329 | bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 330 | |
Chris Lattner | e914b59 | 2009-01-05 08:24:46 +0000 | [diff] [blame] | 331 | bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, |
| 332 | unsigned OperandType); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 333 | bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 334 | bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 335 | bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc); |
| 336 | bool ParseSelect(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | 0088a5c | 2009-01-05 08:18:44 +0000 | [diff] [blame] | 337 | bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 338 | bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS); |
| 339 | bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS); |
| 340 | bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | a7d7f2c | 2009-12-30 05:27:33 +0000 | [diff] [blame] | 341 | int ParsePHI(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 342 | bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail); |
Chris Lattner | c3a6c5c | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 343 | int ParseAlloc(Instruction *&I, PerFunctionState &PFS, |
Victor Hernandez | 13ad5aa | 2009-10-17 00:00:19 +0000 | [diff] [blame] | 344 | BasicBlock *BB = 0, bool isAlloca = true); |
Victor Hernandez | 66284e0 | 2009-10-24 04:23:03 +0000 | [diff] [blame] | 345 | bool ParseFree(Instruction *&I, PerFunctionState &PFS, BasicBlock *BB); |
Chris Lattner | c3a6c5c | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 346 | int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile); |
| 347 | int ParseStore(Instruction *&I, PerFunctionState &PFS, bool isVolatile); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 348 | bool ParseGetResult(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | a7d7f2c | 2009-12-30 05:27:33 +0000 | [diff] [blame] | 349 | int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS); |
| 350 | int ParseExtractValue(Instruction *&I, PerFunctionState &PFS); |
| 351 | int ParseInsertValue(Instruction *&I, PerFunctionState &PFS); |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 352 | |
| 353 | bool ResolveForwardRefBlockAddresses(Function *TheFn, |
| 354 | std::vector<std::pair<ValID, GlobalValue*> > &Refs, |
| 355 | PerFunctionState *PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 356 | }; |
| 357 | } // End llvm namespace |
| 358 | |
| 359 | #endif |