LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
Parameter.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_DWARF_PARAMETER_H
16#define LIEF_DWARF_PARAMETER_H
17
18#include "LIEF/visibility.h"
20
21#include <memory>
22#include <string>
23#include <cstdint>
24
25namespace LIEF {
26namespace dwarf {
27
28class Type;
29
30namespace details {
31class Parameter;
32}
33
39 public:
40 enum class KIND {
41 UNKNOWN = 0,
42 TEMPLATE_TYPE,
43 TEMPLATE_VALUE,
44 FORMAL,
45 };
46
49 public:
50 enum class Type : uint8_t {
51 UNKNOWN = 0,
52 REG,
53 };
55 type(ty) {}
56
57 template<class T>
58 const T* as() const {
59 if (T::classof(this)) {
60 return static_cast<const T*>(this);
61 }
62 return nullptr;
63 }
64
66 };
67
69 class LIEF_API RegisterLoc : public Location {
70 public:
71 RegisterLoc(uint64_t reg_id) :
72 Location(Type::REG),
73 id(reg_id) {}
74
75 static bool classof(const Location* loc) {
76 return loc->type == Type::REG;
77 }
78
80 uint64_t id = 0;
81 };
82
83 Parameter() = delete;
86 Parameter& operator=(const Parameter&) = delete;
87 Parameter(const Parameter&) = delete;
88
89
90 KIND kind() const;
91
93 std::string name() const;
94
96 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
97
100 std::unique_ptr<Location> location() const LIEF_LIFETIMEBOUND;
101
102 template<class T>
103 const T* as() const {
104 if (T::classof(this)) {
105 return static_cast<const T*>(this);
106 }
107 return nullptr;
108 }
109
110 virtual ~Parameter();
111
112 LIEF_LOCAL static std::unique_ptr<Parameter>
113 create(std::unique_ptr<details::Parameter> impl);
114
115 protected:
116 Parameter(std::unique_ptr<details::Parameter> impl);
117 std::unique_ptr<details::Parameter> impl_;
118};
119
120namespace parameters {
121
135class LIEF_API Formal : public Parameter {
136 public:
138 static bool classof(const Parameter* P) {
139 return P->kind() == Parameter::KIND::FORMAL;
140 }
141
142 ~Formal() override = default;
143};
144
145
157 public:
159 static bool classof(const Parameter* P) {
160 return P->kind() == Parameter::KIND::TEMPLATE_VALUE;
161 }
162
163 ~TemplateValue() override = default;
164};
165
177 public:
179 static bool classof(const Parameter* P) {
180 return P->kind() == Parameter::KIND::TEMPLATE_TYPE;
181 }
182
183 ~TemplateType() override = default;
184};
185
186}
187
188}
189}
190#endif
This class exposes information about the location of a parameter.
Definition Parameter.hpp:48
Type
Definition Parameter.hpp:50
@ UNKNOWN
Definition Parameter.hpp:51
@ REG
Definition Parameter.hpp:52
const T * as() const
Definition Parameter.hpp:58
Type type
Definition Parameter.hpp:65
Location(Type ty)
Definition Parameter.hpp:54
static bool classof(const Location *loc)
Definition Parameter.hpp:75
uint64_t id
DWARF id of the register.
Definition Parameter.hpp:80
RegisterLoc(uint64_t reg_id)
Definition Parameter.hpp:71
std::string name() const
Name of the parameter.
Parameter(Parameter &&other)
Parameter & operator=(Parameter &&other)
KIND
Definition Parameter.hpp:40
@ TEMPLATE_VALUE
DW_TAG_template_value_parameter.
Definition Parameter.hpp:43
@ TEMPLATE_TYPE
DW_TAG_template_type_parameter.
Definition Parameter.hpp:42
@ FORMAL
DW_TAG_formal_parameter.
Definition Parameter.hpp:44
static std::unique_ptr< Parameter > create(std::unique_ptr< details::Parameter > impl)
std::unique_ptr< Type > type() const
Type of this parameter.
Parameter(const Parameter &)=delete
std::unique_ptr< Location > location() const
Location of this parameter. For instance it can be a specific register that is not following the call...
const T * as() const
Definition Parameter.hpp:103
Parameter & operator=(const Parameter &)=delete
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:67
This class represents a regular function parameter.
Definition Parameter.hpp:135
static bool classof(const Parameter *P)
Definition Parameter.hpp:138
This class represents a template type parameter.
Definition Parameter.hpp:176
static bool classof(const Parameter *P)
Definition Parameter.hpp:179
This class represents a template value parameter.
Definition Parameter.hpp:156
static bool classof(const Parameter *P)
Definition Parameter.hpp:159
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:32
Definition Parameter.hpp:120
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46