ROSE 0.11.145.147
StoragePool.h
1#ifndef ROSE_BinaryAnalysis_CallingConvention_StoragePool_H
2#define ROSE_BinaryAnalysis_CallingConvention_StoragePool_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/CallingConvention/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/Address.h>
8#include <Rose/BinaryAnalysis/Alignment.h>
9#include <Rose/BinaryAnalysis/ByteOrder.h>
10#include <Rose/BinaryAnalysis/ConcreteLocation.h>
11
12#include <string>
13#include <vector>
14
15class SgAsmType;
16
17namespace Rose {
18namespace BinaryAnalysis {
19namespace CallingConvention {
20
22
25public:
33public:
34 virtual ~TypePredicate();
35protected:
37
38public:
42 virtual bool test(SgAsmType*) const = 0;
43 bool operator()(SgAsmType*) const;
45};
46
47template<class F>
49 F f;
50public:
52 : f(f) {}
53
54 bool test(SgAsmType *type) const override {
55 return f(type);
56 }
57};
58
61
64
67
70
73
75
81public:
89private:
90 std::string name_; // name for debugging
91 TypePredicateConstPtr canStore_; // predicate for types that the locations can store
92
93public:
94 virtual ~StoragePoolBase();
95protected:
96 StoragePoolBase() = delete;
97 StoragePoolBase(const std::string &name, const TypePredicateConstPtr&);
98
99public:
103 virtual Ptr copy() const = 0;
104
109 virtual bool canStore(SgAsmType*) const;
110
116 virtual void reset() = 0;
117
121 virtual std::vector<ConcreteLocation> consume(SgAsmType*) = 0;
122
134 virtual std::vector<ConcreteLocation> constantLocations() const;
135};
136
138
143public:
151private:
152 std::vector<ConcreteLocation> locations_;
153 size_t current_ = 0; // points to the next available location in `locations_`
154
155public:
157protected:
158 StoragePoolEnumerated() = delete;
159 StoragePoolEnumerated(const std::string &name, const TypePredicateConstPtr&);
160
161public:
166 static Ptr instance(const std::string &name, const TypePredicateConstPtr&);
167
173
174public:
175 StoragePoolBasePtr copy() const override;
176 std::vector<ConcreteLocation> constantLocations() const override;
177 std::vector<ConcreteLocation> consume(SgAsmType*) override;
178 void reset() override;
179};
180
182
188public:
196private:
198 size_t minimumValueSize_ = 1;
199 Alignment valuePadding_;
200 ByteOrder::Endianness valueJustification_ = ByteOrder::ORDER_LSB;
201 Alignment alignment_;
202 RegisterDescriptor baseRegister_;
203 RegisterDictionaryPtr registerDictionary_;
204
205 // Stack offsets are signed quantities measured from the perspective of the called function immediately after the "call"
206 // instruction (whatever that might be for the architecture, such as `CALL` on x86). If the stack grows down then the storage
207 // addresses are higher than the current stack pointer; or vice versa.
208 int64_t initialOffset_ = 0; // offset from caller's SP to nearest storage location on the stack
209 int64_t offset_ = 0; // adjusted by allocation: down if stack grows down, up if stack grows up
210
211public:
213 StoragePoolStack() = delete;
214 StoragePoolStack(const std::string &name, const TypePredicateConstPtr&,
216
217public:
221 static Ptr instance(const std::string &name, const TypePredicateConstPtr&, const Architecture::BaseConstPtr&);
222
223public:
240 int64_t initialOffset() const;
241 void initialOffset(int64_t);
249 size_t minimumValueSize() const;
250 void minimumValueSize(size_t m);
258 const Alignment& valuePadding() const;
279 const Alignment& alignment() const;
280 void alignment(const Alignment&);
294public:
295 StoragePoolBasePtr copy() const override;
296 std::vector<ConcreteLocation> consume(SgAsmType*) override;
297 void reset() override;
298};
299
301
309public:
317private:
318 std::vector<StoragePoolBaseConstPtr> initialPools_;
319
320 // Initialized with copies of the `initialPools_` above when `reset` is called. That way, the methods that modify the state of
321 // the pools (allocating space for arguments, etc) operate on copies without modifying the originals.
322 std::vector<StoragePoolBasePtr> activePools_;
323
324public:
325 ~Allocator();
326 Allocator();
327
328public:
332 static Ptr instance();
333
336
340 void reset();
341
346 std::vector<ConcreteLocation> allocate(SgAsmType*);
347};
348
349} // namespace
350} // namespace
351} // namespace
352
353#endif
354#endif
Information about alignments.
Definition Alignment.h:16
Allocates storage for an argument or return value.
AllocatorConstPtr ConstPtr
Shared-ownership pointer.
void reset()
Reset the allocation algorithm.
void append(const StoragePoolBaseConstPtr &)
Add a storage pool to the allocator.
AllocatorPtr Ptr
Shared-ownership pointer.
std::vector< ConcreteLocation > allocate(SgAsmType *)
Allocate storage for a value.
virtual bool canStore(SgAsmType *) const
Test whether locations can store type.
virtual Ptr copy() const =0
Copy constructor.
StoragePoolBaseConstPtr ConstPtr
Shared-ownership pointer.
Definition StoragePool.h:86
virtual std::vector< ConcreteLocation > constantLocations() const
List of constant storage locations.
StoragePoolBasePtr Ptr
Shared-ownership pointer.
Definition StoragePool.h:85
virtual std::vector< ConcreteLocation > consume(SgAsmType *)=0
Consume a storage location.
std::vector< ConcreteLocation > constantLocations() const override
List of constant storage locations.
void append(const ConcreteLocation &)
Append an additional location.
StoragePoolBasePtr copy() const override
Copy constructor.
static Ptr instance(const std::string &name, const TypePredicateConstPtr &)
Constructor.
StoragePoolEnumeratedPtr Ptr
Shared-ownership pointer.
std::vector< ConcreteLocation > consume(SgAsmType *) override
Consume a storage location.
StoragePoolEnumeratedConstPtr ConstPtr
Shared-ownership pointer.
A storage pool for stack-based argument locations.
void alignment(const Alignment &)
Property: Alignment of stack offsets.
int64_t initialOffset() const
Property: Initial stack offset.
const Alignment & valuePadding() const
Property: Aligned value size.
static Ptr instance(const std::string &name, const TypePredicateConstPtr &, const Architecture::BaseConstPtr &)
Constructor.
StackDirection stackDirection() const
Property: Stack direction.
const Alignment & alignment() const
Property: Alignment of stack offsets.
void minimumValueSize(size_t m)
Property: Minimum value size.
void valueJustification(ByteOrder::Endianness)
Property: Value justification within allocated storage.
void initialOffset(int64_t)
Property: Initial stack offset.
void stackDirection(StackDirection)
Property: Stack direction.
RegisterDescriptor baseRegister() const
Property: Base register.
ByteOrder::Endianness valueJustification() const
Property: Value justification within allocated storage.
StoragePoolStackPtr Ptr
Shared-ownership pointer.
StoragePoolStackConstPtr ConstPtr
Shared-ownership pointer.
void valuePadding(const Alignment &)
Property: Aligned value size.
StoragePoolBasePtr copy() const override
Copy constructor.
size_t minimumValueSize() const
Property: Minimum value size.
void baseRegister(RegisterDescriptor)
Property: Base register.
std::vector< ConcreteLocation > consume(SgAsmType *) override
Consume a storage location.
bool test(SgAsmType *type) const override
Evaluate this predicate on a type.
Definition StoragePool.h:54
TypePredicateConstPtr ConstPtr
Shared-ownership pointer.
Definition StoragePool.h:30
virtual bool test(SgAsmType *) const =0
Evaluate this predicate on a type.
bool operator()(SgAsmType *) const
Evaluate this predicate on a type.
TypePredicatePtr Ptr
Shared-ownership pointer.
Definition StoragePool.h:29
Describes (part of) a physical CPU register.
Base class for binary types.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
@ ORDER_LSB
Least significant byte first, i.e., little-endian.
Definition ByteOrder.h:22
std::shared_ptr< TypePredicate > TypePredicatePtr
Shared-ownership pointer to TypePredicate.
std::shared_ptr< const StoragePoolEnumerated > StoragePoolEnumeratedConstPtr
Shared-ownership pointer to StoragePoolEnumerated.
std::shared_ptr< const Allocator > AllocatorConstPtr
Shared-ownership pointer to Allocator.
TypePredicate::Ptr isFpNotWiderThan(size_t nBits)
Functor returning true for floating-point types not wider than specified.
TypePredicate::Ptr isNonFpNotWiderThan(size_t nBits)
Functor returning true for non-floating-point types not wider than specified.
std::shared_ptr< Allocator > AllocatorPtr
Shared-ownership pointer to Allocator.
TypePredicate::Ptr isPointerNotWiderThan(size_t nBits)
Functor returning true for pointers not wider than specified.
std::shared_ptr< StoragePoolStack > StoragePoolStackPtr
Shared-ownership pointer to StoragePoolStack.
std::shared_ptr< const StoragePoolBase > StoragePoolBaseConstPtr
Shared-ownership pointer to StoragePoolBase.
std::shared_ptr< const TypePredicate > TypePredicateConstPtr
Shared-ownership pointer to TypePredicate.
TypePredicate::Ptr isIntegerNotWiderThan(size_t nBits)
Functor returning true for integer types not wider than specified.
std::shared_ptr< StoragePoolEnumerated > StoragePoolEnumeratedPtr
Shared-ownership pointer to StoragePoolEnumerated.
@ GROWS_DOWN
A push decrements the stack pointer.
std::shared_ptr< StoragePoolBase > StoragePoolBasePtr
Shared-ownership pointer to StoragePoolBase.
std::shared_ptr< const StoragePoolStack > StoragePoolStackConstPtr
Shared-ownership pointer to StoragePoolStack.
TypePredicate::Ptr isAnyType()
Functor returning true for any non-null type.
The ROSE library.