blob: fd3516d493c46ab06a6efef8190dcbb49c2c1462 [file] [log] [blame]
Loganf7f0ac52011-01-07 03:53:43 +08001/*
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>
Logan856ceb22011-01-07 05:21:26 +080029#include <stdint.h>
Loganf7f0ac52011-01-07 03:53:43 +080030
31struct OBCC_Header;
32
33namespace bcc {
34 class FileHandle;
35 class Script;
36
37 class CacheReader {
38 private:
Loganf7f0ac52011-01-07 03:53:43 +080039 FileHandle *mFile;
40 off_t mFileSize;
41
Logan856ceb22011-01-07 05:21:26 +080042 OBCC_Header *mpHeader;
43 OBCC_DependencyTable *mpCachedDependTable;
44 OBCC_PragmaList *mpPragmaList;
45 OBCC_FuncTable *mpFuncTable;
Loganf7f0ac52011-01-07 03:53:43 +080046
Logan856ceb22011-01-07 05:21:26 +080047 llvm::OwningPtr<ScriptCached> mpResult;
Loganf7f0ac52011-01-07 03:53:43 +080048
Logan75cc8a52011-01-07 06:06:52 +080049 std::map<std::string,
50 std::pair<uint32_t, unsigned char const *> > mDependencies;
Loganf7f0ac52011-01-07 03:53:43 +080051
Logan42598052011-01-26 22:41:13 +080052 bool mIsContextSlotNotAvail;
53
Loganf7f0ac52011-01-07 03:53:43 +080054 public:
Logane7eb7732011-01-07 07:11:56 +080055 CacheReader()
56 : mFile(NULL), mFileSize(0), mpHeader(NULL),
Logan42598052011-01-26 22:41:13 +080057 mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL),
58 mIsContextSlotNotAvail(false) {
Loganf7f0ac52011-01-07 03:53:43 +080059 }
60
Logan856ceb22011-01-07 05:21:26 +080061 ~CacheReader();
62
63 void addDependency(OBCC_ResourceType resType,
64 std::string const &resName,
Logan75cc8a52011-01-07 06:06:52 +080065 unsigned char const *sha1) {
Logan856ceb22011-01-07 05:21:26 +080066 mDependencies.insert(std::make_pair(resName,
67 std::make_pair((uint32_t)resType, sha1)));
Loganf7f0ac52011-01-07 03:53:43 +080068 }
69
Logane7eb7732011-01-07 07:11:56 +080070 ScriptCached *readCacheFile(FileHandle *file, Script *s);
Loganf7f0ac52011-01-07 03:53:43 +080071
Logan42598052011-01-26 22:41:13 +080072 bool isContextSlotNotAvail() const {
73 return mIsContextSlotNotAvail;
74 }
75
Loganf7f0ac52011-01-07 03:53:43 +080076 private:
77 bool readHeader();
78 bool readStringPool();
79 bool readDependencyTable();
80 bool readExportVarList();
81 bool readExportFuncList();
82 bool readPragmaList();
83 bool readFuncTable();
Stephen Hines071288a2011-01-27 14:38:26 -080084 bool readObjectSlotList();
Loganf7f0ac52011-01-07 03:53:43 +080085 bool readContext();
86 bool readRelocationTable();
87
88 bool checkFileSize();
89 bool checkHeader();
90 bool checkMachineIntType();
91 bool checkSectionOffsetAndSize();
92 bool checkStringPool();
93 bool checkDependency();
94 bool checkContext();
95
96 bool relocate();
97 };
98
99} // namespace bcc
100
101#endif // BCC_CACHEREADER_H