Require assembler sections to specify where in virtual memory they begin

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-02-10 18:02:44 -05:00
parent a4a37b5a27
commit 7504b81b2d
4 changed files with 15 additions and 17 deletions

View File

@@ -38,7 +38,6 @@ impl<'a> Assemble<'a> {
}
pub fn assemble(&mut self) -> Result<Object> {
let mut pos = 0;
let mut sections = Vec::new();
// gather global symbols
@@ -78,11 +77,9 @@ impl<'a> Assemble<'a> {
}
}
let (start, end) = match org {
Some(SectionOrg::Start(start)) => (*start, start + bytes.len() as u64),
Some(SectionOrg::Range(start, end)) => (*start, *end),
None => (pos, pos + bytes.len() as u64),
SectionOrg::Start(start) => (*start, start + bytes.len() as u64),
SectionOrg::Range(start, end) => (*start, *end),
};
pos = end;
let section = match block {
SectionBlock::Data { .. } => Section::Data {
@@ -121,10 +118,12 @@ impl<'a> Assemble<'a> {
fn gather_symbols(block: &SectionBlock, export: bool) -> Result<HashMap<String, u64>> {
match block {
SectionBlock::Data { body, .. } | SectionBlock::Code { body, .. } => {
SectionBlock::Data { org, body, .. } | SectionBlock::Code { org, body, .. } => {
let mut exports = HashSet::new();
let mut labels = HashMap::new();
let mut pos = 0;
let mut pos = match org {
SectionOrg::Start(start) | SectionOrg::Range(start, _) => (*start) as usize,
};
for line in body.iter() {
match line {
Line::Inst(inst) => {