| OLD | NEW |
| 1 //===- subzero/src/IceGlobalInits.cpp - Global declarations ---------------===// | 1 //===- subzero/src/IceGlobalInits.cpp - Global declarations ---------------===// |
| 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 notion of function declarations, global | 10 // This file implements the notion of function declarations, global |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 llvm::CallingConv::ID CallingConv, | 61 llvm::CallingConv::ID CallingConv, |
| 62 llvm::GlobalValue::LinkageTypes Linkage, | 62 llvm::GlobalValue::LinkageTypes Linkage, |
| 63 bool IsProto) { | 63 bool IsProto) { |
| 64 return Ctx->newFunctionDeclaration(&Signature, CallingConv, Linkage, IsProto); | 64 return Ctx->newFunctionDeclaration(&Signature, CallingConv, Linkage, IsProto); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void FunctionDeclaration::dumpType(Ostream &Stream) const { | 67 void FunctionDeclaration::dumpType(Ostream &Stream) const { |
| 68 Stream << Signature; | 68 Stream << Signature; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void FunctionDeclaration::dump(Ostream &Stream) const { | 71 void FunctionDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const { |
| 72 if (IsProto) | 72 if (IsProto) |
| 73 Stream << "declare "; | 73 Stream << "declare "; |
| 74 ::dumpLinkage(Stream, Linkage); | 74 ::dumpLinkage(Stream, Linkage); |
| 75 ::dumpCallingConv(Stream, CallingConv); | 75 ::dumpCallingConv(Stream, CallingConv); |
| 76 Stream << Signature.getReturnType() << " @" << Name << "("; | 76 Stream << Signature.getReturnType() << " @" |
| 77 << (Ctx ? Ctx->mangleName(Name) : Name) << "("; |
| 77 bool IsFirst = true; | 78 bool IsFirst = true; |
| 78 for (Type ArgTy : Signature.getArgList()) { | 79 for (Type ArgTy : Signature.getArgList()) { |
| 79 if (IsFirst) | 80 if (IsFirst) |
| 80 IsFirst = false; | 81 IsFirst = false; |
| 81 else | 82 else |
| 82 Stream << ", "; | 83 Stream << ", "; |
| 83 Stream << ArgTy; | 84 Stream << ArgTy; |
| 84 } | 85 } |
| 85 Stream << ")"; | 86 Stream << ")"; |
| 86 } | 87 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 104 IsFirst = false; | 105 IsFirst = false; |
| 105 } else { | 106 } else { |
| 106 Stream << ", "; | 107 Stream << ", "; |
| 107 } | 108 } |
| 108 Init->dumpType(Stream); | 109 Init->dumpType(Stream); |
| 109 } | 110 } |
| 110 Stream << " }>"; | 111 Stream << " }>"; |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 void VariableDeclaration::dump(Ostream &Stream) const { | 115 void VariableDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const { |
| 115 Stream << "@" << Name << " = internal " | 116 Stream << "@" << ((Ctx && !getSuppressMangling()) |
| 116 << (IsConstant ? "constant" : "global") << " "; | 117 ? Ctx->mangleName(Name) : Name) << " = "; |
| 118 ::dumpLinkage(Stream, Linkage); |
| 119 Stream << " " << (IsConstant ? "constant" : "global") << " "; |
| 117 | 120 |
| 118 // Add initializer. | 121 // Add initializer. |
| 119 if (Initializers.size() == 1) { | 122 if (Initializers.size() == 1) { |
| 120 Initializers.front()->dump(Stream); | 123 Initializers.front()->dump(Stream); |
| 121 } else { | 124 } else { |
| 122 dumpType(Stream); | 125 dumpType(Stream); |
| 123 Stream << " <{ "; | 126 Stream << " <{ "; |
| 124 bool IsFirst = true; | 127 bool IsFirst = true; |
| 125 for (Initializer *Init : Initializers) { | 128 for (Initializer *Init : Initializers) { |
| 126 if (IsFirst) { | 129 if (IsFirst) { |
| 127 IsFirst = false; | 130 IsFirst = false; |
| 128 } else { | 131 } else { |
| 129 Stream << ", "; | 132 Stream << ", "; |
| 130 } | 133 } |
| 131 Init->dump(Stream); | 134 Init->dump(Ctx, Stream); |
| 132 } | 135 } |
| 133 Stream << " }>"; | 136 Stream << " }>"; |
| 134 } | 137 } |
| 135 | 138 |
| 136 // Add alignment. | 139 // Add alignment. |
| 137 if (Alignment > 0) | 140 if (Alignment > 0) |
| 138 Stream << ", align " << Alignment; | 141 Stream << ", align " << Alignment; |
| 139 Stream << "\n"; | 142 Stream << "\n"; |
| 140 } | 143 } |
| 141 | 144 |
| 142 void VariableDeclaration::Initializer::dumpType(Ostream &Stream) const { | 145 void VariableDeclaration::Initializer::dumpType(Ostream &Stream) const { |
| 143 Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]"; | 146 Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]"; |
| 144 } | 147 } |
| 145 | 148 |
| 146 void VariableDeclaration::DataInitializer::dump(Ostream &Stream) const { | 149 void VariableDeclaration::DataInitializer::dump( |
| 150 GlobalContext *, Ostream &Stream) const { |
| 147 dumpType(Stream); | 151 dumpType(Stream); |
| 148 Stream << " c\""; | 152 Stream << " c\""; |
| 149 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep | 153 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep |
| 150 // the strings in the same format as the .ll file for practical | 154 // the strings in the same format as the .ll file for practical |
| 151 // diffing. | 155 // diffing. |
| 152 for (uint8_t C : Contents) { | 156 for (uint8_t C : Contents) { |
| 153 if (isprint(C) && C != '\\' && C != '"') | 157 if (isprint(C) && C != '\\' && C != '"') |
| 154 Stream << C; | 158 Stream << C; |
| 155 else | 159 else |
| 156 Stream << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); | 160 Stream << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); |
| 157 } | 161 } |
| 158 Stream << "\""; | 162 Stream << "\""; |
| 159 } | 163 } |
| 160 | 164 |
| 161 void VariableDeclaration::ZeroInitializer::dump(Ostream &Stream) const { | 165 void VariableDeclaration::ZeroInitializer::dump( |
| 166 GlobalContext *, Ostream &Stream) const { |
| 162 dumpType(Stream); | 167 dumpType(Stream); |
| 163 Stream << " zeroinitializer"; | 168 Stream << " zeroinitializer"; |
| 164 } | 169 } |
| 165 | 170 |
| 166 void VariableDeclaration::RelocInitializer::dumpType(Ostream &Stream) const { | 171 void VariableDeclaration::RelocInitializer::dumpType(Ostream &Stream) const { |
| 167 Stream << Ice::IceType_i32; | 172 Stream << Ice::IceType_i32; |
| 168 } | 173 } |
| 169 | 174 |
| 170 void VariableDeclaration::RelocInitializer::dump(Ostream &Stream) const { | 175 void VariableDeclaration::RelocInitializer::dump( |
| 176 GlobalContext *Ctx, Ostream &Stream) const { |
| 171 if (Offset != 0) { | 177 if (Offset != 0) { |
| 172 dumpType(Stream); | 178 dumpType(Stream); |
| 173 Stream << " add ("; | 179 Stream << " add ("; |
| 174 } | 180 } |
| 175 dumpType(Stream); | 181 dumpType(Stream); |
| 176 Stream << " ptrtoint ("; | 182 Stream << " ptrtoint ("; |
| 177 Declaration->dumpType(Stream); | 183 Declaration->dumpType(Stream); |
| 178 Stream << "* @" << Declaration->getName() << " to "; | 184 Stream << "* @"; |
| 185 if (Ctx) |
| 186 Stream << Ctx->mangleName(Declaration->getName()); |
| 187 else |
| 188 Stream << Declaration->getName(); |
| 189 Stream << " to "; |
| 179 dumpType(Stream); | 190 dumpType(Stream); |
| 180 Stream << ")"; | 191 Stream << ")"; |
| 181 if (Offset != 0) { | 192 if (Offset != 0) { |
| 182 Stream << ", "; | 193 Stream << ", "; |
| 183 dumpType(Stream); | 194 dumpType(Stream); |
| 184 Stream << " " << Offset << ")"; | 195 Stream << " " << Offset << ")"; |
| 185 } | 196 } |
| 186 } | 197 } |
| 187 | 198 |
| 188 } // end of namespace Ice | 199 } // end of namespace Ice |
| OLD | NEW |