1 /* 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 "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 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: MCCacheWriter()58 MCCacheWriter() 59 : mpHeaderSection(NULL), mpStringPoolSection(NULL), 60 mpDependencyTableSection(NULL), mpPragmaListSection(NULL), 61 mpObjectSlotSection(NULL) { 62 } 63 64 ~MCCacheWriter(); 65 66 bool writeCacheFile(FileHandle *objFile, FileHandle *infoFile, 67 Script *S, uint32_t libRS_threadable); 68 addDependency(MCO_ResourceType resType,std::string const & resName,unsigned char const * sha1)69 void addDependency(MCO_ResourceType resType, 70 std::string const &resName, 71 unsigned char const *sha1) { 72 mDependencies.insert(std::make_pair(resName, 73 std::make_pair((uint32_t)resType, sha1))); 74 } 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 addString(char const * str,size_t size)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 102