slang.cpp revision e67239de8d94975e7e2216ee6860ae2e6cb8b15a
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 2c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Copyright 2010, The Android Open Source Project 3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License. 6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at 7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software 11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and 14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License. 15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */ 16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang 176315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang.h" 18462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 196315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include <stdlib.h> 20462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 21e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <string> 22e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <vector> 238c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang 24e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/ASTConsumer.h" 25e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/AST/ASTContext.h" 26462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 27be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "clang/Basic/DiagnosticIDs.h" 28e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Basic/FileManager.h" 29df5bcce1582d839eead432a5e24435236c90fb05Shih-wei Liao#include "clang/Basic/FileSystemOptions.h" 306315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/Basic/LangOptions.h" 313a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#include "clang/Basic/SourceManager.h" 323a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#include "clang/Basic/TargetInfo.h" 336315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/Basic/TargetOptions.h" 34462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 35e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Frontend/CodeGenOptions.h" 36e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Frontend/DiagnosticOptions.h" 37cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines#include "clang/Frontend/DependencyOutputOptions.h" 38cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines#include "clang/Frontend/FrontendDiagnostic.h" 39e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Frontend/TextDiagnosticPrinter.h" 40cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines#include "clang/Frontend/Utils.h" 41cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 423a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#include "clang/Lex/Preprocessor.h" 433a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang#include "clang/Lex/HeaderSearch.h" 443a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 456315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "clang/Parse/ParseAST.h" 466315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 47be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "llvm/ADT/IntrusiveRefCntPtr.h" 48be27482cdeaf08576bc39b72a15d35d13014a636Logan 49e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Bitcode/ReaderWriter.h" 509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 5108df36e5c0a990306d958c9f6d59a5de23b748f6Zonr Chang// More force linking 5208df36e5c0a990306d958c9f6d59a5de23b748f6Zonr Chang#include "llvm/Linker.h" 5308df36e5c0a990306d958c9f6d59a5de23b748f6Zonr Chang 54e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines// Force linking all passes/vmcore stuffs to libslang.so 55e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/LinkAllPasses.h" 56e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/LinkAllVMCore.h" 57e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 58e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/raw_ostream.h" 59e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/MemoryBuffer.h" 60e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/ErrorHandling.h" 61e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/Support/ManagedStatic.h" 62be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "llvm/Support/Path.h" 639207a2e495c8363606861e4f034504ec5c153dabLogan Chien#include "llvm/Support/TargetSelect.h" 649207a2e495c8363606861e4f034504ec5c153dabLogan Chien#include "llvm/Support/ToolOutputFile.h" 65e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 666e6578a360497f78a181e63d7783422a9c9bfb15Stephen Hines#include "slang_assert.h" 67e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "slang_backend.h" 68e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "slang_utils.h" 69b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao 7008df36e5c0a990306d958c9f6d59a5de23b748f6Zonr Changnamespace { 7108df36e5c0a990306d958c9f6d59a5de23b748f6Zonr Chang 72e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hinesstruct ForceSlangLinking { 73e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines ForceSlangLinking() { 74e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // We must reference the functions in such a way that compilers will not 75e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // delete it all as dead code, even with whole program optimization, 76e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // yet is effectively a NO-OP. As the compiler isn't smart enough 77e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // to know that getenv() never returns -1, this will do the job. 78e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines if (std::getenv("bar") != reinterpret_cast<char*>(-1)) 79e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines return; 80e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 81e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // llvm-rs-link needs following functions existing in libslang. 82e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines llvm::ParseBitcodeFile(NULL, llvm::getGlobalContext(), NULL); 839207a2e495c8363606861e4f034504ec5c153dabLogan Chien llvm::Linker::LinkModules(NULL, NULL, 0, NULL); 84e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 85e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines // llvm-rs-cc need this. 86e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines new clang::TextDiagnosticPrinter(llvm::errs(), 87e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines clang::DiagnosticOptions()); 88e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines } 89e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines} ForceSlangLinking; 90e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 91e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines} // namespace 92e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 93e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hinesnamespace slang { 949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 95462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#if defined(__arm__) 96462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao# define DEFAULT_TARGET_TRIPLE_STRING "armv7-none-linux-gnueabi" 97462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#elif defined(__x86_64__) 98462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao# define DEFAULT_TARGET_TRIPLE_STRING "x86_64-unknown-linux" 99462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#else 1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// let's use x86 as default target 1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao# define DEFAULT_TARGET_TRIPLE_STRING "i686-unknown-linux" 102462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#endif 103462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 104462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaobool Slang::GlobalInitialized = false; 105462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// Language option (define the language feature for compiler such as C99) 1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liaoclang::LangOptions Slang::LangOpts; 108462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1096315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr// Code generation option for the compiler 1109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liaoclang::CodeGenOptions Slang::CodeGenOpts; 111462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// The named of metadata node that pragma resides (should be synced with 1139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao// bcc.cpp) 114f52a620440fa62257dfdcf2583f0f9df5b855c76Shih-wei Liaoconst llvm::StringRef Slang::PragmaMetadataName = "#pragma"; 115462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1169207a2e495c8363606861e4f034504ec5c153dabLogan Chienstatic inline llvm::tool_output_file * 1179207a2e495c8363606861e4f034504ec5c153dabLogan ChienOpenOutputFile(const char *OutputFile, 1189207a2e495c8363606861e4f034504ec5c153dabLogan Chien unsigned Flags, 1199207a2e495c8363606861e4f034504ec5c153dabLogan Chien std::string* Error, 120e67239de8d94975e7e2216ee6860ae2e6cb8b15aStephen Hines clang::DiagnosticsEngine *DiagEngine) { 1219207a2e495c8363606861e4f034504ec5c153dabLogan Chien slangAssert((OutputFile != NULL) && (Error != NULL) && 1229207a2e495c8363606861e4f034504ec5c153dabLogan Chien (DiagEngine != NULL) && "Invalid parameter!"); 123e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 1246f4e0a9955a53a6f715af7e674e68ed15270a47cLogan Chien if (SlangUtils::CreateDirectoryWithParents( 1256f4e0a9955a53a6f715af7e674e68ed15270a47cLogan Chien llvm::sys::path::parent_path(OutputFile), Error)) { 126e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang llvm::tool_output_file *F = 127e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang new llvm::tool_output_file(OutputFile, *Error, Flags); 128e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang if (F != NULL) 129e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang return F; 130e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang } 131e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 132e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Report error here. 1339207a2e495c8363606861e4f034504ec5c153dabLogan Chien DiagEngine->Report(clang::diag::err_fe_error_opening) 1349207a2e495c8363606861e4f034504ec5c153dabLogan Chien << OutputFile << *Error; 135e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 136e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang return NULL; 137e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang} 138e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 139462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaovoid Slang::GlobalInitialization() { 1409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (!GlobalInitialized) { 1419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // We only support x86, x64 and ARM target 142462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // For ARM 1449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeARMTargetInfo(); 1459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeARMTarget(); 1469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeARMAsmPrinter(); 147462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // For x86 and x64 1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeX86TargetInfo(); 1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeX86Target(); 1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LLVMInitializeX86AsmPrinter(); 152462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1533a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang // Please refer to include/clang/Basic/LangOptions.h to setup 1549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // the options. 1559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LangOpts.RTTI = 0; // Turn off the RTTI information support 1569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LangOpts.NeXTRuntime = 0; // Turn off the NeXT runtime uses 157245eba133628ef5b52c78d6f538c9268c9bc5828Shih-wei Liao LangOpts.C99 = 1; 158462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao CodeGenOpts.OptimizationLevel = 3; /* -O3 */ 160462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao GlobalInitialized = true; 1629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 163462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 164462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 165462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaovoid Slang::LLVMErrorHandler(void *UserData, const std::string &Message) { 1669207a2e495c8363606861e4f034504ec5c153dabLogan Chien clang::DiagnosticsEngine* DiagEngine = 1679207a2e495c8363606861e4f034504ec5c153dabLogan Chien static_cast<clang::DiagnosticsEngine *>(UserData); 1689207a2e495c8363606861e4f034504ec5c153dabLogan Chien 1699207a2e495c8363606861e4f034504ec5c153dabLogan Chien DiagEngine->Report(clang::diag::err_fe_error_backend) << Message; 1709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao exit(1); 171462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 172462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 173b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liaovoid Slang::createTarget(const std::string &Triple, const std::string &CPU, 174b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao const std::vector<std::string> &Features) { 175b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao if (!Triple.empty()) 1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mTargetOpts.Triple = Triple; 1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao else 1789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mTargetOpts.Triple = DEFAULT_TARGET_TRIPLE_STRING; 179462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 180b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao if (!CPU.empty()) 1819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mTargetOpts.CPU = CPU; 182462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 183b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao if (!Features.empty()) 184b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao mTargetOpts.Features = Features; 185b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao 1869207a2e495c8363606861e4f034504ec5c153dabLogan Chien mTarget.reset(clang::TargetInfo::CreateTargetInfo(*mDiagEngine, 1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mTargetOpts)); 188462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 189462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 1903a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changvoid Slang::createFileManager() { 191df5bcce1582d839eead432a5e24435236c90fb05Shih-wei Liao mFileSysOpt.reset(new clang::FileSystemOptions()); 192be27482cdeaf08576bc39b72a15d35d13014a636Logan mFileMgr.reset(new clang::FileManager(*mFileSysOpt)); 1933a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang} 1943a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 1953a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changvoid Slang::createSourceManager() { 1969207a2e495c8363606861e4f034504ec5c153dabLogan Chien mSourceMgr.reset(new clang::SourceManager(*mDiagEngine, *mFileMgr)); 1973a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang} 1983a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 19968e8e9f98730b3672fb96d49e33b9db70a90ed3fShih-wei Liaovoid Slang::createPreprocessor() { 2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Default only search header file in current dir 2014c622e0953afe3dca4da0aee364a811f3ccb61d9Stephen Hines clang::HeaderSearch *HeaderInfo = new clang::HeaderSearch(*mFileMgr, 2024c622e0953afe3dca4da0aee364a811f3ccb61d9Stephen Hines *mDiagEngine); 2039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 2049207a2e495c8363606861e4f034504ec5c153dabLogan Chien mPP.reset(new clang::Preprocessor(*mDiagEngine, 2059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao LangOpts, 2069207a2e495c8363606861e4f034504ec5c153dabLogan Chien mTarget.get(), 2079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao *mSourceMgr, 2089207a2e495c8363606861e4f034504ec5c153dabLogan Chien *HeaderInfo, 2099207a2e495c8363606861e4f034504ec5c153dabLogan Chien *this, 2109ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao NULL, 2113a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang /* OwnsHeaderSearch = */true)); 2123fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines // Initialize the preprocessor 21368e8e9f98730b3672fb96d49e33b9db70a90ed3fShih-wei Liao mPragmas.clear(); 2143fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines mPP->AddPragmaHandler(new PragmaRecorder(&mPragmas)); 21568e8e9f98730b3672fb96d49e33b9db70a90ed3fShih-wei Liao 2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::vector<clang::DirectoryLookup> SearchList; 2173a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang for (unsigned i = 0, e = mIncludePaths.size(); i != e; i++) { 2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (const clang::DirectoryEntry *DE = 219be27482cdeaf08576bc39b72a15d35d13014a636Logan mFileMgr->getDirectory(mIncludePaths[i])) { 2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao SearchList.push_back(clang::DirectoryLookup(DE, 2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao clang::SrcMgr::C_System, 2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao false, 2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao false)); 2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 2259089828a995422a5ed3beeed0890b755c4abe188Shih-wei Liao } 2269089828a995422a5ed3beeed0890b755c4abe188Shih-wei Liao 2279207a2e495c8363606861e4f034504ec5c153dabLogan Chien HeaderInfo->SetSearchPaths(SearchList, 2289207a2e495c8363606861e4f034504ec5c153dabLogan Chien /* angledDirIdx = */1, 2299207a2e495c8363606861e4f034504ec5c153dabLogan Chien /* systemDixIdx = */1, 2309207a2e495c8363606861e4f034504ec5c153dabLogan Chien /* noCurDirSearch = */false); 2319089828a995422a5ed3beeed0890b755c4abe188Shih-wei Liao 2323a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang initPreprocessor(); 23368e8e9f98730b3672fb96d49e33b9db70a90ed3fShih-wei Liao} 23468e8e9f98730b3672fb96d49e33b9db70a90ed3fShih-wei Liao 2353a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changvoid Slang::createASTContext() { 2363a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mASTContext.reset(new clang::ASTContext(LangOpts, 2373a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang *mSourceMgr, 2389207a2e495c8363606861e4f034504ec5c153dabLogan Chien mTarget.get(), 2393a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mPP->getIdentifierTable(), 2403a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mPP->getSelectorTable(), 2413a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mPP->getBuiltinInfo(), 2423a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang /* size_reserve = */0)); 2433a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang initASTContext(); 2443a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang} 2453a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 2469207a2e495c8363606861e4f034504ec5c153dabLogan Chienclang::ASTConsumer * 2479207a2e495c8363606861e4f034504ec5c153dabLogan ChienSlang::createBackend(const clang::CodeGenOptions& CodeGenOpts, 2489207a2e495c8363606861e4f034504ec5c153dabLogan Chien llvm::raw_ostream *OS, OutputType OT) { 2498f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines return new Backend(mDiagEngine, CodeGenOpts, mTargetOpts, 2509207a2e495c8363606861e4f034504ec5c153dabLogan Chien &mPragmas, OS, OT); 2513a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang} 2523a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 253641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr ChangSlang::Slang() : mInitialized(false), mDiagClient(NULL), mOT(OT_Default) { 2549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao GlobalInitialization(); 255641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang} 256641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 257641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Changvoid Slang::init(const std::string &Triple, const std::string &CPU, 2588f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines const std::vector<std::string> &Features, 2598f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines clang::DiagnosticsEngine *DiagEngine, 2608f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines DiagnosticBuffer *DiagClient) { 261641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang if (mInitialized) 262641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang return; 263462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2648f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines mDiagEngine = DiagEngine; 2658f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines mDiagClient = DiagClient; 2668f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines mDiag.reset(new clang::Diagnostic(mDiagEngine)); 2678f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines initDiagnostic(); 2688f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines llvm::install_fatal_error_handler(LLVMErrorHandler, mDiagEngine); 269462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao createTarget(Triple, CPU, Features); 2719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao createFileManager(); 2729ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao createSourceManager(); 273462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 274641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang mInitialized = true; 2759207a2e495c8363606861e4f034504ec5c153dabLogan Chien} 276641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang 277ac4e18584b8768b3f68535fa5f16232e03974323Logan Chienclang::Module *Slang::loadModule(clang::SourceLocation ImportLoc, 278ac4e18584b8768b3f68535fa5f16232e03974323Logan Chien clang::ModuleIdPath Path, 279ac4e18584b8768b3f68535fa5f16232e03974323Logan Chien clang::Module::NameVisibilityKind Visibility, 280ac4e18584b8768b3f68535fa5f16232e03974323Logan Chien bool IsInclusionDirective) { 2819207a2e495c8363606861e4f034504ec5c153dabLogan Chien slangAssert(0 && "Not implemented"); 2829207a2e495c8363606861e4f034504ec5c153dabLogan Chien return NULL; 283462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 284462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2853a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changbool Slang::setInputSource(llvm::StringRef InputFile, 2863a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang const char *Text, 2873a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang size_t TextLength) { 2883a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mInputFileName = InputFile.str(); 289462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Reset the ID tables if we are reusing the SourceManager 2919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mSourceMgr->clearIDTables(); 292462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Load the source 2946315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr llvm::MemoryBuffer *SB = 2953a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang llvm::MemoryBuffer::getMemBuffer(Text, Text + TextLength); 2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mSourceMgr->createMainFileIDForMemBuffer(SB); 297462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 2989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (mSourceMgr->getMainFileID().isInvalid()) { 2999207a2e495c8363606861e4f034504ec5c153dabLogan Chien mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; 3009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return false; 3019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return true; 303462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 304462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3053a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changbool Slang::setInputSource(llvm::StringRef InputFile) { 3063a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mInputFileName = InputFile.str(); 307462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mSourceMgr->clearIDTables(); 309462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 310be27482cdeaf08576bc39b72a15d35d13014a636Logan const clang::FileEntry *File = mFileMgr->getFile(InputFile); 3119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (File) 3129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mSourceMgr->createMainFileID(File); 313462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (mSourceMgr->getMainFileID().isInvalid()) { 3159207a2e495c8363606861e4f034504ec5c153dabLogan Chien mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile; 3169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return false; 3179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 318462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return true; 320462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 321462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3223a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changbool Slang::setOutput(const char *OutputFile) { 3238c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang llvm::sys::Path OutputFilePath(OutputFile); 3249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao std::string Error; 325e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang llvm::tool_output_file *OS = NULL; 326462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3273a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang switch (mOT) { 328cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines case OT_Dependency: 3293a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang case OT_Assembly: 3303a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang case OT_LLVMAssembly: { 3318f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines OS = OpenOutputFile(OutputFile, 0, &Error, mDiagEngine); 3329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao break; 333462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao } 3343a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang case OT_Nothing: { 3359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao break; 336462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao } 3373a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang case OT_Object: 338cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines case OT_Bitcode: { 3399207a2e495c8363606861e4f034504ec5c153dabLogan Chien OS = OpenOutputFile(OutputFile, llvm::raw_fd_ostream::F_Binary, 3408f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines &Error, mDiagEngine); 3419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao break; 3429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 3438c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang default: { 344cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines llvm_unreachable("Unknown compiler output type"); 3458c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang } 3469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 347462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 348e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang if (!Error.empty()) 3499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return false; 350e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 351e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mOS.reset(OS); 3529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 3533a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mOutputFileName = OutputFile; 354462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao return true; 356462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 357462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 3580b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hinesbool Slang::setDepOutput(const char *OutputFile) { 3598c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang llvm::sys::Path OutputFilePath(OutputFile); 3600b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines std::string Error; 3618c6d9b2d36ed2d6d811279fd9bddc05fffe16803Zonr Chang 3628f4d972ef6c6796ffdde603e456979a7004d1e20Stephen Hines mDOS.reset(OpenOutputFile(OutputFile, 0, &Error, mDiagEngine)); 363e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang if (!Error.empty() || (mDOS.get() == NULL)) 3640b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines return false; 3650b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines 3660b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines mDepOutputFileName = OutputFile; 3670b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines 3680b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines return true; 3690b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines} 3700b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines 371cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hinesint Slang::generateDepFile() { 3729207a2e495c8363606861e4f034504ec5c153dabLogan Chien if (mDiagEngine->hasErrorOccurred()) 373be27482cdeaf08576bc39b72a15d35d13014a636Logan return 1; 3740b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines if (mDOS.get() == NULL) 375f7de85223c8728d5dc147e8a19ddf039da72b431Stephen Hines return 1; 376cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 377e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Initialize options for generating dependency file 378cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines clang::DependencyOutputOptions DepOpts; 379cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines DepOpts.IncludeSystemHeaders = 1; 3800b7ef1a176b9ddd1e0d437efdce20743373fd7dbStephen Hines DepOpts.OutputFile = mDepOutputFileName; 381b81c6a4cbd9c08e0b20ea4fbc615b416ac1bc9ecShih-wei Liao DepOpts.Targets = mAdditionalDepTargets; 382cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines DepOpts.Targets.push_back(mDepTargetBCFileName); 3834cc67fce91f43215d61b2695746eab102a3db516Stephen Hines for (std::vector<std::string>::const_iterator 3844cc67fce91f43215d61b2695746eab102a3db516Stephen Hines I = mGeneratedFileNames.begin(), E = mGeneratedFileNames.end(); 3854cc67fce91f43215d61b2695746eab102a3db516Stephen Hines I != E; 3864cc67fce91f43215d61b2695746eab102a3db516Stephen Hines I++) { 3874cc67fce91f43215d61b2695746eab102a3db516Stephen Hines DepOpts.Targets.push_back(*I); 3884cc67fce91f43215d61b2695746eab102a3db516Stephen Hines } 3894cc67fce91f43215d61b2695746eab102a3db516Stephen Hines mGeneratedFileNames.clear(); 390cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 391e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Per-compilation needed initialization 392cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines createPreprocessor(); 393cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines AttachDependencyFileGen(*mPP.get(), DepOpts); 394cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 395e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Inform the diagnostic client we are processing a source file 396cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines mDiagClient->BeginSourceFile(LangOpts, mPP.get()); 397cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 398e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Go through the source file (no operations necessary) 399cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines clang::Token Tok; 400cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines mPP->EnterMainSourceFile(); 401cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines do { 402cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines mPP->Lex(Tok); 403cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines } while (Tok.isNot(clang::tok::eof)); 404cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 405cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines mPP->EndSourceFile(); 406cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 407e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Declare success if no error 4089207a2e495c8363606861e4f034504ec5c153dabLogan Chien if (!mDiagEngine->hasErrorOccurred()) 409e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mDOS->keep(); 410e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 411e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Clean up after compilation 412cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines mPP.reset(); 413e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mDOS.reset(); 414cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 4159207a2e495c8363606861e4f034504ec5c153dabLogan Chien return mDiagEngine->hasErrorOccurred() ? 1 : 0; 416cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines} 417cc0efad052e944f64bb71cfdaa8a825e30192e78Stephen Hines 418462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoint Slang::compile() { 4199207a2e495c8363606861e4f034504ec5c153dabLogan Chien if (mDiagEngine->hasErrorOccurred()) 420be27482cdeaf08576bc39b72a15d35d13014a636Logan return 1; 421f7de85223c8728d5dc147e8a19ddf039da72b431Stephen Hines if (mOS.get() == NULL) 422f7de85223c8728d5dc147e8a19ddf039da72b431Stephen Hines return 1; 423462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Here is per-compilation needed initialization 4259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao createPreprocessor(); 4269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao createASTContext(); 4273a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang 428df5bcce1582d839eead432a5e24435236c90fb05Shih-wei Liao mBackend.reset(createBackend(CodeGenOpts, &mOS->os(), mOT)); 429462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // Inform the diagnostic client we are processing a source file 4319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mDiagClient->BeginSourceFile(LangOpts, mPP.get()); 432462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // The core of the slang compiler 4349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ParseAST(*mPP, mBackend.get(), *mASTContext); 435462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 436e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Inform the diagnostic client we are done with previous source file 437e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mDiagClient->EndSourceFile(); 438e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 439e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang // Declare success if no error 4409207a2e495c8363606861e4f034504ec5c153dabLogan Chien if (!mDiagEngine->hasErrorOccurred()) 441e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mOS->keep(); 442e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang 4433a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang // The compilation ended, clear 4449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mBackend.reset(); 4459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mASTContext.reset(); 4469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mPP.reset(); 447e8c263a1c5df81594cf302ecadd813909c894487Zonr Chang mOS.reset(); 448462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4499207a2e495c8363606861e4f034504ec5c153dabLogan Chien return mDiagEngine->hasErrorOccurred() ? 1 : 0; 450462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 451462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 4523a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Changvoid Slang::reset() { 453c632be206ac4fe49a5db05cfa54942d774329dbeStephen Hines llvm::errs() << mDiagClient->str(); 4549207a2e495c8363606861e4f034504ec5c153dabLogan Chien mDiagEngine->Reset(); 4553a9ca1f0d6bd8f12c2bb2adea51f95c255996180Zonr Chang mDiagClient->reset(); 456462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 457462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 458462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei LiaoSlang::~Slang() { 4599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao llvm::llvm_shutdown(); 460462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 461e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 462e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines} // namespace slang 463