blob: 42cdbd51227eb0018a34a864caf360ad3863e509 [file] [log] [blame]
Chris Lattnerdf986172009-01-02 07:01:27 +00001//===-- 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"
Chandler Carrutha1514e22012-12-04 07:12:27 +000018#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringMap.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000020#include "llvm/IR/Attributes.h"
21#include "llvm/IR/Instructions.h"
22#include "llvm/IR/Module.h"
23#include "llvm/IR/Operator.h"
24#include "llvm/IR/Type.h"
Chris Lattner56608462009-12-28 08:20:46 +000025#include "llvm/Support/ValueHandle.h"
Chris Lattnere80250e2009-12-29 21:43:58 +000026#include <map>
Chris Lattnerdf986172009-01-02 07:01:27 +000027
28namespace llvm {
29 class Module;
30 class OpaqueType;
31 class Function;
32 class Value;
33 class BasicBlock;
34 class Instruction;
35 class Constant;
36 class GlobalValue;
Nick Lewycky21cc4462009-04-04 07:22:01 +000037 class MDString;
38 class MDNode;
Chris Lattner1afcace2011-07-09 17:41:24 +000039 class StructType;
Misha Brukman9ea40342009-01-02 22:46:48 +000040
Chris Lattner09d9ef42009-10-28 03:39:23 +000041 /// ValID - Represents a reference of a definition of some sort with no type.
42 /// There are several cases where we have to parse the value but where the
43 /// type can depend on later context. This may either be a numeric reference
44 /// or a symbolic (%var) reference. This is just a discriminated union.
45 struct ValID {
46 enum {
47 t_LocalID, t_GlobalID, // ID in UIntVal.
48 t_LocalName, t_GlobalName, // Name in StrVal.
49 t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal.
50 t_Null, t_Undef, t_Zero, // No value.
51 t_EmptyArray, // No value: []
52 t_Constant, // Value in ConstantVal.
53 t_InlineAsm, // Value in StrVal/StrVal2/UIntVal.
Chris Lattner287881d2009-12-30 02:11:14 +000054 t_MDNode, // Value in MDNodeVal.
Chris Lattner1afcace2011-07-09 17:41:24 +000055 t_MDString, // Value in MDStringVal.
56 t_ConstantStruct, // Value in ConstantStructElts.
57 t_PackedConstantStruct // Value in ConstantStructElts.
Chris Lattner09d9ef42009-10-28 03:39:23 +000058 } Kind;
Michael Ilseman407a6162012-11-15 22:34:00 +000059
Chris Lattner09d9ef42009-10-28 03:39:23 +000060 LLLexer::LocTy Loc;
61 unsigned UIntVal;
62 std::string StrVal, StrVal2;
63 APSInt APSIntVal;
64 APFloat APFloatVal;
65 Constant *ConstantVal;
Chris Lattner287881d2009-12-30 02:11:14 +000066 MDNode *MDNodeVal;
67 MDString *MDStringVal;
Chris Lattner1afcace2011-07-09 17:41:24 +000068 Constant **ConstantStructElts;
Michael Ilseman407a6162012-11-15 22:34:00 +000069
Chris Lattner1afcace2011-07-09 17:41:24 +000070 ValID() : Kind(t_LocalID), APFloatVal(0.0) {}
71 ~ValID() {
72 if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct)
73 delete [] ConstantStructElts;
74 }
Michael Ilseman407a6162012-11-15 22:34:00 +000075
Chris Lattner09d9ef42009-10-28 03:39:23 +000076 bool operator<(const ValID &RHS) const {
77 if (Kind == t_LocalID || Kind == t_GlobalID)
78 return UIntVal < RHS.UIntVal;
Chris Lattner1afcace2011-07-09 17:41:24 +000079 assert((Kind == t_LocalName || Kind == t_GlobalName ||
Michael Ilseman407a6162012-11-15 22:34:00 +000080 Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
Chris Lattner09d9ef42009-10-28 03:39:23 +000081 "Ordering not defined for this ValID kind yet");
82 return StrVal < RHS.StrVal;
83 }
84 };
Michael Ilseman407a6162012-11-15 22:34:00 +000085
Chris Lattnerdf986172009-01-02 07:01:27 +000086 class LLParser {
87 public:
88 typedef LLLexer::LocTy LocTy;
89 private:
Chris Lattner4ba9d9b2010-04-07 04:08:57 +000090 LLVMContext &Context;
Chris Lattnerdf986172009-01-02 07:01:27 +000091 LLLexer Lex;
92 Module *M;
Michael Ilseman407a6162012-11-15 22:34:00 +000093
Chris Lattner449c3102010-04-01 05:14:45 +000094 // Instruction metadata resolution. Each instruction can have a list of
95 // MDRef info associated with them.
Dan Gohman41d6ab42010-08-24 14:31:06 +000096 //
97 // The simpler approach of just creating temporary MDNodes and then calling
98 // RAUW on them when the definition is processed doesn't work because some
99 // instruction metadata kinds, such as dbg, get stored in the IR in an
100 // "optimized" format which doesn't participate in the normal value use
101 // lists. This means that RAUW doesn't work, even on temporary MDNodes
102 // which otherwise support RAUW. Instead, we defer resolving MDNode
103 // references until the definitions have been processed.
Chris Lattner449c3102010-04-01 05:14:45 +0000104 struct MDRef {
105 SMLoc Loc;
106 unsigned MDKind, MDSlot;
107 };
108 DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata;
Misha Brukman9ea40342009-01-02 22:46:48 +0000109
Chris Lattner1afcace2011-07-09 17:41:24 +0000110 // Type resolution handling data structures. The location is set when we
111 // have processed a use of the type but not a definition yet.
112 StringMap<std::pair<Type*, LocTy> > NamedTypes;
113 std::vector<std::pair<Type*, LocTy> > NumberedTypes;
Michael Ilseman407a6162012-11-15 22:34:00 +0000114
Chris Lattner0834e6a2009-12-30 04:51:58 +0000115 std::vector<TrackingVH<MDNode> > NumberedMetadata;
Chris Lattnere80250e2009-12-29 21:43:58 +0000116 std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes;
Chris Lattnerdf986172009-01-02 07:01:27 +0000117
118 // Global Value reference information.
119 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
120 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
121 std::vector<GlobalValue*> NumberedVals;
Michael Ilseman407a6162012-11-15 22:34:00 +0000122
Chris Lattner09d9ef42009-10-28 03:39:23 +0000123 // References to blockaddress. The key is the function ValID, the value is
124 // a list of references to blocks in that function.
125 std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >
126 ForwardRefBlockAddresses;
Michael Ilseman407a6162012-11-15 22:34:00 +0000127
Bill Wendling95ce4c22013-02-06 06:52:58 +0000128 // Attribute builder reference information.
Bill Wendlingbaad55c2013-02-08 06:32:06 +0000129 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
130 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
Bill Wendling95ce4c22013-02-06 06:52:58 +0000131
Chris Lattnerdf986172009-01-02 07:01:27 +0000132 public:
Michael Ilseman407a6162012-11-15 22:34:00 +0000133 LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
Victor Hernandez13ad5aa2009-10-17 00:00:19 +0000134 Context(m->getContext()), Lex(F, SM, Err, m->getContext()),
Chris Lattnerf3a789d2011-06-17 03:16:47 +0000135 M(m) {}
Chris Lattnerad7d1e22009-01-04 20:44:11 +0000136 bool Run();
Misha Brukman9ea40342009-01-02 22:46:48 +0000137
Chris Lattner1afcace2011-07-09 17:41:24 +0000138 LLVMContext &getContext() { return Context; }
Owen Andersonb43eae72009-07-02 17:04:01 +0000139
Chris Lattnerdf986172009-01-02 07:01:27 +0000140 private:
141
Benjamin Kramerd1e17032010-09-27 17:42:11 +0000142 bool Error(LocTy L, const Twine &Msg) const {
Chris Lattnerdf986172009-01-02 07:01:27 +0000143 return Lex.Error(L, Msg);
144 }
Benjamin Kramerd1e17032010-09-27 17:42:11 +0000145 bool TokError(const Twine &Msg) const {
Chris Lattnerdf986172009-01-02 07:01:27 +0000146 return Error(Lex.getLoc(), Msg);
147 }
Misha Brukman9ea40342009-01-02 22:46:48 +0000148
Chris Lattnerdf986172009-01-02 07:01:27 +0000149 /// GetGlobalVal - Get a value with the specified name or ID, creating a
150 /// forward reference record if needed. This can return null if the value
151 /// exists but does not have the right type.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000152 GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
153 GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
Misha Brukman9ea40342009-01-02 22:46:48 +0000154
Chris Lattnerdf986172009-01-02 07:01:27 +0000155 // Helper Routines.
156 bool ParseToken(lltok::Kind T, const char *ErrMsg);
Chris Lattner3ed88ef2009-01-02 08:05:26 +0000157 bool EatIfPresent(lltok::Kind T) {
158 if (Lex.getKind() != T) return false;
159 Lex.Lex();
160 return true;
161 }
Michael Ilseman15c13d32012-11-27 00:42:44 +0000162
163 FastMathFlags EatFastMathFlagsIfPresent() {
164 FastMathFlags FMF;
165 while (true)
166 switch (Lex.getKind()) {
Michael Ilseman1638b832012-12-09 21:12:04 +0000167 case lltok::kw_fast: FMF.setUnsafeAlgebra(); Lex.Lex(); continue;
168 case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
169 case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
170 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
171 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
Michael Ilseman15c13d32012-11-27 00:42:44 +0000172 default: return FMF;
173 }
174 return FMF;
175 }
176
Rafael Espindolad72479c2011-01-13 01:30:30 +0000177 bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
Chris Lattnerdf986172009-01-02 07:01:27 +0000178 if (Lex.getKind() != T) {
179 Present = false;
180 } else {
Rafael Espindolad72479c2011-01-13 01:30:30 +0000181 if (Loc)
182 *Loc = Lex.getLoc();
Chris Lattnerdf986172009-01-02 07:01:27 +0000183 Lex.Lex();
184 Present = true;
185 }
186 return false;
187 }
Chris Lattner3ed88ef2009-01-02 08:05:26 +0000188 bool ParseStringConstant(std::string &Result);
189 bool ParseUInt32(unsigned &Val);
190 bool ParseUInt32(unsigned &Val, LocTy &Loc) {
Chris Lattnerdf986172009-01-02 07:01:27 +0000191 Loc = Lex.getLoc();
Chris Lattner3ed88ef2009-01-02 08:05:26 +0000192 return ParseUInt32(Val);
Chris Lattnerdf986172009-01-02 07:01:27 +0000193 }
Hans Wennborgce718ff2012-06-23 11:37:03 +0000194
195 bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
196 bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
Chris Lattnerdf986172009-01-02 07:01:27 +0000197 bool ParseOptionalAddrSpace(unsigned &AddrSpace);
Bill Wendlinge01b81b2012-12-04 23:40:58 +0000198 bool ParseOptionalParamAttrs(AttrBuilder &B);
199 bool ParseOptionalReturnAttrs(AttrBuilder &B);
Chris Lattnerdf986172009-01-02 07:01:27 +0000200 bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
201 bool ParseOptionalLinkage(unsigned &Linkage) {
202 bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
203 }
204 bool ParseOptionalVisibility(unsigned &Visibility);
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000205 bool ParseOptionalCallingConv(CallingConv::ID &CC);
Chris Lattnerdf986172009-01-02 07:01:27 +0000206 bool ParseOptionalAlignment(unsigned &Alignment);
Eli Friedman47f35132011-07-25 23:16:38 +0000207 bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
208 AtomicOrdering &Ordering);
Charles Davis1e063d12010-02-12 00:31:15 +0000209 bool ParseOptionalStackAlignment(unsigned &Alignment);
Chris Lattnerc3a6c5c2009-12-30 05:44:30 +0000210 bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma);
Chris Lattner628c13a2009-12-30 05:14:00 +0000211 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma);
212 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
213 bool AteExtraComma;
214 if (ParseIndexList(Indices, AteExtraComma)) return true;
215 if (AteExtraComma)
216 return TokError("expected index");
217 return false;
218 }
Misha Brukman9ea40342009-01-02 22:46:48 +0000219
Chris Lattnerdf986172009-01-02 07:01:27 +0000220 // Top-Level Entities
221 bool ParseTopLevelEntities();
222 bool ValidateEndOfModule();
223 bool ParseTargetDefinition();
Chris Lattnerdf986172009-01-02 07:01:27 +0000224 bool ParseModuleAsm();
Bill Wendling3defc0b2012-11-28 08:41:48 +0000225 bool ParseDepLibs(); // FIXME: Remove in 4.0.
Chris Lattnerdf986172009-01-02 07:01:27 +0000226 bool ParseUnnamedType();
227 bool ParseNamedType();
228 bool ParseDeclare();
229 bool ParseDefine();
Misha Brukman9ea40342009-01-02 22:46:48 +0000230
Chris Lattnerdf986172009-01-02 07:01:27 +0000231 bool ParseGlobalType(bool &IsConstant);
Dan Gohman3845e502009-08-12 23:32:33 +0000232 bool ParseUnnamedGlobal();
Chris Lattnerdf986172009-01-02 07:01:27 +0000233 bool ParseNamedGlobal();
234 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
235 bool HasLinkage, unsigned Visibility);
236 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
Devang Patel923078c2009-07-01 19:21:12 +0000237 bool ParseStandaloneMetadata();
Devang Pateleff2ab62009-07-29 00:34:02 +0000238 bool ParseNamedMetadata();
Chris Lattner442ffa12009-12-29 21:53:55 +0000239 bool ParseMDString(MDString *&Result);
Chris Lattner4a72efc2009-12-30 04:15:23 +0000240 bool ParseMDNodeID(MDNode *&Result);
Chris Lattner449c3102010-04-01 05:14:45 +0000241 bool ParseMDNodeID(MDNode *&Result, unsigned &SlotNo);
Bill Wendling95ce4c22013-02-06 06:52:58 +0000242 bool ParseUnnamedAttrGrp();
Bill Wendlingbaad55c2013-02-08 06:32:06 +0000243 bool ParseFnAttributeValuePairs(AttrBuilder &B,
244 std::vector<unsigned> &FwdRefAttrGrps,
245 bool inAttrGrp);
Misha Brukman9ea40342009-01-02 22:46:48 +0000246
Chris Lattnerdf986172009-01-02 07:01:27 +0000247 // Type Parsing.
Chris Lattner1afcace2011-07-09 17:41:24 +0000248 bool ParseType(Type *&Result, bool AllowVoid = false);
249 bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
Chris Lattnerdf986172009-01-02 07:01:27 +0000250 Loc = Lex.getLoc();
Chris Lattnera9a9e072009-03-09 04:49:14 +0000251 return ParseType(Result, AllowVoid);
Chris Lattnerdf986172009-01-02 07:01:27 +0000252 }
Chris Lattner1afcace2011-07-09 17:41:24 +0000253 bool ParseAnonStructType(Type *&Result, bool Packed);
254 bool ParseStructBody(SmallVectorImpl<Type*> &Body);
255 bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
256 std::pair<Type*, LocTy> &Entry,
257 Type *&ResultTy);
258
259 bool ParseArrayVectorType(Type *&Result, bool isVector);
260 bool ParseFunctionType(Type *&Result);
Chris Lattnerdf986172009-01-02 07:01:27 +0000261
Chris Lattnerdf986172009-01-02 07:01:27 +0000262 // Function Semantic Analysis.
263 class PerFunctionState {
264 LLParser &P;
265 Function &F;
266 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
267 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
268 std::vector<Value*> NumberedVals;
Michael Ilseman407a6162012-11-15 22:34:00 +0000269
Chris Lattner09d9ef42009-10-28 03:39:23 +0000270 /// FunctionNumber - If this is an unnamed function, this is the slot
271 /// number of it, otherwise it is -1.
272 int FunctionNumber;
Chris Lattnerdf986172009-01-02 07:01:27 +0000273 public:
Chris Lattner09d9ef42009-10-28 03:39:23 +0000274 PerFunctionState(LLParser &p, Function &f, int FunctionNumber);
Chris Lattnerdf986172009-01-02 07:01:27 +0000275 ~PerFunctionState();
Misha Brukman9ea40342009-01-02 22:46:48 +0000276
Chris Lattnerdf986172009-01-02 07:01:27 +0000277 Function &getFunction() const { return F; }
Misha Brukman9ea40342009-01-02 22:46:48 +0000278
Chris Lattner09d9ef42009-10-28 03:39:23 +0000279 bool FinishFunction();
Misha Brukman9ea40342009-01-02 22:46:48 +0000280
Chris Lattnerdf986172009-01-02 07:01:27 +0000281 /// GetVal - Get a value with the specified name or ID, creating a
282 /// forward reference record if needed. This can return null if the value
283 /// exists but does not have the right type.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000284 Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc);
285 Value *GetVal(unsigned ID, Type *Ty, LocTy Loc);
Misha Brukman9ea40342009-01-02 22:46:48 +0000286
Chris Lattnerdf986172009-01-02 07:01:27 +0000287 /// SetInstName - After an instruction is parsed and inserted into its
288 /// basic block, this installs its name.
289 bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
290 Instruction *Inst);
Misha Brukman9ea40342009-01-02 22:46:48 +0000291
Chris Lattnerdf986172009-01-02 07:01:27 +0000292 /// GetBB - Get a basic block with the specified name or ID, creating a
293 /// forward reference record if needed. This can return null if the value
294 /// is not a BasicBlock.
295 BasicBlock *GetBB(const std::string &Name, LocTy Loc);
296 BasicBlock *GetBB(unsigned ID, LocTy Loc);
Misha Brukman9ea40342009-01-02 22:46:48 +0000297
Chris Lattnerdf986172009-01-02 07:01:27 +0000298 /// DefineBB - Define the specified basic block, which is either named or
299 /// unnamed. If there is an error, this returns null otherwise it returns
300 /// the block being defined.
301 BasicBlock *DefineBB(const std::string &Name, LocTy Loc);
302 };
Misha Brukman9ea40342009-01-02 22:46:48 +0000303
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000304 bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
Victor Hernandez92f238d2010-01-11 22:31:58 +0000305 PerFunctionState *PFS);
Misha Brukman9ea40342009-01-02 22:46:48 +0000306
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000307 bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
308 bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
Chris Lattner1afcace2011-07-09 17:41:24 +0000309 return ParseValue(Ty, V, &PFS);
310 }
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000311 bool ParseValue(Type *Ty, Value *&V, LocTy &Loc,
Chris Lattnerdf986172009-01-02 07:01:27 +0000312 PerFunctionState &PFS) {
313 Loc = Lex.getLoc();
Chris Lattner1afcace2011-07-09 17:41:24 +0000314 return ParseValue(Ty, V, &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000315 }
Misha Brukman9ea40342009-01-02 22:46:48 +0000316
Chris Lattner1afcace2011-07-09 17:41:24 +0000317 bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
318 bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
319 return ParseTypeAndValue(V, &PFS);
320 }
Chris Lattnerdf986172009-01-02 07:01:27 +0000321 bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
322 Loc = Lex.getLoc();
323 return ParseTypeAndValue(V, PFS);
324 }
Chris Lattnerf9be95f2009-10-27 19:13:16 +0000325 bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
326 PerFunctionState &PFS);
327 bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
328 LocTy Loc;
329 return ParseTypeAndBasicBlock(BB, Loc, PFS);
330 }
Victor Hernandez19715562009-12-03 23:40:58 +0000331
Chris Lattnerfdfeb692010-02-12 20:49:41 +0000332
Chris Lattnerdf986172009-01-02 07:01:27 +0000333 struct ParamInfo {
334 LocTy Loc;
335 Value *V;
Bill Wendling73dee182013-01-31 00:29:54 +0000336 AttributeSet Attrs;
337 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
Chris Lattnerdf986172009-01-02 07:01:27 +0000338 : Loc(loc), V(v), Attrs(attrs) {}
339 };
340 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
341 PerFunctionState &PFS);
Misha Brukman9ea40342009-01-02 22:46:48 +0000342
Victor Hernandezbf170d42010-01-05 22:22:14 +0000343 // Constant Parsing.
344 bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000345 bool ParseGlobalValue(Type *Ty, Constant *&V);
Victor Hernandezbf170d42010-01-05 22:22:14 +0000346 bool ParseGlobalTypeAndValue(Constant *&V);
347 bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
Dan Gohman309b3af2010-08-24 02:24:03 +0000348 bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS);
Dan Gohman83448032010-07-14 18:26:50 +0000349 bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS);
Victor Hernandez24e64df2010-01-10 07:14:18 +0000350 bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS);
Dan Gohman9d072f52010-08-24 02:05:17 +0000351 bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
Victor Hernandezbf170d42010-01-05 22:22:14 +0000352
Chris Lattnerdf986172009-01-02 07:01:27 +0000353 // Function Parsing.
354 struct ArgInfo {
355 LocTy Loc;
Chris Lattner1afcace2011-07-09 17:41:24 +0000356 Type *Ty;
Bill Wendling73dee182013-01-31 00:29:54 +0000357 AttributeSet Attrs;
Chris Lattnerdf986172009-01-02 07:01:27 +0000358 std::string Name;
Bill Wendling73dee182013-01-31 00:29:54 +0000359 ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
Chris Lattner1afcace2011-07-09 17:41:24 +0000360 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
Chris Lattnerdf986172009-01-02 07:01:27 +0000361 };
Chris Lattner1afcace2011-07-09 17:41:24 +0000362 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
Chris Lattnerdf986172009-01-02 07:01:27 +0000363 bool ParseFunctionHeader(Function *&Fn, bool isDefine);
364 bool ParseFunctionBody(Function &Fn);
365 bool ParseBasicBlock(PerFunctionState &PFS);
Misha Brukman9ea40342009-01-02 22:46:48 +0000366
Chris Lattnerf1bc7ce2009-12-30 05:23:43 +0000367 // Instruction Parsing. Each instruction parsing routine can return with a
368 // normal result, an error result, or return having eaten an extra comma.
369 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
370 int ParseInstruction(Instruction *&Inst, BasicBlock *BB,
371 PerFunctionState &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000372 bool ParseCmpPredicate(unsigned &Pred, unsigned Opc);
Misha Brukman9ea40342009-01-02 22:46:48 +0000373
Chris Lattner437544f2011-06-17 06:49:41 +0000374 bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000375 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
376 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
Chris Lattnerab21db72009-10-28 00:19:10 +0000377 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000378 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
Bill Wendlingdccc03b2011-07-31 06:30:59 +0000379 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
Misha Brukman9ea40342009-01-02 22:46:48 +0000380
Chris Lattnere914b592009-01-05 08:24:46 +0000381 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
382 unsigned OperandType);
Chris Lattnerdf986172009-01-02 07:01:27 +0000383 bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
384 bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
385 bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
386 bool ParseSelect(Instruction *&I, PerFunctionState &PFS);
Chris Lattner0088a5c2009-01-05 08:18:44 +0000387 bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000388 bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS);
389 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
390 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
Chris Lattnera7d7f2c2009-12-30 05:27:33 +0000391 int ParsePHI(Instruction *&I, PerFunctionState &PFS);
Bill Wendlinge6e88262011-08-12 20:24:12 +0000392 bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000393 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
Chris Lattnerf3a789d2011-06-17 03:16:47 +0000394 int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerfbe910e2011-11-27 06:56:53 +0000395 int ParseLoad(Instruction *&I, PerFunctionState &PFS);
396 int ParseStore(Instruction *&I, PerFunctionState &PFS);
Eli Friedmanf03bb262011-08-12 22:50:01 +0000397 int ParseCmpXchg(Instruction *&I, PerFunctionState &PFS);
398 int ParseAtomicRMW(Instruction *&I, PerFunctionState &PFS);
Eli Friedman47f35132011-07-25 23:16:38 +0000399 int ParseFence(Instruction *&I, PerFunctionState &PFS);
Chris Lattnera7d7f2c2009-12-30 05:27:33 +0000400 int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
401 int ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
402 int ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
Michael Ilseman407a6162012-11-15 22:34:00 +0000403
404 bool ResolveForwardRefBlockAddresses(Function *TheFn,
Chris Lattner09d9ef42009-10-28 03:39:23 +0000405 std::vector<std::pair<ValID, GlobalValue*> > &Refs,
406 PerFunctionState *PFS);
Chris Lattnerdf986172009-01-02 07:01:27 +0000407 };
408} // End llvm namespace
409
410#endif