blob: c62979e6f29e22c5a8ab74b517918861601b0458 [file] [log] [blame]
Chris Lattnerac161bf2009-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 Carruth802d7552012-12-04 07:12:27 +000018#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringMap.h"
Chandler Carruth9fb823b2013-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 Lattnerf8d22fc2009-12-28 08:20:46 +000025#include "llvm/Support/ValueHandle.h"
Chris Lattner218b22f2009-12-29 21:43:58 +000026#include <map>
Chris Lattnerac161bf2009-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 Lewycky49f89192009-04-04 07:22:01 +000037 class MDString;
38 class MDNode;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +000039 class StructType;
Misha Brukman1d9a93d2009-01-02 22:46:48 +000040
Chris Lattner3432c622009-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.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000045 struct ValID {
Chris Lattner3432c622009-10-28 03:39:23 +000046 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 Lattner5b4a9622009-12-30 02:11:14 +000054 t_MDNode, // Value in MDNodeVal.
Chris Lattnerb1ed91f2011-07-09 17:41:24 +000055 t_MDString, // Value in MDStringVal.
56 t_ConstantStruct, // Value in ConstantStructElts.
57 t_PackedConstantStruct // Value in ConstantStructElts.
Chris Lattner3432c622009-10-28 03:39:23 +000058 } Kind;
Michael Ilseman26ee2b82012-11-15 22:34:00 +000059
Chris Lattner3432c622009-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 Lattner5b4a9622009-12-30 02:11:14 +000066 MDNode *MDNodeVal;
67 MDString *MDStringVal;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +000068 Constant **ConstantStructElts;
Michael Ilseman26ee2b82012-11-15 22:34:00 +000069
Chris Lattnerb1ed91f2011-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 Ilseman26ee2b82012-11-15 22:34:00 +000075
Chris Lattner3432c622009-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 Lattnerb1ed91f2011-07-09 17:41:24 +000079 assert((Kind == t_LocalName || Kind == t_GlobalName ||
Michael Ilseman26ee2b82012-11-15 22:34:00 +000080 Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
Chris Lattner3432c622009-10-28 03:39:23 +000081 "Ordering not defined for this ValID kind yet");
82 return StrVal < RHS.StrVal;
83 }
84 };
Michael Ilseman26ee2b82012-11-15 22:34:00 +000085
Benjamin Kramer079b96e2013-09-11 18:05:11 +000086 class LLParser {
Chris Lattnerac161bf2009-01-02 07:01:27 +000087 public:
88 typedef LLLexer::LocTy LocTy;
89 private:
Chris Lattner2e664bd2010-04-07 04:08:57 +000090 LLVMContext &Context;
Chris Lattnerac161bf2009-01-02 07:01:27 +000091 LLLexer Lex;
92 Module *M;
Michael Ilseman26ee2b82012-11-15 22:34:00 +000093
Chris Lattner8eff0152010-04-01 05:14:45 +000094 // Instruction metadata resolution. Each instruction can have a list of
95 // MDRef info associated with them.
Dan Gohman7c7f13a2010-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 Lattner8eff0152010-04-01 05:14:45 +0000104 struct MDRef {
105 SMLoc Loc;
106 unsigned MDKind, MDSlot;
107 };
108 DenseMap<Instruction*, std::vector<MDRef> > ForwardRefInstMetadata;
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000109
Manman Ren209b17c2013-09-28 00:22:27 +0000110 SmallVector<Instruction*, 64> InstsWithTBAATag;
111
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000112 // Type resolution handling data structures. The location is set when we
113 // have processed a use of the type but not a definition yet.
114 StringMap<std::pair<Type*, LocTy> > NamedTypes;
115 std::vector<std::pair<Type*, LocTy> > NumberedTypes;
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000116
Chris Lattnerfc58af22009-12-30 04:51:58 +0000117 std::vector<TrackingVH<MDNode> > NumberedMetadata;
Chris Lattner218b22f2009-12-29 21:43:58 +0000118 std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes;
Chris Lattnerac161bf2009-01-02 07:01:27 +0000119
120 // Global Value reference information.
121 std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals;
122 std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs;
123 std::vector<GlobalValue*> NumberedVals;
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000124
Chris Lattner3432c622009-10-28 03:39:23 +0000125 // References to blockaddress. The key is the function ValID, the value is
126 // a list of references to blocks in that function.
127 std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >
128 ForwardRefBlockAddresses;
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000129
Bill Wendling63b88192013-02-06 06:52:58 +0000130 // Attribute builder reference information.
Bill Wendlingb32b0412013-02-08 06:32:06 +0000131 std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups;
132 std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
Bill Wendling63b88192013-02-06 06:52:58 +0000133
Chris Lattnerac161bf2009-01-02 07:01:27 +0000134 public:
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000135 LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) :
Victor Hernandezc7d6a832009-10-17 00:00:19 +0000136 Context(m->getContext()), Lex(F, SM, Err, m->getContext()),
Chris Lattner78103722011-06-17 03:16:47 +0000137 M(m) {}
Chris Lattnerad6f3352009-01-04 20:44:11 +0000138 bool Run();
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000139
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000140 LLVMContext &getContext() { return Context; }
Owen Anderson09063ce2009-07-02 17:04:01 +0000141
Chris Lattnerac161bf2009-01-02 07:01:27 +0000142 private:
143
Benjamin Kramerc7583112010-09-27 17:42:11 +0000144 bool Error(LocTy L, const Twine &Msg) const {
Chris Lattnerac161bf2009-01-02 07:01:27 +0000145 return Lex.Error(L, Msg);
146 }
Benjamin Kramerc7583112010-09-27 17:42:11 +0000147 bool TokError(const Twine &Msg) const {
Chris Lattnerac161bf2009-01-02 07:01:27 +0000148 return Error(Lex.getLoc(), Msg);
149 }
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000150
Chris Lattnerac161bf2009-01-02 07:01:27 +0000151 /// GetGlobalVal - Get a value with the specified name or ID, creating a
152 /// forward reference record if needed. This can return null if the value
153 /// exists but does not have the right type.
Chris Lattner229907c2011-07-18 04:54:35 +0000154 GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc);
155 GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000156
Chris Lattnerac161bf2009-01-02 07:01:27 +0000157 // Helper Routines.
158 bool ParseToken(lltok::Kind T, const char *ErrMsg);
Chris Lattner3822f632009-01-02 08:05:26 +0000159 bool EatIfPresent(lltok::Kind T) {
160 if (Lex.getKind() != T) return false;
161 Lex.Lex();
162 return true;
163 }
Michael Ilseman92053172012-11-27 00:42:44 +0000164
165 FastMathFlags EatFastMathFlagsIfPresent() {
166 FastMathFlags FMF;
167 while (true)
168 switch (Lex.getKind()) {
Michael Ilseman65f14352012-12-09 21:12:04 +0000169 case lltok::kw_fast: FMF.setUnsafeAlgebra(); Lex.Lex(); continue;
170 case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue;
171 case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue;
172 case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue;
173 case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue;
Michael Ilseman92053172012-11-27 00:42:44 +0000174 default: return FMF;
175 }
176 return FMF;
177 }
178
Rafael Espindola026d1522011-01-13 01:30:30 +0000179 bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
Chris Lattnerac161bf2009-01-02 07:01:27 +0000180 if (Lex.getKind() != T) {
181 Present = false;
182 } else {
Rafael Espindola026d1522011-01-13 01:30:30 +0000183 if (Loc)
184 *Loc = Lex.getLoc();
Chris Lattnerac161bf2009-01-02 07:01:27 +0000185 Lex.Lex();
186 Present = true;
187 }
188 return false;
189 }
Chris Lattner3822f632009-01-02 08:05:26 +0000190 bool ParseStringConstant(std::string &Result);
191 bool ParseUInt32(unsigned &Val);
192 bool ParseUInt32(unsigned &Val, LocTy &Loc) {
Chris Lattnerac161bf2009-01-02 07:01:27 +0000193 Loc = Lex.getLoc();
Chris Lattner3822f632009-01-02 08:05:26 +0000194 return ParseUInt32(Val);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000195 }
Hans Wennborgcbe34b42012-06-23 11:37:03 +0000196
197 bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
198 bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000199 bool ParseOptionalAddrSpace(unsigned &AddrSpace);
Bill Wendling34c2eb22012-12-04 23:40:58 +0000200 bool ParseOptionalParamAttrs(AttrBuilder &B);
201 bool ParseOptionalReturnAttrs(AttrBuilder &B);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000202 bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage);
203 bool ParseOptionalLinkage(unsigned &Linkage) {
204 bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage);
205 }
206 bool ParseOptionalVisibility(unsigned &Visibility);
Nico Rieck7157bb72014-01-14 15:22:47 +0000207 bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
Sandeep Patel68c5f472009-09-02 08:44:58 +0000208 bool ParseOptionalCallingConv(CallingConv::ID &CC);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000209 bool ParseOptionalAlignment(unsigned &Alignment);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000210 bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
211 AtomicOrdering &Ordering);
Charles Davisbe5557e2010-02-12 00:31:15 +0000212 bool ParseOptionalStackAlignment(unsigned &Alignment);
Chris Lattnerb2f39502009-12-30 05:44:30 +0000213 bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma);
Chris Lattner28f1eeb2009-12-30 05:14:00 +0000214 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices,bool &AteExtraComma);
215 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) {
216 bool AteExtraComma;
217 if (ParseIndexList(Indices, AteExtraComma)) return true;
218 if (AteExtraComma)
219 return TokError("expected index");
220 return false;
221 }
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000222
Chris Lattnerac161bf2009-01-02 07:01:27 +0000223 // Top-Level Entities
224 bool ParseTopLevelEntities();
225 bool ValidateEndOfModule();
226 bool ParseTargetDefinition();
Chris Lattnerac161bf2009-01-02 07:01:27 +0000227 bool ParseModuleAsm();
Bill Wendling706d3d62012-11-28 08:41:48 +0000228 bool ParseDepLibs(); // FIXME: Remove in 4.0.
Chris Lattnerac161bf2009-01-02 07:01:27 +0000229 bool ParseUnnamedType();
230 bool ParseNamedType();
231 bool ParseDeclare();
232 bool ParseDefine();
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000233
Chris Lattnerac161bf2009-01-02 07:01:27 +0000234 bool ParseGlobalType(bool &IsConstant);
Dan Gohman466876b2009-08-12 23:32:33 +0000235 bool ParseUnnamedGlobal();
Chris Lattnerac161bf2009-01-02 07:01:27 +0000236 bool ParseNamedGlobal();
237 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage,
Nico Rieck7157bb72014-01-14 15:22:47 +0000238 bool HasLinkage, unsigned Visibility,
239 unsigned DLLStorageClass);
240 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility,
241 unsigned DLLStorageClass);
Devang Patel39e64d42009-07-01 19:21:12 +0000242 bool ParseStandaloneMetadata();
Devang Patelbe626972009-07-29 00:34:02 +0000243 bool ParseNamedMetadata();
Chris Lattner1797fc72009-12-29 21:53:55 +0000244 bool ParseMDString(MDString *&Result);
Chris Lattner6dac02a2009-12-30 04:15:23 +0000245 bool ParseMDNodeID(MDNode *&Result);
Chris Lattner8eff0152010-04-01 05:14:45 +0000246 bool ParseMDNodeID(MDNode *&Result, unsigned &SlotNo);
Bill Wendling63b88192013-02-06 06:52:58 +0000247 bool ParseUnnamedAttrGrp();
Bill Wendlingb32b0412013-02-08 06:32:06 +0000248 bool ParseFnAttributeValuePairs(AttrBuilder &B,
249 std::vector<unsigned> &FwdRefAttrGrps,
Michael Gottesman41748d72013-06-27 00:25:01 +0000250 bool inAttrGrp, LocTy &BuiltinLoc);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000251
Chris Lattnerac161bf2009-01-02 07:01:27 +0000252 // Type Parsing.
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000253 bool ParseType(Type *&Result, bool AllowVoid = false);
254 bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) {
Chris Lattnerac161bf2009-01-02 07:01:27 +0000255 Loc = Lex.getLoc();
Chris Lattnerf880ca22009-03-09 04:49:14 +0000256 return ParseType(Result, AllowVoid);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000257 }
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000258 bool ParseAnonStructType(Type *&Result, bool Packed);
259 bool ParseStructBody(SmallVectorImpl<Type*> &Body);
260 bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name,
261 std::pair<Type*, LocTy> &Entry,
262 Type *&ResultTy);
263
264 bool ParseArrayVectorType(Type *&Result, bool isVector);
265 bool ParseFunctionType(Type *&Result);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000266
Chris Lattnerac161bf2009-01-02 07:01:27 +0000267 // Function Semantic Analysis.
268 class PerFunctionState {
269 LLParser &P;
270 Function &F;
271 std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals;
272 std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs;
273 std::vector<Value*> NumberedVals;
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000274
Chris Lattner3432c622009-10-28 03:39:23 +0000275 /// FunctionNumber - If this is an unnamed function, this is the slot
276 /// number of it, otherwise it is -1.
277 int FunctionNumber;
Chris Lattnerac161bf2009-01-02 07:01:27 +0000278 public:
Chris Lattner3432c622009-10-28 03:39:23 +0000279 PerFunctionState(LLParser &p, Function &f, int FunctionNumber);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000280 ~PerFunctionState();
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000281
Chris Lattnerac161bf2009-01-02 07:01:27 +0000282 Function &getFunction() const { return F; }
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000283
Chris Lattner3432c622009-10-28 03:39:23 +0000284 bool FinishFunction();
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000285
Chris Lattnerac161bf2009-01-02 07:01:27 +0000286 /// GetVal - Get a value with the specified name or ID, creating a
287 /// forward reference record if needed. This can return null if the value
288 /// exists but does not have the right type.
Chris Lattner229907c2011-07-18 04:54:35 +0000289 Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc);
290 Value *GetVal(unsigned ID, Type *Ty, LocTy Loc);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000291
Chris Lattnerac161bf2009-01-02 07:01:27 +0000292 /// SetInstName - After an instruction is parsed and inserted into its
293 /// basic block, this installs its name.
294 bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc,
295 Instruction *Inst);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000296
Chris Lattnerac161bf2009-01-02 07:01:27 +0000297 /// GetBB - Get a basic block with the specified name or ID, creating a
298 /// forward reference record if needed. This can return null if the value
299 /// is not a BasicBlock.
300 BasicBlock *GetBB(const std::string &Name, LocTy Loc);
301 BasicBlock *GetBB(unsigned ID, LocTy Loc);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000302
Chris Lattnerac161bf2009-01-02 07:01:27 +0000303 /// DefineBB - Define the specified basic block, which is either named or
304 /// unnamed. If there is an error, this returns null otherwise it returns
305 /// the block being defined.
306 BasicBlock *DefineBB(const std::string &Name, LocTy Loc);
307 };
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000308
Chris Lattner229907c2011-07-18 04:54:35 +0000309 bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
Victor Hernandez9d75c962010-01-11 22:31:58 +0000310 PerFunctionState *PFS);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000311
Chris Lattner229907c2011-07-18 04:54:35 +0000312 bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
313 bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000314 return ParseValue(Ty, V, &PFS);
315 }
Chris Lattner229907c2011-07-18 04:54:35 +0000316 bool ParseValue(Type *Ty, Value *&V, LocTy &Loc,
Chris Lattnerac161bf2009-01-02 07:01:27 +0000317 PerFunctionState &PFS) {
318 Loc = Lex.getLoc();
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000319 return ParseValue(Ty, V, &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000320 }
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000321
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000322 bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS);
323 bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
324 return ParseTypeAndValue(V, &PFS);
325 }
Chris Lattnerac161bf2009-01-02 07:01:27 +0000326 bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) {
327 Loc = Lex.getLoc();
328 return ParseTypeAndValue(V, PFS);
329 }
Chris Lattner3ed871f2009-10-27 19:13:16 +0000330 bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc,
331 PerFunctionState &PFS);
332 bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) {
333 LocTy Loc;
334 return ParseTypeAndBasicBlock(BB, Loc, PFS);
335 }
Victor Hernandezfa232232009-12-03 23:40:58 +0000336
Chris Lattner392be582010-02-12 20:49:41 +0000337
Chris Lattnerac161bf2009-01-02 07:01:27 +0000338 struct ParamInfo {
339 LocTy Loc;
340 Value *V;
Bill Wendlingfe0021a2013-01-31 00:29:54 +0000341 AttributeSet Attrs;
342 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
Chris Lattnerac161bf2009-01-02 07:01:27 +0000343 : Loc(loc), V(v), Attrs(attrs) {}
344 };
345 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
346 PerFunctionState &PFS);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000347
Victor Hernandezdc6e65a2010-01-05 22:22:14 +0000348 // Constant Parsing.
349 bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
Chris Lattner229907c2011-07-18 04:54:35 +0000350 bool ParseGlobalValue(Type *Ty, Constant *&V);
Victor Hernandezdc6e65a2010-01-05 22:22:14 +0000351 bool ParseGlobalTypeAndValue(Constant *&V);
352 bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
Dan Gohmanc828c542010-08-24 02:24:03 +0000353 bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS);
Dan Gohman8939ba332010-07-14 18:26:50 +0000354 bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS);
Victor Hernandezb8fd1522010-01-10 07:14:18 +0000355 bool ParseMDNodeVector(SmallVectorImpl<Value*> &, PerFunctionState *PFS);
Dan Gohman338d9a42010-08-24 02:05:17 +0000356 bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
Victor Hernandezdc6e65a2010-01-05 22:22:14 +0000357
Chris Lattnerac161bf2009-01-02 07:01:27 +0000358 // Function Parsing.
359 struct ArgInfo {
360 LocTy Loc;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000361 Type *Ty;
Bill Wendlingfe0021a2013-01-31 00:29:54 +0000362 AttributeSet Attrs;
Chris Lattnerac161bf2009-01-02 07:01:27 +0000363 std::string Name;
Bill Wendlingfe0021a2013-01-31 00:29:54 +0000364 ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000365 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
Chris Lattnerac161bf2009-01-02 07:01:27 +0000366 };
Chris Lattnerb1ed91f2011-07-09 17:41:24 +0000367 bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000368 bool ParseFunctionHeader(Function *&Fn, bool isDefine);
369 bool ParseFunctionBody(Function &Fn);
370 bool ParseBasicBlock(PerFunctionState &PFS);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000371
Chris Lattner77b89dc2009-12-30 05:23:43 +0000372 // Instruction Parsing. Each instruction parsing routine can return with a
373 // normal result, an error result, or return having eaten an extra comma.
374 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 };
375 int ParseInstruction(Instruction *&Inst, BasicBlock *BB,
376 PerFunctionState &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000377 bool ParseCmpPredicate(unsigned &Pred, unsigned Opc);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000378
Chris Lattner33de4272011-06-17 06:49:41 +0000379 bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000380 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS);
381 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS);
Chris Lattnerd04cb6d2009-10-28 00:19:10 +0000382 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000383 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS);
Bill Wendlingf891bf82011-07-31 06:30:59 +0000384 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
Misha Brukman1d9a93d2009-01-02 22:46:48 +0000385
Chris Lattnereeefa9a2009-01-05 08:24:46 +0000386 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
387 unsigned OperandType);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000388 bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
389 bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
390 bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc);
391 bool ParseSelect(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerb55ab542009-01-05 08:18:44 +0000392 bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000393 bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS);
394 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
395 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerf4f03422009-12-30 05:27:33 +0000396 int ParsePHI(Instruction *&I, PerFunctionState &PFS);
Bill Wendlingfae14752011-08-12 20:24:12 +0000397 bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000398 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
Chris Lattner78103722011-06-17 03:16:47 +0000399 int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerbc639292011-11-27 06:56:53 +0000400 int ParseLoad(Instruction *&I, PerFunctionState &PFS);
401 int ParseStore(Instruction *&I, PerFunctionState &PFS);
Eli Friedman02e737b2011-08-12 22:50:01 +0000402 int ParseCmpXchg(Instruction *&I, PerFunctionState &PFS);
403 int ParseAtomicRMW(Instruction *&I, PerFunctionState &PFS);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000404 int ParseFence(Instruction *&I, PerFunctionState &PFS);
Chris Lattnerf4f03422009-12-30 05:27:33 +0000405 int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS);
406 int ParseExtractValue(Instruction *&I, PerFunctionState &PFS);
407 int ParseInsertValue(Instruction *&I, PerFunctionState &PFS);
Michael Ilseman26ee2b82012-11-15 22:34:00 +0000408
409 bool ResolveForwardRefBlockAddresses(Function *TheFn,
Chris Lattner3432c622009-10-28 03:39:23 +0000410 std::vector<std::pair<ValID, GlobalValue*> > &Refs,
411 PerFunctionState *PFS);
Chris Lattnerac161bf2009-01-02 07:01:27 +0000412 };
413} // End llvm namespace
414
415#endif