| OLD | NEW |
| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } else { | 287 } else { |
| 288 return ValueIDConstants.size(); | 288 return ValueIDConstants.size(); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 /// Creates Count global variable declarations. | 292 /// Creates Count global variable declarations. |
| 293 void CreateGlobalVariables(size_t Count) { | 293 void CreateGlobalVariables(size_t Count) { |
| 294 assert(VariableDeclarations); | 294 assert(VariableDeclarations); |
| 295 assert(VariableDeclarations->empty()); | 295 assert(VariableDeclarations->empty()); |
| 296 for (size_t i = 0; i < Count; ++i) { | 296 for (size_t i = 0; i < Count; ++i) { |
| 297 VariableDeclarations->push_back(Ice::VariableDeclaration::create()); | 297 VariableDeclarations->push_back( |
| 298 Ice::VariableDeclaration::create(getTranslator().getContext())); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 | 301 |
| 301 /// Returns the number of global variable declarations in the | 302 /// Returns the number of global variable declarations in the |
| 302 /// bitcode file. | 303 /// bitcode file. |
| 303 Ice::SizeT getNumGlobalVariables() const { | 304 Ice::SizeT getNumGlobalVariables() const { |
| 304 if (VariableDeclarations) { | 305 if (VariableDeclarations) { |
| 305 return VariableDeclarations->size(); | 306 return VariableDeclarations->size(); |
| 306 } else { | 307 } else { |
| 307 return ValueIDConstants.size() - FunctionDeclarationList.size(); | 308 return ValueIDConstants.size() - FunctionDeclarationList.size(); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 class GlobalsParser : public BlockParserBaseClass { | 901 class GlobalsParser : public BlockParserBaseClass { |
| 901 GlobalsParser() = delete; | 902 GlobalsParser() = delete; |
| 902 GlobalsParser(const GlobalsParser &) = delete; | 903 GlobalsParser(const GlobalsParser &) = delete; |
| 903 GlobalsParser &operator=(const GlobalsParser &) = delete; | 904 GlobalsParser &operator=(const GlobalsParser &) = delete; |
| 904 | 905 |
| 905 public: | 906 public: |
| 906 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 907 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 907 : BlockParserBaseClass(BlockID, EnclosingParser), | 908 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 908 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), | 909 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), |
| 909 InitializersNeeded(0), NextGlobalID(0), | 910 InitializersNeeded(0), NextGlobalID(0), |
| 910 DummyGlobalVar(Ice::VariableDeclaration::create()), | 911 DummyGlobalVar( |
| 912 Ice::VariableDeclaration::create(getTranslator().getContext())), |
| 911 CurGlobalVar(DummyGlobalVar) {} | 913 CurGlobalVar(DummyGlobalVar) {} |
| 912 | 914 |
| 913 ~GlobalsParser() final {} | 915 ~GlobalsParser() final {} |
| 914 | 916 |
| 915 const char *getBlockName() const override { return "globals"; } | 917 const char *getBlockName() const override { return "globals"; } |
| 916 | 918 |
| 917 private: | 919 private: |
| 918 Ice::TimerMarker Timer; | 920 Ice::TimerMarker Timer; |
| 919 // Keeps track of how many initializers are expected for the global variable | 921 // Keeps track of how many initializers are expected for the global variable |
| 920 // declaration being built. | 922 // declaration being built. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 return; | 1015 return; |
| 1014 InitializersNeeded = Values[0]; | 1016 InitializersNeeded = Values[0]; |
| 1015 return; | 1017 return; |
| 1016 case naclbitc::GLOBALVAR_ZEROFILL: { | 1018 case naclbitc::GLOBALVAR_ZEROFILL: { |
| 1017 // ZEROFILL: [size] | 1019 // ZEROFILL: [size] |
| 1018 if (!isValidRecordSize(1, "zerofill")) | 1020 if (!isValidRecordSize(1, "zerofill")) |
| 1019 return; | 1021 return; |
| 1020 if (isIRGenerationDisabled()) | 1022 if (isIRGenerationDisabled()) |
| 1021 return; | 1023 return; |
| 1022 CurGlobalVar->addInitializer( | 1024 CurGlobalVar->addInitializer( |
| 1023 new Ice::VariableDeclaration::ZeroInitializer(Values[0])); | 1025 Ice::VariableDeclaration::ZeroInitializer::create(Values[0])); |
| 1024 return; | 1026 return; |
| 1025 } | 1027 } |
| 1026 case naclbitc::GLOBALVAR_DATA: { | 1028 case naclbitc::GLOBALVAR_DATA: { |
| 1027 // DATA: [b0, b1, ...] | 1029 // DATA: [b0, b1, ...] |
| 1028 if (!isValidRecordSizeAtLeast(1, "data")) | 1030 if (!isValidRecordSizeAtLeast(1, "data")) |
| 1029 return; | 1031 return; |
| 1030 if (isIRGenerationDisabled()) | 1032 if (isIRGenerationDisabled()) |
| 1031 return; | 1033 return; |
| 1032 CurGlobalVar->addInitializer( | 1034 CurGlobalVar->addInitializer( |
| 1033 new Ice::VariableDeclaration::DataInitializer(Values)); | 1035 Ice::VariableDeclaration::DataInitializer::create(Values)); |
| 1034 return; | 1036 return; |
| 1035 } | 1037 } |
| 1036 case naclbitc::GLOBALVAR_RELOC: { | 1038 case naclbitc::GLOBALVAR_RELOC: { |
| 1037 // RELOC: [val, [addend]] | 1039 // RELOC: [val, [addend]] |
| 1038 if (!isValidRecordSizeInRange(1, 2, "reloc")) | 1040 if (!isValidRecordSizeInRange(1, 2, "reloc")) |
| 1039 return; | 1041 return; |
| 1040 if (isIRGenerationDisabled()) | 1042 if (isIRGenerationDisabled()) |
| 1041 return; | 1043 return; |
| 1042 unsigned Index = Values[0]; | 1044 unsigned Index = Values[0]; |
| 1043 Ice::SizeT Offset = 0; | 1045 Ice::SizeT Offset = 0; |
| 1044 if (Values.size() == 2) | 1046 if (Values.size() == 2) |
| 1045 Offset = Values[1]; | 1047 Offset = Values[1]; |
| 1046 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( | 1048 CurGlobalVar->addInitializer( |
| 1047 Context->getGlobalDeclarationByID(Index), Offset)); | 1049 Ice::VariableDeclaration::RelocInitializer::create( |
| 1050 Context->getGlobalDeclarationByID(Index), Offset)); |
| 1048 return; | 1051 return; |
| 1049 } | 1052 } |
| 1050 default: | 1053 default: |
| 1051 BlockParserBaseClass::ProcessRecord(); | 1054 BlockParserBaseClass::ProcessRecord(); |
| 1052 return; | 1055 return; |
| 1053 } | 1056 } |
| 1054 } | 1057 } |
| 1055 | 1058 |
| 1056 /// Base class for parsing a valuesymtab block in the bitcode file. | 1059 /// Base class for parsing a valuesymtab block in the bitcode file. |
| 1057 class ValuesymtabParser : public BlockParserBaseClass { | 1060 class ValuesymtabParser : public BlockParserBaseClass { |
| (...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2944 GlobalValue::LinkageTypes Linkage; | 2947 GlobalValue::LinkageTypes Linkage; |
| 2945 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { | 2948 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { |
| 2946 std::string Buffer; | 2949 std::string Buffer; |
| 2947 raw_string_ostream StrBuf(Buffer); | 2950 raw_string_ostream StrBuf(Buffer); |
| 2948 StrBuf << "Function address has unknown linkage. Found " << Values[3]; | 2951 StrBuf << "Function address has unknown linkage. Found " << Values[3]; |
| 2949 Error(StrBuf.str()); | 2952 Error(StrBuf.str()); |
| 2950 return; | 2953 return; |
| 2951 } | 2954 } |
| 2952 bool IsProto = Values[2] == 1; | 2955 bool IsProto = Values[2] == 1; |
| 2953 Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create( | 2956 Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create( |
| 2954 Signature, CallingConv, Linkage, IsProto); | 2957 Context->getTranslator().getContext(), Signature, CallingConv, Linkage, |
| 2958 IsProto); |
| 2955 Context->setNextFunctionID(Func); | 2959 Context->setNextFunctionID(Func); |
| 2956 return; | 2960 return; |
| 2957 } | 2961 } |
| 2958 default: | 2962 default: |
| 2959 BlockParserBaseClass::ProcessRecord(); | 2963 BlockParserBaseClass::ProcessRecord(); |
| 2960 return; | 2964 return; |
| 2961 } | 2965 } |
| 2962 } | 2966 } |
| 2963 | 2967 |
| 2964 bool TopLevelParser::ParseBlock(unsigned BlockID) { | 2968 bool TopLevelParser::ParseBlock(unsigned BlockID) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 } | 3030 } |
| 3027 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3031 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3028 ErrStream | 3032 ErrStream |
| 3029 << IRFilename | 3033 << IRFilename |
| 3030 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3034 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
| 3031 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3035 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3032 } | 3036 } |
| 3033 } | 3037 } |
| 3034 | 3038 |
| 3035 } // end of namespace Ice | 3039 } // end of namespace Ice |
| OLD | NEW |