Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 758d00c | 2012-05-03 12:30:15 -0700 | [diff] [blame] | 22 | #include "FileHandle.h" |
| 23 | |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 24 | #include <map> |
| 25 | #include <string> |
| 26 | #include <utility> |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace bcc { |
Stephen Hines | 97c92c2 | 2012-05-03 12:30:24 -0700 | [diff] [blame] | 30 | class Script; |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 31 | |
| 32 | class MCCacheWriter { |
| 33 | private: |
Stephen Hines | 97c92c2 | 2012-05-03 12:30:24 -0700 | [diff] [blame] | 34 | Script *mpOwner; |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 35 | |
Stephen Hines | 758d00c | 2012-05-03 12:30:15 -0700 | [diff] [blame] | 36 | FileHandle *mObjFile, *mInfoFile; |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 37 | |
| 38 | std::vector<std::pair<char const *, size_t> > mStringPool; |
| 39 | |
Stephen Hines | 0f6b1d3 | 2012-05-03 12:29:33 -0700 | [diff] [blame] | 40 | std::map<std::string, |
| 41 | std::pair<uint32_t, unsigned char const *> > mDependencies; |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 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: |
| 58 | MCCacheWriter() |
| 59 | : mpHeaderSection(NULL), mpStringPoolSection(NULL), |
| 60 | mpDependencyTableSection(NULL), mpPragmaListSection(NULL), |
| 61 | mpObjectSlotSection(NULL) { |
| 62 | } |
| 63 | |
| 64 | ~MCCacheWriter(); |
| 65 | |
Stephen Hines | 758d00c | 2012-05-03 12:30:15 -0700 | [diff] [blame] | 66 | bool writeCacheFile(FileHandle *objFile, FileHandle *infoFile, |
Stephen Hines | 97c92c2 | 2012-05-03 12:30:24 -0700 | [diff] [blame] | 67 | Script *S, uint32_t libRS_threadable); |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 68 | |
Stephen Hines | 0f6b1d3 | 2012-05-03 12:29:33 -0700 | [diff] [blame] | 69 | void addDependency(MCO_ResourceType resType, |
| 70 | std::string const &resName, |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 71 | unsigned char const *sha1) { |
Stephen Hines | 0f6b1d3 | 2012-05-03 12:29:33 -0700 | [diff] [blame] | 72 | mDependencies.insert(std::make_pair(resName, |
| 73 | std::make_pair((uint32_t)resType, sha1))); |
Stephen Hines | 4a68b1c | 2012-05-03 12:28:14 -0700 | [diff] [blame] | 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 | |
| 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 |