blob: 47f1e40fdac82b847789465216cffda2bb4c3c3c [file] [log] [blame]
Stephen Hines4a68b1c2012-05-03 12:28:14 -07001/*
2 * Copyright 2010-2012, 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_MCCACHEWRITER_H
18#define BCC_MCCACHEWRITER_H
19
20#include <bcc/bcc_mccache.h>
21
22#include <map>
23#include <string>
24#include <utility>
25#include <vector>
26
27namespace bcc {
28 class OutputFile;
29 class RSScript;
30
31 class MCCacheWriter {
32 private:
33 RSScript *mpOwner;
34
35 OutputFile *mObjFile, *mInfoFile;
36
37 std::vector<std::pair<char const *, size_t> > mStringPool;
38
39 std::map<std::string, unsigned char const *> mDependencies;
40
41 MCO_Header *mpHeaderSection;
42 MCO_StringPool *mpStringPoolSection;
43 MCO_DependencyTable *mpDependencyTableSection;
44 MCO_PragmaList *mpPragmaListSection;
45 MCO_ObjectSlotList *mpObjectSlotSection;
46
47 MCO_String_Ptr *mpExportVarNameListSection;
48 MCO_String_Ptr *mpExportFuncNameListSection;
49 MCO_String_Ptr *mpExportForEachNameListSection;
50
51 std::vector<std::string> varNameList;
52 std::vector<std::string> funcNameList;
53 std::vector<std::string> forEachNameList;
54
55 public:
56 MCCacheWriter()
57 : mpHeaderSection(NULL), mpStringPoolSection(NULL),
58 mpDependencyTableSection(NULL), mpPragmaListSection(NULL),
59 mpObjectSlotSection(NULL) {
60 }
61
62 ~MCCacheWriter();
63
64 bool writeCacheFile(OutputFile &objFile, OutputFile &infoFile,
65 RSScript *S, uint32_t libRS_threadable);
66
67 void addDependency(std::string const &resName,
68 unsigned char const *sha1) {
69 mDependencies.insert(std::make_pair(resName, sha1));
70 }
71
72 private:
73 bool prepareHeader(uint32_t libRS_threadable);
74 bool prepareStringPool();
75 bool prepareDependencyTable();
76 bool prepareRelocationTable();
77 bool preparePragmaList();
78 bool prepareObjectSlotList();
79
80 bool prepareExportVarNameList();
81 bool prepareExportFuncNameList();
82 bool prepareExportForEachNameList();
83
84 bool writeAll();
85
86 bool calcSectionOffset();
87
88 size_t addString(char const *str, size_t size) {
89 mStringPool.push_back(std::make_pair(str, size));
90 return mStringPool.size() - 1;
91 }
92
93 };
94
95} // namespace bcc
96
97#endif // BCC_MCCACHEWRITER_H