Zonr Chang | c383a50 | 2010-10-12 01:52:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010, The Android Open Source Project |
| 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 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 17 | #include "slang.h" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 18 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include "clang/AST/ASTConsumer.h" |
| 25 | #include "clang/AST/ASTContext.h" |
| 26 | |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 27 | #include "clang/Basic/DiagnosticIDs.h" |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 28 | #include "clang/Basic/DiagnosticOptions.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 29 | #include "clang/Basic/FileManager.h" |
Shih-wei Liao | df5bcce | 2011-02-28 18:39:23 -0800 | [diff] [blame] | 30 | #include "clang/Basic/FileSystemOptions.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 31 | #include "clang/Basic/LangOptions.h" |
| 32 | #include "clang/Basic/SourceManager.h" |
| 33 | #include "clang/Basic/TargetInfo.h" |
| 34 | #include "clang/Basic/TargetOptions.h" |
| 35 | |
| 36 | #include "clang/Frontend/CodeGenOptions.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 37 | #include "clang/Frontend/DependencyOutputOptions.h" |
| 38 | #include "clang/Frontend/FrontendDiagnostic.h" |
| 39 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 40 | #include "clang/Frontend/Utils.h" |
| 41 | |
| 42 | #include "clang/Lex/Preprocessor.h" |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 43 | #include "clang/Lex/PreprocessorOptions.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 44 | #include "clang/Lex/HeaderSearch.h" |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 45 | #include "clang/Lex/HeaderSearchOptions.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 46 | |
| 47 | #include "clang/Parse/ParseAST.h" |
| 48 | |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 49 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 50 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 51 | #include "llvm/Bitcode/ReaderWriter.h" |
| 52 | |
| 53 | // More force linking |
| 54 | #include "llvm/Linker.h" |
| 55 | |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 56 | // Force linking all passes/vmcore stuffs to libslang.so |
Stephen Hines | 0da7f6c | 2013-03-05 15:19:02 -0800 | [diff] [blame] | 57 | #include "llvm/LinkAllIR.h" |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 58 | #include "llvm/LinkAllPasses.h" |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 59 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 60 | #include "llvm/Support/raw_ostream.h" |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 61 | #include "llvm/Support/MemoryBuffer.h" |
| 62 | #include "llvm/Support/ErrorHandling.h" |
| 63 | #include "llvm/Support/ManagedStatic.h" |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 64 | #include "llvm/Support/Path.h" |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 65 | #include "llvm/Support/TargetSelect.h" |
| 66 | #include "llvm/Support/ToolOutputFile.h" |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 67 | |
Stephen Hines | 6e6578a | 2011-02-07 18:05:48 -0800 | [diff] [blame] | 68 | #include "slang_assert.h" |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 69 | #include "slang_backend.h" |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 70 | #include "slang_utils.h" |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 71 | |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 72 | namespace { |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 73 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 74 | struct ForceSlangLinking { |
| 75 | ForceSlangLinking() { |
| 76 | // We must reference the functions in such a way that compilers will not |
| 77 | // delete it all as dead code, even with whole program optimization, |
| 78 | // yet is effectively a NO-OP. As the compiler isn't smart enough |
| 79 | // to know that getenv() never returns -1, this will do the job. |
| 80 | if (std::getenv("bar") != reinterpret_cast<char*>(-1)) |
| 81 | return; |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 82 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 83 | // llvm-rs-link needs following functions existing in libslang. |
| 84 | llvm::ParseBitcodeFile(NULL, llvm::getGlobalContext(), NULL); |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 85 | llvm::Linker::LinkModules(NULL, NULL, 0, NULL); |
Zonr Chang | 08df36e | 2010-10-07 18:50:42 +0800 | [diff] [blame] | 86 | |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 87 | // llvm-rs-cc need this. |
| 88 | new clang::TextDiagnosticPrinter(llvm::errs(), |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 89 | new clang::DiagnosticOptions()); |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 90 | } |
| 91 | } ForceSlangLinking; |
| 92 | |
| 93 | } // namespace |
| 94 | |
| 95 | namespace slang { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 96 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 97 | #if defined(__arm__) |
| 98 | # define DEFAULT_TARGET_TRIPLE_STRING "armv7-none-linux-gnueabi" |
| 99 | #elif defined(__x86_64__) |
| 100 | # define DEFAULT_TARGET_TRIPLE_STRING "x86_64-unknown-linux" |
| 101 | #else |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 102 | // let's use x86 as default target |
| 103 | # define DEFAULT_TARGET_TRIPLE_STRING "i686-unknown-linux" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 104 | #endif |
| 105 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 106 | bool Slang::GlobalInitialized = false; |
| 107 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 108 | // Language option (define the language feature for compiler such as C99) |
| 109 | clang::LangOptions Slang::LangOpts; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 110 | |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 111 | // Code generation option for the compiler |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 112 | clang::CodeGenOptions Slang::CodeGenOpts; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 113 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 114 | // The named of metadata node that pragma resides (should be synced with |
| 115 | // bcc.cpp) |
Shih-wei Liao | f52a620 | 2010-09-10 17:40:53 -0700 | [diff] [blame] | 116 | const llvm::StringRef Slang::PragmaMetadataName = "#pragma"; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 117 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 118 | static inline llvm::tool_output_file * |
| 119 | OpenOutputFile(const char *OutputFile, |
| 120 | unsigned Flags, |
| 121 | std::string* Error, |
Stephen Hines | e67239d | 2012-02-24 15:08:36 -0800 | [diff] [blame] | 122 | clang::DiagnosticsEngine *DiagEngine) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 123 | slangAssert((OutputFile != NULL) && (Error != NULL) && |
| 124 | (DiagEngine != NULL) && "Invalid parameter!"); |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 125 | |
Logan Chien | 6f4e0a9 | 2011-03-10 01:10:25 +0800 | [diff] [blame] | 126 | if (SlangUtils::CreateDirectoryWithParents( |
| 127 | llvm::sys::path::parent_path(OutputFile), Error)) { |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 128 | llvm::tool_output_file *F = |
| 129 | new llvm::tool_output_file(OutputFile, *Error, Flags); |
| 130 | if (F != NULL) |
| 131 | return F; |
| 132 | } |
| 133 | |
| 134 | // Report error here. |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 135 | DiagEngine->Report(clang::diag::err_fe_error_opening) |
| 136 | << OutputFile << *Error; |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 137 | |
| 138 | return NULL; |
| 139 | } |
| 140 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 141 | void Slang::GlobalInitialization() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 142 | if (!GlobalInitialized) { |
| 143 | // We only support x86, x64 and ARM target |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 144 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 145 | // For ARM |
| 146 | LLVMInitializeARMTargetInfo(); |
| 147 | LLVMInitializeARMTarget(); |
| 148 | LLVMInitializeARMAsmPrinter(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 149 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 150 | // For x86 and x64 |
| 151 | LLVMInitializeX86TargetInfo(); |
| 152 | LLVMInitializeX86Target(); |
| 153 | LLVMInitializeX86AsmPrinter(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 154 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 155 | // Please refer to include/clang/Basic/LangOptions.h to setup |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 156 | // the options. |
| 157 | LangOpts.RTTI = 0; // Turn off the RTTI information support |
Shih-wei Liao | 245eba1 | 2011-01-19 02:14:07 -0800 | [diff] [blame] | 158 | LangOpts.C99 = 1; |
Stephen Hines | 52d132c | 2012-08-01 18:48:06 -0700 | [diff] [blame] | 159 | LangOpts.Renderscript = 1; |
Stephen Hines | 194d403 | 2012-02-27 18:01:09 -0800 | [diff] [blame] | 160 | LangOpts.CharIsSigned = 1; // Signed char is our default. |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 161 | |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 162 | CodeGenOpts.OptimizationLevel = 3; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 163 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 164 | GlobalInitialized = true; |
| 165 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void Slang::LLVMErrorHandler(void *UserData, const std::string &Message) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 169 | clang::DiagnosticsEngine* DiagEngine = |
| 170 | static_cast<clang::DiagnosticsEngine *>(UserData); |
| 171 | |
| 172 | DiagEngine->Report(clang::diag::err_fe_error_backend) << Message; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 173 | exit(1); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 176 | void Slang::createTarget(const std::string &Triple, const std::string &CPU, |
| 177 | const std::vector<std::string> &Features) { |
| 178 | if (!Triple.empty()) |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 179 | mTargetOpts->Triple = Triple; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 180 | else |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 181 | mTargetOpts->Triple = DEFAULT_TARGET_TRIPLE_STRING; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 182 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 183 | if (!CPU.empty()) |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 184 | mTargetOpts->CPU = CPU; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 185 | |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 186 | if (!Features.empty()) |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 187 | mTargetOpts->FeaturesAsWritten = Features; |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 188 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 189 | mTarget.reset(clang::TargetInfo::CreateTargetInfo(*mDiagEngine, |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 190 | mTargetOpts.getPtr())); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 193 | void Slang::createFileManager() { |
Shih-wei Liao | df5bcce | 2011-02-28 18:39:23 -0800 | [diff] [blame] | 194 | mFileSysOpt.reset(new clang::FileSystemOptions()); |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 195 | mFileMgr.reset(new clang::FileManager(*mFileSysOpt)); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void Slang::createSourceManager() { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 199 | mSourceMgr.reset(new clang::SourceManager(*mDiagEngine, *mFileMgr)); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 200 | } |
| 201 | |
Shih-wei Liao | 68e8e9f | 2010-07-18 18:46:49 -0700 | [diff] [blame] | 202 | void Slang::createPreprocessor() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 203 | // Default only search header file in current dir |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 204 | llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions> HSOpts = |
| 205 | new clang::HeaderSearchOptions(); |
| 206 | clang::HeaderSearch *HeaderInfo = new clang::HeaderSearch(HSOpts, |
| 207 | *mFileMgr, |
Stephen Hines | 0444de0 | 2012-03-02 23:19:06 -0800 | [diff] [blame] | 208 | *mDiagEngine, |
| 209 | LangOpts, |
| 210 | mTarget.get()); |
Shih-wei Liao | 68e8e9f | 2010-07-18 18:46:49 -0700 | [diff] [blame] | 211 | |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 212 | llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions> PPOpts = |
| 213 | new clang::PreprocessorOptions(); |
| 214 | mPP.reset(new clang::Preprocessor(PPOpts, |
| 215 | *mDiagEngine, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 216 | LangOpts, |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 217 | mTarget.get(), |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 218 | *mSourceMgr, |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 219 | *HeaderInfo, |
| 220 | *this, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 221 | NULL, |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 222 | /* OwnsHeaderSearch = */true)); |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 223 | // Initialize the preprocessor |
Shih-wei Liao | 68e8e9f | 2010-07-18 18:46:49 -0700 | [diff] [blame] | 224 | mPragmas.clear(); |
Stephen Hines | 3fd0a94 | 2011-01-18 12:27:39 -0800 | [diff] [blame] | 225 | mPP->AddPragmaHandler(new PragmaRecorder(&mPragmas)); |
Shih-wei Liao | 68e8e9f | 2010-07-18 18:46:49 -0700 | [diff] [blame] | 226 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 227 | std::vector<clang::DirectoryLookup> SearchList; |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 228 | for (unsigned i = 0, e = mIncludePaths.size(); i != e; i++) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 229 | if (const clang::DirectoryEntry *DE = |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 230 | mFileMgr->getDirectory(mIncludePaths[i])) { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 231 | SearchList.push_back(clang::DirectoryLookup(DE, |
| 232 | clang::SrcMgr::C_System, |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 233 | false)); |
| 234 | } |
Shih-wei Liao | 9089828 | 2010-07-19 18:38:57 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 237 | HeaderInfo->SetSearchPaths(SearchList, |
| 238 | /* angledDirIdx = */1, |
| 239 | /* systemDixIdx = */1, |
| 240 | /* noCurDirSearch = */false); |
Shih-wei Liao | 9089828 | 2010-07-19 18:38:57 -0700 | [diff] [blame] | 241 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 242 | initPreprocessor(); |
Shih-wei Liao | 68e8e9f | 2010-07-18 18:46:49 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 245 | void Slang::createASTContext() { |
| 246 | mASTContext.reset(new clang::ASTContext(LangOpts, |
| 247 | *mSourceMgr, |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 248 | mTarget.get(), |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 249 | mPP->getIdentifierTable(), |
| 250 | mPP->getSelectorTable(), |
| 251 | mPP->getBuiltinInfo(), |
| 252 | /* size_reserve = */0)); |
| 253 | initASTContext(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 254 | } |
| 255 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 256 | clang::ASTConsumer * |
| 257 | Slang::createBackend(const clang::CodeGenOptions& CodeGenOpts, |
| 258 | llvm::raw_ostream *OS, OutputType OT) { |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 259 | return new Backend(mDiagEngine, CodeGenOpts, getTargetOptions(), |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 260 | &mPragmas, OS, OT); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 261 | } |
| 262 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 263 | Slang::Slang() : mInitialized(false), mDiagClient(NULL), mOT(OT_Default) { |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 264 | mTargetOpts = new clang::TargetOptions(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 265 | GlobalInitialization(); |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void Slang::init(const std::string &Triple, const std::string &CPU, |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 269 | const std::vector<std::string> &Features, |
| 270 | clang::DiagnosticsEngine *DiagEngine, |
| 271 | DiagnosticBuffer *DiagClient) { |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 272 | if (mInitialized) |
| 273 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 274 | |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 275 | mDiagEngine = DiagEngine; |
| 276 | mDiagClient = DiagClient; |
| 277 | mDiag.reset(new clang::Diagnostic(mDiagEngine)); |
| 278 | initDiagnostic(); |
| 279 | llvm::install_fatal_error_handler(LLVMErrorHandler, mDiagEngine); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 280 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 281 | createTarget(Triple, CPU, Features); |
| 282 | createFileManager(); |
| 283 | createSourceManager(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 284 | |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 285 | mInitialized = true; |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 286 | } |
Zonr Chang | 641558f | 2010-10-12 21:07:06 +0800 | [diff] [blame] | 287 | |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 288 | clang::ModuleLoadResult Slang::loadModule( |
| 289 | clang::SourceLocation ImportLoc, |
| 290 | clang::ModuleIdPath Path, |
| 291 | clang::Module::NameVisibilityKind Visibility, |
| 292 | bool IsInclusionDirective) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 293 | slangAssert(0 && "Not implemented"); |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 294 | return clang::ModuleLoadResult(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 297 | bool Slang::setInputSource(llvm::StringRef InputFile, |
| 298 | const char *Text, |
| 299 | size_t TextLength) { |
| 300 | mInputFileName = InputFile.str(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 301 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 302 | // Reset the ID tables if we are reusing the SourceManager |
| 303 | mSourceMgr->clearIDTables(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 304 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 305 | // Load the source |
zonr | 6315f76 | 2010-10-05 15:35:14 +0800 | [diff] [blame] | 306 | llvm::MemoryBuffer *SB = |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 307 | llvm::MemoryBuffer::getMemBuffer(Text, Text + TextLength); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 308 | mSourceMgr->createMainFileIDForMemBuffer(SB); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 309 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 310 | if (mSourceMgr->getMainFileID().isInvalid()) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 311 | mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 312 | return false; |
| 313 | } |
| 314 | return true; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 317 | bool Slang::setInputSource(llvm::StringRef InputFile) { |
| 318 | mInputFileName = InputFile.str(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 319 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 320 | mSourceMgr->clearIDTables(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 321 | |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 322 | const clang::FileEntry *File = mFileMgr->getFile(InputFile); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 323 | if (File) |
| 324 | mSourceMgr->createMainFileID(File); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 325 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 326 | if (mSourceMgr->getMainFileID().isInvalid()) { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 327 | mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 328 | return false; |
| 329 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 330 | |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 331 | return true; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 334 | bool Slang::setOutput(const char *OutputFile) { |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 335 | llvm::sys::Path OutputFilePath(OutputFile); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 336 | std::string Error; |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 337 | llvm::tool_output_file *OS = NULL; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 338 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 339 | switch (mOT) { |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 340 | case OT_Dependency: |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 341 | case OT_Assembly: |
| 342 | case OT_LLVMAssembly: { |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 343 | OS = OpenOutputFile(OutputFile, 0, &Error, mDiagEngine); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 344 | break; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 345 | } |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 346 | case OT_Nothing: { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 347 | break; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 348 | } |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 349 | case OT_Object: |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 350 | case OT_Bitcode: { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 351 | OS = OpenOutputFile(OutputFile, llvm::raw_fd_ostream::F_Binary, |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 352 | &Error, mDiagEngine); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 353 | break; |
| 354 | } |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 355 | default: { |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 356 | llvm_unreachable("Unknown compiler output type"); |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 357 | } |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 358 | } |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 359 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 360 | if (!Error.empty()) |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 361 | return false; |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 362 | |
| 363 | mOS.reset(OS); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 364 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 365 | mOutputFileName = OutputFile; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 366 | |
| 367 | return true; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 370 | bool Slang::setDepOutput(const char *OutputFile) { |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 371 | llvm::sys::Path OutputFilePath(OutputFile); |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 372 | std::string Error; |
Zonr Chang | 8c6d9b2 | 2010-10-07 18:01:19 +0800 | [diff] [blame] | 373 | |
Stephen Hines | 8f4d972 | 2011-12-05 14:14:42 -0800 | [diff] [blame] | 374 | mDOS.reset(OpenOutputFile(OutputFile, 0, &Error, mDiagEngine)); |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 375 | if (!Error.empty() || (mDOS.get() == NULL)) |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 376 | return false; |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 377 | |
| 378 | mDepOutputFileName = OutputFile; |
| 379 | |
| 380 | return true; |
| 381 | } |
| 382 | |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 383 | int Slang::generateDepFile() { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 384 | if (mDiagEngine->hasErrorOccurred()) |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 385 | return 1; |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 386 | if (mDOS.get() == NULL) |
Stephen Hines | f7de852 | 2010-10-06 11:46:18 -0700 | [diff] [blame] | 387 | return 1; |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 388 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 389 | // Initialize options for generating dependency file |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 390 | clang::DependencyOutputOptions DepOpts; |
| 391 | DepOpts.IncludeSystemHeaders = 1; |
Stephen Hines | 0b7ef1a | 2010-10-07 16:36:59 -0700 | [diff] [blame] | 392 | DepOpts.OutputFile = mDepOutputFileName; |
Shih-wei Liao | b81c6a4 | 2010-10-10 14:15:00 -0700 | [diff] [blame] | 393 | DepOpts.Targets = mAdditionalDepTargets; |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 394 | DepOpts.Targets.push_back(mDepTargetBCFileName); |
Stephen Hines | 4cc67fc | 2011-01-31 16:48:57 -0800 | [diff] [blame] | 395 | for (std::vector<std::string>::const_iterator |
| 396 | I = mGeneratedFileNames.begin(), E = mGeneratedFileNames.end(); |
| 397 | I != E; |
| 398 | I++) { |
| 399 | DepOpts.Targets.push_back(*I); |
| 400 | } |
| 401 | mGeneratedFileNames.clear(); |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 402 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 403 | // Per-compilation needed initialization |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 404 | createPreprocessor(); |
| 405 | AttachDependencyFileGen(*mPP.get(), DepOpts); |
| 406 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 407 | // Inform the diagnostic client we are processing a source file |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 408 | mDiagClient->BeginSourceFile(LangOpts, mPP.get()); |
| 409 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 410 | // Go through the source file (no operations necessary) |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 411 | clang::Token Tok; |
| 412 | mPP->EnterMainSourceFile(); |
| 413 | do { |
| 414 | mPP->Lex(Tok); |
| 415 | } while (Tok.isNot(clang::tok::eof)); |
| 416 | |
| 417 | mPP->EndSourceFile(); |
| 418 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 419 | // Declare success if no error |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 420 | if (!mDiagEngine->hasErrorOccurred()) |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 421 | mDOS->keep(); |
| 422 | |
| 423 | // Clean up after compilation |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 424 | mPP.reset(); |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 425 | mDOS.reset(); |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 426 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 427 | return mDiagEngine->hasErrorOccurred() ? 1 : 0; |
Stephen Hines | cc0efad | 2010-10-04 16:13:02 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 430 | int Slang::compile() { |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 431 | if (mDiagEngine->hasErrorOccurred()) |
Logan | be27482 | 2011-02-16 22:02:54 +0800 | [diff] [blame] | 432 | return 1; |
Stephen Hines | f7de852 | 2010-10-06 11:46:18 -0700 | [diff] [blame] | 433 | if (mOS.get() == NULL) |
| 434 | return 1; |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 435 | |
| 436 | // Here is per-compilation needed initialization |
| 437 | createPreprocessor(); |
| 438 | createASTContext(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 439 | |
Shih-wei Liao | df5bcce | 2011-02-28 18:39:23 -0800 | [diff] [blame] | 440 | mBackend.reset(createBackend(CodeGenOpts, &mOS->os(), mOT)); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 441 | |
| 442 | // Inform the diagnostic client we are processing a source file |
| 443 | mDiagClient->BeginSourceFile(LangOpts, mPP.get()); |
| 444 | |
| 445 | // The core of the slang compiler |
| 446 | ParseAST(*mPP, mBackend.get(), *mASTContext); |
| 447 | |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 448 | // Inform the diagnostic client we are done with previous source file |
| 449 | mDiagClient->EndSourceFile(); |
| 450 | |
| 451 | // Declare success if no error |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 452 | if (!mDiagEngine->hasErrorOccurred()) |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 453 | mOS->keep(); |
| 454 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 455 | // The compilation ended, clear |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 456 | mBackend.reset(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 457 | mASTContext.reset(); |
| 458 | mPP.reset(); |
Zonr Chang | e8c263a | 2010-10-12 00:35:29 +0800 | [diff] [blame] | 459 | mOS.reset(); |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 460 | |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 461 | return mDiagEngine->hasErrorOccurred() ? 1 : 0; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 462 | } |
| 463 | |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 464 | void Slang::setDebugMetadataEmission(bool EmitDebug) { |
Shih-wei Liao | 43730fe | 2012-08-02 23:06:18 -0700 | [diff] [blame] | 465 | if (EmitDebug) |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 466 | CodeGenOpts.setDebugInfo(clang::CodeGenOptions::FullDebugInfo); |
Shih-wei Liao | 43730fe | 2012-08-02 23:06:18 -0700 | [diff] [blame] | 467 | else |
Stephen Hines | 23c4358 | 2013-01-09 20:02:04 -0800 | [diff] [blame] | 468 | CodeGenOpts.setDebugInfo(clang::CodeGenOptions::NoDebugInfo); |
mkopec1 | c460b37 | 2012-01-09 11:21:50 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void Slang::setOptimizationLevel(llvm::CodeGenOpt::Level OptimizationLevel) { |
| 472 | CodeGenOpts.OptimizationLevel = OptimizationLevel; |
| 473 | } |
| 474 | |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 475 | void Slang::reset() { |
Stephen Hines | c632be2 | 2011-09-23 15:53:16 -0700 | [diff] [blame] | 476 | llvm::errs() << mDiagClient->str(); |
Logan Chien | 9207a2e | 2011-10-21 15:39:28 +0800 | [diff] [blame] | 477 | mDiagEngine->Reset(); |
Zonr Chang | 3a9ca1f | 2010-10-06 17:52:56 +0800 | [diff] [blame] | 478 | mDiagClient->reset(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | Slang::~Slang() { |
Shih-wei Liao | 9ef2f78 | 2010-10-01 12:31:37 -0700 | [diff] [blame] | 482 | llvm::llvm_shutdown(); |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 483 | } |
Stephen Hines | e639eb5 | 2010-11-08 19:27:20 -0800 | [diff] [blame] | 484 | |
| 485 | } // namespace slang |