pub struct Label(pub Rc<RealLabel>);
Expand description
A Label
represents a value not yet known that is stored in a Section
.
As long as all the labels a section refers to are defined by the time its contents are retrieved as bytes, undefined labels can be used freely in that section’s construction. A label can be in one of three states:
- undefined,
- defined as the sum of some other label and a constant, or
- a constant.
A label’s value never changes, but it can accumulate constraints. Adding labels and integers is permitted, and yields a label. Subtracting a constant from a label is permitted, and also yields a label. Subtracting two labels that have some relationship to each other is permitted, and yields a constant.
A common usage of Label
is to use Section::mark
to make a Label
contain an offset into the Section
without having to hard-code it.
The Section
methods for inserting fixed-width integer values (such as
Section::L32
) all accept &Label
for the purpose of writing a value
that is not yet available.
§Examples
Label
s can be set to point to other Label
s, potentially with an offset.
use test_assembler::*;
let l1 = Label::new();
// l2 is l1's value (which is currently undefined) + 10
let l2 = &l1 + 10;
// Now give l1 a value.
l1.set_const(1);
// l2's value is derived from l1.
assert_eq!(l2.value().unwrap(), 11);
Tuple Fields§
§0: Rc<RealLabel>
Trait Implementations§
Source§impl<'a> Add<i64> for &'a Label
Add a constant to a Label
, producing a new Label
.
impl<'a> Add<i64> for &'a Label
Add a constant to a Label
, producing a new Label
.
The new Label
references the existing Label
.
Source§impl LabelMaker for Label
impl LabelMaker for Label
Source§fn from_const(val: u64) -> Label
fn from_const(val: u64) -> Label
val
.Source§fn from_label(other: &Label) -> Label
fn from_label(other: &Label) -> Label
other
.Source§impl<'a> Sub<i64> for &'a Label
Subtract a constant from a Label
, producing a new Label
.
impl<'a> Sub<i64> for &'a Label
Subtract a constant from a Label
, producing a new Label
.
The new Label
references the existing Label
.
Source§impl<'a> Sub for &'a Label
Subtract a Label
from another Label
, returning an i64
.
impl<'a> Sub for &'a Label
Subtract a Label
from another Label
, returning an i64
.
If the labels are unrelated this will panic.