blob: fb76e5ccfce5765f269222a20da9a498fa73359b [file] [log] [blame]
Jeff Haoa8621002016-10-04 18:13:44 +00001/*
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#ifndef ART_DEXLAYOUT_DEX_WRITER_H_
20#define ART_DEXLAYOUT_DEX_WRITER_H_
21
22#include "base/unix_file/fd_file.h"
23#include "dex_ir.h"
Jeff Haoea7c6292016-11-14 18:10:16 -080024#include "mem_map.h"
Jeff Haoa8621002016-10-04 18:13:44 +000025#include "os.h"
26
27namespace art {
28
29class DexWriter {
30 public:
Jeff Haoea7c6292016-11-14 18:10:16 -080031 DexWriter(dex_ir::Header* header, MemMap* mem_map) : header_(header), mem_map_(mem_map) { }
Jeff Haoa8621002016-10-04 18:13:44 +000032
Jeff Haoea7c6292016-11-14 18:10:16 -080033 static void Output(dex_ir::Header* header, MemMap* mem_map);
Jeff Haoa8621002016-10-04 18:13:44 +000034
35 private:
Jeff Haoea7c6292016-11-14 18:10:16 -080036 void WriteMemMap();
Jeff Haoa8621002016-10-04 18:13:44 +000037
38 size_t Write(const void* buffer, size_t length, size_t offset);
39 size_t WriteSleb128(uint32_t value, size_t offset);
40 size_t WriteUleb128(uint32_t value, size_t offset);
41 size_t WriteEncodedValue(dex_ir::EncodedValue* encoded_value, size_t offset);
42 size_t WriteEncodedValueHeader(int8_t value_type, size_t value_arg, size_t offset);
43 size_t WriteEncodedArray(dex_ir::EncodedValueVector* values, size_t offset);
44 size_t WriteEncodedAnnotation(dex_ir::EncodedAnnotation* annotation, size_t offset);
45 size_t WriteEncodedFields(dex_ir::FieldItemVector* fields, size_t offset);
46 size_t WriteEncodedMethods(dex_ir::MethodItemVector* methods, size_t offset);
47
48 void WriteStrings();
49 void WriteTypes();
50 void WriteTypeLists();
51 void WriteProtos();
52 void WriteFields();
53 void WriteMethods();
54 void WriteEncodedArrays();
55 void WriteAnnotations();
56 void WriteAnnotationSets();
57 void WriteAnnotationSetRefs();
58 void WriteAnnotationsDirectories();
59 void WriteDebugInfoItems();
60 void WriteCodeItems();
61 void WriteClasses();
62 void WriteMapItem();
63 void WriteHeader();
64
Jeff Haoea7c6292016-11-14 18:10:16 -080065 dex_ir::Header* const header_;
66 MemMap* const mem_map_;
Jeff Haoa8621002016-10-04 18:13:44 +000067
68 DISALLOW_COPY_AND_ASSIGN(DexWriter);
69};
70
Jeff Haoa8621002016-10-04 18:13:44 +000071} // namespace art
72
73#endif // ART_DEXLAYOUT_DEX_WRITER_H_