[go: nahoru, domu]

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