blob: f838f7118b2087f661691403800d0fb4a2f4e245 [file] [log] [blame]
Stephen Hinesead5ccb2012-05-03 12:30:38 -07001/*
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_SOURCEINFO_H
18#define BCC_SOURCEINFO_H
19
20#include "Config.h"
21
22#include <llvm/Module.h>
23
24#include <stddef.h>
25
26namespace bcc {
27 namespace SourceKind {
28 enum SourceType {
29 File,
30 Buffer,
31 Module,
32 };
33 }
34
35 class SourceInfo {
36 private:
37 SourceKind::SourceType type;
38
39 // Note: module should not be a part of union. Since, we are going to
40 // use module to store the pointer to parsed bitcode.
41 llvm::Module *module;
42
43 union {
44 struct {
45 char const *resName;
46 char const *bitcode;
47 size_t bitcodeSize;
48 } buffer;
49
50 struct {
51 char const *path;
52 } file;
53 };
54
55 unsigned long flags;
56
57 unsigned char sha1[20];
58
59 private:
60 SourceInfo() : module(NULL) { }
61
62 public:
63 static SourceInfo *createFromBuffer(char const *resName,
64 char const *bitcode,
65 size_t bitcodeSize,
66 unsigned long flags);
67
68 static SourceInfo *createFromFile(char const *path,
69 unsigned long flags);
70
71 static SourceInfo *createFromModule(llvm::Module *module,
72 unsigned long flags);
73
74 inline llvm::Module *getModule() const {
75 return module;
76 }
77
78 // Share with the given context if it's provided.
79 int prepareModule(llvm::LLVMContext &context);
80
81 template <typename T> void introDependency(T &checker);
82
83 ~SourceInfo();
84 };
85
86
87} // namespace bcc
88
89#endif // BCC_SOURCEINFO_H