blob: 201bee2a425cb8275b786591f28827efbed0d21e [file] [log] [blame]
Stephen Hines0164f462011-11-22 19:43:31 -08001/*
Stephen Hines7cd4c492012-03-13 19:57:37 -07002 * Copyright 2011-2012, The Android Open Source Project
Stephen Hines0164f462011-11-22 19:43:31 -08003 *
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"
Stephen Hines7cd4c492012-03-13 19:57:37 -070018#include "bcinfo/Wrap/bitcode_wrapperer.h"
19#include "bcinfo/Wrap/in_memory_wrapper_input.h"
Stephen Hines0164f462011-11-22 19:43:31 -080020
Stephen Hines0164f462011-11-22 19:43:31 -080021#include "llvm/Bitcode/ReaderWriter.h"
22
23#include <cstdlib>
24#include <cstring>
25
26namespace bcinfo {
27
28BitcodeWrapper::BitcodeWrapper(const char *bitcode, size_t bitcodeSize)
29 : mFileType(BC_NOT_BC), mBitcode(bitcode),
Tareq A. Siraj0a048982012-08-14 16:18:12 -040030 mBitcodeSize(bitcodeSize),
Stephen Hinesb67c9e72012-03-22 11:02:48 -070031 mHeaderVersion(0), mTargetAPI(0), mCompilerVersion(0),
32 mOptimizationLevel(3) {
Stephen Hines7cd4c492012-03-13 19:57:37 -070033 InMemoryWrapperInput inMem(mBitcode, mBitcodeSize);
Chris Wailes900c6c12014-08-13 15:40:00 -070034 BitcodeWrapperer wrapperer(&inMem, nullptr);
Stephen Hines7cd4c492012-03-13 19:57:37 -070035 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 }
Stephen Hines0164f462011-11-22 19:43:31 -080044}
45
46
47BitcodeWrapper::~BitcodeWrapper() {
48 return;
49}
50
51
52bool BitcodeWrapper::unwrap() {
Stephen Hines7cd4c492012-03-13 19:57:37 -070053 return mFileType != BC_NOT_BC;
Stephen Hines0164f462011-11-22 19:43:31 -080054}
55
56} // namespace bcinfo
57