Chromium Code Reviews| Index: src/PNaClTranslator.cpp |
| diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp |
| index e87e0aa2b2cfb6254a016e05fd1c988d463e49c5..c24f2af899662658b922a27bdd2d3b2a731b1544 100644 |
| --- a/src/PNaClTranslator.cpp |
| +++ b/src/PNaClTranslator.cpp |
| @@ -351,7 +351,9 @@ protected: |
| Context(EnclosingParser->Context) {} |
| // Gets the translator associated with the bitcode parser. |
| - Ice::Translator &getTranslator() { return Context->getTranslator(); } |
| + Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
| + |
| + const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
| // Generates an error Message with the bit address prefixed to it. |
| virtual bool Error(const std::string &Message) LLVM_OVERRIDE { |
| @@ -1376,7 +1378,7 @@ private: |
| }; |
| FunctionParser::~FunctionParser() { |
| - if (getTranslator().getFlags().SubzeroTimingEnabled) { |
| + if (getFlags().SubzeroTimingEnabled) { |
| errs() << "[Subzero timing] Convert function " << Func->getFunctionName() |
| << ": " << TConvert.getElapsedSec() << " sec\n"; |
| } |
| @@ -2216,16 +2218,36 @@ bool FunctionParser::ParseBlock(unsigned BlockID) { |
| class ModuleParser : public BlockParserBaseClass { |
| public: |
| ModuleParser(unsigned BlockID, TopLevelParser *Context) |
| - : BlockParserBaseClass(BlockID, Context), FoundFirstFunctionBlock(false) { |
| - } |
| + : BlockParserBaseClass(BlockID, Context), |
| + GlobalAddressNamesAndInitializersInstalled(false) {} |
| virtual ~ModuleParser() LLVM_OVERRIDE {} |
| private: |
| - // True if we have parsed a function block. |
| - bool FoundFirstFunctionBlock; |
| + // True if we have already install names for unnamed global addresses, |
|
Jim Stichnoth
2014/09/22 17:01:43
installed
Karl
2014/09/22 17:29:22
Done.
|
| + // and generated global constant initializers. |
| + bool GlobalAddressNamesAndInitializersInstalled; |
| + |
| + // Temporary hack to generate names for unnamed global addresses, |
| + // and generate global constant initializers. May be called multiple |
| + // times. Only the first call will do the installation. |
| + // NOTE: Doesn't handle relocations for global constant initializers. |
| + void InstallGlobalAddressNamesAndInitializers() { |
| + if (!GlobalAddressNamesAndInitializersInstalled) { |
| + getTranslator().nameUnnamedGlobalAddresses(Context->getModule()); |
| + if (!getFlags().DisableGlobals) |
| + getTranslator().convertGlobals(Context->getModule()); |
| + GlobalAddressNamesAndInitializersInstalled = true; |
| + } |
| + } |
| + |
| virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; |
| + virtual void ExitBlock() LLVM_OVERRIDE { |
| + InstallGlobalAddressNamesAndInitializers(); |
| + getTranslator().emitConstants(); |
| + } |
| + |
| virtual void ProcessRecord() LLVM_OVERRIDE; |
| }; |
| @@ -2282,10 +2304,7 @@ bool ModuleParser::ParseBlock(unsigned BlockID) LLVM_OVERRIDE { |
| return Parser.ParseThisBlock(); |
| } |
| case naclbitc::FUNCTION_BLOCK_ID: { |
| - if (!FoundFirstFunctionBlock) { |
| - getTranslator().nameUnnamedGlobalAddresses(Context->getModule()); |
| - FoundFirstFunctionBlock = true; |
| - } |
| + InstallGlobalAddressNamesAndInitializers(); |
| FunctionParser Parser(BlockID, this); |
| return Parser.ParseThisBlock(); |
| } |