1 /* 2 * Copyright 2012, 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 17 #ifndef BCC_ABC_COMPILER_DRIVER_H 18 #define BCC_ABC_COMPILER_DRIVER_H 19 20 #include "bcc/AndroidBitcode/ABCCompiler.h" 21 #include "bcc/BCCContext.h" 22 #include "bcc/Compiler.h" 23 #include "bcc/Linker.h" 24 25 #include <string> 26 27 namespace bcc { 28 29 class ABCExpandVAArgPass; 30 class CompilerConfig; 31 class LinkerConfig; 32 33 class ABCCompilerDriver { 34 private: 35 BCCContext mContext; 36 ABCCompiler mCompiler; 37 Linker mLinker; 38 39 CompilerConfig *mCompilerConfig; 40 LinkerConfig *mLinkerConfig; 41 42 std::string mAndroidSysroot; 43 44 private: 45 bool configCompiler(); 46 bool configLinker(); 47 48 private: 49 Script *prepareScript(int pInputFd); 50 bool compile(Script &pScript, llvm::raw_ostream &pOutput); 51 bool link(const Script &pScript, const std::string &input_relocatable, 52 int pOutputFd); 53 54 private: 55 virtual CompilerConfig *createCompilerConfig() const = 0; 56 virtual LinkerConfig *createLinkerConfig() const = 0; 57 58 protected: 59 virtual const char **getNonPortableList() const { 60 return NULL; 61 } 62 63 public: 64 virtual ABCExpandVAArgPass *createExpandVAArgPass() const = 0; 65 66 protected: 67 ABCCompilerDriver(); 68 69 public: 70 static ABCCompilerDriver *Create(const std::string &pTriple); 71 72 virtual ~ABCCompilerDriver(); 73 74 inline const std::string &getAndroidSysroot() const { 75 return mAndroidSysroot; 76 } 77 78 inline void setAndroidSysroot(const std::string &pAndroidSysroot) { 79 mAndroidSysroot = pAndroidSysroot; 80 } 81 82 // Compile the bitcode and link the shared object 83 bool build(int pInputFd, int pOutputFd); 84 }; 85 86 } // end namespace bcc 87 88 #endif // BCC_ABC_COMPILER_DRIVER_H 89