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 // This file defines the basic commandline-based compile server. | 10 // This file defines the basic commandline-based compile server. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #include <fstream> | 14 #include <fstream> |
15 #include <iostream> | 15 #include <iostream> |
16 #include <thread> | 16 #include <thread> |
17 | 17 |
18 #ifdef INPUT_IS_TEXTUAL_BITCODE | |
Jim Stichnoth
2015/06/21 07:09:34
Can this be included unconditionally? (maybe with
Karl
2015/06/22 19:52:02
Done.
| |
19 #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" | |
20 #endif | |
21 | |
18 #include "llvm/Support/FileSystem.h" | 22 #include "llvm/Support/FileSystem.h" |
19 #include "llvm/Support/raw_os_ostream.h" | 23 #include "llvm/Support/raw_os_ostream.h" |
20 #include "llvm/Support/Signals.h" | 24 #include "llvm/Support/Signals.h" |
21 #include "llvm/Support/SourceMgr.h" | 25 #include "llvm/Support/SourceMgr.h" |
22 #include "llvm/Support/StreamingMemoryObject.h" | 26 #include "llvm/Support/StreamingMemoryObject.h" |
23 | 27 |
24 #include "IceClFlags.h" | 28 #include "IceClFlags.h" |
25 #include "IceClFlagsExtra.h" | 29 #include "IceClFlagsExtra.h" |
26 #include "IceCompileServer.h" | 30 #include "IceCompileServer.h" |
27 #include "IceELFStreamer.h" | 31 #include "IceELFStreamer.h" |
28 #include "IceGlobalContext.h" | 32 #include "IceGlobalContext.h" |
29 | 33 |
30 namespace Ice { | 34 namespace Ice { |
31 | 35 |
32 namespace { | 36 namespace { |
33 | 37 |
38 #ifdef INPUT_IS_TEXTUAL_BITCODE | |
Jim Stichnoth
2015/06/21 07:09:34
Would it be possible to define TextDataStreamer ev
Karl
2015/06/22 19:52:02
Done.
| |
39 #if PNACL_BROWSER_TRANSLATOR | |
40 #error Can not define INPUT_IS_TEXTUAL_BITCODE when building browswer translator | |
41 #endif | |
42 | |
43 // Define a SmallVector backed buffer as a data stream, so that it | |
44 // can hold the generated binary version of the textual bitcode in the | |
45 // input file. | |
46 class TextDataStreamer : public llvm::DataStreamer { | |
47 public: | |
48 TextDataStreamer() {} | |
49 ~TextDataStreamer() final {} | |
50 static TextDataStreamer *create(const IceString &Filename, std::string *Err); | |
51 size_t GetBytes(unsigned char *Buf, size_t Len) final; | |
52 private: | |
53 llvm::SmallVector<char, 1024> BitcodeBuffer; | |
54 size_t Cursor = 0; | |
55 }; | |
56 | |
57 TextDataStreamer *TextDataStreamer::create(const IceString &Filename, | |
58 std::string *Err) { | |
59 TextDataStreamer *Streamer = new TextDataStreamer(); | |
60 llvm::raw_string_ostream ErrStrm(*Err); | |
61 if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( | |
62 Filename, Streamer->BitcodeBuffer, &ErrStrm)) { | |
63 ErrStrm << "Error: " << EC.message() << "\n"; | |
64 ErrStrm.flush(); | |
65 delete Streamer; | |
66 return nullptr; | |
67 } | |
68 ErrStrm.flush(); | |
69 return Streamer; | |
70 } | |
71 | |
72 size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { | |
73 if (Cursor >= BitcodeBuffer.size()) | |
74 return 0; | |
75 if (Cursor + Len > BitcodeBuffer.size()) | |
76 Len = BitcodeBuffer.size() - Cursor; | |
77 for (size_t i = 0; i < Len; ++i) | |
78 Buf[i] = BitcodeBuffer[Cursor + i]; | |
79 Cursor += Len; | |
80 return Len; | |
81 } | |
82 #endif | |
83 | |
34 std::unique_ptr<Ostream> makeStream(const IceString &Filename, | 84 std::unique_ptr<Ostream> makeStream(const IceString &Filename, |
35 std::error_code &EC) { | 85 std::error_code &EC) { |
36 if (Filename == "-") { | 86 if (Filename == "-") { |
37 return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout)); | 87 return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout)); |
38 } else { | 88 } else { |
39 return std::unique_ptr<Ostream>( | 89 return std::unique_ptr<Ostream>( |
40 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); | 90 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); |
41 } | 91 } |
42 } | 92 } |
43 | 93 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 *Ls << "Failed to open output file: " << ExtraFlags.getOutputFilename() | 143 *Ls << "Failed to open output file: " << ExtraFlags.getOutputFilename() |
94 << ":\n" << EC.message() << "\n"; | 144 << ":\n" << EC.message() << "\n"; |
95 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Args)); | 145 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Args)); |
96 } | 146 } |
97 Os->SetUnbuffered(); | 147 Os->SetUnbuffered(); |
98 } break; | 148 } break; |
99 } | 149 } |
100 | 150 |
101 IceString StrError; | 151 IceString StrError; |
102 std::unique_ptr<llvm::DataStreamer> InputStream( | 152 std::unique_ptr<llvm::DataStreamer> InputStream( |
103 llvm::getDataFileStreamer(ExtraFlags.getIRFilename(), &StrError)); | 153 #ifdef INPUT_IS_TEXTUAL_BITCODE |
Jim Stichnoth
2015/06/21 07:09:34
Hopefully you could use this instead?
INPUT_IS_TE
Karl
2015/06/22 19:52:01
Done.
| |
154 TextDataStreamer::create(ExtraFlags.getIRFilename(), &StrError) | |
155 #else | |
156 llvm::getDataFileStreamer(ExtraFlags.getIRFilename(), &StrError) | |
157 #endif | |
158 ); | |
104 if (!StrError.empty() || !InputStream) { | 159 if (!StrError.empty() || !InputStream) { |
105 llvm::SMDiagnostic Err(ExtraFlags.getIRFilename(), | 160 llvm::SMDiagnostic Err(ExtraFlags.getIRFilename(), |
106 llvm::SourceMgr::DK_Error, StrError); | 161 llvm::SourceMgr::DK_Error, StrError); |
107 Err.print(ExtraFlags.getAppName().c_str(), *Ls); | 162 Err.print(ExtraFlags.getAppName().c_str(), *Ls); |
108 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Bitcode)); | 163 return transferErrorCode(getReturnValue(ExtraFlags, Ice::EC_Bitcode)); |
109 } | 164 } |
110 | 165 |
111 Ctx.reset( | 166 Ctx.reset( |
112 new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get(), Flags)); | 167 new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get(), Flags)); |
113 if (Ctx->getFlags().getNumTranslationThreads() != 0) { | 168 if (Ctx->getFlags().getNumTranslationThreads() != 0) { |
114 std::thread CompileThread([this, &ExtraFlags, &InputStream]() { | 169 std::thread CompileThread([this, &ExtraFlags, &InputStream]() { |
115 Ctx->initParserThread(); | 170 Ctx->initParserThread(); |
116 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); | 171 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); |
117 }); | 172 }); |
118 CompileThread.join(); | 173 CompileThread.join(); |
119 } else { | 174 } else { |
120 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); | 175 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); |
121 } | 176 } |
122 transferErrorCode(getReturnValue( | 177 transferErrorCode(getReturnValue( |
123 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); | 178 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); |
124 } | 179 } |
125 | 180 |
126 } // end of namespace Ice | 181 } // end of namespace Ice |
OLD | NEW |