OLD | NEW |
1 //===- subzero/src/IceCompileServer.cpp - Compile server ------------------===// | 1 //===- subzero/src/IceCompileServer.cpp - Compile server ------------------===// |
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 /// \file | 10 /// \file |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 namespace Ice { | 43 namespace Ice { |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // Define a SmallVector backed buffer as a data stream, so that it can hold the | 47 // Define a SmallVector backed buffer as a data stream, so that it can hold the |
48 // generated binary version of the textual bitcode in the input file. | 48 // generated binary version of the textual bitcode in the input file. |
49 class TextDataStreamer : public llvm::DataStreamer { | 49 class TextDataStreamer : public llvm::DataStreamer { |
50 public: | 50 public: |
51 TextDataStreamer() = default; | 51 TextDataStreamer() = default; |
52 ~TextDataStreamer() final = default; | 52 ~TextDataStreamer() final = default; |
53 static TextDataStreamer *create(const IceString &Filename, std::string *Err); | 53 static TextDataStreamer *create(const std::string &Filename, |
| 54 std::string *Err); |
54 size_t GetBytes(unsigned char *Buf, size_t Len) final; | 55 size_t GetBytes(unsigned char *Buf, size_t Len) final; |
55 | 56 |
56 private: | 57 private: |
57 llvm::SmallVector<char, 1024> BitcodeBuffer; | 58 llvm::SmallVector<char, 1024> BitcodeBuffer; |
58 size_t Cursor = 0; | 59 size_t Cursor = 0; |
59 }; | 60 }; |
60 | 61 |
61 TextDataStreamer *TextDataStreamer::create(const IceString &Filename, | 62 TextDataStreamer *TextDataStreamer::create(const std::string &Filename, |
62 std::string *Err) { | 63 std::string *Err) { |
63 TextDataStreamer *Streamer = new TextDataStreamer(); | 64 TextDataStreamer *Streamer = new TextDataStreamer(); |
64 llvm::raw_string_ostream ErrStrm(*Err); | 65 llvm::raw_string_ostream ErrStrm(*Err); |
65 if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( | 66 if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( |
66 Filename, Streamer->BitcodeBuffer, &ErrStrm)) { | 67 Filename, Streamer->BitcodeBuffer, &ErrStrm)) { |
67 ErrStrm << EC.message(); | 68 ErrStrm << EC.message(); |
68 ErrStrm.flush(); | 69 ErrStrm.flush(); |
69 delete Streamer; | 70 delete Streamer; |
70 return nullptr; | 71 return nullptr; |
71 } | 72 } |
72 ErrStrm.flush(); | 73 ErrStrm.flush(); |
73 return Streamer; | 74 return Streamer; |
74 } | 75 } |
75 | 76 |
76 size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { | 77 size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { |
77 if (Cursor >= BitcodeBuffer.size()) | 78 if (Cursor >= BitcodeBuffer.size()) |
78 return 0; | 79 return 0; |
79 size_t Remaining = BitcodeBuffer.size(); | 80 size_t Remaining = BitcodeBuffer.size(); |
80 Len = std::min(Len, Remaining); | 81 Len = std::min(Len, Remaining); |
81 for (size_t i = 0; i < Len; ++i) | 82 for (size_t i = 0; i < Len; ++i) |
82 Buf[i] = BitcodeBuffer[Cursor + i]; | 83 Buf[i] = BitcodeBuffer[Cursor + i]; |
83 Cursor += Len; | 84 Cursor += Len; |
84 return Len; | 85 return Len; |
85 } | 86 } |
86 | 87 |
87 std::unique_ptr<Ostream> makeStream(const IceString &Filename, | 88 std::unique_ptr<Ostream> makeStream(const std::string &Filename, |
88 std::error_code &EC) { | 89 std::error_code &EC) { |
89 if (Filename == "-") { | 90 if (Filename == "-") { |
90 return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout)); | 91 return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout)); |
91 } else { | 92 } else { |
92 return std::unique_ptr<Ostream>( | 93 return std::unique_ptr<Ostream>( |
93 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); | 94 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 ErrorCodes getReturnValue(ErrorCodes Val) { | 98 ErrorCodes getReturnValue(ErrorCodes Val) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return transferErrorCode(getReturnValue(Ice::EC_Args)); | 204 return transferErrorCode(getReturnValue(Ice::EC_Args)); |
204 } | 205 } |
205 Os->SetUnbuffered(); | 206 Os->SetUnbuffered(); |
206 } break; | 207 } break; |
207 } | 208 } |
208 | 209 |
209 if (BuildDefs::minimal() && Flags.getBitcodeAsText()) | 210 if (BuildDefs::minimal() && Flags.getBitcodeAsText()) |
210 llvm::report_fatal_error("Can't specify 'bitcode-as-text' flag in " | 211 llvm::report_fatal_error("Can't specify 'bitcode-as-text' flag in " |
211 "minimal build"); | 212 "minimal build"); |
212 | 213 |
213 IceString StrError; | 214 std::string StrError; |
214 std::unique_ptr<llvm::DataStreamer> InputStream( | 215 std::unique_ptr<llvm::DataStreamer> InputStream( |
215 (!BuildDefs::minimal() && Flags.getBitcodeAsText()) | 216 (!BuildDefs::minimal() && Flags.getBitcodeAsText()) |
216 ? TextDataStreamer::create(Flags.getIRFilename(), &StrError) | 217 ? TextDataStreamer::create(Flags.getIRFilename(), &StrError) |
217 : llvm::getDataFileStreamer(Flags.getIRFilename(), &StrError)); | 218 : llvm::getDataFileStreamer(Flags.getIRFilename(), &StrError)); |
218 if (!StrError.empty() || !InputStream) { | 219 if (!StrError.empty() || !InputStream) { |
219 llvm::SMDiagnostic Err(Flags.getIRFilename(), llvm::SourceMgr::DK_Error, | 220 llvm::SMDiagnostic Err(Flags.getIRFilename(), llvm::SourceMgr::DK_Error, |
220 StrError); | 221 StrError); |
221 Err.print(Flags.getAppName().c_str(), *Ls); | 222 Err.print(Flags.getAppName().c_str(), *Ls); |
222 return transferErrorCode(getReturnValue(Ice::EC_Bitcode)); | 223 return transferErrorCode(getReturnValue(Ice::EC_Bitcode)); |
223 } | 224 } |
224 | 225 |
225 if (Flags.getGenerateBuildAtts()) { | 226 if (Flags.getGenerateBuildAtts()) { |
226 dumpBuildAttributes(*Os.get()); | 227 dumpBuildAttributes(*Os.get()); |
227 return transferErrorCode(getReturnValue(Ice::EC_None)); | 228 return transferErrorCode(getReturnValue(Ice::EC_None)); |
228 } | 229 } |
229 | 230 |
230 Ctx.reset(new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get())); | 231 Ctx.reset(new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get())); |
231 if (Ctx->getFlags().getNumTranslationThreads() != 0) { | 232 if (Ctx->getFlags().getNumTranslationThreads() != 0) { |
232 std::thread CompileThread([this, &Flags, &InputStream]() { | 233 std::thread CompileThread([this, &Flags, &InputStream]() { |
233 Ctx->initParserThread(); | 234 Ctx->initParserThread(); |
234 getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); | 235 getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); |
235 }); | 236 }); |
236 CompileThread.join(); | 237 CompileThread.join(); |
237 } else { | 238 } else { |
238 getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); | 239 getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); |
239 } | 240 } |
240 transferErrorCode( | 241 transferErrorCode( |
241 getReturnValue(static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); | 242 getReturnValue(static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); |
242 Ctx->dumpConstantLookupCounts(); | 243 Ctx->dumpConstantLookupCounts(); |
| 244 Ctx->dumpStrings(); |
243 } | 245 } |
244 | 246 |
245 } // end of namespace Ice | 247 } // end of namespace Ice |
OLD | NEW |