blob: e6868d74bca099e446e9a24046383e5344b0dbec [file] [log] [blame]
David Sehr853a8e12016-09-01 13:03:50 -07001/*
2 * Copyright (C) 2016 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 * Header file of an in-memory representation of DEX files.
17 */
18
19#include <stdint.h>
20#include <vector>
21
22#include "dex_ir_builder.h"
23
24namespace art {
25namespace dex_ir {
26
David Sehr853a8e12016-09-01 13:03:50 -070027Header* DexIrBuilder(const DexFile& dex_file) {
28 const DexFile::Header& disk_header = dex_file.GetHeader();
29 Header* header = new Header(disk_header.magic_,
30 disk_header.checksum_,
31 disk_header.signature_,
32 disk_header.endian_tag_,
33 disk_header.file_size_,
34 disk_header.header_size_,
35 disk_header.link_size_,
36 disk_header.link_off_,
37 disk_header.data_size_,
38 disk_header.data_off_);
Jeff Hao3ab96b42016-09-09 18:35:01 -070039 Collections& collections = header->GetCollections();
David Sehr853a8e12016-09-01 13:03:50 -070040 // Walk the rest of the header fields.
41 // StringId table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070042 collections.SetStringIdsOffset(disk_header.string_ids_off_);
David Sehr853a8e12016-09-01 13:03:50 -070043 for (uint32_t i = 0; i < dex_file.NumStringIds(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070044 collections.CreateStringId(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070045 }
46 // TypeId table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070047 collections.SetTypeIdsOffset(disk_header.type_ids_off_);
David Sehr853a8e12016-09-01 13:03:50 -070048 for (uint32_t i = 0; i < dex_file.NumTypeIds(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070049 collections.CreateTypeId(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070050 }
51 // ProtoId table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070052 collections.SetProtoIdsOffset(disk_header.proto_ids_off_);
David Sehr853a8e12016-09-01 13:03:50 -070053 for (uint32_t i = 0; i < dex_file.NumProtoIds(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070054 collections.CreateProtoId(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070055 }
56 // FieldId table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070057 collections.SetFieldIdsOffset(disk_header.field_ids_off_);
David Sehr853a8e12016-09-01 13:03:50 -070058 for (uint32_t i = 0; i < dex_file.NumFieldIds(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070059 collections.CreateFieldId(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070060 }
61 // MethodId table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070062 collections.SetMethodIdsOffset(disk_header.method_ids_off_);
David Sehr853a8e12016-09-01 13:03:50 -070063 for (uint32_t i = 0; i < dex_file.NumMethodIds(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070064 collections.CreateMethodId(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070065 }
66 // ClassDef table.
Jeff Hao3ab96b42016-09-09 18:35:01 -070067 collections.SetClassDefsOffset(disk_header.class_defs_off_);
David Sehr853a8e12016-09-01 13:03:50 -070068 for (uint32_t i = 0; i < dex_file.NumClassDefs(); ++i) {
Jeff Hao3ab96b42016-09-09 18:35:01 -070069 collections.CreateClassDef(dex_file, i);
David Sehr853a8e12016-09-01 13:03:50 -070070 }
71
72 return header;
73}
74
75} // namespace dex_ir
76} // namespace art