-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDimeta.h
62 lines (44 loc) · 1.88 KB
/
Dimeta.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// llvm-dimeta library
// Copyright (c) 2022-2025 llvm-dimeta authors
// Distributed under the BSD 3-Clause license.
// (See accompanying file LICENSE)
// SPDX-License-Identifier: BSD-3-Clause
//
#ifndef DIMETA_DIMETA_H
#define DIMETA_DIMETA_H
#include "DimetaData.h"
#include <optional>
#include <variant>
namespace llvm {
class AllocaInst;
class CallBase;
class DILocalVariable;
class DIGlobalVariable;
class DIType;
class DILocation;
class Value;
class GlobalVariable;
class Module;
} // namespace llvm
namespace dimeta {
using DimetaDIVar = std::variant<llvm::DILocalVariable*, llvm::DIGlobalVariable*>;
struct DimetaData {
enum MemLoc { kStack = 0, kHeap, kGlobal };
MemLoc memory_location{kStack};
std::optional<DimetaDIVar> di_variable{}; // if existing the named variable w.r.t. allocation
std::optional<llvm::DIType*> entry_type{}; // determined to be the allocation including "pointer" DITypes
std::optional<llvm::DIType*> base_type{}; // The base type (int, struct X...) of the allocated memory
std::optional<llvm::DILocation*> di_location{}; // Loc of call (malloc etc.)/alloca. Not set for global
int pointer_level{0}; // e.g., 1 -> int*, 2 -> int**, etc.
};
std::optional<DimetaData> type_for(const llvm::AllocaInst*);
std::optional<DimetaData> type_for(const llvm::CallBase*);
std::optional<DimetaData> type_for(const llvm::GlobalVariable*);
std::optional<location::SourceLocation> location_for(const DimetaData&);
std::optional<LocatedType> located_type_for(const DimetaData&);
std::optional<LocatedType> located_type_for(const llvm::AllocaInst*);
std::optional<LocatedType> located_type_for(const llvm::CallBase*);
std::optional<LocatedType> located_type_for(const llvm::GlobalVariable*);
std::optional<CompileUnitTypeList> compile_unit_types(const llvm::Module* module);
} // namespace dimeta
#endif // DIMETA_DIMETA_H