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 |
11 /// This file defines the basic commandline-based compile server. | 11 /// This file defines the basic commandline-based compile server. |
12 /// | 12 /// |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "IceCompileServer.h" | 15 #include "IceCompileServer.h" |
16 | 16 |
17 #include "IceClFlags.h" | 17 #include "IceClFlags.h" |
18 #include "IceClFlagsExtra.h" | 18 #include "IceClFlagsExtra.h" |
19 #include "IceELFStreamer.h" | 19 #include "IceELFStreamer.h" |
20 #include "IceGlobalContext.h" | 20 #include "IceGlobalContext.h" |
21 | 21 |
22 #pragma clang diagnostic push | 22 #pragma clang diagnostic push |
23 #pragma clang diagnostic ignored "-Wunused-parameter" | 23 #pragma clang diagnostic ignored "-Wunused-parameter" |
24 // Include code to handle converting textual bitcode records to binary (for | |
25 // INPUT_IS_TEXTUAL_BITCODE). | |
26 #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" | 24 #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" |
27 #include "llvm/Support/FileSystem.h" | 25 #include "llvm/Support/FileSystem.h" |
28 #include "llvm/Support/raw_os_ostream.h" | 26 #include "llvm/Support/raw_os_ostream.h" |
29 #include "llvm/Support/Signals.h" | 27 #include "llvm/Support/Signals.h" |
30 #include "llvm/Support/SourceMgr.h" | 28 #include "llvm/Support/SourceMgr.h" |
31 #include "llvm/Support/StreamingMemoryObject.h" | 29 #include "llvm/Support/StreamingMemoryObject.h" |
32 #pragma clang diagnostic pop | 30 #pragma clang diagnostic pop |
33 | 31 |
34 #include <fstream> | 32 #include <fstream> |
35 #include <iostream> | 33 #include <iostream> |
36 #include <thread> | 34 #include <thread> |
37 | 35 |
38 namespace Ice { | 36 namespace Ice { |
39 | 37 |
40 namespace { | 38 namespace { |
41 | 39 |
42 static_assert(!(BuildDefs::textualBitcode() && PNACL_BROWSER_TRANSLATOR), | |
43 "Can not define INPUT_IS_TEXTUAL_BITCODE when building browswer " | |
44 "translator"); | |
45 | |
46 // Define a SmallVector backed buffer as a data stream, so that it | 40 // Define a SmallVector backed buffer as a data stream, so that it |
47 // can hold the generated binary version of the textual bitcode in the | 41 // can hold the generated binary version of the textual bitcode in the |
48 // input file. | 42 // input file. |
49 class TextDataStreamer : public llvm::DataStreamer { | 43 class TextDataStreamer : public llvm::DataStreamer { |
50 public: | 44 public: |
51 TextDataStreamer() = default; | 45 TextDataStreamer() = default; |
52 ~TextDataStreamer() final = default; | 46 ~TextDataStreamer() final = default; |
53 static TextDataStreamer *create(const IceString &Filename, std::string *Err); | 47 static TextDataStreamer *create(const IceString &Filename, std::string *Err); |
54 size_t GetBytes(unsigned char *Buf, size_t Len) final; | 48 size_t GetBytes(unsigned char *Buf, size_t Len) final; |
55 | 49 |
56 private: | 50 private: |
57 llvm::SmallVector<char, 1024> BitcodeBuffer; | 51 llvm::SmallVector<char, 1024> BitcodeBuffer; |
58 size_t Cursor = 0; | 52 size_t Cursor = 0; |
59 }; | 53 }; |
60 | 54 |
61 TextDataStreamer *TextDataStreamer::create(const IceString &Filename, | 55 TextDataStreamer *TextDataStreamer::create(const IceString &Filename, |
62 std::string *Err) { | 56 std::string *Err) { |
63 TextDataStreamer *Streamer = new TextDataStreamer(); | 57 TextDataStreamer *Streamer = new TextDataStreamer(); |
64 llvm::raw_string_ostream ErrStrm(*Err); | 58 llvm::raw_string_ostream ErrStrm(*Err); |
65 if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( | 59 if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( |
66 Filename, Streamer->BitcodeBuffer, &ErrStrm)) { | 60 Filename, Streamer->BitcodeBuffer, &ErrStrm)) { |
67 ErrStrm << EC.message(); // << "\n"; | 61 ErrStrm << EC.message(); |
68 ErrStrm.flush(); | 62 ErrStrm.flush(); |
69 delete Streamer; | 63 delete Streamer; |
70 return nullptr; | 64 return nullptr; |
71 } | 65 } |
72 // ErrStrm.flush(); | 66 ErrStrm.flush(); |
73 return Streamer; | 67 return Streamer; |
74 } | 68 } |
75 | 69 |
76 size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { | 70 size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { |
77 if (Cursor >= BitcodeBuffer.size()) | 71 if (Cursor >= BitcodeBuffer.size()) |
78 return 0; | 72 return 0; |
79 size_t Remaining = BitcodeBuffer.size(); | 73 size_t Remaining = BitcodeBuffer.size(); |
80 Len = std::min(Len, Remaining); | 74 Len = std::min(Len, Remaining); |
81 for (size_t i = 0; i < Len; ++i) | 75 for (size_t i = 0; i < Len; ++i) |
82 Buf[i] = BitcodeBuffer[Cursor + i]; | 76 Buf[i] = BitcodeBuffer[Cursor + i]; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 Os = makeStream(ExtraFlags.getOutputFilename(), EC); | 138 Os = makeStream(ExtraFlags.getOutputFilename(), EC); |
145 if (EC) { | 139 if (EC) { |
146 *Ls << "Failed to open output file: " << ExtraFlags.getOutputFilename() | 140 *Ls << "Failed to open output file: " << ExtraFlags.getOutputFilename() |
147 << ":\n" << EC.message() << "\n"; | 141 << ":\n" << EC.message() << "\n"; |
148 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Args)); | 142 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Args)); |
149 } | 143 } |
150 Os->SetUnbuffered(); | 144 Os->SetUnbuffered(); |
151 } break; | 145 } break; |
152 } | 146 } |
153 | 147 |
| 148 if (BuildDefs::minimal() && ExtraFlags.getBitcodeAsText()) |
| 149 llvm::report_fatal_error("Can't specify 'bitcode-as-text' flag in " |
| 150 "minimal build"); |
| 151 |
154 IceString StrError; | 152 IceString StrError; |
155 std::unique_ptr<llvm::DataStreamer> InputStream( | 153 std::unique_ptr<llvm::DataStreamer> InputStream( |
156 BuildDefs::textualBitcode() | 154 (!BuildDefs::minimal() && ExtraFlags.getBitcodeAsText()) |
157 ? TextDataStreamer::create(ExtraFlags.getIRFilename(), &StrError) | 155 ? TextDataStreamer::create(ExtraFlags.getIRFilename(), &StrError) |
158 : llvm::getDataFileStreamer(ExtraFlags.getIRFilename(), &StrError)); | 156 : llvm::getDataFileStreamer(ExtraFlags.getIRFilename(), &StrError)); |
159 if (!StrError.empty() || !InputStream) { | 157 if (!StrError.empty() || !InputStream) { |
160 llvm::SMDiagnostic Err(ExtraFlags.getIRFilename(), | 158 llvm::SMDiagnostic Err(ExtraFlags.getIRFilename(), |
161 llvm::SourceMgr::DK_Error, StrError); | 159 llvm::SourceMgr::DK_Error, StrError); |
162 Err.print(ExtraFlags.getAppName().c_str(), *Ls); | 160 Err.print(ExtraFlags.getAppName().c_str(), *Ls); |
163 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Bitcode)); | 161 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Bitcode)); |
164 } | 162 } |
165 | 163 |
166 Ctx.reset( | 164 Ctx.reset( |
167 new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get(), Flags)); | 165 new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get(), Flags)); |
168 if (Ctx->getFlags().getNumTranslationThreads() != 0) { | 166 if (Ctx->getFlags().getNumTranslationThreads() != 0) { |
169 std::thread CompileThread([this, &ExtraFlags, &InputStream]() { | 167 std::thread CompileThread([this, &ExtraFlags, &InputStream]() { |
170 Ctx->initParserThread(); | 168 Ctx->initParserThread(); |
171 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); | 169 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); |
172 }); | 170 }); |
173 CompileThread.join(); | 171 CompileThread.join(); |
174 } else { | 172 } else { |
175 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); | 173 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); |
176 } | 174 } |
177 transferErrorCode(getReturnValue( | 175 transferErrorCode(getReturnValue( |
178 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); | 176 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); |
179 } | 177 } |
180 | 178 |
181 } // end of namespace Ice | 179 } // end of namespace Ice |
OLD | NEW |