blob: e66503e40c0c0debc009add064fe52b1a0851a18 [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
52 public:
Logane7eb7732011-01-07 07:11:56 +080053 CacheReader()
54 : mFile(NULL), mFileSize(0), mpHeader(NULL),
Logan856ceb22011-01-07 05:21:26 +080055 mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL) {
Loganf7f0ac52011-01-07 03:53:43 +080056 }
57
Logan856ceb22011-01-07 05:21:26 +080058 ~CacheReader();
59
60 void addDependency(OBCC_ResourceType resType,
61 std::string const &resName,
Logan75cc8a52011-01-07 06:06:52 +080062 unsigned char const *sha1) {
Logan856ceb22011-01-07 05:21:26 +080063 mDependencies.insert(std::make_pair(resName,
64 std::make_pair((uint32_t)resType, sha1)));
Loganf7f0ac52011-01-07 03:53:43 +080065 }
66
Logane7eb7732011-01-07 07:11:56 +080067 ScriptCached *readCacheFile(FileHandle *file, Script *s);
Loganf7f0ac52011-01-07 03:53:43 +080068
69 private:
70 bool readHeader();
71 bool readStringPool();
72 bool readDependencyTable();
73 bool readExportVarList();
74 bool readExportFuncList();
75 bool readPragmaList();
76 bool readFuncTable();
Stephen Hines071288a2011-01-27 14:38:26 -080077 bool readObjectSlotList();
Loganf7f0ac52011-01-07 03:53:43 +080078 bool readContext();
79 bool readRelocationTable();
80
81 bool checkFileSize();
82 bool checkHeader();
83 bool checkMachineIntType();
84 bool checkSectionOffsetAndSize();
85 bool checkStringPool();
86 bool checkDependency();
87 bool checkContext();
88
89 bool relocate();
90 };
91
92} // namespace bcc
93
94#endif // BCC_CACHEREADER_H