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