Chromium Code Reviews| Index: src/PNaClTranslator.cpp |
| diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp |
| index 4d8357879281c78eae49809c717a3ebcdf94450c..dc2178abd48955b21e211a24311d849db23d0e9a 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) { |
|
Karl
2015/02/04 22:46:54
Added parameter so that we can default if no stubb
|
| + 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 && |
| + Callee->getKind() == llvm::isa<Ice::ConstantInteger32>(Callee)) { |
|
jvoung (off chromium)
2015/02/05 17:43:36
You mean just "llvm::isa..." not "getKind() == llv
Karl
2015/02/05 18:26:51
I can't believe I did that. Fixing...
|
| + Callee = Context->getStubbedConstCallValue(Callee); |
|
Karl
2015/02/04 22:46:54
Added parameter to call.
|
| + } |
| ReturnType = Context->getSimpleTypeByID(Values[2]); |
| } |