blob: 5da24b33378c987996a5ea56d052ebd09db90ec9 [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
Logan856ceb22011-01-07 05:21:26 +080051 std::map<std::string, std::pair<uint32_t, char const *> > mDependencies;
Loganf7f0ac52011-01-07 03:53:43 +080052
53 public:
54 CacheReader(Script *owner)
Logan856ceb22011-01-07 05:21:26 +080055 : mpOwner(owner), mFile(NULL), mFileSize(0), mpHeader(NULL),
56 mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL) {
Loganf7f0ac52011-01-07 03:53:43 +080057 }
58
Logan856ceb22011-01-07 05:21:26 +080059 ~CacheReader();
60
61 void addDependency(OBCC_ResourceType resType,
62 std::string const &resName,
63 char const *sha1) {
64 mDependencies.insert(std::make_pair(resName,
65 std::make_pair((uint32_t)resType, sha1)));
Loganf7f0ac52011-01-07 03:53:43 +080066 }
67
68 ScriptCached *readCacheFile(FileHandle *file);
69
70 private:
71 bool readHeader();
72 bool readStringPool();
73 bool readDependencyTable();
74 bool readExportVarList();
75 bool readExportFuncList();
76 bool readPragmaList();
77 bool readFuncTable();
78 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