blob: 3e3f0afd5e62a14a7a8855d90526be74c820ca63 [file] [log] [blame]
Logana27a83f2011-01-07 10:25:48 +08001/*
2 * Copyright 2010, 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#ifndef BCC_CACHEWRITER_H
18#define BCC_CACHEWRITER_H
19
20#include <bcc/bcc_cache.h>
21
22#include "FileHandle.h"
23
24#include <map>
25#include <string>
26#include <utility>
27#include <vector>
28
29namespace bcc {
30 class Script;
31
32 class CacheWriter {
33 private:
34 Script *mpOwner;
35
36 FileHandle *mFile;
37
38 std::vector<std::pair<char const *, size_t> > mStringPool;
39
40 std::map<std::string,
41 std::pair<uint32_t, unsigned char const *> > mDependencies;
42
43 OBCC_Header *mpHeaderSection;
44 OBCC_StringPool *mpStringPoolSection;
45 OBCC_DependencyTable *mpDependencyTableSection;
46 //OBCC_RelocationTable *mpRelocationTableSection;
47 OBCC_ExportVarList *mpExportVarListSection;
48 OBCC_ExportFuncList *mpExportFuncListSection;
49 OBCC_PragmaList *mpPragmaListSection;
50 OBCC_FuncTable *mpFuncTableSection;
Stephen Hines071288a2011-01-27 14:38:26 -080051 OBCC_ObjectSlotList *mpObjectSlotSection;
Logana27a83f2011-01-07 10:25:48 +080052
53 public:
54 CacheWriter()
55 : mpHeaderSection(NULL), mpStringPoolSection(NULL),
56 mpDependencyTableSection(NULL), mpExportVarListSection(NULL),
57 mpExportFuncListSection(NULL), mpPragmaListSection(NULL),
Stephen Hines071288a2011-01-27 14:38:26 -080058 mpFuncTableSection(NULL), mpObjectSlotSection(NULL) {
Logana27a83f2011-01-07 10:25:48 +080059 }
60
61 ~CacheWriter();
62
63 bool writeCacheFile(FileHandle *file, Script *S,
64 uint32_t libRS_threadable);
65
66 void addDependency(OBCC_ResourceType resType,
67 std::string const &resName,
68 unsigned char const *sha1) {
69 mDependencies.insert(std::make_pair(resName,
70 std::make_pair((uint32_t)resType, sha1)));
71 }
72
73 private:
74 bool prepareHeader(uint32_t libRS_threadable);
75 bool prepareStringPool();
76 bool prepareDependencyTable();
77 bool prepareRelocationTable();
78 bool prepareExportVarList();
79 bool prepareExportFuncList();
80 bool preparePragmaList();
81 bool prepareFuncTable();
Stephen Hines071288a2011-01-27 14:38:26 -080082 bool prepareObjectSlotList();
Logana27a83f2011-01-07 10:25:48 +080083
84 bool writeAll();
85
86 bool calcSectionOffset();
87 bool calcContextChecksum();
88
89 size_t addString(char const *str, size_t size) {
90 mStringPool.push_back(std::make_pair(str, size));
91 return mStringPool.size() - 1;
92 }
93
94 };
95
96} // namespace bcc
97
98#endif // BCC_CACHEWRITER_H