Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 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_CACHEREADER_H |
| 18 | #define BCC_CACHEREADER_H |
| 19 | |
| 20 | #include "ScriptCached.h" |
| 21 | |
| 22 | #include <llvm/ADT/OwningPtr.h> |
| 23 | |
| 24 | #include <map> |
| 25 | #include <string> |
| 26 | #include <utility> |
| 27 | |
| 28 | #include <stddef.h> |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 29 | #include <stdint.h> |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 30 | |
| 31 | struct OBCC_Header; |
| 32 | |
| 33 | namespace bcc { |
| 34 | class FileHandle; |
| 35 | class Script; |
| 36 | |
| 37 | class CacheReader { |
| 38 | private: |
| 39 | Script *mpOwner; |
| 40 | |
| 41 | FileHandle *mFile; |
| 42 | off_t mFileSize; |
| 43 | |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 44 | OBCC_Header *mpHeader; |
| 45 | OBCC_DependencyTable *mpCachedDependTable; |
| 46 | OBCC_PragmaList *mpPragmaList; |
| 47 | OBCC_FuncTable *mpFuncTable; |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 48 | |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 49 | llvm::OwningPtr<ScriptCached> mpResult; |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 50 | |
Logan | 75cc8a5 | 2011-01-07 06:06:52 +0800 | [diff] [blame^] | 51 | std::map<std::string, |
| 52 | std::pair<uint32_t, unsigned char const *> > mDependencies; |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 53 | |
| 54 | public: |
| 55 | CacheReader(Script *owner) |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 56 | : mpOwner(owner), mFile(NULL), mFileSize(0), mpHeader(NULL), |
| 57 | mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL) { |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 60 | ~CacheReader(); |
| 61 | |
| 62 | void addDependency(OBCC_ResourceType resType, |
| 63 | std::string const &resName, |
Logan | 75cc8a5 | 2011-01-07 06:06:52 +0800 | [diff] [blame^] | 64 | unsigned char const *sha1) { |
Logan | 856ceb2 | 2011-01-07 05:21:26 +0800 | [diff] [blame] | 65 | mDependencies.insert(std::make_pair(resName, |
| 66 | std::make_pair((uint32_t)resType, sha1))); |
Logan | f7f0ac5 | 2011-01-07 03:53:43 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | ScriptCached *readCacheFile(FileHandle *file); |
| 70 | |
| 71 | private: |
| 72 | bool readHeader(); |
| 73 | bool readStringPool(); |
| 74 | bool readDependencyTable(); |
| 75 | bool readExportVarList(); |
| 76 | bool readExportFuncList(); |
| 77 | bool readPragmaList(); |
| 78 | bool readFuncTable(); |
| 79 | bool readContext(); |
| 80 | bool readRelocationTable(); |
| 81 | |
| 82 | bool checkFileSize(); |
| 83 | bool checkHeader(); |
| 84 | bool checkMachineIntType(); |
| 85 | bool checkSectionOffsetAndSize(); |
| 86 | bool checkStringPool(); |
| 87 | bool checkDependency(); |
| 88 | bool checkContext(); |
| 89 | |
| 90 | bool relocate(); |
| 91 | }; |
| 92 | |
| 93 | } // namespace bcc |
| 94 | |
| 95 | #endif // BCC_CACHEREADER_H |