• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_MCCACHEWRITER_H
18 #define BCC_MCCACHEWRITER_H
19 
20 #include <bcc/bcc_mccache.h>
21 
22 #include "FileHandle.h"
23 
24 #include <map>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace bcc {
30   class Script;
31 
32   class MCCacheWriter {
33   private:
34     Script *mpOwner;
35 
36     FileHandle *mObjFile, *mInfoFile;
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     MCO_Header *mpHeaderSection;
44     OBCC_StringPool *mpStringPoolSection;
45     OBCC_DependencyTable *mpDependencyTableSection;
46     OBCC_PragmaList *mpPragmaListSection;
47     OBCC_ObjectSlotList *mpObjectSlotSection;
48 
49     OBCC_String_Ptr *mpExportVarNameListSection;
50     OBCC_String_Ptr *mpExportFuncNameListSection;
51 
52     std::vector<std::string> varNameList;
53     std::vector<std::string> funcNameList;
54 
55   public:
MCCacheWriter()56     MCCacheWriter()
57       : mpHeaderSection(NULL), mpStringPoolSection(NULL),
58         mpDependencyTableSection(NULL), mpPragmaListSection(NULL),
59         mpObjectSlotSection(NULL) {
60     }
61 
62     ~MCCacheWriter();
63 
64     bool writeCacheFile(FileHandle *objFile, FileHandle *infoFile,
65                         Script *S, uint32_t libRS_threadable);
66 
addDependency(OBCC_ResourceType resType,std::string const & resName,unsigned char const * sha1)67     void addDependency(OBCC_ResourceType resType,
68                        std::string const &resName,
69                        unsigned char const *sha1) {
70       mDependencies.insert(std::make_pair(resName,
71                            std::make_pair((uint32_t)resType, sha1)));
72     }
73 
74   private:
75     bool prepareHeader(uint32_t libRS_threadable);
76     bool prepareStringPool();
77     bool prepareDependencyTable();
78     bool prepareRelocationTable();
79     bool preparePragmaList();
80     bool prepareObjectSlotList();
81 
82     bool prepareExportVarNameList();
83     bool prepareExportFuncNameList();
84 
85     bool writeAll();
86 
87     bool calcSectionOffset();
88 
addString(char const * str,size_t size)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_MCCACHEWRITER_H
99