Home | History | Annotate | Download | only in bcc
      1 /*
      2  * Copyright 2010-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_SOURCE_H
     18 #define BCC_SOURCE_H
     19 
     20 #include <string>
     21 
     22 namespace llvm {
     23   class Module;
     24 }
     25 
     26 namespace bcc {
     27 
     28 class BCCContext;
     29 
     30 class Source {
     31 private:
     32   const std::string mName; // A unique name
     33   BCCContext &mContext;
     34   llvm::Module *mModule;
     35 
     36   // If true, destructor won't destroy the mModule.
     37   bool mNoDelete;
     38 
     39 private:
     40   Source(const char* name, BCCContext &pContext, llvm::Module &pModule,
     41          bool pNoDelete = false);
     42 
     43 public:
     44   static Source *CreateFromBuffer(BCCContext &pContext,
     45                                   const char *pName,
     46                                   const char *pBitcode,
     47                                   size_t pBitcodeSize);
     48 
     49   static Source *CreateFromFile(BCCContext &pContext,
     50                                 const std::string &pPath);
     51 
     52   // Create a Source object from an existing module. If pNoDelete
     53   // is true, destructor won't call delete on the given module.
     54   static Source *CreateFromModule(BCCContext &pContext,
     55                                   const char* name,
     56                                   llvm::Module &pModule,
     57                                   bool pNoDelete = false);
     58 
     59   static Source *CreateEmpty(BCCContext &pContext, const std::string &pName);
     60 
     61   const std::string& getName() const { return mName; }
     62 
     63   // Merge the current source with pSource. pSource
     64   // will be destroyed after successfully merged. Return false on error.
     65   bool merge(Source &pSource);
     66 
     67   inline BCCContext &getContext()
     68   { return mContext; }
     69   inline const BCCContext &getContext() const
     70   { return mContext; }
     71 
     72   void setModule(llvm::Module *pModule);
     73 
     74   inline llvm::Module &getModule()
     75   { return *mModule;  }
     76   inline const llvm::Module &getModule() const
     77   { return *mModule;  }
     78 
     79   // Get the "identifier" of the bitcode. This will return the value of pName
     80   // when it's created using CreateFromBuffer and pPath if CreateFromFile().
     81   const std::string &getIdentifier() const;
     82 
     83   void addBuildChecksumMetadata(const char *) const;
     84 
     85   ~Source();
     86 };
     87 
     88 } // namespace bcc
     89 
     90 #endif // BCC_SOURCE_H
     91