Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceCompileServer.cpp - Compile server ------------------===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Defines the basic commandline-based compile server. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 15 | #include "IceCompileServer.h" |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 16 | |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 17 | #include "IceASanInstrumentation.h" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 18 | #include "IceClFlags.h" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 19 | #include "IceELFStreamer.h" |
| 20 | #include "IceGlobalContext.h" |
Jim Stichnoth | 54cf1a2 | 2016-08-08 14:15:00 -0700 | [diff] [blame] | 21 | #include "IceRevision.h" |
David Sehr | 4c16ac0 | 2016-03-17 13:51:42 -0700 | [diff] [blame] | 22 | #include "LinuxMallocProfiling.h" |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 23 | |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 24 | #ifdef __clang__ |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 25 | #pragma clang diagnostic push |
| 26 | #pragma clang diagnostic ignored "-Wunused-parameter" |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 27 | #endif // __clang__ |
| 28 | |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 29 | #ifdef PNACL_LLVM |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 30 | #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 31 | #endif // PNACL_LLVM |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 32 | #include "llvm/Support/FileSystem.h" |
| 33 | #include "llvm/Support/raw_os_ostream.h" |
Jan Voung | b2d5084 | 2015-05-12 09:53:50 -0700 | [diff] [blame] | 34 | #include "llvm/Support/Signals.h" |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 35 | #include "llvm/Support/SourceMgr.h" |
| 36 | #include "llvm/Support/StreamingMemoryObject.h" |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 37 | |
| 38 | #ifdef __clang__ |
Jim Stichnoth | 98da966 | 2015-06-27 06:38:08 -0700 | [diff] [blame] | 39 | #pragma clang diagnostic pop |
Jim Stichnoth | b0051df | 2016-01-13 11:39:15 -0800 | [diff] [blame] | 40 | #endif // __clang__ |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 41 | |
Karl Schimpf | 7e64eaa | 2015-10-02 10:49:49 -0700 | [diff] [blame] | 42 | #include <cstdio> |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 43 | #include <fstream> |
| 44 | #include <iostream> |
| 45 | #include <thread> |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 46 | |
| 47 | namespace Ice { |
| 48 | |
| 49 | namespace { |
| 50 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 51 | // Define a SmallVector backed buffer as a data stream, so that it can hold the |
| 52 | // generated binary version of the textual bitcode in the input file. |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 53 | class TextDataStreamer : public llvm::DataStreamer { |
| 54 | public: |
| 55 | TextDataStreamer() = default; |
| 56 | ~TextDataStreamer() final = default; |
Jim Stichnoth | f5fdd23 | 2016-05-09 12:24:36 -0700 | [diff] [blame] | 57 | #ifdef PNACL_LLVM |
| 58 | using CreateType = TextDataStreamer *; |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 59 | #else // !PNACL_LLVM |
Jim Stichnoth | f5fdd23 | 2016-05-09 12:24:36 -0700 | [diff] [blame] | 60 | using CreateType = std::unique_ptr<TextDataStreamer>; |
| 61 | #endif // !PNACL_LLVM |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 62 | static CreateType create(const std::string &Filename, std::string *Err); |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 63 | size_t GetBytes(unsigned char *Buf, size_t Len) final; |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 64 | |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 65 | private: |
| 66 | llvm::SmallVector<char, 1024> BitcodeBuffer; |
| 67 | size_t Cursor = 0; |
| 68 | }; |
| 69 | |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 70 | TextDataStreamer::CreateType |
| 71 | TextDataStreamer::create(const std::string &Filename, std::string *Err) { |
Jim Stichnoth | f5fdd23 | 2016-05-09 12:24:36 -0700 | [diff] [blame] | 72 | #ifdef PNACL_LLVM |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 73 | TextDataStreamer *Streamer = new TextDataStreamer(); |
| 74 | llvm::raw_string_ostream ErrStrm(*Err); |
| 75 | if (std::error_code EC = llvm::readNaClRecordTextAndBuildBitcode( |
| 76 | Filename, Streamer->BitcodeBuffer, &ErrStrm)) { |
Karl Schimpf | cb6e95a | 2015-07-23 09:10:03 -0700 | [diff] [blame] | 77 | ErrStrm << EC.message(); |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 78 | ErrStrm.flush(); |
| 79 | delete Streamer; |
| 80 | return nullptr; |
| 81 | } |
Karl Schimpf | cb6e95a | 2015-07-23 09:10:03 -0700 | [diff] [blame] | 82 | ErrStrm.flush(); |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 83 | return Streamer; |
Jim Stichnoth | a5b16ab | 2016-05-10 11:20:41 -0700 | [diff] [blame] | 84 | #else // !PNACL_LLVM |
Jim Stichnoth | f5fdd23 | 2016-05-09 12:24:36 -0700 | [diff] [blame] | 85 | return CreateType(); |
| 86 | #endif // !PNACL_LLVM |
Karl Schimpf | 6f9ba11 | 2015-06-22 13:20:23 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | size_t TextDataStreamer::GetBytes(unsigned char *Buf, size_t Len) { |
| 90 | if (Cursor >= BitcodeBuffer.size()) |
| 91 | return 0; |
| 92 | size_t Remaining = BitcodeBuffer.size(); |
| 93 | Len = std::min(Len, Remaining); |
| 94 | for (size_t i = 0; i < Len; ++i) |
| 95 | Buf[i] = BitcodeBuffer[Cursor + i]; |
| 96 | Cursor += Len; |
| 97 | return Len; |
| 98 | } |
| 99 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 100 | std::unique_ptr<Ostream> makeStream(const std::string &Filename, |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 101 | std::error_code &EC) { |
| 102 | if (Filename == "-") { |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 103 | return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout)); |
Jim Stichnoth | fd07ad0 | 2016-04-20 10:12:46 -0700 | [diff] [blame] | 104 | } else if (Filename == "/dev/stderr") { |
| 105 | return std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cerr)); |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 106 | } else { |
| 107 | return std::unique_ptr<Ostream>( |
| 108 | new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 112 | ErrorCodes getReturnValue(ErrorCodes Val) { |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 113 | if (getFlags().getAlwaysExitSuccess()) |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 114 | return EC_None; |
| 115 | return Val; |
| 116 | } |
| 117 | |
Karl Schimpf | db2fd9c | 2015-09-30 15:02:05 -0700 | [diff] [blame] | 118 | // Reports fatal error message, and then exits with success status 0. |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 119 | void reportFatalErrorThenExitSuccess(void *UserData, const std::string &Reason, |
Karl Schimpf | db2fd9c | 2015-09-30 15:02:05 -0700 | [diff] [blame] | 120 | bool GenCrashDag) { |
| 121 | (void)UserData; |
| 122 | (void)GenCrashDag; |
| 123 | |
| 124 | // Note: This code is (mostly) copied from llvm/lib/Support/ErrorHandling.cpp |
| 125 | |
| 126 | // Blast the result out to stderr. We don't try hard to make sure this |
| 127 | // succeeds (e.g. handling EINTR) and we can't use errs() here because |
| 128 | // raw ostreams can call report_fatal_error. |
| 129 | llvm::SmallVector<char, 64> Buffer; |
| 130 | llvm::raw_svector_ostream OS(Buffer); |
| 131 | OS << "LLVM ERROR: " << Reason << "\n"; |
| 132 | llvm::StringRef MessageStr = OS.str(); |
Karl Schimpf | 4e6ea83 | 2015-10-02 12:42:47 -0700 | [diff] [blame] | 133 | ssize_t Written = |
| 134 | std::fwrite(MessageStr.data(), sizeof(char), MessageStr.size(), stderr); |
| 135 | (void)Written; // If something went wrong, we deliberately just give up. |
Karl Schimpf | db2fd9c | 2015-09-30 15:02:05 -0700 | [diff] [blame] | 136 | |
| 137 | // If we reached here, we are failing ungracefully. Run the interrupt handlers |
| 138 | // to make sure any special cleanups get done, in particular that we remove |
| 139 | // files registered with RemoveFileOnSignal. |
| 140 | llvm::sys::RunInterruptHandlers(); |
| 141 | |
| 142 | exit(0); |
| 143 | } |
| 144 | |
Jim Stichnoth | 686f35e | 2016-01-13 13:48:46 -0800 | [diff] [blame] | 145 | struct { |
| 146 | const char *FlagName; |
| 147 | bool FlagValue; |
| 148 | } ConditionalBuildAttributes[] = { |
| 149 | {"dump", BuildDefs::dump()}, |
| 150 | {"llvm_cl", BuildDefs::llvmCl()}, |
| 151 | {"llvm_ir", BuildDefs::llvmIr()}, |
| 152 | {"llvm_ir_as_input", BuildDefs::llvmIrAsInput()}, |
| 153 | {"minimal_build", BuildDefs::minimal()}, |
| 154 | {"browser_mode", BuildDefs::browser()}}; |
| 155 | |
| 156 | /// Dumps values of build attributes to Stream if Stream is non-null. |
| 157 | void dumpBuildAttributes(Ostream &Str) { |
| 158 | // List the supported targets. |
Jim Stichnoth | 84ea9a7 | 2016-09-09 09:33:07 -0700 | [diff] [blame^] | 159 | #define SUBZERO_TARGET(TARGET) Str << "target_" XSTRINGIFY(TARGET) "\n"; |
Jim Stichnoth | 999a22f | 2016-03-12 10:22:53 -0800 | [diff] [blame] | 160 | #include "SZTargets.def" |
Jim Stichnoth | 686f35e | 2016-01-13 13:48:46 -0800 | [diff] [blame] | 161 | const char *Prefix[2] = {"no", "allow"}; |
| 162 | for (size_t i = 0; i < llvm::array_lengthof(ConditionalBuildAttributes); |
| 163 | ++i) { |
| 164 | const auto &A = ConditionalBuildAttributes[i]; |
| 165 | Str << Prefix[A.FlagValue] << "_" << A.FlagName << "\n"; |
| 166 | } |
Jim Stichnoth | 54cf1a2 | 2016-08-08 14:15:00 -0700 | [diff] [blame] | 167 | Str << "revision_" << getSubzeroRevision() << "\n"; |
Jim Stichnoth | 686f35e | 2016-01-13 13:48:46 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 170 | } // end of anonymous namespace |
| 171 | |
| 172 | void CLCompileServer::run() { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 173 | if (BuildDefs::dump()) { |
Jim Stichnoth | efdf412 | 2016-08-17 09:12:52 -0700 | [diff] [blame] | 174 | #ifdef PNACL_LLVM |
Jan Voung | b2d5084 | 2015-05-12 09:53:50 -0700 | [diff] [blame] | 175 | llvm::sys::PrintStackTraceOnErrorSignal(); |
Jim Stichnoth | efdf412 | 2016-08-17 09:12:52 -0700 | [diff] [blame] | 176 | #else // !PNACL_LLVM |
| 177 | llvm::sys::PrintStackTraceOnErrorSignal(argv[0]); |
| 178 | #endif // !PNACL_LLVM |
Jan Voung | b2d5084 | 2015-05-12 09:53:50 -0700 | [diff] [blame] | 179 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 180 | ClFlags::parseFlags(argc, argv); |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 181 | ClFlags &Flags = ClFlags::Flags; |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 182 | ClFlags::getParsedClFlags(Flags); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 183 | |
Karl Schimpf | db2fd9c | 2015-09-30 15:02:05 -0700 | [diff] [blame] | 184 | // Override report_fatal_error if we want to exit with 0 status. |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 185 | if (Flags.getAlwaysExitSuccess()) |
Karl Schimpf | db2fd9c | 2015-09-30 15:02:05 -0700 | [diff] [blame] | 186 | llvm::install_fatal_error_handler(reportFatalErrorThenExitSuccess, this); |
| 187 | |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 188 | std::error_code EC; |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 189 | std::unique_ptr<Ostream> Ls = makeStream(Flags.getLogFilename(), EC); |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 190 | if (EC) { |
| 191 | llvm::report_fatal_error("Unable to open log file"); |
| 192 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 193 | Ls->SetUnbuffered(); |
David Sehr | 4c16ac0 | 2016-03-17 13:51:42 -0700 | [diff] [blame] | 194 | Ice::LinuxMallocProfiling _(Flags.getNumTranslationThreads(), Ls.get()); |
| 195 | |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 196 | std::unique_ptr<Ostream> Os; |
| 197 | std::unique_ptr<ELFStreamer> ELFStr; |
| 198 | switch (Flags.getOutFileType()) { |
| 199 | case FT_Elf: { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 200 | if (Flags.getOutputFilename() == "-" && !Flags.getGenerateBuildAtts()) { |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 201 | *Ls << "Error: writing binary ELF to stdout is unsupported\n"; |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 202 | return transferErrorCode(getReturnValue(Ice::EC_Args)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 203 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 204 | std::unique_ptr<llvm::raw_fd_ostream> FdOs(new llvm::raw_fd_ostream( |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 205 | Flags.getOutputFilename(), EC, llvm::sys::fs::F_None)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 206 | if (EC) { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 207 | *Ls << "Failed to open output file: " << Flags.getOutputFilename() |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 208 | << ":\n" << EC.message() << "\n"; |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 209 | return transferErrorCode(getReturnValue(Ice::EC_Args)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 210 | } |
| 211 | ELFStr.reset(new ELFStreamer(*FdOs.get())); |
| 212 | Os.reset(FdOs.release()); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 213 | // NaCl sets st_blksize to 0, and LLVM uses that to pick the default |
| 214 | // preferred buffer size. Set to something non-zero. |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 215 | Os->SetBufferSize(1 << 14); |
| 216 | } break; |
| 217 | case FT_Asm: |
| 218 | case FT_Iasm: { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 219 | Os = makeStream(Flags.getOutputFilename(), EC); |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 220 | if (EC) { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 221 | *Ls << "Failed to open output file: " << Flags.getOutputFilename() |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 222 | << ":\n" << EC.message() << "\n"; |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 223 | return transferErrorCode(getReturnValue(Ice::EC_Args)); |
Jim Stichnoth | 620ad73 | 2015-04-28 14:12:20 -0700 | [diff] [blame] | 224 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 225 | Os->SetUnbuffered(); |
| 226 | } break; |
| 227 | } |
| 228 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 229 | if (BuildDefs::minimal() && Flags.getBitcodeAsText()) |
Karl Schimpf | cb6e95a | 2015-07-23 09:10:03 -0700 | [diff] [blame] | 230 | llvm::report_fatal_error("Can't specify 'bitcode-as-text' flag in " |
| 231 | "minimal build"); |
| 232 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 233 | std::string StrError; |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 234 | std::unique_ptr<llvm::DataStreamer> InputStream( |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 235 | (!BuildDefs::minimal() && Flags.getBitcodeAsText()) |
| 236 | ? TextDataStreamer::create(Flags.getIRFilename(), &StrError) |
| 237 | : llvm::getDataFileStreamer(Flags.getIRFilename(), &StrError)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 238 | if (!StrError.empty() || !InputStream) { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 239 | llvm::SMDiagnostic Err(Flags.getIRFilename(), llvm::SourceMgr::DK_Error, |
| 240 | StrError); |
| 241 | Err.print(Flags.getAppName().c_str(), *Ls); |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 242 | return transferErrorCode(getReturnValue(Ice::EC_Bitcode)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 243 | } |
| 244 | |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 245 | if (Flags.getGenerateBuildAtts()) { |
Jim Stichnoth | 686f35e | 2016-01-13 13:48:46 -0800 | [diff] [blame] | 246 | dumpBuildAttributes(*Os.get()); |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 247 | return transferErrorCode(getReturnValue(Ice::EC_None)); |
Jim Stichnoth | 686f35e | 2016-01-13 13:48:46 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 250 | Ctx.reset(new GlobalContext(Ls.get(), Os.get(), Ls.get(), ELFStr.get())); |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 251 | |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 252 | if (!BuildDefs::minimal() && getFlags().getSanitizeAddresses()) { |
Thomas Lively | 3f5cb6f | 2016-06-13 11:23:29 -0700 | [diff] [blame] | 253 | std::unique_ptr<Instrumentation> Instr(new ASanInstrumentation(Ctx.get())); |
Thomas Lively | aab7099 | 2016-06-07 13:54:59 -0700 | [diff] [blame] | 254 | Ctx->setInstrumentation(std::move(Instr)); |
| 255 | } |
| 256 | |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 257 | if (getFlags().getNumTranslationThreads() != 0) { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 258 | std::thread CompileThread([this, &Flags, &InputStream]() { |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 259 | Ctx->initParserThread(); |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 260 | getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 261 | }); |
| 262 | CompileThread.join(); |
| 263 | } else { |
John Porto | c5bc5cb | 2016-03-21 11:18:02 -0700 | [diff] [blame] | 264 | getCompiler().run(Flags, *Ctx.get(), std::move(InputStream)); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 265 | } |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 266 | transferErrorCode( |
| 267 | getReturnValue(static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); |
Jim Stichnoth | 9f9aa2c | 2016-03-07 08:25:24 -0800 | [diff] [blame] | 268 | Ctx->dumpConstantLookupCounts(); |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame] | 269 | Ctx->dumpStrings(); |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | } // end of namespace Ice |