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