Files
revng-revng/include/revng/Model/Segment.h
Alessandro Di Federico 1d91ed9beb tuple_tree_generator: make C++ just a regular backend
The `tuple_tree_generator` component was still heavily treating C++ as a
special citizen.
This commit normalizes the situation.
2022-08-11 16:20:42 +02:00

109 lines
2.7 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "revng/ADT/SortedVector.h"
#include "revng/Model/Identifier.h"
#include "revng/Model/Section.h"
#include "revng/Model/Type.h"
#include "revng/Model/VerifyHelper.h"
#include "revng/Support/MetaAddress.h"
#include "revng/Support/MetaAddress/YAMLTraits.h"
/* TUPLE-TREE-YAML
name: Segment
type: struct
fields:
- name: StartAddress
type: MetaAddress
- name: VirtualSize
type: uint64_t
- name: StartOffset
type: uint64_t
- name: FileSize
type: uint64_t
- name: IsReadable
type: bool
- name: IsWriteable
type: bool
- name: IsExecutable
type: bool
- name: CustomName
type: Identifier
optional: true
- name: OriginalName
type: string
optional: true
- name: CanonicalRegisterValues
optional: true
sequence:
type: SortedVector
elementType: CanonicalRegisterValue
- name: Relocations
optional: true
sequence:
type: SortedVector
elementType: Relocation
- name: Sections
optional: true
sequence:
type: SortedVector
elementType: Section
doc: If there's at least one Section, only Sections where
ContainsCode == true will be searched for code.
- name: Type
type: QualifiedType
optional: true
key:
- StartAddress
- VirtualSize
TUPLE-TREE-YAML */
#include "revng/Model/Generated/Early/Segment.h"
class model::Segment : public model::generated::Segment {
public:
using generated::Segment::Segment;
public:
Identifier name() const;
public:
bool contains(MetaAddress Address) const {
auto EndAddress = StartAddress + VirtualSize;
return (Address.isValid() and StartAddress.addressLowerThanOrEqual(Address)
and Address.addressLowerThan(EndAddress));
}
bool contains(MetaAddress Start, uint64_t Size) const {
return contains(Start) and (Size <= 1 or contains(Start + Size - 1));
}
/// \return the end offset (guaranteed to be greater than StartOffset).
auto endOffset() const { return StartOffset + FileSize; }
/// \return a valid MetaAddress.
auto endAddress() const { return StartAddress + VirtualSize; }
std::pair<MetaAddress, MetaAddress> pagesRange() const {
MetaAddress Start = StartAddress;
Start = Start - (Start.address() % 4096);
MetaAddress End = endAddress();
End = End + (((End.address() + (4096 - 1)) / 4096) * 4096 - End.address());
return { Start, End };
}
public:
bool verify() const debug_function;
bool verify(bool Assert) const debug_function;
bool verify(VerifyHelper &VH) const;
void dump() const debug_function;
};
#include "revng/Model/Generated/Late/Segment.h"