LLParser.h (200581) | LLParser.h (201360) |
---|---|
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" 18#include "llvm/Module.h" 19#include "llvm/Type.h" | 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" 18#include "llvm/Module.h" 19#include "llvm/Type.h" |
20#include "llvm/Support/ValueHandle.h" |
|
20#include <map> 21 22namespace llvm { 23 class Module; 24 class OpaqueType; 25 class Function; 26 class Value; 27 class BasicBlock; --- 12 unchanged lines hidden (view full) --- 40 enum { 41 t_LocalID, t_GlobalID, // ID in UIntVal. 42 t_LocalName, t_GlobalName, // Name in StrVal. 43 t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal. 44 t_Null, t_Undef, t_Zero, // No value. 45 t_EmptyArray, // No value: [] 46 t_Constant, // Value in ConstantVal. 47 t_InlineAsm, // Value in StrVal/StrVal2/UIntVal. | 21#include <map> 22 23namespace llvm { 24 class Module; 25 class OpaqueType; 26 class Function; 27 class Value; 28 class BasicBlock; --- 12 unchanged lines hidden (view full) --- 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. |
48 t_Metadata // Value in MetadataVal. | 49 t_MDNode, // Value in MDNodeVal. 50 t_MDString // Value in MDStringVal. |
49 } Kind; 50 51 LLLexer::LocTy Loc; 52 unsigned UIntVal; 53 std::string StrVal, StrVal2; 54 APSInt APSIntVal; 55 APFloat APFloatVal; 56 Constant *ConstantVal; | 51 } Kind; 52 53 LLLexer::LocTy Loc; 54 unsigned UIntVal; 55 std::string StrVal, StrVal2; 56 APSInt APSIntVal; 57 APFloat APFloatVal; 58 Constant *ConstantVal; |
57 MetadataBase *MetadataVal; | 59 MDNode *MDNodeVal; 60 MDString *MDStringVal; |
58 ValID() : APFloatVal(0.0) {} 59 60 bool operator<(const ValID &RHS) const { 61 if (Kind == t_LocalID || Kind == t_GlobalID) 62 return UIntVal < RHS.UIntVal; 63 assert((Kind == t_LocalName || Kind == t_GlobalName) && 64 "Ordering not defined for this ValID kind yet"); 65 return StrVal < RHS.StrVal; --- 7 unchanged lines hidden (view full) --- 73 LLVMContext& Context; 74 LLLexer Lex; 75 Module *M; 76 77 // Type resolution handling data structures. 78 std::map<std::string, std::pair<PATypeHolder, LocTy> > ForwardRefTypes; 79 std::map<unsigned, std::pair<PATypeHolder, LocTy> > ForwardRefTypeIDs; 80 std::vector<PATypeHolder> NumberedTypes; | 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; --- 7 unchanged lines hidden (view full) --- 76 LLVMContext& Context; 77 LLLexer Lex; 78 Module *M; 79 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; |
81 /// MetadataCache - This map keeps track of parsed metadata constants. 82 std::map<unsigned, WeakVH> MetadataCache; 83 std::map<unsigned, std::pair<WeakVH, LocTy> > ForwardRefMDNodes; 84 SmallVector<std::pair<unsigned, MDNode *>, 2> MDsOnInst; | 84 std::vector<TrackingVH<MDNode> > NumberedMetadata; 85 std::map<unsigned, std::pair<TrackingVH<MDNode>, LocTy> > ForwardRefMDNodes; |
85 struct UpRefRecord { 86 /// Loc - This is the location of the upref. 87 LocTy Loc; 88 89 /// NestingLevel - The number of nesting levels that need to be popped 90 /// before this type is resolved. 91 unsigned NestingLevel; 92 --- 71 unchanged lines hidden (view full) --- 164 bool ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind); 165 bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage); 166 bool ParseOptionalLinkage(unsigned &Linkage) { 167 bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage); 168 } 169 bool ParseOptionalVisibility(unsigned &Visibility); 170 bool ParseOptionalCallingConv(CallingConv::ID &CC); 171 bool ParseOptionalAlignment(unsigned &Alignment); | 86 struct UpRefRecord { 87 /// Loc - This is the location of the upref. 88 LocTy Loc; 89 90 /// NestingLevel - The number of nesting levels that need to be popped 91 /// before this type is resolved. 92 unsigned NestingLevel; 93 --- 71 unchanged lines hidden (view full) --- 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); 171 bool ParseOptionalCallingConv(CallingConv::ID &CC); 172 bool ParseOptionalAlignment(unsigned &Alignment); |
172 bool ParseOptionalCustomMetadata(); 173 bool ParseOptionalInfo(unsigned &Alignment); 174 bool ParseIndexList(SmallVectorImpl<unsigned> &Indices); | 173 bool ParseInstructionMetadata(SmallVectorImpl<std::pair<unsigned, 174 MDNode *> > &); 175 bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); 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 } |
175 176 // Top-Level Entities 177 bool ParseTopLevelEntities(); 178 bool ValidateEndOfModule(); 179 bool ParseTargetDefinition(); 180 bool ParseDepLibs(); 181 bool ParseModuleAsm(); 182 bool ParseUnnamedType(); --- 4 unchanged lines hidden (view full) --- 187 bool ParseGlobalType(bool &IsConstant); 188 bool ParseUnnamedGlobal(); 189 bool ParseNamedGlobal(); 190 bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, 191 bool HasLinkage, unsigned Visibility); 192 bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility); 193 bool ParseStandaloneMetadata(); 194 bool ParseNamedMetadata(); | 184 185 // Top-Level Entities 186 bool ParseTopLevelEntities(); 187 bool ValidateEndOfModule(); 188 bool ParseTargetDefinition(); 189 bool ParseDepLibs(); 190 bool ParseModuleAsm(); 191 bool ParseUnnamedType(); --- 4 unchanged lines hidden (view full) --- 196 bool ParseGlobalType(bool &IsConstant); 197 bool ParseUnnamedGlobal(); 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); 202 bool ParseStandaloneMetadata(); 203 bool ParseNamedMetadata(); |
195 bool ParseMDString(MetadataBase *&S); 196 bool ParseMDNode(MetadataBase *&N); | 204 bool ParseMDString(MDString *&Result); 205 bool ParseMDNodeID(MDNode *&Result); |
197 198 // Type Parsing. 199 bool ParseType(PATypeHolder &Result, bool AllowVoid = false); 200 bool ParseType(PATypeHolder &Result, LocTy &Loc, bool AllowVoid = false) { 201 Loc = Lex.getLoc(); 202 return ParseType(Result, AllowVoid); 203 } 204 bool ParseTypeRec(PATypeHolder &H); 205 bool ParseStructType(PATypeHolder &H, bool Packed); 206 bool ParseArrayVectorType(PATypeHolder &H, bool isVector); 207 bool ParseFunctionType(PATypeHolder &Result); 208 PATypeHolder HandleUpRefs(const Type *Ty); 209 210 // Constants. 211 bool ParseValID(ValID &ID); 212 bool ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, Constant *&V); | 206 207 // Type Parsing. 208 bool ParseType(PATypeHolder &Result, bool AllowVoid = false); 209 bool ParseType(PATypeHolder &Result, LocTy &Loc, bool AllowVoid = false) { 210 Loc = Lex.getLoc(); 211 return ParseType(Result, AllowVoid); 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 219 // Constants. 220 bool ParseValID(ValID &ID); 221 bool ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, Constant *&V); |
222 bool ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID, 223 Value *&V); |
|
213 bool ParseGlobalValue(const Type *Ty, Constant *&V); 214 bool ParseGlobalTypeAndValue(Constant *&V); 215 bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts); 216 bool ParseMDNodeVector(SmallVectorImpl<Value*> &); 217 218 219 // Function Semantic Analysis. 220 class PerFunctionState { --- 54 unchanged lines hidden (view full) --- 275 } 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 } 282 | 224 bool ParseGlobalValue(const Type *Ty, Constant *&V); 225 bool ParseGlobalTypeAndValue(Constant *&V); 226 bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts); 227 bool ParseMDNodeVector(SmallVectorImpl<Value*> &); 228 229 230 // Function Semantic Analysis. 231 class PerFunctionState { --- 54 unchanged lines hidden (view full) --- 286 } 287 bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc, 288 PerFunctionState &PFS); 289 bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) { 290 LocTy Loc; 291 return ParseTypeAndBasicBlock(BB, Loc, PFS); 292 } 293 |
283 bool ParseInlineMetadata(Value *&V, PerFunctionState &PFS); 284 | |
285 struct ParamInfo { 286 LocTy Loc; 287 Value *V; 288 unsigned Attrs; 289 ParamInfo(LocTy loc, Value *v, unsigned attrs) 290 : Loc(loc), V(v), Attrs(attrs) {} 291 }; 292 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, --- 9 unchanged lines hidden (view full) --- 302 : Loc(L), Type(Ty), Attrs(Attr), Name(N) {} 303 }; 304 bool ParseArgumentList(std::vector<ArgInfo> &ArgList, 305 bool &isVarArg, bool inType); 306 bool ParseFunctionHeader(Function *&Fn, bool isDefine); 307 bool ParseFunctionBody(Function &Fn); 308 bool ParseBasicBlock(PerFunctionState &PFS); 309 | 294 struct ParamInfo { 295 LocTy Loc; 296 Value *V; 297 unsigned Attrs; 298 ParamInfo(LocTy loc, Value *v, unsigned attrs) 299 : Loc(loc), V(v), Attrs(attrs) {} 300 }; 301 bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, --- 9 unchanged lines hidden (view full) --- 311 : Loc(L), Type(Ty), Attrs(Attr), Name(N) {} 312 }; 313 bool ParseArgumentList(std::vector<ArgInfo> &ArgList, 314 bool &isVarArg, bool inType); 315 bool ParseFunctionHeader(Function *&Fn, bool isDefine); 316 bool ParseFunctionBody(Function &Fn); 317 bool ParseBasicBlock(PerFunctionState &PFS); 318 |
310 // Instruction Parsing. 311 bool ParseInstruction(Instruction *&Inst, BasicBlock *BB, 312 PerFunctionState &PFS); | 319 // Instruction Parsing. Each instruction parsing routine can return with a 320 // normal result, an error result, or return having eaten an extra comma. 321 enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; 322 int ParseInstruction(Instruction *&Inst, BasicBlock *BB, 323 PerFunctionState &PFS); |
313 bool ParseCmpPredicate(unsigned &Pred, unsigned Opc); 314 | 324 bool ParseCmpPredicate(unsigned &Pred, unsigned Opc); 325 |
315 bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); | 326 int ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); |
316 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); 317 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); 318 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); 319 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); 320 321 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, 322 unsigned OperandType); 323 bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 324 bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 325 bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 326 bool ParseSelect(Instruction *&I, PerFunctionState &PFS); 327 bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS); 328 bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS); 329 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS); 330 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); | 327 bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); 328 bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); 329 bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); 330 bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); 331 332 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, 333 unsigned OperandType); 334 bool ParseLogical(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 335 bool ParseCompare(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 336 bool ParseCast(Instruction *&I, PerFunctionState &PFS, unsigned Opc); 337 bool ParseSelect(Instruction *&I, PerFunctionState &PFS); 338 bool ParseVA_Arg(Instruction *&I, PerFunctionState &PFS); 339 bool ParseExtractElement(Instruction *&I, PerFunctionState &PFS); 340 bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS); 341 bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); |
331 bool ParsePHI(Instruction *&I, PerFunctionState &PFS); | 342 int ParsePHI(Instruction *&I, PerFunctionState &PFS); |
332 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail); | 343 bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail); |
333 bool ParseAlloc(Instruction *&I, PerFunctionState &PFS, | 344 int ParseAlloc(Instruction *&I, PerFunctionState &PFS, |
334 BasicBlock *BB = 0, bool isAlloca = true); 335 bool ParseFree(Instruction *&I, PerFunctionState &PFS, BasicBlock *BB); | 345 BasicBlock *BB = 0, bool isAlloca = true); 346 bool ParseFree(Instruction *&I, PerFunctionState &PFS, BasicBlock *BB); |
336 bool ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile); 337 bool ParseStore(Instruction *&I, PerFunctionState &PFS, bool isVolatile); | 347 int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile); 348 int ParseStore(Instruction *&I, PerFunctionState &PFS, bool isVolatile); |
338 bool ParseGetResult(Instruction *&I, PerFunctionState &PFS); | 349 bool ParseGetResult(Instruction *&I, PerFunctionState &PFS); |
339 bool ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS); 340 bool ParseExtractValue(Instruction *&I, PerFunctionState &PFS); 341 bool ParseInsertValue(Instruction *&I, PerFunctionState &PFS); | 350 int ParseGetElementPtr(Instruction *&I, PerFunctionState &PFS); 351 int ParseExtractValue(Instruction *&I, PerFunctionState &PFS); 352 int ParseInsertValue(Instruction *&I, PerFunctionState &PFS); |
342 343 bool ResolveForwardRefBlockAddresses(Function *TheFn, 344 std::vector<std::pair<ValID, GlobalValue*> > &Refs, 345 PerFunctionState *PFS); 346 }; 347} // End llvm namespace 348 349#endif | 353 354 bool ResolveForwardRefBlockAddresses(Function *TheFn, 355 std::vector<std::pair<ValID, GlobalValue*> > &Refs, 356 PerFunctionState *PFS); 357 }; 358} // End llvm namespace 359 360#endif |