blob: b6d05f69486ce715286423ff7c1e0fd7488fb080 [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;
51
52 public:
53 CacheWriter()
54 : mpHeaderSection(NULL), mpStringPoolSection(NULL),
55 mpDependencyTableSection(NULL), mpExportVarListSection(NULL),
56 mpExportFuncListSection(NULL), mpPragmaListSection(NULL),
57 mpFuncTableSection(NULL) {
58 }
59
60 ~CacheWriter();
61
62 bool writeCacheFile(FileHandle *file, Script *S,
63 uint32_t libRS_threadable);
64
65 void addDependency(OBCC_ResourceType resType,
66 std::string const &resName,
67 unsigned char const *sha1) {
68 mDependencies.insert(std::make_pair(resName,
69 std::make_pair((uint32_t)resType, sha1)));
70 }
71
72 private:
73 bool prepareHeader(uint32_t libRS_threadable);
74 bool prepareStringPool();
75 bool prepareDependencyTable();
76 bool prepareRelocationTable();
77 bool prepareExportVarList();
78 bool prepareExportFuncList();
79 bool preparePragmaList();
80 bool prepareFuncTable();
81
82 bool writeAll();
83
84 bool calcSectionOffset();
85 bool calcContextChecksum();
86
87 size_t addString(char const *str, size_t size) {
88 mStringPool.push_back(std::make_pair(str, size));
89 return mStringPool.size() - 1;
90 }
91
92 };
93
94} // namespace bcc
95
96#endif // BCC_CACHEWRITER_H