• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011-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 #include "bcinfo/BitcodeWrapper.h"
18 #include "bcinfo/Wrap/bitcode_wrapperer.h"
19 #include "bcinfo/Wrap/in_memory_wrapper_input.h"
20 
21 #include "llvm/Bitcode/ReaderWriter.h"
22 
23 #include <cstdlib>
24 #include <cstring>
25 
26 namespace bcinfo {
27 
BitcodeWrapper(const char * bitcode,size_t bitcodeSize)28 BitcodeWrapper::BitcodeWrapper(const char *bitcode, size_t bitcodeSize)
29     : mFileType(BC_NOT_BC), mBitcode(bitcode),
30       mBitcodeSize(bitcodeSize),
31       mHeaderVersion(0), mTargetAPI(0), mCompilerVersion(0),
32       mOptimizationLevel(3) {
33   InMemoryWrapperInput inMem(mBitcode, mBitcodeSize);
34   BitcodeWrapperer wrapperer(&inMem, nullptr);
35   if (wrapperer.IsInputBitcodeWrapper()) {
36     mFileType = BC_WRAPPER;
37     mHeaderVersion = wrapperer.getAndroidHeaderVersion();
38     mTargetAPI = wrapperer.getAndroidTargetAPI();
39     mCompilerVersion = wrapperer.getAndroidCompilerVersion();
40     mOptimizationLevel = wrapperer.getAndroidOptimizationLevel();
41   } else if (wrapperer.IsInputBitcodeFile()) {
42     mFileType = BC_RAW;
43   }
44 }
45 
46 
~BitcodeWrapper()47 BitcodeWrapper::~BitcodeWrapper() {
48   return;
49 }
50 
51 
unwrap()52 bool BitcodeWrapper::unwrap() {
53   return mFileType != BC_NOT_BC;
54 }
55 
56 }  // namespace bcinfo
57 
58