Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
Stephen Hines | 0a813a3 | 2012-08-03 16:52:40 -0700 | [diff] [blame] | 2 | * Copyright 2010-2012, The Android Open Source Project |
Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Stephen Hines | 8b5c5c6 | 2014-06-06 18:03:18 -0700 | [diff] [blame] | 17 | #include "clang/Basic/DiagnosticOptions.h" |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 18 | #include "clang/Driver/DriverDiagnostic.h" |
Stephen Hines | a1f95ee | 2013-08-09 01:26:08 -0700 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 20 | #include "clang/Frontend/CompilerInvocation.h" |
| 21 | #include "clang/Frontend/FrontendDiagnostic.h" |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 22 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 23 | #include "clang/Frontend/Utils.h" |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 24 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 25 | #include "llvm/ADT/SmallVector.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 26 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 27 | |
Stephen Hines | a1f95ee | 2013-08-09 01:26:08 -0700 | [diff] [blame] | 28 | #include "llvm/Option/OptTable.h" |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 29 | #include "llvm/Support/Allocator.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 30 | #include "llvm/Support/ManagedStatic.h" |
| 31 | #include "llvm/Support/MemoryBuffer.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 32 | #include "llvm/Support/Path.h" |
Stephen Hines | ba7c6dc | 2011-09-07 19:57:04 -0700 | [diff] [blame] | 33 | #include "llvm/Support/raw_ostream.h" |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 34 | #include "llvm/Support/Signals.h" |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 35 | #include "llvm/Support/StringSaver.h" |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 36 | #include "llvm/Target/TargetMachine.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 37 | |
Elliott Hughes | 9534de1 | 2015-07-29 14:07:37 -0700 | [diff] [blame] | 38 | #include "os_sep.h" |
Stephen Hines | 8b5c5c6 | 2014-06-06 18:03:18 -0700 | [diff] [blame] | 39 | #include "rs_cc_options.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 40 | #include "slang.h" |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 41 | #include "slang_assert.h" |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 42 | #include "slang_diagnostic_buffer.h" |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 43 | #include "slang_rs_reflect_utils.h" |
| 44 | |
Stephen Hines | 8b5c5c6 | 2014-06-06 18:03:18 -0700 | [diff] [blame] | 45 | #include <list> |
| 46 | #include <set> |
| 47 | #include <string> |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 48 | |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 49 | namespace { |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 50 | class StringSet : public llvm::StringSaver { |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 51 | public: |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 52 | const char *saveImpl(llvm::StringRef Str) override { |
| 53 | return Strings.insert(Str.str()).first->c_str(); |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 56 | StringSet() : llvm::StringSaver(A), A() {} |
| 57 | |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 58 | private: |
| 59 | std::set<std::string> Strings; |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 60 | llvm::BumpPtrAllocator A; |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 61 | }; |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 62 | } |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 63 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 64 | static const char *DetermineOutputFile(const std::string &OutputDir, |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 65 | const std::string &PathSuffix, |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 66 | const char *InputFile, |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 67 | slang::Slang::OutputType OutputType, |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 68 | StringSet *SavedStrings) { |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 69 | if (OutputType == slang::Slang::OT_Nothing) |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 70 | return "/dev/null"; |
| 71 | |
| 72 | std::string OutputFile(OutputDir); |
| 73 | |
Stephen Hines | 7f5704e | 2014-06-10 18:06:50 -0700 | [diff] [blame] | 74 | // Append '/' to Opts.mBitcodeOutputDir if not presents |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 75 | if (!OutputFile.empty() && |
Raphael | 8d5a2f6 | 2011-02-08 00:15:05 -0800 | [diff] [blame] | 76 | (OutputFile[OutputFile.size() - 1]) != OS_PATH_SEPARATOR) |
| 77 | OutputFile.append(1, OS_PATH_SEPARATOR); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 78 | |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 79 | if (!PathSuffix.empty()) { |
| 80 | OutputFile.append(PathSuffix); |
| 81 | OutputFile.append(1, OS_PATH_SEPARATOR); |
| 82 | } |
| 83 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 84 | if (OutputType == slang::Slang::OT_Dependency) { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 85 | // The build system wants the .d file name stem to be exactly the same as |
| 86 | // the source .rs file, instead of the .bc file. |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 87 | OutputFile.append(slang::RSSlangReflectUtils::GetFileNameStem(InputFile)); |
| 88 | } else { |
| 89 | OutputFile.append( |
| 90 | slang::RSSlangReflectUtils::BCFileNameFromRSFileName(InputFile)); |
| 91 | } |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 92 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 93 | switch (OutputType) { |
| 94 | case slang::Slang::OT_Dependency: { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 95 | OutputFile.append(".d"); |
| 96 | break; |
| 97 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 98 | case slang::Slang::OT_Assembly: { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 99 | OutputFile.append(".S"); |
| 100 | break; |
| 101 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 102 | case slang::Slang::OT_LLVMAssembly: { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 103 | OutputFile.append(".ll"); |
| 104 | break; |
| 105 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 106 | case slang::Slang::OT_Object: { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 107 | OutputFile.append(".o"); |
| 108 | break; |
| 109 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 110 | case slang::Slang::OT_Bitcode: { |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 111 | OutputFile.append(".bc"); |
| 112 | break; |
| 113 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 114 | case slang::Slang::OT_Nothing: |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 115 | default: { |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 116 | slangAssert(false && "Invalid output type!"); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Pirama Arumuga Nainar | 1906a00 | 2015-06-29 10:30:41 -0700 | [diff] [blame] | 120 | return SavedStrings->save(OutputFile.c_str()); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 123 | typedef std::list<std::pair<const char*, const char*> > NamePairList; |
| 124 | |
| 125 | /* |
| 126 | * Compile the Inputs. |
| 127 | * |
| 128 | * Returns 0 on success and nonzero on failure. |
| 129 | * |
| 130 | * IOFiles - list of (foo.rs, foo.bc) pairs of input/output files. |
| 131 | * IOFiles32 - list of input/output pairs for 32-bit compilation. |
| 132 | * Inputs - input filenames. |
| 133 | * Opts - options controlling compilation. |
| 134 | * DiagEngine - Clang diagnostic engine (for creating diagnostics). |
| 135 | * DiagClient - Slang diagnostic consumer (collects and displays diagnostics). |
| 136 | * SavedStrings - expanded strings copied from argv source input files. |
| 137 | * |
| 138 | * We populate IOFiles dynamically while working through the list of Inputs. |
| 139 | * On any 64-bit compilation, we pass back in the 32-bit pairs of files as |
| 140 | * IOFiles32. This allows the 64-bit compiler to later bundle up both the |
| 141 | * 32-bit and 64-bit bitcode outputs to be included in the final reflected |
| 142 | * source code that is emitted. |
| 143 | */ |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 144 | static void makeFileList(NamePairList *IOFiles, NamePairList *DepFiles, |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 145 | const llvm::SmallVector<const char*, 16> &Inputs, slang::RSCCOptions &Opts, |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 146 | StringSet *SavedStrings) { |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 147 | std::string PathSuffix = ""; |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 148 | // In our mixed 32/64-bit path, we need to suffix our files differently for |
| 149 | // both 32-bit and 64-bit versions. |
| 150 | if (Opts.mEmit3264) { |
| 151 | if (Opts.mBitWidth == 64) { |
| 152 | PathSuffix = "bc64"; |
| 153 | } else { |
| 154 | PathSuffix = "bc32"; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | for (int i = 0, e = Inputs.size(); i != e; i++) { |
| 159 | const char *InputFile = Inputs[i]; |
| 160 | |
| 161 | const char *BCOutputFile = DetermineOutputFile(Opts.mBitcodeOutputDir, |
| 162 | PathSuffix, InputFile, |
Yang Ni | 76837a1 | 2015-04-28 17:30:51 -0700 | [diff] [blame] | 163 | Opts.mOutputType, |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 164 | SavedStrings); |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 165 | const char *OutputFile = BCOutputFile; |
| 166 | |
| 167 | if (Opts.mEmitDependency) { |
| 168 | // The dependency file is always emitted without a PathSuffix. |
| 169 | // Collisions between 32-bit and 64-bit files don't make a difference, |
| 170 | // because they share the same sources/dependencies. |
| 171 | const char *DepOutputFile = |
| 172 | DetermineOutputFile(Opts.mDependencyOutputDir, "", InputFile, |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 173 | slang::Slang::OT_Dependency, SavedStrings); |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 174 | if (Opts.mOutputType == slang::Slang::OT_Dependency) { |
| 175 | OutputFile = DepOutputFile; |
| 176 | } |
| 177 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 178 | DepFiles->push_back(std::make_pair(BCOutputFile, DepOutputFile)); |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | IOFiles->push_back(std::make_pair(InputFile, OutputFile)); |
| 182 | } |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Stephen Hines | ba7c6dc | 2011-09-07 19:57:04 -0700 | [diff] [blame] | 185 | #define str(s) #s |
| 186 | #define wrap_str(s) str(s) |
| 187 | static void llvm_rs_cc_VersionPrinter() { |
| 188 | llvm::raw_ostream &OS = llvm::outs(); |
| 189 | OS << "llvm-rs-cc: Renderscript compiler\n" |
| 190 | << " (http://developer.android.com/guide/topics/renderscript)\n" |
| 191 | << " based on LLVM (http://llvm.org):\n"; |
| 192 | OS << " Built " << __DATE__ << " (" << __TIME__ ").\n"; |
| 193 | OS << " Target APIs: " << SLANG_MINIMUM_TARGET_API << " - " |
| 194 | << SLANG_MAXIMUM_TARGET_API; |
| 195 | OS << "\n Build type: " << wrap_str(TARGET_BUILD_VARIANT); |
| 196 | #ifndef __DISABLE_ASSERTS |
| 197 | OS << " with assertions"; |
| 198 | #endif |
| 199 | OS << ".\n"; |
Stephen Hines | ba7c6dc | 2011-09-07 19:57:04 -0700 | [diff] [blame] | 200 | } |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 201 | #undef wrap_str |
| 202 | #undef str |
Stephen Hines | ba7c6dc | 2011-09-07 19:57:04 -0700 | [diff] [blame] | 203 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 204 | static void LLVMErrorHandler(void *UserData, const std::string &Message, |
| 205 | bool GenCrashDialog) { |
| 206 | clang::DiagnosticsEngine *DiagEngine = |
| 207 | static_cast<clang::DiagnosticsEngine *>(UserData); |
| 208 | |
| 209 | DiagEngine->Report(clang::diag::err_fe_error_backend) << Message; |
| 210 | |
| 211 | // Run the interrupt handlers to make sure any special cleanups get done, in |
| 212 | // particular that we remove files registered with RemoveFileOnSignal. |
| 213 | llvm::sys::RunInterruptHandlers(); |
| 214 | |
| 215 | exit(1); |
| 216 | } |
| 217 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 218 | int main(int argc, const char **argv) { |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 219 | llvm::llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 220 | LLVMInitializeARMTargetInfo(); |
| 221 | LLVMInitializeARMTarget(); |
| 222 | LLVMInitializeARMAsmPrinter(); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 223 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 224 | StringSet SavedStrings; // Keeps track of strings to be destroyed at the end. |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 225 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 226 | // Parse the command line arguments and respond to show help & version |
| 227 | // commands. |
| 228 | llvm::SmallVector<const char *, 16> Inputs; |
Jean-Luc Brouillet | c247363 | 2015-05-14 13:07:47 -0700 | [diff] [blame] | 229 | slang::RSCCOptions Opts; |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 230 | llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts = |
| 231 | new clang::DiagnosticOptions(); |
| 232 | if (!slang::ParseArguments(llvm::makeArrayRef(argv, argc), Inputs, Opts, |
| 233 | *DiagOpts, SavedStrings)) { |
| 234 | // Exits when there's any error occurred during parsing the arguments |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 235 | return 1; |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 236 | } |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 237 | if (Opts.mShowHelp) { |
Stephen Hines | 7ac9d0d | 2014-07-15 16:50:03 -0700 | [diff] [blame] | 238 | std::unique_ptr<llvm::opt::OptTable> OptTbl(slang::createRSCCOptTable()); |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 239 | const std::string Argv0 = llvm::sys::path::stem(argv[0]); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 240 | OptTbl->PrintHelp(llvm::outs(), Argv0.c_str(), |
Stephen Hines | b7d1269 | 2011-09-02 18:16:19 -0700 | [diff] [blame] | 241 | "Renderscript source compiler"); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 242 | return 0; |
| 243 | } |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 244 | if (Opts.mShowVersion) { |
Stephen Hines | ba7c6dc | 2011-09-07 19:57:04 -0700 | [diff] [blame] | 245 | llvm_rs_cc_VersionPrinter(); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 249 | // Initialize the diagnostic objects |
| 250 | llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagIDs( |
| 251 | new clang::DiagnosticIDs()); |
| 252 | slang::DiagnosticBuffer DiagsBuffer; |
| 253 | clang::DiagnosticsEngine DiagEngine(DiagIDs, &*DiagOpts, &DiagsBuffer, false); |
| 254 | clang::ProcessWarningOptions(DiagEngine, *DiagOpts); |
| 255 | (void)DiagEngine.setSeverityForGroup(clang::diag::Flavor::WarningOrError, |
| 256 | "implicit-function-declaration", |
| 257 | clang::diag::Severity::Error); |
| 258 | |
| 259 | // Report error if no input file |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 260 | if (Inputs.empty()) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 261 | DiagEngine.Report(clang::diag::err_drv_no_input_files); |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 262 | llvm::errs() << DiagsBuffer.str(); |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 263 | return 1; |
| 264 | } |
| 265 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 266 | llvm::install_fatal_error_handler(LLVMErrorHandler, &DiagEngine); |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 267 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 268 | // Compile the 32 bit version |
| 269 | NamePairList IOFiles32; |
| 270 | NamePairList DepFiles32; |
| 271 | makeFileList(&IOFiles32, &DepFiles32, Inputs, Opts, &SavedStrings); |
| 272 | |
Miao Wang | bfbdd98 | 2015-06-25 15:04:35 -0700 | [diff] [blame] | 273 | int CompileFailed = 0; |
| 274 | // Handle 32-bit case for Java and C++ reflection. |
| 275 | // For Java, both 32bit and 64bit will be generated. |
| 276 | // For C++, either 64bit or 32bit will be generated based on the target. |
| 277 | if (Opts.mEmit3264 || Opts.mBitWidth == 32) { |
| 278 | std::unique_ptr<slang::Slang> Compiler( |
| 279 | new slang::Slang(32, &DiagEngine, &DiagsBuffer)); |
| 280 | CompileFailed = |
| 281 | !Compiler->compile(IOFiles32, IOFiles32, DepFiles32, Opts, *DiagOpts); |
| 282 | } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 283 | |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 284 | // Handle the 64-bit case too! |
Miao Wang | bfbdd98 | 2015-06-25 15:04:35 -0700 | [diff] [blame] | 285 | bool needEmit64 = Opts.mEmit3264 || Opts.mBitWidth == 64; |
| 286 | if (needEmit64 && !CompileFailed) { |
Stephen Hines | 9ae18b2 | 2014-06-10 23:53:00 -0700 | [diff] [blame] | 287 | Opts.mBitWidth = 64; |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 288 | NamePairList IOFiles64; |
| 289 | NamePairList DepFiles64; |
| 290 | makeFileList(&IOFiles64, &DepFiles64, Inputs, Opts, &SavedStrings); |
| 291 | |
| 292 | std::unique_ptr<slang::Slang> Compiler( |
| 293 | new slang::Slang(64, &DiagEngine, &DiagsBuffer)); |
| 294 | CompileFailed = |
| 295 | !Compiler->compile(IOFiles64, IOFiles32, DepFiles64, Opts, *DiagOpts); |
Zonr Chang | cf6af6a | 2010-10-12 12:38:51 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Jean-Luc Brouillet | 5309b0c | 2015-05-01 16:13:11 -0700 | [diff] [blame] | 298 | llvm::errs() << DiagsBuffer.str(); |
| 299 | llvm::remove_fatal_error_handler(); |
Stephen Hines | d7f0ea2 | 2011-02-22 17:45:19 -0800 | [diff] [blame] | 300 | return CompileFailed; |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 301 | } |