Require assembler sections to specify where in virtual memory they begin
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -3,11 +3,11 @@ use crate::vm::{inst::*, reg::Reg};
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum SectionBlock {
|
||||
Data {
|
||||
org: Option<SectionOrg>,
|
||||
org: SectionOrg,
|
||||
body: Vec<Line>,
|
||||
},
|
||||
Code {
|
||||
org: Option<SectionOrg>,
|
||||
org: SectionOrg,
|
||||
body: Vec<Line>,
|
||||
},
|
||||
Meta {
|
||||
|
||||
@@ -82,11 +82,11 @@ SectionOrg: SectionOrg = {
|
||||
}
|
||||
|
||||
Section: SectionBlock = {
|
||||
"data" <org:SectionOrg?> "{" <body:Line*> "}" => {
|
||||
"data" <org:SectionOrg> "{" <body:Line*> "}" => {
|
||||
SectionBlock::Data { org, body }
|
||||
},
|
||||
|
||||
"code" <org:SectionOrg?> "{" <body:Line*> "}" => {
|
||||
"code" <org:SectionOrg> "{" <body:Line*> "}" => {
|
||||
SectionBlock::Code { org, body }
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user