blob: cfd32e38afacdf7b2fa973048c557af214f9f851 [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:
39 Script *mpOwner;
40
41 FileHandle *mFile;
42 off_t mFileSize;
43
Logan856ceb22011-01-07 05:21:26 +080044 OBCC_Header *mpHeader;
45 OBCC_DependencyTable *mpCachedDependTable;
46 OBCC_PragmaList *mpPragmaList;
47 OBCC_FuncTable *mpFuncTable;
Loganf7f0ac52011-01-07 03:53:43 +080048
Logan856ceb22011-01-07 05:21:26 +080049 llvm::OwningPtr<ScriptCached> mpResult;
Loganf7f0ac52011-01-07 03:53:43 +080050
Logan75cc8a52011-01-07 06:06:52 +080051 std::map<std::string,
52 std::pair<uint32_t, unsigned char const *> > mDependencies;
Loganf7f0ac52011-01-07 03:53:43 +080053
54 public:
55 CacheReader(Script *owner)
Logan856ceb22011-01-07 05:21:26 +080056 : mpOwner(owner), mFile(NULL), mFileSize(0), mpHeader(NULL),
57 mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL) {
Loganf7f0ac52011-01-07 03:53:43 +080058 }
59
Logan856ceb22011-01-07 05:21:26 +080060 ~CacheReader();
61
62 void addDependency(OBCC_ResourceType resType,
63 std::string const &resName,
Logan75cc8a52011-01-07 06:06:52 +080064 unsigned char const *sha1) {
Logan856ceb22011-01-07 05:21:26 +080065 mDependencies.insert(std::make_pair(resName,
66 std::make_pair((uint32_t)resType, sha1)));
Loganf7f0ac52011-01-07 03:53:43 +080067 }
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