Home | History | Annotate | Download | only in bcinfo
      1 /*
      2  * Copyright 2011, 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 __ANDROID_BCINFO_BITCODEWRAPPER_H__
     18 #define __ANDROID_BCINFO_BITCODEWRAPPER_H__
     19 
     20 #include <cstddef>
     21 #include <stdint.h>
     22 
     23 namespace bcinfo {
     24 
     25 struct BCWrapperHeader {
     26   uint32_t Magic;
     27   uint32_t Version;
     28   uint32_t BitcodeOffset;
     29   uint32_t BitcodeSize;
     30   uint32_t HeaderVersion;
     31   uint32_t TargetAPI;
     32 };
     33 
     34 enum BCFileType {
     35   BC_NOT_BC = 0,
     36   BC_WRAPPER = 1,
     37   BC_RAW = 2
     38 };
     39 
     40 class BitcodeWrapper {
     41  private:
     42   enum BCFileType mFileType;
     43   const char *mBitcode;
     44   const char *mBitcodeEnd;
     45   size_t mBitcodeSize;
     46 
     47   struct BCWrapperHeader mBCHeader;
     48 
     49  public:
     50   /**
     51    * Reads wrapper information from \p bitcode.
     52    *
     53    * \param bitcode - input bitcode string.
     54    * \param bitcodeSize - length of \p bitcode string (in bytes).
     55    */
     56   BitcodeWrapper(const char *bitcode, size_t bitcodeSize);
     57 
     58   ~BitcodeWrapper();
     59 
     60   /**
     61    * Attempt to unwrap the target bitcode.
     62    *
     63    * \return true on success and false if an error occurred.
     64    */
     65   bool unwrap();
     66 
     67   /**
     68    * \return type of bitcode file.
     69    */
     70   enum BCFileType getBCFileType() const {
     71     return mFileType;
     72   }
     73 
     74   /**
     75    * \return header version of bitcode wrapper. This can only be 0 currently.
     76    */
     77   uint32_t getHeaderVersion() const {
     78     return mBCHeader.HeaderVersion;
     79   }
     80 
     81   /**
     82    * \return target API version of this script.
     83    */
     84   uint32_t getTargetAPI() const {
     85     return mBCHeader.TargetAPI;
     86   }
     87 };
     88 
     89 }  // namespace bcinfo
     90 
     91 #endif  // __ANDROID_BCINFO_BITCODEWRAPPER_H__
     92