RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
segment.h
1#ifndef SEGMENT_H
2#define SEGMENT_H
3
4#include <iostream>
5#include <memory>
6#include <string>
7#include <vector>
8#include "../common.h"
9#include "writable.h"
10#include "writer.h"
11
12namespace Linker
13{
14 class Section;
15 class Writable;
16
25 class Segment : public Writable, public std::enable_shared_from_this<Segment>
26 {
27 public:
31 std::string name;
35 std::vector<std::shared_ptr<Section>> sections;
39 offset_t base_address;
43 offset_t align = 1;
50 offset_t data_size = 0;
57 offset_t zero_fill = 0;
61 offset_t optional_extra = 0;
62
63 Segment(std::string name, offset_t base_address = 0)
65 {
66 }
67
71 bool IsMissing();
75 void Fill();
79 void RealignEnd(offset_t align);
85 void Append(std::shared_ptr<Section> section);
89 offset_t WriteFile(std::ostream& out, offset_t size, offset_t offset = 0);
93 offset_t WriteFile(std::ostream& out);
97 offset_t WriteFile(Writer& wr, offset_t count, offset_t offset = 0) override;
101 offset_t WriteFile(Writer& wr);
102 int GetByte(offset_t offset) override;
106 offset_t TotalSize();
113 offset_t ActualDataSize() override;
117 offset_t GetStartAddress();
121 offset_t GetEndAddress();
127 void SetEndAddress(offset_t address);
131 void AlignEndAddress(offset_t align);
132 protected:
133 void ShiftAddress(int64_t amount);
134 public:
138 void SetStartAddress(offset_t address);
139 };
140
141 std::ostream& operator<<(std::ostream& out, const Segment& segment);
142}
143
144#endif /* SEGMENT_H */
A class representing a sequence of sections that must be written to the output file as a group.
Definition segment.h:26
std::string name
The name of the segment.
Definition segment.h:31
void Append(std::shared_ptr< Section > section)
Appends section to segment.
Definition segment.cc:40
offset_t zero_fill
Extra zero filled space following filled data.
Definition segment.h:57
offset_t GetEndAddress()
Returns end address (GetStartAddress() + TotalSize())
Definition segment.cc:171
void AlignEndAddress(offset_t align)
Aligns the end of the segment.
Definition segment.cc:203
offset_t base_address
Address where segment starts.
Definition segment.h:39
std::vector< std::shared_ptr< Section > > sections
Sequence of sections belonging to the segment.
Definition segment.h:35
void RealignEnd(offset_t align)
Aligns end of segment by increasing size of last section.
Definition segment.cc:26
void Fill()
Fills zero filled sections with zero data, making them non-zero filled in the sense that they have to...
Definition segment.cc:12
offset_t data_size
Cached value of the non-filled data for the entire segment.
Definition segment.h:50
offset_t optional_extra
Optional extra space after zero filled data.
Definition segment.h:61
offset_t WriteFile(std::ostream &out, offset_t size, offset_t offset=0)
Writes data of non-zero filled sections.
Definition segment.cc:86
void SetStartAddress(offset_t address)
Forcibly resets starting address of segment.
Definition segment.cc:226
offset_t ActualDataSize() override
Retrieves size of all data in segment.
Definition segment.cc:154
offset_t TotalSize()
Retrieves total size of segment.
Definition segment.cc:149
bool IsMissing()
Segment that contains neither non zero filled, nor zero filled, nor optional extra data.
Definition segment.cc:7
int GetByte(offset_t offset) override
Retrieve byte at a certain offset (optional, might not be defined)
Definition segment.cc:133
void SetEndAddress(offset_t address)
Increases final section to end on specified address.
Definition segment.cc:176
offset_t GetStartAddress()
Returns starting address (base_address)
Definition segment.cc:166
offset_t align
Alignment requirements of segment.
Definition segment.h:43
Represents an abstract interface whose data can be written to a file.
Definition writable.h:15
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15