blob: e2d10c5fc9d3f7adc6a100a02f413248d900c34c [file] [log] [blame]
Stephen Hines4a68b1c2012-05-03 12:28:14 -07001/*
2 * Copyright 2010-2012, 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_MCCACHEREADER_H
18#define BCC_MCCACHEREADER_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#include <stdint.h>
30
31struct MCO_Header;
32
33namespace bcc {
34 class Script;
35 class InputFile;
36
37 class MCCacheReader {
38 private:
39 InputFile *mObjFile, *mInfoFile;
40 off_t mInfoFileSize;
41
42 MCO_Header *mpHeader;
43 MCO_DependencyTable *mpCachedDependTable;
44 MCO_PragmaList *mpPragmaList;
45 MCO_FuncTable *mpFuncTable;
46
47 MCO_String_Ptr *mpVarNameList;
48 MCO_String_Ptr *mpFuncNameList;
49 MCO_String_Ptr *mpForEachNameList;
50
51 llvm::OwningPtr<ScriptCached> mpResult;
52
53 std::map<std::string, unsigned char const *> mDependencies;
54
55 bool mIsContextSlotNotAvail;
56
57 BCCSymbolLookupFn mpSymbolLookupFn;
58 void *mpSymbolLookupContext;
59
60 public:
61 MCCacheReader()
62 : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
63 mpCachedDependTable(NULL), mpPragmaList(NULL),
64 mpVarNameList(NULL), mpFuncNameList(NULL), mpForEachNameList(NULL),
65 mIsContextSlotNotAvail(false) {
66 }
67
68 ~MCCacheReader();
69
70 void addDependency(std::string const &resName,
71 unsigned char const *sha1) {
72 mDependencies.insert(std::make_pair(resName, sha1));
73 }
74
75 ScriptCached *readCacheFile(InputFile &objFile, InputFile &infoFile, Script *s);
76 bool checkCacheFile(InputFile &objFile, InputFile &infoFile, Script *S);
77
78 bool isContextSlotNotAvail() const {
79 return mIsContextSlotNotAvail;
80 }
81
82 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
83 mpSymbolLookupFn = pFn;
84 mpSymbolLookupContext = pContext;
85 }
86
87 private:
88 bool readHeader();
89 bool readStringPool();
90 bool readDependencyTable();
91 bool readPragmaList();
92 bool readObjectSlotList();
93 bool readObjFile();
94 bool readRelocationTable();
95
96 bool readVarNameList();
97 bool readFuncNameList();
98 bool readForEachNameList();
99
100 bool checkFileSize();
101 bool checkHeader();
102 bool checkMachineIntType();
103 bool checkSectionOffsetAndSize();
104 bool checkStringPool();
105 bool checkDependency();
106 bool checkContext();
107
108 bool relocate();
109 };
110
111} // namespace bcc
112
113#endif // BCC_MCCACHEREADER_H