Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
partial hlorenzi#115: increment address within asm blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmett81 committed Oct 20, 2021
1 parent 1ecb2d5 commit 2259eb1
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 23 deletions.
51 changes: 29 additions & 22 deletions src/asm/parser/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ pub fn parse_file<TFilename: Into<String>>(
fileserver: &dyn util::FileServer,
filename: TFilename,
span: Option<&diagn::Span>,
parsed_filenames: &mut std::collections::HashSet<String>)
parsed_filenames: &mut std::collections::HashSet<String>,
ignored_filenames: &mut std::collections::HashSet<String>)
-> Result<(), ()>
{
let filename = filename.into();
let chars = fileserver.get_chars(report.clone(), &filename, span)?;
let tokens = syntax::tokenize(report.clone(), &filename, &chars)?;
let parser = syntax::Parser::new(Some(report.clone()), &tokens);

parsed_filenames.insert(filename.clone());

let mut state = asm::parser::State

if !ignored_filenames.contains(&filename)
{
report,
asm_state,
fileserver,
filename: std::rc::Rc::new(filename.clone()),
parser,
parsed_filenames,
};
let chars = fileserver.get_chars(report.clone(), &filename, span)?;
let tokens = syntax::tokenize(report.clone(), &filename, &chars)?;
let parser = syntax::Parser::new(Some(report.clone()), &tokens);

//println!("{:#?}", state.parser.tokens.iter().map(|t| t.kind).collect::<Vec<_>>());

while !state.parser.is_over()
{
parse_line(&mut state)?;
parsed_filenames.insert(filename.clone());

let mut state = asm::parser::State
{
report,
asm_state,
fileserver,
filename: std::rc::Rc::new(filename.clone()),
parser,
parsed_filenames,
ignored_filenames
};

//println!("{:#?}", state.parser.tokens.iter().map(|t| t.kind).collect::<Vec<_>>());

while !state.parser.is_over()
{
parse_line(&mut state)?;
}

parsed_filenames.remove(&filename);
}

parsed_filenames.remove(&filename);
Ok(())
}

Expand Down Expand Up @@ -113,6 +119,7 @@ pub fn parse_directive(state: &mut asm::parser::State)
"align" => asm::parser::parse_directive_align(state)?,
"labelalign" => asm::parser::parse_directive_labelalign(state)?,
"addr" => asm::parser::parse_directive_addr(state)?,
"once" => asm::parser::parse_directive_once(state)?,
//"enable" => asm::parser::parse_directive_enable(state)?,
_ =>
{
Expand Down
13 changes: 12 additions & 1 deletion src/asm/parser/include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,16 @@ pub fn parse_directive_include(
state.fileserver,
new_filename,
Some(&tk_filename.span),
state.parsed_filenames)
state.parsed_filenames,
state.ignored_filenames)
}

pub fn parse_directive_once(
state: &mut asm::parser::State)
-> Result<(), ()>
{
state.ignored_filenames.insert(
state.filename.as_ref().clone());

Ok(())
}
1 change: 1 addition & 0 deletions src/asm/parser/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pub struct State<'a>
pub filename: std::rc::Rc<String>,
pub parser: syntax::Parser<'a>,
pub parsed_filenames: &'a mut std::collections::HashSet<String>,
pub ignored_filenames: &'a mut std::collections::HashSet<String>,
}
1 change: 1 addition & 0 deletions src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Assembler
fileserver,
filename,
None,
&mut std::collections::HashSet::new(),
&mut std::collections::HashSet::new());

if pass_report.has_errors() || result.is_err()
Expand Down
Binary file added test.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions test2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#d32 0xC0DE
8 changes: 8 additions & 0 deletions tests/once/1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ruledef
{
emit {x:u8} => x
}

#include "inc.asm"
#include "inc.asm"
emit $ ; = 0x02
8 changes: 8 additions & 0 deletions tests/once/2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ruledef
{
emit {x:u8} => x
}

#include "inc2.asm"
#include "inc2.asm"
emit $ ; = 0x01
1 change: 1 addition & 0 deletions tests/once/inc.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#d8 0xA
2 changes: 2 additions & 0 deletions tests/once/inc2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#once
#d8 0xA

0 comments on commit 2259eb1

Please sign in to comment.