Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: src/PNaClTranslator.cpp

Issue 625243002: Convert Subzero's bitcode reader to generate ICE types. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceTypes.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the PNaCl bitcode file to Ice, to machine code 10 // This file implements the PNaCl bitcode file to Ice, to machine code
(...skipping 28 matching lines...) Expand all
39 using namespace llvm; 39 using namespace llvm;
40 40
41 namespace { 41 namespace {
42 42
43 // TODO(kschimpf) Remove error recovery once implementation complete. 43 // TODO(kschimpf) Remove error recovery once implementation complete.
44 static cl::opt<bool> AllowErrorRecovery( 44 static cl::opt<bool> AllowErrorRecovery(
45 "allow-pnacl-reader-error-recovery", 45 "allow-pnacl-reader-error-recovery",
46 cl::desc("Allow error recovery when reading PNaCl bitcode."), 46 cl::desc("Allow error recovery when reading PNaCl bitcode."),
47 cl::init(false)); 47 cl::init(false));
48 48
49 // Models elements in the list of types defined in the types block.
50 // These elements can be undefined, a (simple) type, or a function type
51 // signature. Note that an extended type is undefined on construction.
52 // Use methods setAsSimpleType and setAsFuncSigType to define
53 // the extended type.
54 class ExtendedType {
55 // ExtendedType(const ExtendedType &Ty) = delete;
56 ExtendedType &operator=(const ExtendedType &Ty) = delete;
57 public:
58 /// Discriminator for LLVM-style RTTI.
59 enum TypeKind { Undefined, Simple, FuncSig };
60
61 ExtendedType() : Kind(Undefined) {}
62
63 virtual ~ExtendedType() {}
64
65 ExtendedType::TypeKind getKind() const { return Kind; }
66 void Dump(Ice::Ostream &Stream) const;
67
68 /// Changes the extended type to a simple type with the given
69 /// value.
70 void setAsSimpleType(Ice::Type Ty) {
71 assert(Kind == Undefined);
72 Kind = Simple;
73 Signature.setReturnType(Ty);
74 }
75
76 /// Changes the extended type to an (empty) function signature type.
77 void setAsFunctionType() {
78 assert(Kind == Undefined);
79 Kind = FuncSig;
80 }
81
82 protected:
83 // Note: For simple types, the return type of the signature will
84 // be used to hold the simple type.
85 Ice::FuncSigType Signature;
86
87 private:
88 ExtendedType::TypeKind Kind;
89 };
90
91 Ice::Ostream &operator<<(Ice::Ostream &Stream, const ExtendedType &Ty) {
92 Ty.Dump(Stream);
93 return Stream;
94 }
95
96 Ice::Ostream &operator<<(Ice::Ostream &Stream, ExtendedType::TypeKind Kind) {
97 Stream << "ExtendedType::";
98 switch (Kind) {
99 case ExtendedType::Undefined:
100 Stream << "Undefined";
101 break;
102 case ExtendedType::Simple:
103 Stream << "Simple";
104 break;
105 case ExtendedType::FuncSig:
106 Stream << "FuncSig";
107 break;
108 default:
109 Stream << "??";
110 break;
111 }
112 return Stream;
113 }
114
115 // Models an ICE type as an extended type.
116 class SimpleExtendedType : public ExtendedType {
117 SimpleExtendedType(const SimpleExtendedType &) = delete;
118 SimpleExtendedType &operator=(const SimpleExtendedType &) = delete;
119 public:
120 Ice::Type getType() const { return Signature.getReturnType(); }
121
122 static bool classof(const ExtendedType *Ty) {
123 return Ty->getKind() == Simple;
124 }
125 };
126
127 // Models a function signature as an extended type.
128 class FuncSigExtendedType : public ExtendedType {
129 FuncSigExtendedType(const FuncSigExtendedType &) = delete;
130 FuncSigExtendedType &operator=(const FuncSigExtendedType &) = delete;
131 public:
132 const Ice::FuncSigType &getSignature() const { return Signature; }
133 void setReturnType(Ice::Type ReturnType) {
134 Signature.setReturnType(ReturnType);
135 }
136 void appendArgType(Ice::Type ArgType) { Signature.appendArgType(ArgType); }
137 static bool classof(const ExtendedType *Ty) {
138 return Ty->getKind() == FuncSig;
139 }
140 };
141
142 void ExtendedType::Dump(Ice::Ostream &Stream) const {
143 Stream << Kind;
144 switch (Kind) {
145 case Simple: {
146 Stream << " " << Signature.getReturnType();
147 break;
148 }
149 case FuncSig: {
150 Stream << " " << Signature;
151 }
152 default:
153 break;
154 }
155 }
156
49 // Top-level class to read PNaCl bitcode files, and translate to ICE. 157 // Top-level class to read PNaCl bitcode files, and translate to ICE.
50 class TopLevelParser : public NaClBitcodeParser { 158 class TopLevelParser : public NaClBitcodeParser {
51 TopLevelParser(const TopLevelParser &) = delete; 159 TopLevelParser(const TopLevelParser &) = delete;
52 TopLevelParser &operator=(const TopLevelParser &) = delete; 160 TopLevelParser &operator=(const TopLevelParser &) = delete;
53 161
54 public: 162 public:
55 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, 163 TopLevelParser(Ice::Translator &Translator, const std::string &InputName,
56 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, 164 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor,
57 bool &ErrorStatus) 165 bool &ErrorStatus)
58 : NaClBitcodeParser(Cursor), Translator(Translator), 166 : NaClBitcodeParser(Cursor), Translator(Translator),
(...skipping 30 matching lines...) Expand all
89 197
90 /// Returns the number of bytes in the bitcode header. 198 /// Returns the number of bytes in the bitcode header.
91 size_t getHeaderSize() const { return Header.getHeaderSize(); } 199 size_t getHeaderSize() const { return Header.getHeaderSize(); }
92 200
93 /// Returns the llvm context to use. 201 /// Returns the llvm context to use.
94 LLVMContext &getLLVMContext() const { return Mod->getContext(); } 202 LLVMContext &getLLVMContext() const { return Mod->getContext(); }
95 203
96 /// Changes the size of the type list to the given size. 204 /// Changes the size of the type list to the given size.
97 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } 205 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); }
98 206
99 /// Returns the type associated with the given index. 207 /// Returns the undefined type associated with type ID.
100 Type *getTypeByID(unsigned ID) { 208 /// Note: Returns extended type ready to be defined.
101 // Note: method resizeTypeIDValues expands TypeIDValues 209 ExtendedType *getTypeByIDForDefining(unsigned ID) {
102 // to the specified size, and fills elements with nullptr. 210 // Get corresponding element, verifying the value is still undefined
103 Type *Ty = ID < TypeIDValues.size() ? TypeIDValues[ID] : nullptr; 211 // (and hence allowed to be defined).
212 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined);
104 if (Ty) 213 if (Ty)
105 return Ty; 214 return Ty;
106 return reportTypeIDAsUndefined(ID); 215 if (ID >= TypeIDValues.size())
216 TypeIDValues.resize(ID+1);
217 return &TypeIDValues[ID];
107 } 218 }
108 219
109 /// Defines type for ID. 220 /// Returns the type associated with the given index.
110 void setTypeID(unsigned ID, Type *Ty) { 221 Ice::Type getSimpleTypeByID(unsigned ID) {
111 if (ID < TypeIDValues.size() && TypeIDValues[ID] == nullptr) { 222 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Simple);
112 TypeIDValues[ID] = Ty; 223 if (Ty == nullptr)
113 return; 224 // Return error recovery value.
114 } 225 return Ice::IceType_void;
115 reportBadSetTypeID(ID, Ty); 226 return cast<SimpleExtendedType>(Ty)->getType();
227 }
228
229 /// Returns the type signature associated with the given index.
230 const Ice::FuncSigType &getFuncSigTypeByID(unsigned ID) {
231 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::FuncSig);
232 if (Ty == nullptr)
233 // Return error recovery value.
234 return UndefinedFuncSigType;
235 return cast<FuncSigExtendedType>(Ty)->getSignature();
116 } 236 }
117 237
118 /// Sets the next function ID to the given LLVM function. 238 /// Sets the next function ID to the given LLVM function.
119 void setNextFunctionID(Function *Fcn) { 239 void setNextFunctionID(Function *Fcn) {
120 ++NumFunctionIds; 240 ++NumFunctionIds;
121 FunctionIDValues.push_back(Fcn); 241 FunctionIDValues.push_back(Fcn);
122 } 242 }
123 243
124 /// Defines the next function ID as one that has an implementation 244 /// Defines the next function ID as one that has an implementation
125 /// (i.e a corresponding function block in the bitcode). 245 /// (i.e a corresponding function block in the bitcode).
126 void setNextValueIDAsImplementedFunction() { 246 void setNextValueIDAsImplementedFunction() {
127 DefiningFunctionsList.push_back(FunctionIDValues.size()); 247 DefiningFunctionsList.push_back(FunctionIDValues.size());
128 } 248 }
129 249
130 /// Returns the value id that should be associated with the the 250 /// Returns the value id that should be associated with the the
131 /// current function block. Increments internal counters during call 251 /// current function block. Increments internal counters during call
132 /// so that it will be in correct position for next function block. 252 /// so that it will be in correct position for next function block.
133 unsigned getNextFunctionBlockValueID() { 253 unsigned getNextFunctionBlockValueID() {
134 if (NumFunctionBlocks >= DefiningFunctionsList.size()) 254 if (NumFunctionBlocks >= DefiningFunctionsList.size())
135 report_fatal_error( 255 report_fatal_error(
136 "More function blocks than defined function addresses"); 256 "More function blocks than defined function addresses");
137 return DefiningFunctionsList[NumFunctionBlocks++]; 257 return DefiningFunctionsList[NumFunctionBlocks++];
138 } 258 }
139 259
140 /// Returns the LLVM IR value associatd with the global value ID. 260 /// Returns the LLVM Function address associated with ID.
141 Function *getFunctionByID(unsigned ID) const { 261 Function *getFunctionByID(unsigned ID) const {
142 if (ID >= FunctionIDValues.size()) 262 if (ID >= FunctionIDValues.size())
143 return nullptr; 263 return nullptr;
144 Value *V = FunctionIDValues[ID]; 264 Value *V = FunctionIDValues[ID];
145 return cast<Function>(V); 265 return cast<Function>(V);
146 } 266 }
147 267
148 /// Returns the corresponding constant associated with a global value 268 /// Returns the corresponding constant associated with a global value
149 /// (i.e. relocatable). 269 /// (i.e. relocatable).
150 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) { 270 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return convertToIceTypeError(LLVMTy); 354 return convertToIceTypeError(LLVMTy);
235 } 355 }
236 return IceTy; 356 return IceTy;
237 } 357 }
238 358
239 /// Returns the corresponding LLVM type for IceTy. 359 /// Returns the corresponding LLVM type for IceTy.
240 Type *convertToLLVMType(Ice::Type IceTy) const { 360 Type *convertToLLVMType(Ice::Type IceTy) const {
241 return TypeConverter.convertToLLVMType(IceTy); 361 return TypeConverter.convertToLLVMType(IceTy);
242 } 362 }
243 363
244 /// Returns the LLVM integer type with the given number of Bits. If
245 /// Bits is not a valid PNaCl type, returns nullptr.
246 Type *getLLVMIntegerType(unsigned Bits) const {
247 return TypeConverter.getLLVMIntegerType(Bits);
248 }
249
250 /// Returns the LLVM vector with the given Size and Ty. If not a
251 /// valid PNaCl vector type, returns nullptr.
252 Type *getLLVMVectorType(unsigned Size, Ice::Type Ty) const {
253 return TypeConverter.getLLVMVectorType(Size, Ty);
254 }
255
256 /// Returns the model for pointer types in ICE. 364 /// Returns the model for pointer types in ICE.
257 Ice::Type getIcePointerType() const { 365 Ice::Type getIcePointerType() const {
258 return TypeConverter.getIcePointerType(); 366 return TypeConverter.getIcePointerType();
259 } 367 }
260 368
261 private: 369 private:
262 // The translator associated with the parser. 370 // The translator associated with the parser.
263 Ice::Translator &Translator; 371 Ice::Translator &Translator;
264 // The parsed module. 372 // The parsed module.
265 std::unique_ptr<Module> Mod; 373 std::unique_ptr<Module> Mod;
266 // The data layout to use. 374 // The data layout to use.
267 DataLayout DL; 375 DataLayout DL;
268 // The bitcode header. 376 // The bitcode header.
269 NaClBitcodeHeader &Header; 377 NaClBitcodeHeader &Header;
270 // Converter between LLVM and ICE types. 378 // Converter between LLVM and ICE types.
271 Ice::TypeConverter TypeConverter; 379 Ice::TypeConverter TypeConverter;
272 // The exit status that should be set to true if an error occurs. 380 // The exit status that should be set to true if an error occurs.
273 bool &ErrorStatus; 381 bool &ErrorStatus;
274 // The number of errors reported. 382 // The number of errors reported.
275 unsigned NumErrors; 383 unsigned NumErrors;
276 // The types associated with each type ID. 384 // The types associated with each type ID.
277 std::vector<Type *> TypeIDValues; 385 std::vector<ExtendedType> TypeIDValues;
278 // The set of function value IDs. 386 // The set of function value IDs.
279 std::vector<WeakVH> FunctionIDValues; 387 std::vector<WeakVH> FunctionIDValues;
280 // The set of global addresses IDs. 388 // The set of global addresses IDs.
281 Ice::Translator::GlobalAddressList GlobalIDAddresses; 389 Ice::Translator::GlobalAddressList GlobalIDAddresses;
282 // Relocatable constants associated with FunctionIDValues and 390 // Relocatable constants associated with FunctionIDValues and
283 // GlobalIDAddresses. 391 // GlobalIDAddresses.
284 std::vector<Ice::Constant *> ValueIDConstants; 392 std::vector<Ice::Constant *> ValueIDConstants;
285 // The number of function IDs. 393 // The number of function IDs.
286 unsigned NumFunctionIds; 394 unsigned NumFunctionIds;
287 // The number of function blocks (processed so far). 395 // The number of function blocks (processed so far).
288 unsigned NumFunctionBlocks; 396 unsigned NumFunctionBlocks;
289 // The list of value IDs (in the order found) of defining function 397 // The list of value IDs (in the order found) of defining function
290 // addresses. 398 // addresses.
291 std::vector<unsigned> DefiningFunctionsList; 399 std::vector<unsigned> DefiningFunctionsList;
400 // Error recovery value to use when getFuncSigTypeByID fails.
401 Ice::FuncSigType UndefinedFuncSigType;
292 402
293 bool ParseBlock(unsigned BlockID) override; 403 bool ParseBlock(unsigned BlockID) override;
294 404
295 /// Reports that type ID is undefined, and then returns 405 // Gets extended type associated with the given index, assuming the
296 /// the void type. 406 // extended type is of the WantedKind. Generates error message if
297 Type *reportTypeIDAsUndefined(unsigned ID); 407 // corresponding extended type of WantedKind can't be found, and
408 // returns nullptr.
409 ExtendedType *getTypeByIDAsKind(unsigned ID,
410 ExtendedType::TypeKind WantedKind) {
411 ExtendedType *Ty = nullptr;
412 if (ID < TypeIDValues.size()) {
413 Ty = &TypeIDValues[ID];
414 if (Ty->getKind() == WantedKind)
415 return Ty;
416 }
417 // Generate an error message and set ErrorStatus.
418 this->reportBadTypeIDAs(ID, Ty, WantedKind);
419 return nullptr;
420 }
298 421
299 /// Reports error about bad call to setTypeID. 422 // Reports that type ID is undefined, or not of the WantedType.
300 void reportBadSetTypeID(unsigned ID, Type *Ty); 423 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty,
424 ExtendedType::TypeKind WantedType);
301 425
302 // Reports that there is no corresponding ICE type for LLVMTy, and 426 // Reports that there is no corresponding ICE type for LLVMTy, and
303 // returns ICE::IceType_void. 427 // returns ICE::IceType_void.
304 Ice::Type convertToIceTypeError(Type *LLVMTy); 428 Ice::Type convertToIceTypeError(Type *LLVMTy);
305 }; 429 };
306 430
307 Type *TopLevelParser::reportTypeIDAsUndefined(unsigned ID) { 431 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty,
432 ExtendedType::TypeKind WantedType) {
308 std::string Buffer; 433 std::string Buffer;
309 raw_string_ostream StrBuf(Buffer); 434 raw_string_ostream StrBuf(Buffer);
310 StrBuf << "Can't find type for type id: " << ID; 435 if (Ty == nullptr) {
311 Error(StrBuf.str()); 436 StrBuf << "Can't find extended type for type id: " << ID;
312 // TODO(kschimpf) Remove error recovery once implementation complete.
313 Type *Ty = TypeConverter.convertToLLVMType(Ice::IceType_void);
314 // To reduce error messages, update type list if possible.
315 if (ID < TypeIDValues.size())
316 TypeIDValues[ID] = Ty;
317 return Ty;
318 }
319
320 void TopLevelParser::reportBadSetTypeID(unsigned ID, Type *Ty) {
321 std::string Buffer;
322 raw_string_ostream StrBuf(Buffer);
323 if (ID >= TypeIDValues.size()) {
324 StrBuf << "Type index " << ID << " out of range: can't install.";
325 } else { 437 } else {
326 // Must be case that index already defined. 438 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty;
327 StrBuf << "Type index " << ID << " defined as " << *TypeIDValues[ID]
328 << " and " << *Ty << ".";
329 } 439 }
330 Error(StrBuf.str()); 440 Error(StrBuf.str());
331 } 441 }
332 442
333 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { 443 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) {
334 std::string Buffer; 444 std::string Buffer;
335 raw_string_ostream StrBuf(Buffer); 445 raw_string_ostream StrBuf(Buffer);
336 StrBuf << "Invalid LLVM type: " << *LLVMTy; 446 StrBuf << "Invalid LLVM type: " << *LLVMTy;
337 Error(StrBuf.str()); 447 Error(StrBuf.str());
338 return Ice::IceType_void; 448 return Ice::IceType_void;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} 585 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {}
476 586
477 ~TypesParser() override {} 587 ~TypesParser() override {}
478 588
479 private: 589 private:
480 // The type ID that will be associated with the next type defining 590 // The type ID that will be associated with the next type defining
481 // record in the types block. 591 // record in the types block.
482 unsigned NextTypeId; 592 unsigned NextTypeId;
483 593
484 void ProcessRecord() override; 594 void ProcessRecord() override;
595
596 void setNextTypeIDAsSimpleType(Ice::Type Ty) {
597 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty);
598 }
485 }; 599 };
486 600
487 void TypesParser::ProcessRecord() { 601 void TypesParser::ProcessRecord() {
488 Type *Ty = nullptr;
489 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); 602 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues();
490 switch (Record.GetCode()) { 603 switch (Record.GetCode()) {
491 case naclbitc::TYPE_CODE_NUMENTRY: 604 case naclbitc::TYPE_CODE_NUMENTRY:
492 // NUMENTRY: [numentries] 605 // NUMENTRY: [numentries]
493 if (!isValidRecordSize(1, "Type count")) 606 if (!isValidRecordSize(1, "Type count"))
494 return; 607 return;
495 Context->resizeTypeIDValues(Values[0]); 608 Context->resizeTypeIDValues(Values[0]);
496 return; 609 return;
497 case naclbitc::TYPE_CODE_VOID: 610 case naclbitc::TYPE_CODE_VOID:
498 // VOID 611 // VOID
499 if (!isValidRecordSize(0, "Type void")) 612 if (!isValidRecordSize(0, "Type void"))
500 return; 613 return;
501 Ty = Context->convertToLLVMType(Ice::IceType_void); 614 setNextTypeIDAsSimpleType(Ice::IceType_void);
502 break; 615 return;
503 case naclbitc::TYPE_CODE_FLOAT: 616 case naclbitc::TYPE_CODE_FLOAT:
504 // FLOAT 617 // FLOAT
505 if (!isValidRecordSize(0, "Type float")) 618 if (!isValidRecordSize(0, "Type float"))
506 return; 619 return;
507 Ty = Context->convertToLLVMType(Ice::IceType_f32); 620 setNextTypeIDAsSimpleType(Ice::IceType_f32);
508 break; 621 return;
509 case naclbitc::TYPE_CODE_DOUBLE: 622 case naclbitc::TYPE_CODE_DOUBLE:
510 // DOUBLE 623 // DOUBLE
511 if (!isValidRecordSize(0, "Type double")) 624 if (!isValidRecordSize(0, "Type double"))
512 return; 625 return;
513 Ty = Context->convertToLLVMType(Ice::IceType_f64); 626 setNextTypeIDAsSimpleType(Ice::IceType_f64);
514 break; 627 return;
515 case naclbitc::TYPE_CODE_INTEGER: 628 case naclbitc::TYPE_CODE_INTEGER:
516 // INTEGER: [width] 629 // INTEGER: [width]
517 if (!isValidRecordSize(1, "Type integer")) 630 if (!isValidRecordSize(1, "Type integer"))
518 return; 631 return;
519 Ty = Context->getLLVMIntegerType(Values[0]); 632 switch (Values[0]) {
520 if (Ty == nullptr) { 633 case 1:
634 setNextTypeIDAsSimpleType(Ice::IceType_i1);
635 return;
636 case 8:
637 setNextTypeIDAsSimpleType(Ice::IceType_i8);
638 return;
639 case 16:
640 setNextTypeIDAsSimpleType(Ice::IceType_i16);
641 return;
642 case 32:
643 setNextTypeIDAsSimpleType(Ice::IceType_i32);
644 return;
645 case 64:
646 setNextTypeIDAsSimpleType(Ice::IceType_i64);
647 return;
648 default:
649 break;
650 }
651 {
521 std::string Buffer; 652 std::string Buffer;
522 raw_string_ostream StrBuf(Buffer); 653 raw_string_ostream StrBuf(Buffer);
523 StrBuf << "Type integer record with invalid bitsize: " << Values[0]; 654 StrBuf << "Type integer record with invalid bitsize: " << Values[0];
524 Error(StrBuf.str()); 655 Error(StrBuf.str());
525 // TODO(kschimpf) Remove error recovery once implementation complete.
526 // Fix type so that we can continue.
527 Ty = Context->convertToLLVMType(Ice::IceType_i32);
528 } 656 }
529 break; 657 return;
530 case naclbitc::TYPE_CODE_VECTOR: { 658 case naclbitc::TYPE_CODE_VECTOR: {
531 // VECTOR: [numelts, eltty] 659 // VECTOR: [numelts, eltty]
532 if (!isValidRecordSize(2, "Type vector")) 660 if (!isValidRecordSize(2, "Type vector"))
533 return; 661 return;
534 Type *BaseTy = Context->getTypeByID(Values[1]); 662 Ice::Type BaseTy = Context->getSimpleTypeByID(Values[1]);
535 Ty = Context->getLLVMVectorType(Values[0], 663 Ice::SizeT Size = Values[0];
536 Context->convertToIceType(BaseTy)); 664 switch (BaseTy) {
537 if (Ty == nullptr) { 665 case Ice::IceType_i1:
666 switch (Size) {
667 case 4:
668 setNextTypeIDAsSimpleType(Ice::IceType_v4i1);
669 return;
670 case 8:
671 setNextTypeIDAsSimpleType(Ice::IceType_v8i1);
672 return;
673 case 16:
674 setNextTypeIDAsSimpleType(Ice::IceType_v16i1);
675 return;
676 default:
677 break;
678 }
679 break;
680 case Ice::IceType_i8:
681 if (Size == 16) {
682 setNextTypeIDAsSimpleType(Ice::IceType_v16i8);
683 return;
684 }
685 break;
686 case Ice::IceType_i16:
687 if (Size == 8) {
688 setNextTypeIDAsSimpleType(Ice::IceType_v8i16);
689 return;
690 }
691 break;
692 case Ice::IceType_i32:
693 if (Size == 4) {
694 setNextTypeIDAsSimpleType(Ice::IceType_v4i32);
695 return;
696 }
697 break;
698 case Ice::IceType_f32:
699 if (Size == 4) {
700 setNextTypeIDAsSimpleType(Ice::IceType_v4f32);
701 return;
702 }
703 break;
704 default:
705 break;
706 }
707 {
538 std::string Buffer; 708 std::string Buffer;
539 raw_string_ostream StrBuf(Buffer); 709 raw_string_ostream StrBuf(Buffer);
540 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << *BaseTy 710 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << BaseTy
541 << ">"; 711 << ">";
542 Error(StrBuf.str()); 712 Error(StrBuf.str());
543 Ty = Context->convertToLLVMType(Ice::IceType_void);
544 } 713 }
545 break; 714 return;
546 } 715 }
547 case naclbitc::TYPE_CODE_FUNCTION: { 716 case naclbitc::TYPE_CODE_FUNCTION: {
548 // FUNCTION: [vararg, retty, paramty x N] 717 // FUNCTION: [vararg, retty, paramty x N]
549 if (!isValidRecordSizeAtLeast(2, "Type signature")) 718 if (!isValidRecordSizeAtLeast(2, "Type signature"))
550 return; 719 return;
551 SmallVector<Type *, 8> ArgTys; 720 if (Values[0])
721 Error("Function type can't define varargs");
722 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++);
723 Ty->setAsFunctionType();
724 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty);
725 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1]));
552 for (unsigned i = 2, e = Values.size(); i != e; ++i) { 726 for (unsigned i = 2, e = Values.size(); i != e; ++i) {
553 ArgTys.push_back(Context->getTypeByID(Values[i])); 727 // Check that type void not used as argument type.
728 // Note: PNaCl restrictions can't be checked until we
729 // know the name, because we have to check for intrinsic signatures.
730 Ice::Type ArgTy = Context->getSimpleTypeByID(Values[i]);
731 if (ArgTy == Ice::IceType_void) {
732 std::string Buffer;
733 raw_string_ostream StrBuf(Buffer);
734 StrBuf << "Type for parameter " << (i - 1)
735 << " not valid. Found: " << ArgTy;
736 // TODO(kschimpf) Remove error recovery once implementation complete.
737 ArgTy = Ice::IceType_i32;
738 }
739 FuncTy->appendArgType(ArgTy);
554 } 740 }
555 Ty = FunctionType::get(Context->getTypeByID(Values[1]), ArgTys, Values[0]); 741 return;
556 break;
557 } 742 }
558 default: 743 default:
559 BlockParserBaseClass::ProcessRecord(); 744 BlockParserBaseClass::ProcessRecord();
560 return; 745 return;
561 } 746 }
562 // If Ty not defined, assume error. Use void as filler. 747 llvm_unreachable("Unknown type block record not processed!");
563 if (Ty == nullptr)
564 Ty = Context->convertToLLVMType(Ice::IceType_void);
565 Context->setTypeID(NextTypeId++, Ty);
566 } 748 }
567 749
568 /// Parses the globals block (i.e. global variables). 750 /// Parses the globals block (i.e. global variables).
569 class GlobalsParser : public BlockParserBaseClass { 751 class GlobalsParser : public BlockParserBaseClass {
570 public: 752 public:
571 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 753 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
572 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), 754 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0),
573 NextGlobalID(0), CurrentAddress(&DummyAddress) {} 755 NextGlobalID(0), CurrentAddress(&DummyAddress) {}
574 756
575 ~GlobalsParser() override {} 757 ~GlobalsParser() override {}
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 return; 1602 return;
1421 CurrentNode->appendInst(Ice::InstArithmetic::create( 1603 CurrentNode->appendInst(Ice::InstArithmetic::create(
1422 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); 1604 Func, Opcode, getNextInstVar(Type1), Op1, Op2));
1423 break; 1605 break;
1424 } 1606 }
1425 case naclbitc::FUNC_CODE_INST_CAST: { 1607 case naclbitc::FUNC_CODE_INST_CAST: {
1426 // CAST: [opval, destty, castopc] 1608 // CAST: [opval, destty, castopc]
1427 if (!isValidRecordSize(3, "function block cast")) 1609 if (!isValidRecordSize(3, "function block cast"))
1428 return; 1610 return;
1429 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); 1611 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex);
1430 Type *CastType = Context->getTypeByID(Values[1]); 1612 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]);
1431 Instruction::CastOps LLVMCastOp; 1613 Instruction::CastOps LLVMCastOp;
1432 Ice::InstCast::OpKind CastKind; 1614 Ice::InstCast::OpKind CastKind;
1433 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || 1615 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) ||
1434 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { 1616 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) {
1435 std::string Buffer; 1617 std::string Buffer;
1436 raw_string_ostream StrBuf(Buffer); 1618 raw_string_ostream StrBuf(Buffer);
1437 StrBuf << "Cast opcode not understood: " << Values[2]; 1619 StrBuf << "Cast opcode not understood: " << Values[2];
1438 Error(StrBuf.str()); 1620 Error(StrBuf.str());
1439 return; 1621 return;
1440 } 1622 }
1441 Type *SrcType = Context->convertToLLVMType(Src->getType()); 1623 Ice::Type SrcType = Src->getType();
1442 if (!CastInst::castIsValid(LLVMCastOp, SrcType, CastType)) { 1624 if (!CastInst::castIsValid(LLVMCastOp, Context->convertToLLVMType(SrcType),
1625 Context->convertToLLVMType(CastType))) {
1443 std::string Buffer; 1626 std::string Buffer;
1444 raw_string_ostream StrBuf(Buffer); 1627 raw_string_ostream StrBuf(Buffer);
1445 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp) 1628 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp)
1446 << " " << *SrcType << " to " << *CastType; 1629 << " " << SrcType << " to " << CastType;
1447 Error(StrBuf.str()); 1630 Error(StrBuf.str());
1448 return; 1631 return;
1449 } 1632 }
1450 CurrentNode->appendInst(Ice::InstCast::create( 1633 CurrentNode->appendInst(
1451 Func, CastKind, getNextInstVar(Context->convertToIceType(CastType)), 1634 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src));
1452 Src));
1453 break; 1635 break;
1454 } 1636 }
1455 case naclbitc::FUNC_CODE_INST_VSELECT: { 1637 case naclbitc::FUNC_CODE_INST_VSELECT: {
1456 // VSELECT: [opval, opval, pred] 1638 // VSELECT: [opval, opval, pred]
1457 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); 1639 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex);
1458 Ice::Type ThenType = ThenVal->getType(); 1640 Ice::Type ThenType = ThenVal->getType();
1459 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); 1641 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex);
1460 Ice::Type ElseType = ElseVal->getType(); 1642 Ice::Type ElseType = ElseVal->getType();
1461 if (ThenType != ElseType) { 1643 if (ThenType != ElseType) {
1462 std::string Buffer; 1644 std::string Buffer;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] 1844 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...]
1663 // where Case = [1, 1, Value, BbIndex]. 1845 // where Case = [1, 1, Value, BbIndex].
1664 // 1846 //
1665 // Note: Unlike most instructions, we don't infer the type of 1847 // Note: Unlike most instructions, we don't infer the type of
1666 // Cond, but provide it as a separate field. There are also 1848 // Cond, but provide it as a separate field. There are also
1667 // unnecesary data fields (i.e. constants 1). These were not 1849 // unnecesary data fields (i.e. constants 1). These were not
1668 // cleaned up in PNaCl bitcode because the bitcode format was 1850 // cleaned up in PNaCl bitcode because the bitcode format was
1669 // already frozen when the problem was noticed. 1851 // already frozen when the problem was noticed.
1670 if (!isValidRecordSizeAtLeast(4, "function block switch")) 1852 if (!isValidRecordSizeAtLeast(4, "function block switch"))
1671 return; 1853 return;
1672 Ice::Type CondTy = 1854 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]);
1673 Context->convertToIceType(Context->getTypeByID(Values[0]));
1674 if (!Ice::isScalarIntegerType(CondTy)) { 1855 if (!Ice::isScalarIntegerType(CondTy)) {
1675 std::string Buffer; 1856 std::string Buffer;
1676 raw_string_ostream StrBuf(Buffer); 1857 raw_string_ostream StrBuf(Buffer);
1677 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; 1858 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy;
1678 Error(StrBuf.str()); 1859 Error(StrBuf.str());
1679 return; 1860 return;
1680 } 1861 }
1681 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); 1862 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy);
1682 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); 1863 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex);
1683 if (CondTy != Cond->getType()) { 1864 if (CondTy != Cond->getType()) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 if (!isValidRecordSizeAtLeast(3, "function block phi")) 1912 if (!isValidRecordSizeAtLeast(3, "function block phi"))
1732 return; 1913 return;
1733 if ((Values.size() & 0x1) == 0) { 1914 if ((Values.size() & 0x1) == 0) {
1734 // Not an odd number of values. 1915 // Not an odd number of values.
1735 std::string Buffer; 1916 std::string Buffer;
1736 raw_string_ostream StrBuf(Buffer); 1917 raw_string_ostream StrBuf(Buffer);
1737 StrBuf << "function block phi record size not valid: " << Values.size(); 1918 StrBuf << "function block phi record size not valid: " << Values.size();
1738 Error(StrBuf.str()); 1919 Error(StrBuf.str());
1739 return; 1920 return;
1740 } 1921 }
1741 Ice::Type Ty = Context->convertToIceType(Context->getTypeByID(Values[0])); 1922 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]);
1742 if (Ty == Ice::IceType_void) { 1923 if (Ty == Ice::IceType_void) {
1743 Error("Phi record using type void not allowed"); 1924 Error("Phi record using type void not allowed");
1744 return; 1925 return;
1745 } 1926 }
1746 Ice::Variable *Dest = getNextInstVar(Ty); 1927 Ice::Variable *Dest = getNextInstVar(Ty);
1747 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); 1928 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest);
1748 for (unsigned i = 1; i < Values.size(); i += 2) { 1929 for (unsigned i = 1; i < Values.size(); i += 2) {
1749 Ice::Operand *Op = 1930 Ice::Operand *Op =
1750 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); 1931 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex);
1751 if (Op->getType() != Ty) { 1932 if (Op->getType() != Ty) {
(...skipping 30 matching lines...) Expand all
1782 } 1963 }
1783 case naclbitc::FUNC_CODE_INST_LOAD: { 1964 case naclbitc::FUNC_CODE_INST_LOAD: {
1784 // LOAD: [address, align, ty] 1965 // LOAD: [address, align, ty]
1785 if (!isValidRecordSize(3, "function block load")) 1966 if (!isValidRecordSize(3, "function block load"))
1786 return; 1967 return;
1787 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); 1968 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex);
1788 if (!isValidPointerType(Address, "Load")) 1969 if (!isValidPointerType(Address, "Load"))
1789 return; 1970 return;
1790 unsigned Alignment; 1971 unsigned Alignment;
1791 extractAlignment("Load", Values[1], Alignment); 1972 extractAlignment("Load", Values[1], Alignment);
1792 Ice::Type Ty = Context->convertToIceType(Context->getTypeByID(Values[2])); 1973 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]);
1793 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) 1974 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load"))
1794 return; 1975 return;
1795 CurrentNode->appendInst( 1976 CurrentNode->appendInst(
1796 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); 1977 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment));
1797 break; 1978 break;
1798 } 1979 }
1799 case naclbitc::FUNC_CODE_INST_STORE: { 1980 case naclbitc::FUNC_CODE_INST_STORE: {
1800 // STORE: [address, value, align] 1981 // STORE: [address, value, align]
1801 if (!isValidRecordSize(3, "function block store")) 1982 if (!isValidRecordSize(3, "function block store"))
1802 return; 1983 return;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 getTranslator().getContext()->getIntrinsicsInfo().find(Suffix); 2055 getTranslator().getContext()->getIntrinsicsInfo().find(Suffix);
1875 if (!IntrinsicInfo) { 2056 if (!IntrinsicInfo) {
1876 std::string Buffer; 2057 std::string Buffer;
1877 raw_string_ostream StrBuf(Buffer); 2058 raw_string_ostream StrBuf(Buffer);
1878 StrBuf << "Invalid PNaCl intrinsic call to " << Name; 2059 StrBuf << "Invalid PNaCl intrinsic call to " << Name;
1879 Error(StrBuf.str()); 2060 Error(StrBuf.str());
1880 return; 2061 return;
1881 } 2062 }
1882 } 2063 }
1883 } else { 2064 } else {
1884 ReturnType = Context->convertToIceType(Context->getTypeByID(Values[2])); 2065 ReturnType = Context->getSimpleTypeByID(Values[2]);
1885 } 2066 }
1886 2067
1887 // Create the call instruction. 2068 // Create the call instruction.
1888 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) 2069 Ice::Variable *Dest = (ReturnType == Ice::IceType_void)
1889 ? nullptr 2070 ? nullptr
1890 : getNextInstVar(ReturnType); 2071 : getNextInstVar(ReturnType);
1891 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; 2072 Ice::SizeT NumParams = Values.size() - ParamsStartIndex;
1892 Ice::InstCall *Inst = nullptr; 2073 Ice::InstCall *Inst = nullptr;
1893 if (IntrinsicInfo) { 2074 if (IntrinsicInfo) {
1894 Inst = 2075 Inst =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 } 2127 }
1947 } 2128 }
1948 2129
1949 CurrentNode->appendInst(Inst); 2130 CurrentNode->appendInst(Inst);
1950 return; 2131 return;
1951 } 2132 }
1952 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { 2133 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: {
1953 // FORWARDTYPEREF: [opval, ty] 2134 // FORWARDTYPEREF: [opval, ty]
1954 if (!isValidRecordSize(2, "function block forward type ref")) 2135 if (!isValidRecordSize(2, "function block forward type ref"))
1955 return; 2136 return;
1956 setOperand(Values[0], createInstVar(Context->convertToIceType( 2137 setOperand(Values[0], createInstVar(Context->getSimpleTypeByID(Values[1])));
1957 Context->getTypeByID(Values[1]))));
1958 break; 2138 break;
1959 } 2139 }
1960 default: 2140 default:
1961 // Generate error message! 2141 // Generate error message!
1962 BlockParserBaseClass::ProcessRecord(); 2142 BlockParserBaseClass::ProcessRecord();
1963 break; 2143 break;
1964 } 2144 }
1965 } 2145 }
1966 2146
1967 /// Parses constants within a function block. 2147 /// Parses constants within a function block.
(...skipping 28 matching lines...) Expand all
1996 } 2176 }
1997 }; 2177 };
1998 2178
1999 void ConstantsParser::ProcessRecord() { 2179 void ConstantsParser::ProcessRecord() {
2000 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); 2180 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues();
2001 switch (Record.GetCode()) { 2181 switch (Record.GetCode()) {
2002 case naclbitc::CST_CODE_SETTYPE: { 2182 case naclbitc::CST_CODE_SETTYPE: {
2003 // SETTYPE: [typeid] 2183 // SETTYPE: [typeid]
2004 if (!isValidRecordSize(1, "constants block set type")) 2184 if (!isValidRecordSize(1, "constants block set type"))
2005 return; 2185 return;
2006 NextConstantType = 2186 NextConstantType = Context->getSimpleTypeByID(Values[0]);
2007 Context->convertToIceType(Context->getTypeByID(Values[0]));
2008 if (NextConstantType == Ice::IceType_void) 2187 if (NextConstantType == Ice::IceType_void)
2009 Error("constants block set type not allowed for void type"); 2188 Error("constants block set type not allowed for void type");
2010 return; 2189 return;
2011 } 2190 }
2012 case naclbitc::CST_CODE_UNDEF: { 2191 case naclbitc::CST_CODE_UNDEF: {
2013 // UNDEF 2192 // UNDEF
2014 if (!isValidRecordSize(0, "constants block undef")) 2193 if (!isValidRecordSize(0, "constants block undef"))
2015 return; 2194 return;
2016 if (!isValidNextConstantType()) 2195 if (!isValidNextConstantType())
2017 return; 2196 return;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 raw_string_ostream StrBuf(Buffer); 2470 raw_string_ostream StrBuf(Buffer);
2292 StrBuf << "Unknown bitstream version: " << Version; 2471 StrBuf << "Unknown bitstream version: " << Version;
2293 Error(StrBuf.str()); 2472 Error(StrBuf.str());
2294 } 2473 }
2295 return; 2474 return;
2296 } 2475 }
2297 case naclbitc::MODULE_CODE_FUNCTION: { 2476 case naclbitc::MODULE_CODE_FUNCTION: {
2298 // FUNCTION: [type, callingconv, isproto, linkage] 2477 // FUNCTION: [type, callingconv, isproto, linkage]
2299 if (!isValidRecordSize(4, "Function heading")) 2478 if (!isValidRecordSize(4, "Function heading"))
2300 return; 2479 return;
2301 Type *Ty = Context->getTypeByID(Values[0]); 2480 const Ice::FuncSigType &Ty = Context->getFuncSigTypeByID(Values[0]);
2302 FunctionType *FTy = dyn_cast<FunctionType>(Ty);
2303 if (FTy == nullptr) {
2304 std::string Buffer;
2305 raw_string_ostream StrBuf(Buffer);
2306 StrBuf << "Function heading expects function type. Found: " << Ty;
2307 Error(StrBuf.str());
2308 return;
2309 }
2310 CallingConv::ID CallingConv; 2481 CallingConv::ID CallingConv;
2311 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) { 2482 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) {
2312 std::string Buffer; 2483 std::string Buffer;
2313 raw_string_ostream StrBuf(Buffer); 2484 raw_string_ostream StrBuf(Buffer);
2314 StrBuf << "Function heading has unknown calling convention: " 2485 StrBuf << "Function heading has unknown calling convention: "
2315 << Values[1]; 2486 << Values[1];
2316 Error(StrBuf.str()); 2487 Error(StrBuf.str());
2317 return; 2488 return;
2318 } 2489 }
2319 GlobalValue::LinkageTypes Linkage; 2490 GlobalValue::LinkageTypes Linkage;
2320 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { 2491 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) {
2321 std::string Buffer; 2492 std::string Buffer;
2322 raw_string_ostream StrBuf(Buffer); 2493 raw_string_ostream StrBuf(Buffer);
2323 StrBuf << "Function heading has unknown linkage. Found " << Values[3]; 2494 StrBuf << "Function heading has unknown linkage. Found " << Values[3];
2324 Error(StrBuf.str()); 2495 Error(StrBuf.str());
2325 return; 2496 return;
2326 } 2497 }
2327 Function *Func = Function::Create(FTy, Linkage, "", Context->getModule()); 2498 SmallVector<Type *, 8> ArgTys;
2499 for (Ice::Type ArgType : Ty.getArgList()) {
2500 ArgTys.push_back(Context->convertToLLVMType(ArgType));
2501 }
2502 Function *Func = Function::Create(
2503 FunctionType::get(Context->convertToLLVMType(Ty.getReturnType()),
2504 ArgTys, false),
2505 Linkage, "", Context->getModule());
2328 Func->setCallingConv(CallingConv); 2506 Func->setCallingConv(CallingConv);
2329 if (Values[2] == 0) 2507 if (Values[2] == 0)
2330 Context->setNextValueIDAsImplementedFunction(); 2508 Context->setNextValueIDAsImplementedFunction();
2331 Context->setNextFunctionID(Func); 2509 Context->setNextFunctionID(Func);
2332 // TODO(kschimpf) verify if Func matches PNaCl ABI. 2510 // TODO(kschimpf) verify if Func matches PNaCl ABI.
2333 return; 2511 return;
2334 } 2512 }
2335 default: 2513 default:
2336 BlockParserBaseClass::ProcessRecord(); 2514 BlockParserBaseClass::ProcessRecord();
2337 return; 2515 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 2574
2397 if (TopLevelBlocks != 1) { 2575 if (TopLevelBlocks != 1) {
2398 errs() << IRFilename 2576 errs() << IRFilename
2399 << ": Contains more than one module. Found: " << TopLevelBlocks 2577 << ": Contains more than one module. Found: " << TopLevelBlocks
2400 << "\n"; 2578 << "\n";
2401 ErrorStatus = true; 2579 ErrorStatus = true;
2402 } 2580 }
2403 } 2581 }
2404 2582
2405 } // end of namespace Ice 2583 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTypes.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698