1#ifndef SEGMENT_MANAGER_H
2#define SEGMENT_MANAGER_H
10#include "../script/script.h"
90 void ClearSegmentManager();
95 void SetLinkScript(std::string script_file, std::map<std::string, std::string>& options)
override;
131 virtual void OnNewSegment(std::shared_ptr<Segment> segment);
152 std::shared_ptr<Segment>
FetchSegment(std::string name);
164 void ProcessAction(std::unique_ptr<Script::Node>& action,
Module& module);
165 void PostProcessAction(std::unique_ptr<Script::Node>& action,
Module& module);
166 void ProcessCommand(std::unique_ptr<Script::Node>& command,
Module& module);
167 bool CheckPredicate(std::unique_ptr<Script::Node>& predicate, std::shared_ptr<Section> section,
Module& module);
168 offset_t EvaluateExpression(std::unique_ptr<Script::Node>& expression,
Module& module);
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
A helper class to collect sections into segments.
Definition segment_manager.h:32
std::vector< std::shared_ptr< Segment > > segment_vector
Ordered sequence of segments.
Definition segment_manager.h:72
void ProcessScript(std::unique_ptr< Script::List > &directives, Module &module)
Executes a parsed linker script on a module and collects segments The function OnNewSegment can be de...
Definition segment_manager.cc:164
void AlignCurrentAddress(offset_t align)
Aligns current address to alignment, using SetCurrentAddress.
Definition segment_manager.cc:96
void AppendSection(std::shared_ptr< Section > section)
Adds a new section to the current segment, sets the base to the same as the segment.
Definition segment_manager.cc:158
std::shared_ptr< Segment > AppendSegment(std::string name)
Creates a new segment and attaches it to the image.
Definition segment_manager.cc:138
bool condition_failed
Condition to signal end of current for statement.
Definition segment_manager.h:56
std::map< std::string, std::shared_ptr< Segment > > segment_map
Map of segments from their names.
Definition segment_manager.h:76
std::shared_ptr< Segment > current_segment
Currently processed segment.
Definition segment_manager.h:80
bool current_is_template
Set during evaluation of body in a for <guard> { <body> } statement.
Definition segment_manager.h:46
void FinishCurrentSegment()
Closes the current segment, sets current_segment to null.
Definition segment_manager.cc:108
virtual void OnCallDirective(std::string identifier)
Callback function for the CALL directive.
Definition segment_manager.cc:125
offset_t template_counter
Counts how many times a for statement has been invoked.
Definition segment_manager.h:52
std::string current_template_name
Records the name of the currently generating segment for a for statement.
Definition segment_manager.h:60
std::map< std::string, Location > linker_parameters
Parameters that permit customizing the linker script.
Definition segment_manager.h:84
void SetCurrentAddress(offset_t address)
Moves the current address pointer further, and if the current segment already contains data,...
Definition segment_manager.cc:80
offset_t current_address
Holds the current address value when there is no current_segment.
Definition segment_manager.h:37
void SetLatestBase(offset_t address)
Sets the base of the current section (the value from which offsets are counted from)
Definition segment_manager.cc:101
offset_t GetCurrentAddress() const
Retrieves current address pointer.
Definition segment_manager.cc:68
std::string linker_script
Contents of the linker script.
Definition segment_manager.h:88
offset_t current_base
The base address of the current section.
Definition segment_manager.h:68
std::unique_ptr< Script::List > GetScript(Module &module)
Compiles the linker script into an internal format.
Definition segment_manager.cc:49
bool current_is_template_head
Set during evaluation of guard in a for <guard> { <body> } statement.
Definition segment_manager.h:42
void SetLinkScript(std::string script_file, std::map< std::string, std::string > &options) override
Sets up the linker script and linker parameters.
Definition segment_manager.cc:25
virtual void OnNewSegment(std::shared_ptr< Segment > segment)
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition segment_manager.cc:120
std::shared_ptr< Segment > FetchSegment(std::string name)
Attempts to fetch a segment, returns null if not found.
Definition segment_manager.cc:145