LLParser.cpp (194612) | LLParser.cpp (195340) |
---|---|
1//===-- LLParser.cpp - Parser Class ---------------------------------------===// 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//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13 14#include "LLParser.h" 15#include "llvm/AutoUpgrade.h" 16#include "llvm/CallingConv.h" 17#include "llvm/Constants.h" 18#include "llvm/DerivedTypes.h" 19#include "llvm/InlineAsm.h" 20#include "llvm/Instructions.h" | 1//===-- LLParser.cpp - Parser Class ---------------------------------------===// 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//===----------------------------------------------------------------------===// --- 4 unchanged lines hidden (view full) --- 13 14#include "LLParser.h" 15#include "llvm/AutoUpgrade.h" 16#include "llvm/CallingConv.h" 17#include "llvm/Constants.h" 18#include "llvm/DerivedTypes.h" 19#include "llvm/InlineAsm.h" 20#include "llvm/Instructions.h" |
21#include "llvm/LLVMContext.h" |
|
21#include "llvm/MDNode.h" 22#include "llvm/Module.h" 23#include "llvm/ValueSymbolTable.h" 24#include "llvm/ADT/SmallPtrSet.h" 25#include "llvm/ADT/StringExtras.h" 26#include "llvm/Support/raw_ostream.h" 27using namespace llvm; 28 --- 75 unchanged lines hidden (view full) --- 104 case lltok::kw_define: if (ParseDefine()) return true; break; 105 case lltok::kw_module: if (ParseModuleAsm()) return true; break; 106 case lltok::kw_target: if (ParseTargetDefinition()) return true; break; 107 case lltok::kw_deplibs: if (ParseDepLibs()) return true; break; 108 case lltok::kw_type: if (ParseUnnamedType()) return true; break; 109 case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0 110 case lltok::LocalVar: if (ParseNamedType()) return true; break; 111 case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break; | 22#include "llvm/MDNode.h" 23#include "llvm/Module.h" 24#include "llvm/ValueSymbolTable.h" 25#include "llvm/ADT/SmallPtrSet.h" 26#include "llvm/ADT/StringExtras.h" 27#include "llvm/Support/raw_ostream.h" 28using namespace llvm; 29 --- 75 unchanged lines hidden (view full) --- 105 case lltok::kw_define: if (ParseDefine()) return true; break; 106 case lltok::kw_module: if (ParseModuleAsm()) return true; break; 107 case lltok::kw_target: if (ParseTargetDefinition()) return true; break; 108 case lltok::kw_deplibs: if (ParseDepLibs()) return true; break; 109 case lltok::kw_type: if (ParseUnnamedType()) return true; break; 110 case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0 111 case lltok::LocalVar: if (ParseNamedType()) return true; break; 112 case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break; |
113 case lltok::Metadata: if (ParseStandaloneMetadata()) return true; break; |
|
112 113 // The Global variable production with no name can have many different 114 // optional leading prefixes, the production is: 115 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal 116 // OptionalAddrSpace ('constant'|'global') ... 117 case lltok::kw_private: // OptionalLinkage 118 case lltok::kw_internal: // OptionalLinkage 119 case lltok::kw_weak: // OptionalLinkage --- 4 unchanged lines hidden (view full) --- 124 case lltok::kw_dllexport: // OptionalLinkage 125 case lltok::kw_common: // OptionalLinkage 126 case lltok::kw_dllimport: // OptionalLinkage 127 case lltok::kw_extern_weak: // OptionalLinkage 128 case lltok::kw_external: { // OptionalLinkage 129 unsigned Linkage, Visibility; 130 if (ParseOptionalLinkage(Linkage) || 131 ParseOptionalVisibility(Visibility) || | 114 115 // The Global variable production with no name can have many different 116 // optional leading prefixes, the production is: 117 // GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal 118 // OptionalAddrSpace ('constant'|'global') ... 119 case lltok::kw_private: // OptionalLinkage 120 case lltok::kw_internal: // OptionalLinkage 121 case lltok::kw_weak: // OptionalLinkage --- 4 unchanged lines hidden (view full) --- 126 case lltok::kw_dllexport: // OptionalLinkage 127 case lltok::kw_common: // OptionalLinkage 128 case lltok::kw_dllimport: // OptionalLinkage 129 case lltok::kw_extern_weak: // OptionalLinkage 130 case lltok::kw_external: { // OptionalLinkage 131 unsigned Linkage, Visibility; 132 if (ParseOptionalLinkage(Linkage) || 133 ParseOptionalVisibility(Visibility) || |
132 ParseGlobal("", 0, Linkage, true, Visibility)) | 134 ParseGlobal("", SMLoc(), Linkage, true, Visibility)) |
133 return true; 134 break; 135 } 136 case lltok::kw_default: // OptionalVisibility 137 case lltok::kw_hidden: // OptionalVisibility 138 case lltok::kw_protected: { // OptionalVisibility 139 unsigned Visibility; 140 if (ParseOptionalVisibility(Visibility) || | 135 return true; 136 break; 137 } 138 case lltok::kw_default: // OptionalVisibility 139 case lltok::kw_hidden: // OptionalVisibility 140 case lltok::kw_protected: { // OptionalVisibility 141 unsigned Visibility; 142 if (ParseOptionalVisibility(Visibility) || |
141 ParseGlobal("", 0, 0, false, Visibility)) | 143 ParseGlobal("", SMLoc(), 0, false, Visibility)) |
142 return true; 143 break; 144 } 145 146 case lltok::kw_thread_local: // OptionalThreadLocal 147 case lltok::kw_addrspace: // OptionalAddrSpace 148 case lltok::kw_constant: // GlobalType 149 case lltok::kw_global: // GlobalType | 144 return true; 145 break; 146 } 147 148 case lltok::kw_thread_local: // OptionalThreadLocal 149 case lltok::kw_addrspace: // OptionalAddrSpace 150 case lltok::kw_constant: // GlobalType 151 case lltok::kw_global: // GlobalType |
150 if (ParseGlobal("", 0, 0, false, 0)) return true; | 152 if (ParseGlobal("", SMLoc(), 0, false, 0)) return true; |
151 break; 152 } 153 } 154} 155 156 157/// toplevelentity 158/// ::= 'module' 'asm' STRINGCONSTANT --- 191 unchanged lines hidden (view full) --- 350 ParseOptionalVisibility(Visibility)) 351 return true; 352 353 if (HasLinkage || Lex.getKind() != lltok::kw_alias) 354 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility); 355 return ParseAlias(Name, NameLoc, Visibility); 356} 357 | 153 break; 154 } 155 } 156} 157 158 159/// toplevelentity 160/// ::= 'module' 'asm' STRINGCONSTANT --- 191 unchanged lines hidden (view full) --- 352 ParseOptionalVisibility(Visibility)) 353 return true; 354 355 if (HasLinkage || Lex.getKind() != lltok::kw_alias) 356 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility); 357 return ParseAlias(Name, NameLoc, Visibility); 358} 359 |
360/// ParseStandaloneMetadata: 361/// !42 = !{...} 362bool LLParser::ParseStandaloneMetadata() { 363 assert(Lex.getKind() == lltok::Metadata); 364 Lex.Lex(); 365 unsigned MetadataID = 0; 366 if (ParseUInt32(MetadataID)) 367 return true; 368 if (MetadataCache.find(MetadataID) != MetadataCache.end()) 369 return TokError("Metadata id is already used"); 370 if (ParseToken(lltok::equal, "expected '=' here")) 371 return true; 372 373 LocTy TyLoc; 374 bool IsConstant; 375 PATypeHolder Ty(Type::VoidTy); 376 if (ParseGlobalType(IsConstant) || 377 ParseType(Ty, TyLoc)) 378 return true; 379 380 Constant *Init = 0; 381 if (ParseGlobalValue(Ty, Init)) 382 return true; 383 384 MetadataCache[MetadataID] = Init; 385 return false; 386} 387 |
|
358/// ParseAlias: 359/// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee 360/// Aliasee 361/// ::= TypeAndValue 362/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')' 363/// ::= 'getelementptr' '(' ... ')' 364/// 365/// Everything through visibility has already been parsed. --- 597 unchanged lines hidden (view full) --- 963 return TokError("expected type"); 964 case lltok::Type: 965 // TypeRec ::= 'float' | 'void' (etc) 966 Result = Lex.getTyVal(); 967 Lex.Lex(); 968 break; 969 case lltok::kw_opaque: 970 // TypeRec ::= 'opaque' | 388/// ParseAlias: 389/// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee 390/// Aliasee 391/// ::= TypeAndValue 392/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')' 393/// ::= 'getelementptr' '(' ... ')' 394/// 395/// Everything through visibility has already been parsed. --- 597 unchanged lines hidden (view full) --- 993 return TokError("expected type"); 994 case lltok::Type: 995 // TypeRec ::= 'float' | 'void' (etc) 996 Result = Lex.getTyVal(); 997 Lex.Lex(); 998 break; 999 case lltok::kw_opaque: 1000 // TypeRec ::= 'opaque' |
971 Result = OpaqueType::get(); | 1001 Result = Context.getOpaqueType(); |
972 Lex.Lex(); 973 break; 974 case lltok::lbrace: 975 // TypeRec ::= '{' ... '}' 976 if (ParseStructType(Result, false)) 977 return true; 978 break; 979 case lltok::lsquare: --- 13 unchanged lines hidden (view full) --- 993 return true; 994 break; 995 case lltok::LocalVar: 996 case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0 997 // TypeRec ::= %foo 998 if (const Type *T = M->getTypeByName(Lex.getStrVal())) { 999 Result = T; 1000 } else { | 1002 Lex.Lex(); 1003 break; 1004 case lltok::lbrace: 1005 // TypeRec ::= '{' ... '}' 1006 if (ParseStructType(Result, false)) 1007 return true; 1008 break; 1009 case lltok::lsquare: --- 13 unchanged lines hidden (view full) --- 1023 return true; 1024 break; 1025 case lltok::LocalVar: 1026 case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0 1027 // TypeRec ::= %foo 1028 if (const Type *T = M->getTypeByName(Lex.getStrVal())) { 1029 Result = T; 1030 } else { |
1001 Result = OpaqueType::get(); | 1031 Result = Context.getOpaqueType(); |
1002 ForwardRefTypes.insert(std::make_pair(Lex.getStrVal(), 1003 std::make_pair(Result, 1004 Lex.getLoc()))); 1005 M->addTypeName(Lex.getStrVal(), Result.get()); 1006 } 1007 Lex.Lex(); 1008 break; 1009 1010 case lltok::LocalVarID: 1011 // TypeRec ::= %4 1012 if (Lex.getUIntVal() < NumberedTypes.size()) 1013 Result = NumberedTypes[Lex.getUIntVal()]; 1014 else { 1015 std::map<unsigned, std::pair<PATypeHolder, LocTy> >::iterator 1016 I = ForwardRefTypeIDs.find(Lex.getUIntVal()); 1017 if (I != ForwardRefTypeIDs.end()) 1018 Result = I->second.first; 1019 else { | 1032 ForwardRefTypes.insert(std::make_pair(Lex.getStrVal(), 1033 std::make_pair(Result, 1034 Lex.getLoc()))); 1035 M->addTypeName(Lex.getStrVal(), Result.get()); 1036 } 1037 Lex.Lex(); 1038 break; 1039 1040 case lltok::LocalVarID: 1041 // TypeRec ::= %4 1042 if (Lex.getUIntVal() < NumberedTypes.size()) 1043 Result = NumberedTypes[Lex.getUIntVal()]; 1044 else { 1045 std::map<unsigned, std::pair<PATypeHolder, LocTy> >::iterator 1046 I = ForwardRefTypeIDs.find(Lex.getUIntVal()); 1047 if (I != ForwardRefTypeIDs.end()) 1048 Result = I->second.first; 1049 else { |
1020 Result = OpaqueType::get(); | 1050 Result = Context.getOpaqueType(); |
1021 ForwardRefTypeIDs.insert(std::make_pair(Lex.getUIntVal(), 1022 std::make_pair(Result, 1023 Lex.getLoc()))); 1024 } 1025 } 1026 Lex.Lex(); 1027 break; 1028 case lltok::backslash: { 1029 // TypeRec ::= '\' 4 1030 Lex.Lex(); 1031 unsigned Val; 1032 if (ParseUInt32(Val)) return true; | 1051 ForwardRefTypeIDs.insert(std::make_pair(Lex.getUIntVal(), 1052 std::make_pair(Result, 1053 Lex.getLoc()))); 1054 } 1055 } 1056 Lex.Lex(); 1057 break; 1058 case lltok::backslash: { 1059 // TypeRec ::= '\' 4 1060 Lex.Lex(); 1061 unsigned Val; 1062 if (ParseUInt32(Val)) return true; |
1033 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder. | 1063 OpaqueType *OT = Context.getOpaqueType(); //Use temporary placeholder. |
1034 UpRefs.push_back(UpRefRecord(Lex.getLoc(), Val, OT)); 1035 Result = OT; 1036 break; 1037 } 1038 } 1039 1040 // Parse the type suffixes. 1041 while (1) { --- 4 unchanged lines hidden (view full) --- 1046 // TypeRec ::= TypeRec '*' 1047 case lltok::star: 1048 if (Result.get() == Type::LabelTy) 1049 return TokError("basic block pointers are invalid"); 1050 if (Result.get() == Type::VoidTy) 1051 return TokError("pointers to void are invalid; use i8* instead"); 1052 if (!PointerType::isValidElementType(Result.get())) 1053 return TokError("pointer to this type is invalid"); | 1064 UpRefs.push_back(UpRefRecord(Lex.getLoc(), Val, OT)); 1065 Result = OT; 1066 break; 1067 } 1068 } 1069 1070 // Parse the type suffixes. 1071 while (1) { --- 4 unchanged lines hidden (view full) --- 1076 // TypeRec ::= TypeRec '*' 1077 case lltok::star: 1078 if (Result.get() == Type::LabelTy) 1079 return TokError("basic block pointers are invalid"); 1080 if (Result.get() == Type::VoidTy) 1081 return TokError("pointers to void are invalid; use i8* instead"); 1082 if (!PointerType::isValidElementType(Result.get())) 1083 return TokError("pointer to this type is invalid"); |
1054 Result = HandleUpRefs(PointerType::getUnqual(Result.get())); | 1084 Result = HandleUpRefs(Context.getPointerTypeUnqual(Result.get())); |
1055 Lex.Lex(); 1056 break; 1057 1058 // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*' 1059 case lltok::kw_addrspace: { 1060 if (Result.get() == Type::LabelTy) 1061 return TokError("basic block pointers are invalid"); 1062 if (Result.get() == Type::VoidTy) 1063 return TokError("pointers to void are invalid; use i8* instead"); 1064 if (!PointerType::isValidElementType(Result.get())) 1065 return TokError("pointer to this type is invalid"); 1066 unsigned AddrSpace; 1067 if (ParseOptionalAddrSpace(AddrSpace) || 1068 ParseToken(lltok::star, "expected '*' in address space")) 1069 return true; 1070 | 1085 Lex.Lex(); 1086 break; 1087 1088 // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*' 1089 case lltok::kw_addrspace: { 1090 if (Result.get() == Type::LabelTy) 1091 return TokError("basic block pointers are invalid"); 1092 if (Result.get() == Type::VoidTy) 1093 return TokError("pointers to void are invalid; use i8* instead"); 1094 if (!PointerType::isValidElementType(Result.get())) 1095 return TokError("pointer to this type is invalid"); 1096 unsigned AddrSpace; 1097 if (ParseOptionalAddrSpace(AddrSpace) || 1098 ParseToken(lltok::star, "expected '*' in address space")) 1099 return true; 1100 |
1071 Result = HandleUpRefs(PointerType::get(Result.get(), AddrSpace)); | 1101 Result = HandleUpRefs(Context.getPointerType(Result.get(), AddrSpace)); |
1072 break; 1073 } 1074 1075 /// Types '(' ArgTypeListI ')' OptFuncAttrs 1076 case lltok::lparen: 1077 if (ParseFunctionType(Result)) 1078 return true; 1079 break; --- 144 unchanged lines hidden (view full) --- 1224 // FIXME: REJECT ATTRIBUTES ON FUNCTION TYPES in LLVM 3.0 1225 } 1226 } 1227 1228 std::vector<const Type*> ArgListTy; 1229 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 1230 ArgListTy.push_back(ArgList[i].Type); 1231 | 1102 break; 1103 } 1104 1105 /// Types '(' ArgTypeListI ')' OptFuncAttrs 1106 case lltok::lparen: 1107 if (ParseFunctionType(Result)) 1108 return true; 1109 break; --- 144 unchanged lines hidden (view full) --- 1254 // FIXME: REJECT ATTRIBUTES ON FUNCTION TYPES in LLVM 3.0 1255 } 1256 } 1257 1258 std::vector<const Type*> ArgListTy; 1259 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 1260 ArgListTy.push_back(ArgList[i].Type); 1261 |
1232 Result = HandleUpRefs(FunctionType::get(Result.get(), ArgListTy, isVarArg)); | 1262 Result = HandleUpRefs(Context.getFunctionType(Result.get(), 1263 ArgListTy, isVarArg)); |
1233 return false; 1234} 1235 1236/// ParseStructType: Handles packed and unpacked types. </> parsed elsewhere. 1237/// TypeRec 1238/// ::= '{' '}' 1239/// ::= '{' TypeRec (',' TypeRec)* '}' 1240/// ::= '<' '{' '}' '>' 1241/// ::= '<' '{' TypeRec (',' TypeRec)* '}' '>' 1242bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { 1243 assert(Lex.getKind() == lltok::lbrace); 1244 Lex.Lex(); // Consume the '{' 1245 1246 if (EatIfPresent(lltok::rbrace)) { | 1264 return false; 1265} 1266 1267/// ParseStructType: Handles packed and unpacked types. </> parsed elsewhere. 1268/// TypeRec 1269/// ::= '{' '}' 1270/// ::= '{' TypeRec (',' TypeRec)* '}' 1271/// ::= '<' '{' '}' '>' 1272/// ::= '<' '{' TypeRec (',' TypeRec)* '}' '>' 1273bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { 1274 assert(Lex.getKind() == lltok::lbrace); 1275 Lex.Lex(); // Consume the '{' 1276 1277 if (EatIfPresent(lltok::rbrace)) { |
1247 Result = StructType::get(std::vector<const Type*>(), Packed); | 1278 Result = Context.getStructType(Packed); |
1248 return false; 1249 } 1250 1251 std::vector<PATypeHolder> ParamsList; 1252 LocTy EltTyLoc = Lex.getLoc(); 1253 if (ParseTypeRec(Result)) return true; 1254 ParamsList.push_back(Result); 1255 --- 15 unchanged lines hidden (view full) --- 1271 } 1272 1273 if (ParseToken(lltok::rbrace, "expected '}' at end of struct")) 1274 return true; 1275 1276 std::vector<const Type*> ParamsListTy; 1277 for (unsigned i = 0, e = ParamsList.size(); i != e; ++i) 1278 ParamsListTy.push_back(ParamsList[i].get()); | 1279 return false; 1280 } 1281 1282 std::vector<PATypeHolder> ParamsList; 1283 LocTy EltTyLoc = Lex.getLoc(); 1284 if (ParseTypeRec(Result)) return true; 1285 ParamsList.push_back(Result); 1286 --- 15 unchanged lines hidden (view full) --- 1302 } 1303 1304 if (ParseToken(lltok::rbrace, "expected '}' at end of struct")) 1305 return true; 1306 1307 std::vector<const Type*> ParamsListTy; 1308 for (unsigned i = 0, e = ParamsList.size(); i != e; ++i) 1309 ParamsListTy.push_back(ParamsList[i].get()); |
1279 Result = HandleUpRefs(StructType::get(ParamsListTy, Packed)); | 1310 Result = HandleUpRefs(Context.getStructType(ParamsListTy, Packed)); |
1280 return false; 1281} 1282 1283/// ParseArrayVectorType - Parse an array or vector type, assuming the first 1284/// token has already been consumed. 1285/// TypeRec 1286/// ::= '[' APSINTVAL 'x' Types ']' 1287/// ::= '<' APSINTVAL 'x' Types '>' --- 22 unchanged lines hidden (view full) --- 1310 1311 if (isVector) { 1312 if (Size == 0) 1313 return Error(SizeLoc, "zero element vector is illegal"); 1314 if ((unsigned)Size != Size) 1315 return Error(SizeLoc, "size too large for vector"); 1316 if (!VectorType::isValidElementType(EltTy)) 1317 return Error(TypeLoc, "vector element type must be fp or integer"); | 1311 return false; 1312} 1313 1314/// ParseArrayVectorType - Parse an array or vector type, assuming the first 1315/// token has already been consumed. 1316/// TypeRec 1317/// ::= '[' APSINTVAL 'x' Types ']' 1318/// ::= '<' APSINTVAL 'x' Types '>' --- 22 unchanged lines hidden (view full) --- 1341 1342 if (isVector) { 1343 if (Size == 0) 1344 return Error(SizeLoc, "zero element vector is illegal"); 1345 if ((unsigned)Size != Size) 1346 return Error(SizeLoc, "size too large for vector"); 1347 if (!VectorType::isValidElementType(EltTy)) 1348 return Error(TypeLoc, "vector element type must be fp or integer"); |
1318 Result = VectorType::get(EltTy, unsigned(Size)); | 1349 Result = Context.getVectorType(EltTy, unsigned(Size)); |
1319 } else { 1320 if (!ArrayType::isValidElementType(EltTy)) 1321 return Error(TypeLoc, "invalid array element type"); | 1350 } else { 1351 if (!ArrayType::isValidElementType(EltTy)) 1352 return Error(TypeLoc, "invalid array element type"); |
1322 Result = HandleUpRefs(ArrayType::get(EltTy, Size)); | 1353 Result = HandleUpRefs(Context.getArrayType(EltTy, Size)); |
1323 } 1324 return false; 1325} 1326 1327//===----------------------------------------------------------------------===// 1328// Function Semantic Analysis. 1329//===----------------------------------------------------------------------===// 1330 --- 7 unchanged lines hidden (view full) --- 1338 NumberedVals.push_back(AI); 1339} 1340 1341LLParser::PerFunctionState::~PerFunctionState() { 1342 // If there were any forward referenced non-basicblock values, delete them. 1343 for (std::map<std::string, std::pair<Value*, LocTy> >::iterator 1344 I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I) 1345 if (!isa<BasicBlock>(I->second.first)) { | 1354 } 1355 return false; 1356} 1357 1358//===----------------------------------------------------------------------===// 1359// Function Semantic Analysis. 1360//===----------------------------------------------------------------------===// 1361 --- 7 unchanged lines hidden (view full) --- 1369 NumberedVals.push_back(AI); 1370} 1371 1372LLParser::PerFunctionState::~PerFunctionState() { 1373 // If there were any forward referenced non-basicblock values, delete them. 1374 for (std::map<std::string, std::pair<Value*, LocTy> >::iterator 1375 I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I) 1376 if (!isa<BasicBlock>(I->second.first)) { |
1346 I->second.first->replaceAllUsesWith(UndefValue::get(I->second.first 1347 ->getType())); | 1377 I->second.first->replaceAllUsesWith( 1378 P.getContext().getUndef(I->second.first->getType())); |
1348 delete I->second.first; 1349 I->second.first = 0; 1350 } 1351 1352 for (std::map<unsigned, std::pair<Value*, LocTy> >::iterator 1353 I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I) 1354 if (!isa<BasicBlock>(I->second.first)) { | 1379 delete I->second.first; 1380 I->second.first = 0; 1381 } 1382 1383 for (std::map<unsigned, std::pair<Value*, LocTy> >::iterator 1384 I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I) 1385 if (!isa<BasicBlock>(I->second.first)) { |
1355 I->second.first->replaceAllUsesWith(UndefValue::get(I->second.first 1356 ->getType())); | 1386 I->second.first->replaceAllUsesWith( 1387 P.getContext().getUndef(I->second.first->getType())); |
1357 delete I->second.first; 1358 I->second.first = 0; 1359 } 1360} 1361 1362bool LLParser::PerFunctionState::VerifyFunctionComplete() { 1363 if (!ForwardRefVals.empty()) 1364 return P.Error(ForwardRefVals.begin()->second.second, --- 222 unchanged lines hidden (view full) --- 1587 ID.Kind = ValID::t_Constant; 1588 Lex.Lex(); 1589 if (Lex.getKind() == lltok::lbrace) { 1590 SmallVector<Value*, 16> Elts; 1591 if (ParseMDNodeVector(Elts) || 1592 ParseToken(lltok::rbrace, "expected end of metadata node")) 1593 return true; 1594 | 1388 delete I->second.first; 1389 I->second.first = 0; 1390 } 1391} 1392 1393bool LLParser::PerFunctionState::VerifyFunctionComplete() { 1394 if (!ForwardRefVals.empty()) 1395 return P.Error(ForwardRefVals.begin()->second.second, --- 222 unchanged lines hidden (view full) --- 1618 ID.Kind = ValID::t_Constant; 1619 Lex.Lex(); 1620 if (Lex.getKind() == lltok::lbrace) { 1621 SmallVector<Value*, 16> Elts; 1622 if (ParseMDNodeVector(Elts) || 1623 ParseToken(lltok::rbrace, "expected end of metadata node")) 1624 return true; 1625 |
1595 ID.ConstantVal = MDNode::get(Elts.data(), Elts.size()); | 1626 ID.ConstantVal = Context.getMDNode(Elts.data(), Elts.size()); |
1596 return false; 1597 } 1598 | 1627 return false; 1628 } 1629 |
1630 // Standalone metadata reference 1631 // !{ ..., !42, ... } 1632 unsigned MID = 0; 1633 if (!ParseUInt32(MID)) { 1634 std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID); 1635 if (I == MetadataCache.end()) 1636 return TokError("Unknown metadata reference"); 1637 ID.ConstantVal = I->second; 1638 return false; 1639 } 1640 |
|
1599 // MDString: 1600 // ::= '!' STRINGCONSTANT 1601 std::string Str; 1602 if (ParseStringConstant(Str)) return true; 1603 | 1641 // MDString: 1642 // ::= '!' STRINGCONSTANT 1643 std::string Str; 1644 if (ParseStringConstant(Str)) return true; 1645 |
1604 ID.ConstantVal = MDString::get(Str.data(), Str.data() + Str.size()); | 1646 ID.ConstantVal = Context.getMDString(Str.data(), Str.data() + Str.size()); |
1605 return false; 1606 } 1607 case lltok::APSInt: 1608 ID.APSIntVal = Lex.getAPSIntVal(); 1609 ID.Kind = ValID::t_APSInt; 1610 break; 1611 case lltok::APFloat: 1612 ID.APFloatVal = Lex.getAPFloatVal(); 1613 ID.Kind = ValID::t_APFloat; 1614 break; 1615 case lltok::kw_true: | 1647 return false; 1648 } 1649 case lltok::APSInt: 1650 ID.APSIntVal = Lex.getAPSIntVal(); 1651 ID.Kind = ValID::t_APSInt; 1652 break; 1653 case lltok::APFloat: 1654 ID.APFloatVal = Lex.getAPFloatVal(); 1655 ID.Kind = ValID::t_APFloat; 1656 break; 1657 case lltok::kw_true: |
1616 ID.ConstantVal = ConstantInt::getTrue(); | 1658 ID.ConstantVal = Context.getConstantIntTrue(); |
1617 ID.Kind = ValID::t_Constant; 1618 break; 1619 case lltok::kw_false: | 1659 ID.Kind = ValID::t_Constant; 1660 break; 1661 case lltok::kw_false: |
1620 ID.ConstantVal = ConstantInt::getFalse(); | 1662 ID.ConstantVal = Context.getConstantIntFalse(); |
1621 ID.Kind = ValID::t_Constant; 1622 break; 1623 case lltok::kw_null: ID.Kind = ValID::t_Null; break; 1624 case lltok::kw_undef: ID.Kind = ValID::t_Undef; break; 1625 case lltok::kw_zeroinitializer: ID.Kind = ValID::t_Zero; break; 1626 1627 case lltok::lbrace: { 1628 // ValID ::= '{' ConstVector '}' 1629 Lex.Lex(); 1630 SmallVector<Constant*, 16> Elts; 1631 if (ParseGlobalValueVector(Elts) || 1632 ParseToken(lltok::rbrace, "expected end of struct constant")) 1633 return true; 1634 | 1663 ID.Kind = ValID::t_Constant; 1664 break; 1665 case lltok::kw_null: ID.Kind = ValID::t_Null; break; 1666 case lltok::kw_undef: ID.Kind = ValID::t_Undef; break; 1667 case lltok::kw_zeroinitializer: ID.Kind = ValID::t_Zero; break; 1668 1669 case lltok::lbrace: { 1670 // ValID ::= '{' ConstVector '}' 1671 Lex.Lex(); 1672 SmallVector<Constant*, 16> Elts; 1673 if (ParseGlobalValueVector(Elts) || 1674 ParseToken(lltok::rbrace, "expected end of struct constant")) 1675 return true; 1676 |
1635 ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), false); | 1677 ID.ConstantVal = Context.getConstantStruct(Elts.data(), Elts.size(), false); |
1636 ID.Kind = ValID::t_Constant; 1637 return false; 1638 } 1639 case lltok::less: { 1640 // ValID ::= '<' ConstVector '>' --> Vector. 1641 // ValID ::= '<' '{' ConstVector '}' '>' --> Packed Struct. 1642 Lex.Lex(); 1643 bool isPackedStruct = EatIfPresent(lltok::lbrace); 1644 1645 SmallVector<Constant*, 16> Elts; 1646 LocTy FirstEltLoc = Lex.getLoc(); 1647 if (ParseGlobalValueVector(Elts) || 1648 (isPackedStruct && 1649 ParseToken(lltok::rbrace, "expected end of packed struct")) || 1650 ParseToken(lltok::greater, "expected end of constant")) 1651 return true; 1652 1653 if (isPackedStruct) { | 1678 ID.Kind = ValID::t_Constant; 1679 return false; 1680 } 1681 case lltok::less: { 1682 // ValID ::= '<' ConstVector '>' --> Vector. 1683 // ValID ::= '<' '{' ConstVector '}' '>' --> Packed Struct. 1684 Lex.Lex(); 1685 bool isPackedStruct = EatIfPresent(lltok::lbrace); 1686 1687 SmallVector<Constant*, 16> Elts; 1688 LocTy FirstEltLoc = Lex.getLoc(); 1689 if (ParseGlobalValueVector(Elts) || 1690 (isPackedStruct && 1691 ParseToken(lltok::rbrace, "expected end of packed struct")) || 1692 ParseToken(lltok::greater, "expected end of constant")) 1693 return true; 1694 1695 if (isPackedStruct) { |
1654 ID.ConstantVal = ConstantStruct::get(Elts.data(), Elts.size(), true); | 1696 ID.ConstantVal = 1697 Context.getConstantStruct(Elts.data(), Elts.size(), true); |
1655 ID.Kind = ValID::t_Constant; 1656 return false; 1657 } 1658 1659 if (Elts.empty()) 1660 return Error(ID.Loc, "constant vector must not be empty"); 1661 1662 if (!Elts[0]->getType()->isInteger() && 1663 !Elts[0]->getType()->isFloatingPoint()) 1664 return Error(FirstEltLoc, 1665 "vector elements must have integer or floating point type"); 1666 1667 // Verify that all the vector elements have the same type. 1668 for (unsigned i = 1, e = Elts.size(); i != e; ++i) 1669 if (Elts[i]->getType() != Elts[0]->getType()) 1670 return Error(FirstEltLoc, 1671 "vector element #" + utostr(i) + 1672 " is not of type '" + Elts[0]->getType()->getDescription()); 1673 | 1698 ID.Kind = ValID::t_Constant; 1699 return false; 1700 } 1701 1702 if (Elts.empty()) 1703 return Error(ID.Loc, "constant vector must not be empty"); 1704 1705 if (!Elts[0]->getType()->isInteger() && 1706 !Elts[0]->getType()->isFloatingPoint()) 1707 return Error(FirstEltLoc, 1708 "vector elements must have integer or floating point type"); 1709 1710 // Verify that all the vector elements have the same type. 1711 for (unsigned i = 1, e = Elts.size(); i != e; ++i) 1712 if (Elts[i]->getType() != Elts[0]->getType()) 1713 return Error(FirstEltLoc, 1714 "vector element #" + utostr(i) + 1715 " is not of type '" + Elts[0]->getType()->getDescription()); 1716 |
1674 ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size()); | 1717 ID.ConstantVal = Context.getConstantVector(Elts.data(), Elts.size()); |
1675 ID.Kind = ValID::t_Constant; 1676 return false; 1677 } 1678 case lltok::lsquare: { // Array Constant 1679 Lex.Lex(); 1680 SmallVector<Constant*, 16> Elts; 1681 LocTy FirstEltLoc = Lex.getLoc(); 1682 if (ParseGlobalValueVector(Elts) || --- 7 unchanged lines hidden (view full) --- 1690 ID.Kind = ValID::t_EmptyArray; 1691 return false; 1692 } 1693 1694 if (!Elts[0]->getType()->isFirstClassType()) 1695 return Error(FirstEltLoc, "invalid array element type: " + 1696 Elts[0]->getType()->getDescription()); 1697 | 1718 ID.Kind = ValID::t_Constant; 1719 return false; 1720 } 1721 case lltok::lsquare: { // Array Constant 1722 Lex.Lex(); 1723 SmallVector<Constant*, 16> Elts; 1724 LocTy FirstEltLoc = Lex.getLoc(); 1725 if (ParseGlobalValueVector(Elts) || --- 7 unchanged lines hidden (view full) --- 1733 ID.Kind = ValID::t_EmptyArray; 1734 return false; 1735 } 1736 1737 if (!Elts[0]->getType()->isFirstClassType()) 1738 return Error(FirstEltLoc, "invalid array element type: " + 1739 Elts[0]->getType()->getDescription()); 1740 |
1698 ArrayType *ATy = ArrayType::get(Elts[0]->getType(), Elts.size()); | 1741 ArrayType *ATy = Context.getArrayType(Elts[0]->getType(), Elts.size()); |
1699 1700 // Verify all elements are correct type! 1701 for (unsigned i = 0, e = Elts.size(); i != e; ++i) { 1702 if (Elts[i]->getType() != Elts[0]->getType()) 1703 return Error(FirstEltLoc, 1704 "array element #" + utostr(i) + 1705 " is not of type '" +Elts[0]->getType()->getDescription()); 1706 } 1707 | 1742 1743 // Verify all elements are correct type! 1744 for (unsigned i = 0, e = Elts.size(); i != e; ++i) { 1745 if (Elts[i]->getType() != Elts[0]->getType()) 1746 return Error(FirstEltLoc, 1747 "array element #" + utostr(i) + 1748 " is not of type '" +Elts[0]->getType()->getDescription()); 1749 } 1750 |
1708 ID.ConstantVal = ConstantArray::get(ATy, Elts.data(), Elts.size()); | 1751 ID.ConstantVal = Context.getConstantArray(ATy, Elts.data(), Elts.size()); |
1709 ID.Kind = ValID::t_Constant; 1710 return false; 1711 } 1712 case lltok::kw_c: // c "foo" 1713 Lex.Lex(); | 1752 ID.Kind = ValID::t_Constant; 1753 return false; 1754 } 1755 case lltok::kw_c: // c "foo" 1756 Lex.Lex(); |
1714 ID.ConstantVal = ConstantArray::get(Lex.getStrVal(), false); | 1757 ID.ConstantVal = Context.getConstantArray(Lex.getStrVal(), false); |
1715 if (ParseToken(lltok::StringConstant, "expected string")) return true; 1716 ID.Kind = ValID::t_Constant; 1717 return false; 1718 1719 case lltok::kw_asm: { 1720 // ValID ::= 'asm' SideEffect? STRINGCONSTANT ',' STRINGCONSTANT 1721 bool HasSideEffect; 1722 Lex.Lex(); --- 29 unchanged lines hidden (view full) --- 1752 ParseToken(lltok::kw_to, "expected 'to' in constantexpr cast") || 1753 ParseType(DestTy) || 1754 ParseToken(lltok::rparen, "expected ')' at end of constantexpr cast")) 1755 return true; 1756 if (!CastInst::castIsValid((Instruction::CastOps)Opc, SrcVal, DestTy)) 1757 return Error(ID.Loc, "invalid cast opcode for cast from '" + 1758 SrcVal->getType()->getDescription() + "' to '" + 1759 DestTy->getDescription() + "'"); | 1758 if (ParseToken(lltok::StringConstant, "expected string")) return true; 1759 ID.Kind = ValID::t_Constant; 1760 return false; 1761 1762 case lltok::kw_asm: { 1763 // ValID ::= 'asm' SideEffect? STRINGCONSTANT ',' STRINGCONSTANT 1764 bool HasSideEffect; 1765 Lex.Lex(); --- 29 unchanged lines hidden (view full) --- 1795 ParseToken(lltok::kw_to, "expected 'to' in constantexpr cast") || 1796 ParseType(DestTy) || 1797 ParseToken(lltok::rparen, "expected ')' at end of constantexpr cast")) 1798 return true; 1799 if (!CastInst::castIsValid((Instruction::CastOps)Opc, SrcVal, DestTy)) 1800 return Error(ID.Loc, "invalid cast opcode for cast from '" + 1801 SrcVal->getType()->getDescription() + "' to '" + 1802 DestTy->getDescription() + "'"); |
1760 ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc, SrcVal, 1761 DestTy); | 1803 ID.ConstantVal = Context.getConstantExprCast((Instruction::CastOps)Opc, 1804 SrcVal, DestTy); |
1762 ID.Kind = ValID::t_Constant; 1763 return false; 1764 } 1765 case lltok::kw_extractvalue: { 1766 Lex.Lex(); 1767 Constant *Val; 1768 SmallVector<unsigned, 4> Indices; 1769 if (ParseToken(lltok::lparen, "expected '(' in extractvalue constantexpr")|| 1770 ParseGlobalTypeAndValue(Val) || 1771 ParseIndexList(Indices) || 1772 ParseToken(lltok::rparen, "expected ')' in extractvalue constantexpr")) 1773 return true; 1774 if (!isa<StructType>(Val->getType()) && !isa<ArrayType>(Val->getType())) 1775 return Error(ID.Loc, "extractvalue operand must be array or struct"); 1776 if (!ExtractValueInst::getIndexedType(Val->getType(), Indices.begin(), 1777 Indices.end())) 1778 return Error(ID.Loc, "invalid indices for extractvalue"); 1779 ID.ConstantVal = | 1805 ID.Kind = ValID::t_Constant; 1806 return false; 1807 } 1808 case lltok::kw_extractvalue: { 1809 Lex.Lex(); 1810 Constant *Val; 1811 SmallVector<unsigned, 4> Indices; 1812 if (ParseToken(lltok::lparen, "expected '(' in extractvalue constantexpr")|| 1813 ParseGlobalTypeAndValue(Val) || 1814 ParseIndexList(Indices) || 1815 ParseToken(lltok::rparen, "expected ')' in extractvalue constantexpr")) 1816 return true; 1817 if (!isa<StructType>(Val->getType()) && !isa<ArrayType>(Val->getType())) 1818 return Error(ID.Loc, "extractvalue operand must be array or struct"); 1819 if (!ExtractValueInst::getIndexedType(Val->getType(), Indices.begin(), 1820 Indices.end())) 1821 return Error(ID.Loc, "invalid indices for extractvalue"); 1822 ID.ConstantVal = |
1780 ConstantExpr::getExtractValue(Val, Indices.data(), Indices.size()); | 1823 Context.getConstantExprExtractValue(Val, Indices.data(), Indices.size()); |
1781 ID.Kind = ValID::t_Constant; 1782 return false; 1783 } 1784 case lltok::kw_insertvalue: { 1785 Lex.Lex(); 1786 Constant *Val0, *Val1; 1787 SmallVector<unsigned, 4> Indices; 1788 if (ParseToken(lltok::lparen, "expected '(' in insertvalue constantexpr")|| 1789 ParseGlobalTypeAndValue(Val0) || 1790 ParseToken(lltok::comma, "expected comma in insertvalue constantexpr")|| 1791 ParseGlobalTypeAndValue(Val1) || 1792 ParseIndexList(Indices) || 1793 ParseToken(lltok::rparen, "expected ')' in insertvalue constantexpr")) 1794 return true; 1795 if (!isa<StructType>(Val0->getType()) && !isa<ArrayType>(Val0->getType())) 1796 return Error(ID.Loc, "extractvalue operand must be array or struct"); 1797 if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices.begin(), 1798 Indices.end())) 1799 return Error(ID.Loc, "invalid indices for insertvalue"); | 1824 ID.Kind = ValID::t_Constant; 1825 return false; 1826 } 1827 case lltok::kw_insertvalue: { 1828 Lex.Lex(); 1829 Constant *Val0, *Val1; 1830 SmallVector<unsigned, 4> Indices; 1831 if (ParseToken(lltok::lparen, "expected '(' in insertvalue constantexpr")|| 1832 ParseGlobalTypeAndValue(Val0) || 1833 ParseToken(lltok::comma, "expected comma in insertvalue constantexpr")|| 1834 ParseGlobalTypeAndValue(Val1) || 1835 ParseIndexList(Indices) || 1836 ParseToken(lltok::rparen, "expected ')' in insertvalue constantexpr")) 1837 return true; 1838 if (!isa<StructType>(Val0->getType()) && !isa<ArrayType>(Val0->getType())) 1839 return Error(ID.Loc, "extractvalue operand must be array or struct"); 1840 if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices.begin(), 1841 Indices.end())) 1842 return Error(ID.Loc, "invalid indices for insertvalue"); |
1800 ID.ConstantVal = 1801 ConstantExpr::getInsertValue(Val0, Val1, Indices.data(), Indices.size()); | 1843 ID.ConstantVal = Context.getConstantExprInsertValue(Val0, Val1, 1844 Indices.data(), Indices.size()); |
1802 ID.Kind = ValID::t_Constant; 1803 return false; 1804 } 1805 case lltok::kw_icmp: 1806 case lltok::kw_fcmp: 1807 case lltok::kw_vicmp: 1808 case lltok::kw_vfcmp: { 1809 unsigned PredVal, Opc = Lex.getUIntVal(); --- 10 unchanged lines hidden (view full) --- 1820 if (Val0->getType() != Val1->getType()) 1821 return Error(ID.Loc, "compare operands must have the same type"); 1822 1823 CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal; 1824 1825 if (Opc == Instruction::FCmp) { 1826 if (!Val0->getType()->isFPOrFPVector()) 1827 return Error(ID.Loc, "fcmp requires floating point operands"); | 1845 ID.Kind = ValID::t_Constant; 1846 return false; 1847 } 1848 case lltok::kw_icmp: 1849 case lltok::kw_fcmp: 1850 case lltok::kw_vicmp: 1851 case lltok::kw_vfcmp: { 1852 unsigned PredVal, Opc = Lex.getUIntVal(); --- 10 unchanged lines hidden (view full) --- 1863 if (Val0->getType() != Val1->getType()) 1864 return Error(ID.Loc, "compare operands must have the same type"); 1865 1866 CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal; 1867 1868 if (Opc == Instruction::FCmp) { 1869 if (!Val0->getType()->isFPOrFPVector()) 1870 return Error(ID.Loc, "fcmp requires floating point operands"); |
1828 ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1); | 1871 ID.ConstantVal = Context.getConstantExprFCmp(Pred, Val0, Val1); |
1829 } else if (Opc == Instruction::ICmp) { 1830 if (!Val0->getType()->isIntOrIntVector() && 1831 !isa<PointerType>(Val0->getType())) 1832 return Error(ID.Loc, "icmp requires pointer or integer operands"); | 1872 } else if (Opc == Instruction::ICmp) { 1873 if (!Val0->getType()->isIntOrIntVector() && 1874 !isa<PointerType>(Val0->getType())) 1875 return Error(ID.Loc, "icmp requires pointer or integer operands"); |
1833 ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1); | 1876 ID.ConstantVal = Context.getConstantExprICmp(Pred, Val0, Val1); |
1834 } else if (Opc == Instruction::VFCmp) { 1835 // FIXME: REMOVE VFCMP Support 1836 if (!Val0->getType()->isFPOrFPVector() || 1837 !isa<VectorType>(Val0->getType())) 1838 return Error(ID.Loc, "vfcmp requires vector floating point operands"); | 1877 } else if (Opc == Instruction::VFCmp) { 1878 // FIXME: REMOVE VFCMP Support 1879 if (!Val0->getType()->isFPOrFPVector() || 1880 !isa<VectorType>(Val0->getType())) 1881 return Error(ID.Loc, "vfcmp requires vector floating point operands"); |
1839 ID.ConstantVal = ConstantExpr::getVFCmp(Pred, Val0, Val1); | 1882 ID.ConstantVal = Context.getConstantExprVFCmp(Pred, Val0, Val1); |
1840 } else if (Opc == Instruction::VICmp) { 1841 // FIXME: REMOVE VICMP Support 1842 if (!Val0->getType()->isIntOrIntVector() || 1843 !isa<VectorType>(Val0->getType())) 1844 return Error(ID.Loc, "vicmp requires vector floating point operands"); | 1883 } else if (Opc == Instruction::VICmp) { 1884 // FIXME: REMOVE VICMP Support 1885 if (!Val0->getType()->isIntOrIntVector() || 1886 !isa<VectorType>(Val0->getType())) 1887 return Error(ID.Loc, "vicmp requires vector floating point operands"); |
1845 ID.ConstantVal = ConstantExpr::getVICmp(Pred, Val0, Val1); | 1888 ID.ConstantVal = Context.getConstantExprVICmp(Pred, Val0, Val1); |
1846 } 1847 ID.Kind = ValID::t_Constant; 1848 return false; 1849 } 1850 1851 // Binary Operators. 1852 case lltok::kw_add: 1853 case lltok::kw_fadd: --- 16 unchanged lines hidden (view full) --- 1870 ParseGlobalTypeAndValue(Val1) || 1871 ParseToken(lltok::rparen, "expected ')' in binary constantexpr")) 1872 return true; 1873 if (Val0->getType() != Val1->getType()) 1874 return Error(ID.Loc, "operands of constexpr must have same type"); 1875 if (!Val0->getType()->isIntOrIntVector() && 1876 !Val0->getType()->isFPOrFPVector()) 1877 return Error(ID.Loc,"constexpr requires integer, fp, or vector operands"); | 1889 } 1890 ID.Kind = ValID::t_Constant; 1891 return false; 1892 } 1893 1894 // Binary Operators. 1895 case lltok::kw_add: 1896 case lltok::kw_fadd: --- 16 unchanged lines hidden (view full) --- 1913 ParseGlobalTypeAndValue(Val1) || 1914 ParseToken(lltok::rparen, "expected ')' in binary constantexpr")) 1915 return true; 1916 if (Val0->getType() != Val1->getType()) 1917 return Error(ID.Loc, "operands of constexpr must have same type"); 1918 if (!Val0->getType()->isIntOrIntVector() && 1919 !Val0->getType()->isFPOrFPVector()) 1920 return Error(ID.Loc,"constexpr requires integer, fp, or vector operands"); |
1878 ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1); | 1921 ID.ConstantVal = Context.getConstantExpr(Opc, Val0, Val1); |
1879 ID.Kind = ValID::t_Constant; 1880 return false; 1881 } 1882 1883 // Logical Operations 1884 case lltok::kw_shl: 1885 case lltok::kw_lshr: 1886 case lltok::kw_ashr: --- 9 unchanged lines hidden (view full) --- 1896 ParseGlobalTypeAndValue(Val1) || 1897 ParseToken(lltok::rparen, "expected ')' in logical constantexpr")) 1898 return true; 1899 if (Val0->getType() != Val1->getType()) 1900 return Error(ID.Loc, "operands of constexpr must have same type"); 1901 if (!Val0->getType()->isIntOrIntVector()) 1902 return Error(ID.Loc, 1903 "constexpr requires integer or integer vector operands"); | 1922 ID.Kind = ValID::t_Constant; 1923 return false; 1924 } 1925 1926 // Logical Operations 1927 case lltok::kw_shl: 1928 case lltok::kw_lshr: 1929 case lltok::kw_ashr: --- 9 unchanged lines hidden (view full) --- 1939 ParseGlobalTypeAndValue(Val1) || 1940 ParseToken(lltok::rparen, "expected ')' in logical constantexpr")) 1941 return true; 1942 if (Val0->getType() != Val1->getType()) 1943 return Error(ID.Loc, "operands of constexpr must have same type"); 1944 if (!Val0->getType()->isIntOrIntVector()) 1945 return Error(ID.Loc, 1946 "constexpr requires integer or integer vector operands"); |
1904 ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1); | 1947 ID.ConstantVal = Context.getConstantExpr(Opc, Val0, Val1); |
1905 ID.Kind = ValID::t_Constant; 1906 return false; 1907 } 1908 1909 case lltok::kw_getelementptr: 1910 case lltok::kw_shufflevector: 1911 case lltok::kw_insertelement: 1912 case lltok::kw_extractelement: --- 8 unchanged lines hidden (view full) --- 1921 1922 if (Opc == Instruction::GetElementPtr) { 1923 if (Elts.size() == 0 || !isa<PointerType>(Elts[0]->getType())) 1924 return Error(ID.Loc, "getelementptr requires pointer operand"); 1925 1926 if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), 1927 (Value**)&Elts[1], Elts.size()-1)) 1928 return Error(ID.Loc, "invalid indices for getelementptr"); | 1948 ID.Kind = ValID::t_Constant; 1949 return false; 1950 } 1951 1952 case lltok::kw_getelementptr: 1953 case lltok::kw_shufflevector: 1954 case lltok::kw_insertelement: 1955 case lltok::kw_extractelement: --- 8 unchanged lines hidden (view full) --- 1964 1965 if (Opc == Instruction::GetElementPtr) { 1966 if (Elts.size() == 0 || !isa<PointerType>(Elts[0]->getType())) 1967 return Error(ID.Loc, "getelementptr requires pointer operand"); 1968 1969 if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), 1970 (Value**)&Elts[1], Elts.size()-1)) 1971 return Error(ID.Loc, "invalid indices for getelementptr"); |
1929 ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], | 1972 ID.ConstantVal = Context.getConstantExprGetElementPtr(Elts[0], |
1930 &Elts[1], Elts.size()-1); 1931 } else if (Opc == Instruction::Select) { 1932 if (Elts.size() != 3) 1933 return Error(ID.Loc, "expected three operands to select"); 1934 if (const char *Reason = SelectInst::areInvalidOperands(Elts[0], Elts[1], 1935 Elts[2])) 1936 return Error(ID.Loc, Reason); | 1973 &Elts[1], Elts.size()-1); 1974 } else if (Opc == Instruction::Select) { 1975 if (Elts.size() != 3) 1976 return Error(ID.Loc, "expected three operands to select"); 1977 if (const char *Reason = SelectInst::areInvalidOperands(Elts[0], Elts[1], 1978 Elts[2])) 1979 return Error(ID.Loc, Reason); |
1937 ID.ConstantVal = ConstantExpr::getSelect(Elts[0], Elts[1], Elts[2]); | 1980 ID.ConstantVal = Context.getConstantExprSelect(Elts[0], Elts[1], Elts[2]); |
1938 } else if (Opc == Instruction::ShuffleVector) { 1939 if (Elts.size() != 3) 1940 return Error(ID.Loc, "expected three operands to shufflevector"); 1941 if (!ShuffleVectorInst::isValidOperands(Elts[0], Elts[1], Elts[2])) 1942 return Error(ID.Loc, "invalid operands to shufflevector"); | 1981 } else if (Opc == Instruction::ShuffleVector) { 1982 if (Elts.size() != 3) 1983 return Error(ID.Loc, "expected three operands to shufflevector"); 1984 if (!ShuffleVectorInst::isValidOperands(Elts[0], Elts[1], Elts[2])) 1985 return Error(ID.Loc, "invalid operands to shufflevector"); |
1943 ID.ConstantVal = ConstantExpr::getShuffleVector(Elts[0], Elts[1],Elts[2]); | 1986 ID.ConstantVal = 1987 Context.getConstantExprShuffleVector(Elts[0], Elts[1],Elts[2]); |
1944 } else if (Opc == Instruction::ExtractElement) { 1945 if (Elts.size() != 2) 1946 return Error(ID.Loc, "expected two operands to extractelement"); 1947 if (!ExtractElementInst::isValidOperands(Elts[0], Elts[1])) 1948 return Error(ID.Loc, "invalid extractelement operands"); | 1988 } else if (Opc == Instruction::ExtractElement) { 1989 if (Elts.size() != 2) 1990 return Error(ID.Loc, "expected two operands to extractelement"); 1991 if (!ExtractElementInst::isValidOperands(Elts[0], Elts[1])) 1992 return Error(ID.Loc, "invalid extractelement operands"); |
1949 ID.ConstantVal = ConstantExpr::getExtractElement(Elts[0], Elts[1]); | 1993 ID.ConstantVal = Context.getConstantExprExtractElement(Elts[0], Elts[1]); |
1950 } else { 1951 assert(Opc == Instruction::InsertElement && "Unknown opcode"); 1952 if (Elts.size() != 3) 1953 return Error(ID.Loc, "expected three operands to insertelement"); 1954 if (!InsertElementInst::isValidOperands(Elts[0], Elts[1], Elts[2])) 1955 return Error(ID.Loc, "invalid insertelement operands"); | 1994 } else { 1995 assert(Opc == Instruction::InsertElement && "Unknown opcode"); 1996 if (Elts.size() != 3) 1997 return Error(ID.Loc, "expected three operands to insertelement"); 1998 if (!InsertElementInst::isValidOperands(Elts[0], Elts[1], Elts[2])) 1999 return Error(ID.Loc, "invalid insertelement operands"); |
1956 ID.ConstantVal = ConstantExpr::getInsertElement(Elts[0], Elts[1],Elts[2]); | 2000 ID.ConstantVal = 2001 Context.getConstantExprInsertElement(Elts[0], Elts[1],Elts[2]); |
1957 } 1958 1959 ID.Kind = ValID::t_Constant; 1960 return false; 1961 } 1962 } 1963 1964 Lex.Lex(); --- 27 unchanged lines hidden (view full) --- 1992 return V == 0; 1993 case ValID::t_GlobalID: 1994 V = GetGlobalVal(ID.UIntVal, Ty, ID.Loc); 1995 return V == 0; 1996 case ValID::t_APSInt: 1997 if (!isa<IntegerType>(Ty)) 1998 return Error(ID.Loc, "integer constant must have integer type"); 1999 ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits()); | 2002 } 2003 2004 ID.Kind = ValID::t_Constant; 2005 return false; 2006 } 2007 } 2008 2009 Lex.Lex(); --- 27 unchanged lines hidden (view full) --- 2037 return V == 0; 2038 case ValID::t_GlobalID: 2039 V = GetGlobalVal(ID.UIntVal, Ty, ID.Loc); 2040 return V == 0; 2041 case ValID::t_APSInt: 2042 if (!isa<IntegerType>(Ty)) 2043 return Error(ID.Loc, "integer constant must have integer type"); 2044 ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits()); |
2000 V = ConstantInt::get(ID.APSIntVal); | 2045 V = Context.getConstantInt(ID.APSIntVal); |
2001 return false; 2002 case ValID::t_APFloat: 2003 if (!Ty->isFloatingPoint() || 2004 !ConstantFP::isValueValidForType(Ty, ID.APFloatVal)) 2005 return Error(ID.Loc, "floating point constant invalid for type"); 2006 2007 // The lexer has no type info, so builds all float and double FP constants 2008 // as double. Fix this here. Long double does not need this. 2009 if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble && 2010 Ty == Type::FloatTy) { 2011 bool Ignored; 2012 ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, 2013 &Ignored); 2014 } | 2046 return false; 2047 case ValID::t_APFloat: 2048 if (!Ty->isFloatingPoint() || 2049 !ConstantFP::isValueValidForType(Ty, ID.APFloatVal)) 2050 return Error(ID.Loc, "floating point constant invalid for type"); 2051 2052 // The lexer has no type info, so builds all float and double FP constants 2053 // as double. Fix this here. Long double does not need this. 2054 if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble && 2055 Ty == Type::FloatTy) { 2056 bool Ignored; 2057 ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, 2058 &Ignored); 2059 } |
2015 V = ConstantFP::get(ID.APFloatVal); | 2060 V = Context.getConstantFP(ID.APFloatVal); |
2016 2017 if (V->getType() != Ty) 2018 return Error(ID.Loc, "floating point constant does not have type '" + 2019 Ty->getDescription() + "'"); 2020 2021 return false; 2022 case ValID::t_Null: 2023 if (!isa<PointerType>(Ty)) 2024 return Error(ID.Loc, "null must be a pointer type"); | 2061 2062 if (V->getType() != Ty) 2063 return Error(ID.Loc, "floating point constant does not have type '" + 2064 Ty->getDescription() + "'"); 2065 2066 return false; 2067 case ValID::t_Null: 2068 if (!isa<PointerType>(Ty)) 2069 return Error(ID.Loc, "null must be a pointer type"); |
2025 V = ConstantPointerNull::get(cast<PointerType>(Ty)); | 2070 V = Context.getConstantPointerNull(cast<PointerType>(Ty)); |
2026 return false; 2027 case ValID::t_Undef: 2028 // FIXME: LabelTy should not be a first-class type. 2029 if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) && 2030 !isa<OpaqueType>(Ty)) 2031 return Error(ID.Loc, "invalid type for undef constant"); | 2071 return false; 2072 case ValID::t_Undef: 2073 // FIXME: LabelTy should not be a first-class type. 2074 if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) && 2075 !isa<OpaqueType>(Ty)) 2076 return Error(ID.Loc, "invalid type for undef constant"); |
2032 V = UndefValue::get(Ty); | 2077 V = Context.getUndef(Ty); |
2033 return false; 2034 case ValID::t_EmptyArray: 2035 if (!isa<ArrayType>(Ty) || cast<ArrayType>(Ty)->getNumElements() != 0) 2036 return Error(ID.Loc, "invalid empty array initializer"); | 2078 return false; 2079 case ValID::t_EmptyArray: 2080 if (!isa<ArrayType>(Ty) || cast<ArrayType>(Ty)->getNumElements() != 0) 2081 return Error(ID.Loc, "invalid empty array initializer"); |
2037 V = UndefValue::get(Ty); | 2082 V = Context.getUndef(Ty); |
2038 return false; 2039 case ValID::t_Zero: 2040 // FIXME: LabelTy should not be a first-class type. 2041 if (!Ty->isFirstClassType() || Ty == Type::LabelTy) 2042 return Error(ID.Loc, "invalid type for null constant"); | 2083 return false; 2084 case ValID::t_Zero: 2085 // FIXME: LabelTy should not be a first-class type. 2086 if (!Ty->isFirstClassType() || Ty == Type::LabelTy) 2087 return Error(ID.Loc, "invalid type for null constant"); |
2043 V = Constant::getNullValue(Ty); | 2088 V = Context.getNullValue(Ty); |
2044 return false; 2045 case ValID::t_Constant: 2046 if (ID.ConstantVal->getType() != Ty) 2047 return Error(ID.Loc, "constant expression type mismatch"); 2048 V = ID.ConstantVal; 2049 return false; 2050 } 2051} --- 185 unchanged lines hidden (view full) --- 2237 Attrs.push_back(AttributeWithIndex::get(~0, FuncAttrs)); 2238 2239 AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end()); 2240 2241 if (PAL.paramHasAttr(1, Attribute::StructRet) && 2242 RetType != Type::VoidTy) 2243 return Error(RetTypeLoc, "functions with 'sret' argument must return void"); 2244 | 2089 return false; 2090 case ValID::t_Constant: 2091 if (ID.ConstantVal->getType() != Ty) 2092 return Error(ID.Loc, "constant expression type mismatch"); 2093 V = ID.ConstantVal; 2094 return false; 2095 } 2096} --- 185 unchanged lines hidden (view full) --- 2282 Attrs.push_back(AttributeWithIndex::get(~0, FuncAttrs)); 2283 2284 AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end()); 2285 2286 if (PAL.paramHasAttr(1, Attribute::StructRet) && 2287 RetType != Type::VoidTy) 2288 return Error(RetTypeLoc, "functions with 'sret' argument must return void"); 2289 |
2245 const FunctionType *FT = FunctionType::get(RetType, ParamTypeList, isVarArg); 2246 const PointerType *PFT = PointerType::getUnqual(FT); | 2290 const FunctionType *FT = 2291 Context.getFunctionType(RetType, ParamTypeList, isVarArg); 2292 const PointerType *PFT = Context.getPointerTypeUnqual(FT); |
2247 2248 Fn = 0; 2249 if (!FunctionName.empty()) { 2250 // If this was a definition of a forward reference, remove the definition 2251 // from the forward reference table and fill in the forward ref. 2252 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI = 2253 ForwardRefVals.find(FunctionName); 2254 if (FRVI != ForwardRefVals.end()) { --- 298 unchanged lines hidden (view full) --- 2553 SmallVector<Value*, 8> RVs; 2554 RVs.push_back(RV); 2555 2556 while (EatIfPresent(lltok::comma)) { 2557 if (ParseTypeAndValue(RV, PFS)) return true; 2558 RVs.push_back(RV); 2559 } 2560 | 2293 2294 Fn = 0; 2295 if (!FunctionName.empty()) { 2296 // If this was a definition of a forward reference, remove the definition 2297 // from the forward reference table and fill in the forward ref. 2298 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI = 2299 ForwardRefVals.find(FunctionName); 2300 if (FRVI != ForwardRefVals.end()) { --- 298 unchanged lines hidden (view full) --- 2599 SmallVector<Value*, 8> RVs; 2600 RVs.push_back(RV); 2601 2602 while (EatIfPresent(lltok::comma)) { 2603 if (ParseTypeAndValue(RV, PFS)) return true; 2604 RVs.push_back(RV); 2605 } 2606 |
2561 RV = UndefValue::get(PFS.getFunction().getReturnType()); | 2607 RV = Context.getUndef(PFS.getFunction().getReturnType()); |
2562 for (unsigned i = 0, e = RVs.size(); i != e; ++i) { 2563 Instruction *I = InsertValueInst::Create(RV, RVs[i], i, "mrv"); 2564 BB->getInstList().push_back(I); 2565 RV = I; 2566 } 2567 } 2568 Inst = ReturnInst::Create(RV); 2569 return false; --- 121 unchanged lines hidden (view full) --- 2691 // Pull out the types of all of the arguments... 2692 std::vector<const Type*> ParamTypes; 2693 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 2694 ParamTypes.push_back(ArgList[i].V->getType()); 2695 2696 if (!FunctionType::isValidReturnType(RetType)) 2697 return Error(RetTypeLoc, "Invalid result type for LLVM function"); 2698 | 2608 for (unsigned i = 0, e = RVs.size(); i != e; ++i) { 2609 Instruction *I = InsertValueInst::Create(RV, RVs[i], i, "mrv"); 2610 BB->getInstList().push_back(I); 2611 RV = I; 2612 } 2613 } 2614 Inst = ReturnInst::Create(RV); 2615 return false; --- 121 unchanged lines hidden (view full) --- 2737 // Pull out the types of all of the arguments... 2738 std::vector<const Type*> ParamTypes; 2739 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 2740 ParamTypes.push_back(ArgList[i].V->getType()); 2741 2742 if (!FunctionType::isValidReturnType(RetType)) 2743 return Error(RetTypeLoc, "Invalid result type for LLVM function"); 2744 |
2699 Ty = FunctionType::get(RetType, ParamTypes, false); 2700 PFTy = PointerType::getUnqual(Ty); | 2745 Ty = Context.getFunctionType(RetType, ParamTypes, false); 2746 PFTy = Context.getPointerTypeUnqual(Ty); |
2701 } 2702 2703 // Look up the callee. 2704 Value *Callee; 2705 if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true; 2706 2707 // FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional 2708 // function attributes. --- 331 unchanged lines hidden (view full) --- 3040 // Pull out the types of all of the arguments... 3041 std::vector<const Type*> ParamTypes; 3042 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 3043 ParamTypes.push_back(ArgList[i].V->getType()); 3044 3045 if (!FunctionType::isValidReturnType(RetType)) 3046 return Error(RetTypeLoc, "Invalid result type for LLVM function"); 3047 | 2747 } 2748 2749 // Look up the callee. 2750 Value *Callee; 2751 if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true; 2752 2753 // FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional 2754 // function attributes. --- 331 unchanged lines hidden (view full) --- 3086 // Pull out the types of all of the arguments... 3087 std::vector<const Type*> ParamTypes; 3088 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) 3089 ParamTypes.push_back(ArgList[i].V->getType()); 3090 3091 if (!FunctionType::isValidReturnType(RetType)) 3092 return Error(RetTypeLoc, "Invalid result type for LLVM function"); 3093 |
3048 Ty = FunctionType::get(RetType, ParamTypes, false); 3049 PFTy = PointerType::getUnqual(Ty); | 3094 Ty = Context.getFunctionType(RetType, ParamTypes, false); 3095 PFTy = Context.getPointerTypeUnqual(Ty); |
3050 } 3051 3052 // Look up the callee. 3053 Value *Callee; 3054 if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true; 3055 3056 // FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional 3057 // function attributes. --- 53 unchanged lines hidden (view full) --- 3111 3112/// ParseAlloc 3113/// ::= 'malloc' Type (',' TypeAndValue)? (',' OptionalAlignment)? 3114/// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalAlignment)? 3115bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, 3116 unsigned Opc) { 3117 PATypeHolder Ty(Type::VoidTy); 3118 Value *Size = 0; | 3096 } 3097 3098 // Look up the callee. 3099 Value *Callee; 3100 if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true; 3101 3102 // FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional 3103 // function attributes. --- 53 unchanged lines hidden (view full) --- 3157 3158/// ParseAlloc 3159/// ::= 'malloc' Type (',' TypeAndValue)? (',' OptionalAlignment)? 3160/// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalAlignment)? 3161bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, 3162 unsigned Opc) { 3163 PATypeHolder Ty(Type::VoidTy); 3164 Value *Size = 0; |
3119 LocTy SizeLoc = 0; | 3165 LocTy SizeLoc; |
3120 unsigned Alignment = 0; 3121 if (ParseType(Ty)) return true; 3122 3123 if (EatIfPresent(lltok::comma)) { 3124 if (Lex.getKind() == lltok::kw_align) { 3125 if (ParseOptionalAlignment(Alignment)) return true; 3126 } else if (ParseTypeAndValue(Size, SizeLoc, PFS) || 3127 ParseOptionalCommaAlignment(Alignment)) { --- 175 unchanged lines hidden --- | 3166 unsigned Alignment = 0; 3167 if (ParseType(Ty)) return true; 3168 3169 if (EatIfPresent(lltok::comma)) { 3170 if (Lex.getKind() == lltok::kw_align) { 3171 if (ParseOptionalAlignment(Alignment)) return true; 3172 } else if (ParseTypeAndValue(Size, SizeLoc, PFS) || 3173 ParseOptionalCommaAlignment(Alignment)) { --- 175 unchanged lines hidden --- |