blob: b2bcb12610bb6a47e6f3d65f6826d6f05ddccbf7 [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
Stephen Hines758d00c2012-05-03 12:30:15 -070022#include "FileHandle.h"
23
Stephen Hines4a68b1c2012-05-03 12:28:14 -070024#include <map>
25#include <string>
26#include <utility>
27#include <vector>
28
29namespace bcc {
Stephen Hines97c92c22012-05-03 12:30:24 -070030 class Script;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070031
32 class MCCacheWriter {
33 private:
Stephen Hines97c92c22012-05-03 12:30:24 -070034 Script *mpOwner;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070035
Stephen Hines758d00c2012-05-03 12:30:15 -070036 FileHandle *mObjFile, *mInfoFile;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070037
38 std::vector<std::pair<char const *, size_t> > mStringPool;
39
Stephen Hines0f6b1d32012-05-03 12:29:33 -070040 std::map<std::string,
41 std::pair<uint32_t, unsigned char const *> > mDependencies;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070042
43 MCO_Header *mpHeaderSection;
44 MCO_StringPool *mpStringPoolSection;
45 MCO_DependencyTable *mpDependencyTableSection;
46 MCO_PragmaList *mpPragmaListSection;
47 MCO_ObjectSlotList *mpObjectSlotSection;
48
49 MCO_String_Ptr *mpExportVarNameListSection;
50 MCO_String_Ptr *mpExportFuncNameListSection;
51 MCO_String_Ptr *mpExportForEachNameListSection;
52
53 std::vector<std::string> varNameList;
54 std::vector<std::string> funcNameList;
55 std::vector<std::string> forEachNameList;
56
57 public:
58 MCCacheWriter()
59 : mpHeaderSection(NULL), mpStringPoolSection(NULL),
60 mpDependencyTableSection(NULL), mpPragmaListSection(NULL),
61 mpObjectSlotSection(NULL) {
62 }
63
64 ~MCCacheWriter();
65
Stephen Hines758d00c2012-05-03 12:30:15 -070066 bool writeCacheFile(FileHandle *objFile, FileHandle *infoFile,
Stephen Hines97c92c22012-05-03 12:30:24 -070067 Script *S, uint32_t libRS_threadable);
Stephen Hines4a68b1c2012-05-03 12:28:14 -070068
Stephen Hines0f6b1d32012-05-03 12:29:33 -070069 void addDependency(MCO_ResourceType resType,
70 std::string const &resName,
Stephen Hines4a68b1c2012-05-03 12:28:14 -070071 unsigned char const *sha1) {
Stephen Hines0f6b1d32012-05-03 12:29:33 -070072 mDependencies.insert(std::make_pair(resName,
73 std::make_pair((uint32_t)resType, sha1)));
Stephen Hines4a68b1c2012-05-03 12:28:14 -070074 }
75
76 private:
77 bool prepareHeader(uint32_t libRS_threadable);
78 bool prepareStringPool();
79 bool prepareDependencyTable();
80 bool prepareRelocationTable();
81 bool preparePragmaList();
82 bool prepareObjectSlotList();
83
84 bool prepareExportVarNameList();
85 bool prepareExportFuncNameList();
86 bool prepareExportForEachNameList();
87
88 bool writeAll();
89
90 bool calcSectionOffset();
91
92 size_t addString(char const *str, size_t size) {
93 mStringPool.push_back(std::make_pair(str, size));
94 return mStringPool.size() - 1;
95 }
96
97 };
98
99} // namespace bcc
100
101#endif // BCC_MCCACHEWRITER_H