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

Unified 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: Add TODO. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceClFlags.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/PNaClTranslator.cpp
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 4d8357879281c78eae49809c717a3ebcdf94450c..ce7e09c8cc7bcb9bcc0a870d50c8ec4fd0bf99f2 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -163,7 +163,7 @@ public:
NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
- BlockParser(nullptr) {}
+ BlockParser(nullptr), StubbedConstCallValue(nullptr) {}
~TopLevelParser() override {}
@@ -319,6 +319,24 @@ public:
return C;
}
+ /// Returns a defined function reference to be used in place of
+ /// called constant addresses. Returns the corresponding operand
+ /// to replace the calling address with. Reports an error if
+ /// a stub could not be found, returning the CallValue.
+ Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) {
+ if (StubbedConstCallValue)
+ return StubbedConstCallValue;
+ for (unsigned i = 0; i < getNumFunctionIDs(); ++i) {
+ Ice::FunctionDeclaration *Func = getFunctionByID(i);
+ if (!Func->isProto()) {
+ StubbedConstCallValue = getOrCreateGlobalConstantByID(i);
+ return StubbedConstCallValue;
+ }
+ }
+ Error("Unable to find function definition to stub constant calls with");
+ return CallValue;
+ }
+
/// Returns the number of function declarations in the bitcode file.
unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); }
@@ -393,6 +411,8 @@ private:
// The block parser currently being applied. Used for error
// reporting.
BlockParserBaseClass *BlockParser;
+ // Value to use to stub constant calls.
+ Ice::Operand *StubbedConstCallValue;
bool ParseBlock(unsigned BlockID) override;
@@ -2441,6 +2461,10 @@ void FunctionParser::ProcessRecord() {
}
}
} else {
+ if (getFlags().StubConstantCalls &&
+ llvm::isa<Ice::ConstantInteger32>(Callee)) {
+ Callee = Context->getStubbedConstCallValue(Callee);
+ }
ReturnType = Context->getSimpleTypeByID(Values[2]);
}
« 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