Struct test_assembler::Label
[−]
[src]
pub struct Label(pub Rc<RealLabel>);
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.
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);
Methods from Deref<Target=RealLabel>
fn value(&self) -> Option<u64>
Get the constant value of the RealLabel
, if known.
fn offset(&self, other: &RealLabel) -> Option<i64>
Get the relative offset from another label, if possible.
fn set_const(&self, val: u64)
Set this RealLabel
s value to val
.
fn set(&self, other: &RealLabel)
Set this RealLabel
s value equal to other
.
Trait Implementations
impl Clone for Label
[src]
fn clone(&self) -> Label
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Deref for Label
[src]
type Target = RealLabel
The resulting type after dereferencing
fn deref<'a>(&'a self) -> &'a RealLabel
The method called to dereference a value
impl LabelMaker for Label
[src]
fn new() -> Label
Create an undefined label.
fn from_const(val: u64) -> Label
Create a label with a constant value val
.
fn from_label(other: &Label) -> Label
Create a label whose value is equal to other
.
fn from_label_offset(other: &Label, offset: i64) -> Label
Create a label whose value is equal to other
plus offset
.
impl<'a> Add<i64> for &'a Label
[src]
Add a constant to a Label
, producing a new Label
.
The new Label
references the existing Label
.
type Output = Label
The resulting type after applying the +
operator
fn add(self, rhs: i64) -> Label
The method for the +
operator
impl<'a> Sub<i64> for &'a Label
[src]
Subtract a constant from a Label
, producing a new Label
.
The new Label
references the existing Label
.
type Output = Label
The resulting type after applying the -
operator
fn sub(self, rhs: i64) -> Label
The method for the -
operator
impl<'a> Sub<&'a Label> for &'a Label
[src]
Subtract a Label
from another Label
, returning an i64
.
If the labels are unrelated this will panic.
type Output = i64
The resulting type after applying the -
operator
fn sub(self, rhs: &'a Label) -> i64
The method for the -
operator