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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 902713002: Allow stubbing of called constant addresses using command line argument. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix formatting. Created 5 years, 10 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/IceClFlags.h ('k') | src/llvm2ice.cpp » ('j') | 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 TopLevelParser(const TopLevelParser &) = delete; 156 TopLevelParser(const TopLevelParser &) = delete;
157 TopLevelParser &operator=(const TopLevelParser &) = delete; 157 TopLevelParser &operator=(const TopLevelParser &) = delete;
158 158
159 public: 159 public:
160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType;
161 161
162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header,
163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus)
164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
166 BlockParser(nullptr) {} 166 BlockParser(nullptr), StubbedConstCallValue(nullptr) {}
167 167
168 ~TopLevelParser() override {} 168 ~TopLevelParser() override {}
169 169
170 Ice::Translator &getTranslator() { return Translator; } 170 Ice::Translator &getTranslator() { return Translator; }
171 171
172 void setBlockParser(BlockParserBaseClass *NewBlockParser) { 172 void setBlockParser(BlockParserBaseClass *NewBlockParser) {
173 BlockParser = NewBlockParser; 173 BlockParser = NewBlockParser;
174 } 174 }
175 175
176 // Generates error with given Message. Always returns true. 176 // Generates error with given Message. Always returns true.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 C = getTranslator().getContext()->getConstantExternSym(Name); 312 C = getTranslator().getContext()->getConstantExternSym(Name);
313 else { 313 else {
314 const Ice::RelocOffsetT Offset = 0; 314 const Ice::RelocOffsetT Offset = 0;
315 C = getTranslator().getContext()->getConstantSym(Offset, Name, 315 C = getTranslator().getContext()->getConstantSym(Offset, Name,
316 SuppressMangling); 316 SuppressMangling);
317 } 317 }
318 ValueIDConstants[ID] = C; 318 ValueIDConstants[ID] = C;
319 return C; 319 return C;
320 } 320 }
321 321
322 /// Returns a defined function reference to be used in place of
323 /// called constant addresses. Returns the corresponding operand
324 /// to replace the calling address with.
325 Ice::Operand *getStubbedConstCallValue() {
326 if (StubbedConstCallValue)
327 return StubbedConstCallValue;
328 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) {
329 Ice::FunctionDeclaration *Func = getFunctionByID(i);
330 if (!Func->isProto()) {
331 StubbedConstCallValue = getOrCreateGlobalConstantByID(i);
332 return StubbedConstCallValue;
333 }
334 }
335 Error("Unable to find function definition to stub constant calls with");
336 report_fatal_error("Unable to continue");
337 }
338
322 /// Returns the number of function declarations in the bitcode file. 339 /// Returns the number of function declarations in the bitcode file.
323 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } 340 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); }
324 341
325 /// Returns the number of global declarations (i.e. IDs) defined in 342 /// Returns the number of global declarations (i.e. IDs) defined in
326 /// the bitcode file. 343 /// the bitcode file.
327 unsigned getNumGlobalIDs() const { 344 unsigned getNumGlobalIDs() const {
328 return FunctionDeclarationList.size() + VariableDeclarations.size(); 345 return FunctionDeclarationList.size() + VariableDeclarations.size();
329 } 346 }
330 347
331 /// Creates Count global variable declarations. 348 /// Creates Count global variable declarations.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 size_t NextDefiningFunctionID; 403 size_t NextDefiningFunctionID;
387 // The set of global variables. 404 // The set of global variables.
388 Ice::VariableDeclarationList VariableDeclarations; 405 Ice::VariableDeclarationList VariableDeclarations;
389 // Relocatable constants associated with global declarations. 406 // Relocatable constants associated with global declarations.
390 std::vector<Ice::Constant *> ValueIDConstants; 407 std::vector<Ice::Constant *> ValueIDConstants;
391 // Error recovery value to use when getFuncSigTypeByID fails. 408 // Error recovery value to use when getFuncSigTypeByID fails.
392 Ice::FuncSigType UndefinedFuncSigType; 409 Ice::FuncSigType UndefinedFuncSigType;
393 // The block parser currently being applied. Used for error 410 // The block parser currently being applied. Used for error
394 // reporting. 411 // reporting.
395 BlockParserBaseClass *BlockParser; 412 BlockParserBaseClass *BlockParser;
413 // Value to use to stub constant calls.
414 Ice::Operand *StubbedConstCallValue;
396 415
397 bool ParseBlock(unsigned BlockID) override; 416 bool ParseBlock(unsigned BlockID) override;
398 417
399 // Gets extended type associated with the given index, assuming the 418 // Gets extended type associated with the given index, assuming the
400 // extended type is of the WantedKind. Generates error message if 419 // extended type is of the WantedKind. Generates error message if
401 // corresponding extended type of WantedKind can't be found, and 420 // corresponding extended type of WantedKind can't be found, and
402 // returns nullptr. 421 // returns nullptr.
403 ExtendedType *getTypeByIDAsKind(unsigned ID, 422 ExtendedType *getTypeByIDAsKind(unsigned ID,
404 ExtendedType::TypeKind WantedKind) { 423 ExtendedType::TypeKind WantedKind) {
405 ExtendedType *Ty = nullptr; 424 ExtendedType *Ty = nullptr;
(...skipping 2028 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 if (!IntrinsicInfo) { 2453 if (!IntrinsicInfo) {
2435 std::string Buffer; 2454 std::string Buffer;
2436 raw_string_ostream StrBuf(Buffer); 2455 raw_string_ostream StrBuf(Buffer);
2437 StrBuf << "Invalid PNaCl intrinsic call to " << Name; 2456 StrBuf << "Invalid PNaCl intrinsic call to " << Name;
2438 Error(StrBuf.str()); 2457 Error(StrBuf.str());
2439 appendErrorInstruction(ReturnType); 2458 appendErrorInstruction(ReturnType);
2440 return; 2459 return;
2441 } 2460 }
2442 } 2461 }
2443 } else { 2462 } else {
2463 if (getFlags().StubConstantCalls &&
2464 Callee->getKind() == Ice::Operand::kConstInteger32) {
Jim Stichnoth 2015/02/04 22:24:13 Can you use llvm::isa<Ice::ConstantInteger32>(Ca
Karl 2015/02/04 22:46:54 Done.
2465 Callee = Context->getStubbedConstCallValue();
2466 }
2444 ReturnType = Context->getSimpleTypeByID(Values[2]); 2467 ReturnType = Context->getSimpleTypeByID(Values[2]);
2445 } 2468 }
2446 2469
2447 // Extract call information. 2470 // Extract call information.
2448 uint64_t CCInfo = Values[0]; 2471 uint64_t CCInfo = Values[0];
2449 CallingConv::ID CallingConv; 2472 CallingConv::ID CallingConv;
2450 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) { 2473 if (!naclbitc::DecodeCallingConv(CCInfo >> 1, CallingConv)) {
2451 std::string Buffer; 2474 std::string Buffer;
2452 raw_string_ostream StrBuf(Buffer); 2475 raw_string_ostream StrBuf(Buffer);
2453 StrBuf << "Function call calling convention value " << (CCInfo >> 1) 2476 StrBuf << "Function call calling convention value " << (CCInfo >> 1)
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 3020
2998 if (TopLevelBlocks != 1) { 3021 if (TopLevelBlocks != 1) {
2999 errs() << IRFilename 3022 errs() << IRFilename
3000 << ": Contains more than one module. Found: " << TopLevelBlocks 3023 << ": Contains more than one module. Found: " << TopLevelBlocks
3001 << "\n"; 3024 << "\n";
3002 ErrorStatus.assign(EC_Bitcode); 3025 ErrorStatus.assign(EC_Bitcode);
3003 } 3026 }
3004 } 3027 }
3005 3028
3006 } // end of namespace Ice 3029 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceClFlags.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698