Struct test_assembler::Section
[−]
[src]
pub struct Section { pub endian: Endian, // some fields omitted }
A section is a sequence of bytes, constructed by appending bytes to the end.
Sections have a convenient and flexible set of member functions for appending data in various formats: big-endian and little-endian signed and unsigned values of different sizes, and raw blocks of bytes.
There are methods for appending each of u8
, u16
, u32
, and u64
in each of big, little, or the Section
's default endianness.
The method names are {D,L,B}{8,16,32,64} for each variant, so
D16
writes a u16
in the Section
's default endianness, and
L64
writes a u64
in little-endian byte order.
Each of these methods also accepts a Label
to write
non-constant values.
See the module-level documentation for examples.
Fields
endian: Endian
The current endianness of the writer.
This sets the behavior of the D
Methods
impl Section
[src]
fn new() -> Section
Construct a Section
with platform-default endianness.
fn with_endian(endian: Endian) -> Section
Construct a Section
with endian
endianness.
fn size(&self) -> u64
Return the current size of the section.
fn get_contents(self) -> Option<Vec<u8>>
Get the contents of this section as a slice of bytes.
Consumes the section. If there were still undefined labels,
return None
.
fn start(&self) -> Label
Return a label representing the start of the section.
It is up to the user whether this label represents the section's position in an object file, the section's address in memory, or what have you; some applications may need both, in which case this simple-minded interface won't be enough. This class only provides a single start label, for use with the Here and Mark member functions.
fn here(&self) -> Label
A label representing the point at which the next Appended item will appear in the section, relative to start().
fn mark(self, label: &Label) -> Section
Set label
to Here, and return this section.
fn append_bytes(self, data: &[u8]) -> Section
Append data
to the end of this section.
Return this section.
fn append_repeated(self, byte: u8, count: usize) -> Section
Append count
copies of byte
to the end of this section.
Return this section.
fn align(self, alignment: u64) -> Section
Jump to the next location aligned on an alignment
-byte boundary, relative to the start of the section.
Fill the gap with zeroes. alignment
must be a power of two.
Return this section.
fn D8<'a, T: ToLabelOrNum<'a, u8>>(self, byte: T) -> Section
Append byte
with the Section's default endianness.
byte
may be a Label
or a u8
.
Return this section.
fn L8<'a, T: ToLabelOrNum<'a, u8>>(self, byte: T) -> Section
Append byte
as little-endian (identical to D8
).
Return this section.
fn B8<'a, T: ToLabelOrNum<'a, u8>>(self, byte: T) -> Section
Append byte
as big-endian (identical to D8
).
Return this section.
fn D16<'a, T: ToLabelOrNum<'a, u16>>(self, word: T) -> Section
Append word
with the Section's default endianness.
word
may be a Label
or a u16
.
Return this section.
fn L16<'a, T: ToLabelOrNum<'a, u16>>(self, word: T) -> Section
Append word
as little-endian.
word
may be a Label
or a u16
.
Return this section.
fn B16<'a, T: ToLabelOrNum<'a, u16>>(self, word: T) -> Section
Append word
as big-endian.
word
may be a Label
or a u16
.
Return this section.
fn D32<'a, T: ToLabelOrNum<'a, u32>>(self, dword: T) -> Section
Append dword
with the Section's default endianness.
dword
may be a Label
or a u32
.
Return this section.
fn L32<'a, T: ToLabelOrNum<'a, u32>>(self, dword: T) -> Section
Append dword
as little-endian.
dword
may be a Label
or a u32
.
Return this section.
fn B32<'a, T: ToLabelOrNum<'a, u32>>(self, dword: T) -> Section
Append dword
as big-endian.
dword
may be a Label
or a u32
.
Return this section.
fn D64<'a, T: ToLabelOrNum<'a, u64>>(self, qword: T) -> Section
Append qword
with the Section's default endianness.
qword
may be a Label
or a u32
.
Return this section.
fn L64<'a, T: ToLabelOrNum<'a, u64>>(self, qword: T) -> Section
Append qword
as little-endian.
qword
may be a Label
or a u32
.
Return this section.
fn B64<'a, T: ToLabelOrNum<'a, u64>>(self, qword: T) -> Section
Append qword
as big-endian.
qword
may be a Label
or a u32
.
Return this section.