blob: 48f1cd8e038770e3736a00751ed1f124cfa2c1f2 [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>
29
30struct OBCC_Header;
31
32namespace bcc {
33 class FileHandle;
34 class Script;
35
36 class CacheReader {
37 private:
38 Script *mpOwner;
39
40 FileHandle *mFile;
41 off_t mFileSize;
42
43 OBCC_Header *mHeader;
44
45 llvm::OwningPtr<ScriptCached> mResult;
46
47 std::map<std::string, char const *> mDependency;
48
49 public:
50 CacheReader(Script *owner)
51 : mpOwner(owner), mFile(NULL), mFileSize(0), mHeader(NULL) {
52 }
53
54 void addDependency(std::string const &resName, char const *sha1) {
55 mDependency.insert(std::make_pair(resName, sha1));
56 }
57
58 ScriptCached *readCacheFile(FileHandle *file);
59
60 private:
61 bool readHeader();
62 bool readStringPool();
63 bool readDependencyTable();
64 bool readExportVarList();
65 bool readExportFuncList();
66 bool readPragmaList();
67 bool readFuncTable();
68 bool readContext();
69 bool readRelocationTable();
70
71 bool checkFileSize();
72 bool checkHeader();
73 bool checkMachineIntType();
74 bool checkSectionOffsetAndSize();
75 bool checkStringPool();
76 bool checkDependency();
77 bool checkContext();
78
79 bool relocate();
80 };
81
82} // namespace bcc
83
84#endif // BCC_CACHEREADER_H