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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 break; | 98 break; |
99 case ExtendedType::FuncSig: | 99 case ExtendedType::FuncSig: |
100 Stream << "FuncSig"; | 100 Stream << "FuncSig"; |
101 break; | 101 break; |
102 } | 102 } |
103 return Stream; | 103 return Stream; |
104 } | 104 } |
105 | 105 |
106 // Models an ICE type as an extended type. | 106 // Models an ICE type as an extended type. |
107 class SimpleExtendedType : public ExtendedType { | 107 class SimpleExtendedType : public ExtendedType { |
| 108 SimpleExtendedType() = delete; |
108 SimpleExtendedType(const SimpleExtendedType &) = delete; | 109 SimpleExtendedType(const SimpleExtendedType &) = delete; |
109 SimpleExtendedType &operator=(const SimpleExtendedType &) = delete; | 110 SimpleExtendedType &operator=(const SimpleExtendedType &) = delete; |
110 | 111 |
111 public: | 112 public: |
112 Ice::Type getType() const { return Signature.getReturnType(); } | 113 Ice::Type getType() const { return Signature.getReturnType(); } |
113 | 114 |
114 static bool classof(const ExtendedType *Ty) { | 115 static bool classof(const ExtendedType *Ty) { |
115 return Ty->getKind() == Simple; | 116 return Ty->getKind() == Simple; |
116 } | 117 } |
117 }; | 118 }; |
118 | 119 |
119 // Models a function signature as an extended type. | 120 // Models a function signature as an extended type. |
120 class FuncSigExtendedType : public ExtendedType { | 121 class FuncSigExtendedType : public ExtendedType { |
| 122 FuncSigExtendedType() = delete; |
121 FuncSigExtendedType(const FuncSigExtendedType &) = delete; | 123 FuncSigExtendedType(const FuncSigExtendedType &) = delete; |
122 FuncSigExtendedType &operator=(const FuncSigExtendedType &) = delete; | 124 FuncSigExtendedType &operator=(const FuncSigExtendedType &) = delete; |
123 | 125 |
124 public: | 126 public: |
125 const Ice::FuncSigType &getSignature() const { return Signature; } | 127 const Ice::FuncSigType &getSignature() const { return Signature; } |
126 void setReturnType(Ice::Type ReturnType) { | 128 void setReturnType(Ice::Type ReturnType) { |
127 Signature.setReturnType(ReturnType); | 129 Signature.setReturnType(ReturnType); |
128 } | 130 } |
129 void appendArgType(Ice::Type ArgType) { Signature.appendArgType(ArgType); } | 131 void appendArgType(Ice::Type ArgType) { Signature.appendArgType(ArgType); } |
130 static bool classof(const ExtendedType *Ty) { | 132 static bool classof(const ExtendedType *Ty) { |
(...skipping 15 matching lines...) Expand all Loading... |
146 } | 148 } |
147 default: | 149 default: |
148 break; | 150 break; |
149 } | 151 } |
150 } | 152 } |
151 | 153 |
152 class BlockParserBaseClass; | 154 class BlockParserBaseClass; |
153 | 155 |
154 // Top-level class to read PNaCl bitcode files, and translate to ICE. | 156 // Top-level class to read PNaCl bitcode files, and translate to ICE. |
155 class TopLevelParser : public NaClBitcodeParser { | 157 class TopLevelParser : public NaClBitcodeParser { |
| 158 TopLevelParser() = delete; |
156 TopLevelParser(const TopLevelParser &) = delete; | 159 TopLevelParser(const TopLevelParser &) = delete; |
157 TopLevelParser &operator=(const TopLevelParser &) = delete; | 160 TopLevelParser &operator=(const TopLevelParser &) = delete; |
158 | 161 |
159 public: | 162 public: |
160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; | 163 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; |
161 | 164 |
162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, | 165 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, |
163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) | 166 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) |
164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), | 167 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), |
165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), | 168 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 564 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
562 Error(StrBuf.str()); | 565 Error(StrBuf.str()); |
563 return Ice::IceType_void; | 566 return Ice::IceType_void; |
564 } | 567 } |
565 | 568 |
566 // Base class for parsing blocks within the bitcode file. Note: | 569 // Base class for parsing blocks within the bitcode file. Note: |
567 // Because this is the base class of block parsers, we generate error | 570 // Because this is the base class of block parsers, we generate error |
568 // messages if ParseBlock or ParseRecord is not overridden in derived | 571 // messages if ParseBlock or ParseRecord is not overridden in derived |
569 // classes. | 572 // classes. |
570 class BlockParserBaseClass : public NaClBitcodeParser { | 573 class BlockParserBaseClass : public NaClBitcodeParser { |
| 574 BlockParserBaseClass() = delete; |
571 BlockParserBaseClass(const BlockParserBaseClass &) = delete; | 575 BlockParserBaseClass(const BlockParserBaseClass &) = delete; |
572 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; | 576 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; |
573 | 577 |
574 public: | 578 public: |
575 // Constructor for the top-level module block parser. | 579 // Constructor for the top-level module block parser. |
576 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) | 580 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) |
577 : NaClBitcodeParser(BlockID, Context), Context(Context) { | 581 : NaClBitcodeParser(BlockID, Context), Context(Context) { |
578 Context->setBlockParser(this); | 582 Context->setBlockParser(this); |
579 } | 583 } |
580 | 584 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // If called, derived class doesn't know how to handle. | 733 // If called, derived class doesn't know how to handle. |
730 std::string Buffer; | 734 std::string Buffer; |
731 raw_string_ostream StrBuf(Buffer); | 735 raw_string_ostream StrBuf(Buffer); |
732 StrBuf << "Don't know how to process " << getBlockName() | 736 StrBuf << "Don't know how to process " << getBlockName() |
733 << " record:" << Record; | 737 << " record:" << Record; |
734 Error(StrBuf.str()); | 738 Error(StrBuf.str()); |
735 } | 739 } |
736 | 740 |
737 // Class to parse a types block. | 741 // Class to parse a types block. |
738 class TypesParser : public BlockParserBaseClass { | 742 class TypesParser : public BlockParserBaseClass { |
| 743 TypesParser() = delete; |
| 744 TypesParser(const TypesParser &) = delete; |
| 745 TypesParser &operator=(const TypesParser &) = delete; |
| 746 |
739 public: | 747 public: |
740 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 748 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
741 : BlockParserBaseClass(BlockID, EnclosingParser), | 749 : BlockParserBaseClass(BlockID, EnclosingParser), |
742 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), | 750 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), |
743 NextTypeId(0) {} | 751 NextTypeId(0) {} |
744 | 752 |
745 ~TypesParser() override {} | 753 ~TypesParser() override {} |
746 | 754 |
747 private: | 755 private: |
748 Ice::TimerMarker Timer; | 756 Ice::TimerMarker Timer; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 default: | 912 default: |
905 BlockParserBaseClass::ProcessRecord(); | 913 BlockParserBaseClass::ProcessRecord(); |
906 return; | 914 return; |
907 } | 915 } |
908 llvm_unreachable("Unknown type block record not processed!"); | 916 llvm_unreachable("Unknown type block record not processed!"); |
909 } | 917 } |
910 | 918 |
911 /// Parses the globals block (i.e. global variable declarations and | 919 /// Parses the globals block (i.e. global variable declarations and |
912 /// corresponding initializers). | 920 /// corresponding initializers). |
913 class GlobalsParser : public BlockParserBaseClass { | 921 class GlobalsParser : public BlockParserBaseClass { |
| 922 GlobalsParser() = delete; |
| 923 GlobalsParser(const GlobalsParser &) = delete; |
| 924 GlobalsParser &operator=(const GlobalsParser &) = delete; |
| 925 |
914 public: | 926 public: |
915 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 927 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
916 : BlockParserBaseClass(BlockID, EnclosingParser), | 928 : BlockParserBaseClass(BlockID, EnclosingParser), |
917 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), | 929 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), |
918 InitializersNeeded(0), NextGlobalID(0), | 930 InitializersNeeded(0), NextGlobalID(0), |
919 DummyGlobalVar(Ice::VariableDeclaration::create()), | 931 DummyGlobalVar(Ice::VariableDeclaration::create()), |
920 CurGlobalVar(DummyGlobalVar) {} | 932 CurGlobalVar(DummyGlobalVar) {} |
921 | 933 |
922 ~GlobalsParser() final {} | 934 ~GlobalsParser() final {} |
923 | 935 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 return; | 1069 return; |
1058 } | 1070 } |
1059 default: | 1071 default: |
1060 BlockParserBaseClass::ProcessRecord(); | 1072 BlockParserBaseClass::ProcessRecord(); |
1061 return; | 1073 return; |
1062 } | 1074 } |
1063 } | 1075 } |
1064 | 1076 |
1065 /// Base class for parsing a valuesymtab block in the bitcode file. | 1077 /// Base class for parsing a valuesymtab block in the bitcode file. |
1066 class ValuesymtabParser : public BlockParserBaseClass { | 1078 class ValuesymtabParser : public BlockParserBaseClass { |
| 1079 ValuesymtabParser() = delete; |
1067 ValuesymtabParser(const ValuesymtabParser &) = delete; | 1080 ValuesymtabParser(const ValuesymtabParser &) = delete; |
1068 void operator=(const ValuesymtabParser &) = delete; | 1081 void operator=(const ValuesymtabParser &) = delete; |
1069 | 1082 |
1070 public: | 1083 public: |
1071 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1084 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
1072 : BlockParserBaseClass(BlockID, EnclosingParser) {} | 1085 : BlockParserBaseClass(BlockID, EnclosingParser) {} |
1073 | 1086 |
1074 ~ValuesymtabParser() override {} | 1087 ~ValuesymtabParser() override {} |
1075 | 1088 |
1076 const char *getBlockName() const override { return "valuesymtab"; } | 1089 const char *getBlockName() const override { return "valuesymtab"; } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 default: | 1131 default: |
1119 break; | 1132 break; |
1120 } | 1133 } |
1121 // If reached, don't know how to handle record. | 1134 // If reached, don't know how to handle record. |
1122 BlockParserBaseClass::ProcessRecord(); | 1135 BlockParserBaseClass::ProcessRecord(); |
1123 return; | 1136 return; |
1124 } | 1137 } |
1125 | 1138 |
1126 /// Parses function blocks in the bitcode file. | 1139 /// Parses function blocks in the bitcode file. |
1127 class FunctionParser : public BlockParserBaseClass { | 1140 class FunctionParser : public BlockParserBaseClass { |
| 1141 FunctionParser() = delete; |
1128 FunctionParser(const FunctionParser &) = delete; | 1142 FunctionParser(const FunctionParser &) = delete; |
1129 FunctionParser &operator=(const FunctionParser &) = delete; | 1143 FunctionParser &operator=(const FunctionParser &) = delete; |
1130 | 1144 |
1131 public: | 1145 public: |
1132 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1146 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
1133 : BlockParserBaseClass(BlockID, EnclosingParser), | 1147 : BlockParserBaseClass(BlockID, EnclosingParser), |
1134 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), | 1148 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), |
1135 Func(nullptr), CurrentBbIndex(0), | 1149 Func(nullptr), CurrentBbIndex(0), |
1136 FcnId(Context->getNextFunctionBlockValueID()), | 1150 FcnId(Context->getNextFunctionBlockValueID()), |
1137 FuncDecl(Context->getFunctionByID(FcnId)), | 1151 FuncDecl(Context->getFunctionByID(FcnId)), |
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2619 } | 2633 } |
2620 default: | 2634 default: |
2621 // Generate error message! | 2635 // Generate error message! |
2622 BlockParserBaseClass::ProcessRecord(); | 2636 BlockParserBaseClass::ProcessRecord(); |
2623 return; | 2637 return; |
2624 } | 2638 } |
2625 } | 2639 } |
2626 | 2640 |
2627 /// Parses constants within a function block. | 2641 /// Parses constants within a function block. |
2628 class ConstantsParser : public BlockParserBaseClass { | 2642 class ConstantsParser : public BlockParserBaseClass { |
| 2643 ConstantsParser() = delete; |
2629 ConstantsParser(const ConstantsParser &) = delete; | 2644 ConstantsParser(const ConstantsParser &) = delete; |
2630 ConstantsParser &operator=(const ConstantsParser &) = delete; | 2645 ConstantsParser &operator=(const ConstantsParser &) = delete; |
2631 | 2646 |
2632 public: | 2647 public: |
2633 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) | 2648 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) |
2634 : BlockParserBaseClass(BlockID, FuncParser), | 2649 : BlockParserBaseClass(BlockID, FuncParser), |
2635 Timer(Ice::TimerStack::TT_parseConstants, getTranslator().getContext()), | 2650 Timer(Ice::TimerStack::TT_parseConstants, getTranslator().getContext()), |
2636 FuncParser(FuncParser), NextConstantType(Ice::IceType_void) {} | 2651 FuncParser(FuncParser), NextConstantType(Ice::IceType_void) {} |
2637 | 2652 |
2638 ~ConstantsParser() override {} | 2653 ~ConstantsParser() override {} |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2747 } | 2762 } |
2748 default: | 2763 default: |
2749 // Generate error message! | 2764 // Generate error message! |
2750 BlockParserBaseClass::ProcessRecord(); | 2765 BlockParserBaseClass::ProcessRecord(); |
2751 return; | 2766 return; |
2752 } | 2767 } |
2753 } | 2768 } |
2754 | 2769 |
2755 // Parses valuesymtab blocks appearing in a function block. | 2770 // Parses valuesymtab blocks appearing in a function block. |
2756 class FunctionValuesymtabParser : public ValuesymtabParser { | 2771 class FunctionValuesymtabParser : public ValuesymtabParser { |
| 2772 FunctionValuesymtabParser() = delete; |
2757 FunctionValuesymtabParser(const FunctionValuesymtabParser &) = delete; | 2773 FunctionValuesymtabParser(const FunctionValuesymtabParser &) = delete; |
2758 void operator=(const FunctionValuesymtabParser &) = delete; | 2774 void operator=(const FunctionValuesymtabParser &) = delete; |
2759 | 2775 |
2760 public: | 2776 public: |
2761 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) | 2777 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) |
2762 : ValuesymtabParser(BlockID, EnclosingParser), | 2778 : ValuesymtabParser(BlockID, EnclosingParser), |
2763 Timer(Ice::TimerStack::TT_parseFunctionValuesymtabs, | 2779 Timer(Ice::TimerStack::TT_parseFunctionValuesymtabs, |
2764 getTranslator().getContext()) {} | 2780 getTranslator().getContext()) {} |
2765 | 2781 |
2766 private: | 2782 private: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 break; | 2848 break; |
2833 } | 2849 } |
2834 default: | 2850 default: |
2835 break; | 2851 break; |
2836 } | 2852 } |
2837 return BlockParserBaseClass::ParseBlock(BlockID); | 2853 return BlockParserBaseClass::ParseBlock(BlockID); |
2838 } | 2854 } |
2839 | 2855 |
2840 /// Parses the module block in the bitcode file. | 2856 /// Parses the module block in the bitcode file. |
2841 class ModuleParser : public BlockParserBaseClass { | 2857 class ModuleParser : public BlockParserBaseClass { |
| 2858 ModuleParser() = delete; |
| 2859 ModuleParser(const ModuleParser &) = delete; |
| 2860 ModuleParser &operator=(const ModuleParser &) = delete; |
| 2861 |
2842 public: | 2862 public: |
2843 ModuleParser(unsigned BlockID, TopLevelParser *Context) | 2863 ModuleParser(unsigned BlockID, TopLevelParser *Context) |
2844 : BlockParserBaseClass(BlockID, Context), | 2864 : BlockParserBaseClass(BlockID, Context), |
2845 Timer(Ice::TimerStack::TT_parseModule, | 2865 Timer(Ice::TimerStack::TT_parseModule, |
2846 Context->getTranslator().getContext()), | 2866 Context->getTranslator().getContext()), |
2847 GlobalDeclarationNamesAndInitializersInstalled(false) {} | 2867 GlobalDeclarationNamesAndInitializersInstalled(false) {} |
2848 | 2868 |
2849 ~ModuleParser() override {} | 2869 ~ModuleParser() override {} |
2850 | 2870 |
2851 const char *getBlockName() const override { return "module"; } | 2871 const char *getBlockName() const override { return "module"; } |
(...skipping 17 matching lines...) Expand all Loading... |
2869 } | 2889 } |
2870 } | 2890 } |
2871 bool ParseBlock(unsigned BlockID) override; | 2891 bool ParseBlock(unsigned BlockID) override; |
2872 | 2892 |
2873 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } | 2893 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } |
2874 | 2894 |
2875 void ProcessRecord() override; | 2895 void ProcessRecord() override; |
2876 }; | 2896 }; |
2877 | 2897 |
2878 class ModuleValuesymtabParser : public ValuesymtabParser { | 2898 class ModuleValuesymtabParser : public ValuesymtabParser { |
| 2899 ModuleValuesymtabParser() = delete; |
2879 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; | 2900 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; |
2880 void operator=(const ModuleValuesymtabParser &) = delete; | 2901 void operator=(const ModuleValuesymtabParser &) = delete; |
2881 | 2902 |
2882 public: | 2903 public: |
2883 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) | 2904 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) |
2884 : ValuesymtabParser(BlockID, MP), | 2905 : ValuesymtabParser(BlockID, MP), |
2885 Timer(Ice::TimerStack::TT_parseModuleValuesymtabs, | 2906 Timer(Ice::TimerStack::TT_parseModuleValuesymtabs, |
2886 getTranslator().getContext()) {} | 2907 getTranslator().getContext()) {} |
2887 | 2908 |
2888 ~ModuleValuesymtabParser() override {} | 2909 ~ModuleValuesymtabParser() override {} |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3045 | 3066 |
3046 if (TopLevelBlocks != 1) { | 3067 if (TopLevelBlocks != 1) { |
3047 errs() << IRFilename | 3068 errs() << IRFilename |
3048 << ": Contains more than one module. Found: " << TopLevelBlocks | 3069 << ": Contains more than one module. Found: " << TopLevelBlocks |
3049 << "\n"; | 3070 << "\n"; |
3050 ErrorStatus.assign(EC_Bitcode); | 3071 ErrorStatus.assign(EC_Bitcode); |
3051 } | 3072 } |
3052 } | 3073 } |
3053 | 3074 |
3054 } // end of namespace Ice | 3075 } // end of namespace Ice |
OLD | NEW |