Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bwburnsides committed Dec 26, 2023
1 parent 1248c34 commit 4bef7d8
Show file tree
Hide file tree
Showing 90 changed files with 8,670 additions and 9,585 deletions.
23 changes: 11 additions & 12 deletions src/asm/decls/bank.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
use crate::*;


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
let asm::AstAny::DirectiveBank(ref mut node) = any_node
else { continue };
else
{
continue;
};

if node.item_ref.is_some()
{
continue;
}


let item_ref = decls.bankdefs.get_by_name_global(
report,
node.name_span,
&node.name)?;

let item_ref = decls
.bankdefs
.get_by_name_global(report, node.name_span, &node.name)?;

node.item_ref = Some(item_ref);
}


Ok(())
}
}
19 changes: 10 additions & 9 deletions src/asm/decls/bankdef.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use crate::*;


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
let asm::AstAny::DirectiveBankdef(ref mut node) = any_node
else { continue };
else
{
continue;
};

if node.item_ref.is_some()
{
continue;
}


let item_ref = decls.bankdefs.declare(
report,
node.name_span,
&util::SymbolContext::new_global(),
node.name.clone(),
0,
util::SymbolKind::Other)?;

util::SymbolKind::Other,
)?;

node.item_ref = Some(item_ref);
}


Ok(())
}
}
19 changes: 10 additions & 9 deletions src/asm/decls/function.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use crate::*;


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
let asm::AstAny::DirectiveFn(ref mut node) = any_node
else { continue };
else
{
continue;
};

if node.item_ref.is_some()
{
continue;
}


let item_ref = decls.symbols.declare(
report,
node.name_span,
&util::SymbolContext::new_global(),
node.name.clone(),
0,
util::SymbolKind::Function)?;

util::SymbolKind::Function,
)?;

node.item_ref = Some(item_ref);
}


Ok(())
}
}
21 changes: 8 additions & 13 deletions src/asm/decls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::*;


mod bank;
mod bankdef;
mod function;
mod ruledef;
mod symbol;
mod function;


#[derive(Debug)]
pub struct ItemDecls
Expand All @@ -16,10 +14,7 @@ pub struct ItemDecls
pub symbols: util::SymbolManager<asm::Symbol>,
}


pub fn init(
report: &mut diagn::Report)
-> Result<ItemDecls, ()>
pub fn init(report: &mut diagn::Report) -> Result<ItemDecls, ()>
{
let mut decls = ItemDecls {
bankdefs: util::SymbolManager::new("bank"),
Expand All @@ -33,19 +28,19 @@ pub fn init(
&util::SymbolContext::new_global(),
"#global_bankdef".to_string(),
0,
util::SymbolKind::Other)?;

util::SymbolKind::Other,
)?;

debug_assert!(initial_item_ref.0 == 0);

Ok(decls)
}


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
bankdef::collect(report, ast, decls)?;
bank::collect(report, ast, decls)?;
Expand All @@ -56,4 +51,4 @@ pub fn collect(
report.stop_at_errors()?;

Ok(())
}
}
25 changes: 13 additions & 12 deletions src/asm/decls/ruledef.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
use crate::*;


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
let asm::AstAny::DirectiveRuledef(ref mut node) = any_node
else { continue };
else
{
continue;
};

if node.item_ref.is_some()
{
continue;
}


let name = node.name
let name = node
.name
.clone()
.unwrap_or_else(||
decls.ruledefs.generate_anonymous_name());
.unwrap_or_else(|| decls.ruledefs.generate_anonymous_name());

let item_ref = decls.ruledefs.declare(
report,
node.name_span,
&util::SymbolContext::new_global(),
name,
0,
util::SymbolKind::Other)?;

util::SymbolKind::Other,
)?;

node.item_ref = Some(item_ref);
}


Ok(())
}
}
30 changes: 13 additions & 17 deletions src/asm/decls/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
use crate::*;


pub fn collect(
report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
decls: &mut asm::ItemDecls)
-> Result<(), ()>
decls: &mut asm::ItemDecls,
) -> Result<(), ()>
{
let mut symbol_ctx = util::SymbolContext::new_global();


for any_node in &mut ast.nodes
{
let asm::AstAny::Symbol(ref mut node) = any_node
else { continue };
else
{
continue;
};

if node.item_ref.is_none()
{
let kind = {
match node.kind
{
asm::AstSymbolKind::Label =>
util::SymbolKind::Label,
asm::AstSymbolKind::Constant(_) =>
util::SymbolKind::Constant,
asm::AstSymbolKind::Label => util::SymbolKind::Label,
asm::AstSymbolKind::Constant(_) => util::SymbolKind::Constant,
}
};

Expand All @@ -33,17 +32,14 @@ pub fn collect(
&symbol_ctx,
node.name.clone(),
node.hierarchy_level,
kind)?;

kind,
)?;

node.item_ref = Some(item_ref);
}

symbol_ctx = decls.symbols
.get(node.item_ref.unwrap())
.ctx
.clone();
symbol_ctx = decls.symbols.get(node.item_ref.unwrap()).ctx.clone();
}


Ok(())
}
}
13 changes: 5 additions & 8 deletions src/asm/defs/addr.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use crate::*;


#[derive(Debug)]
pub struct AddrDirective
{
pub item_ref: util::ItemRef<Self>,
pub address: util::BigInt,
}


pub fn define(
_report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
_decls: &mut asm::ItemDecls,
defs: &mut asm::ItemDefs)
-> Result<(), ()>
defs: &mut asm::ItemDefs,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
Expand All @@ -26,13 +24,12 @@ pub fn define(
item_ref,
address: util::BigInt::new(0, None),
};

defs.addr_directives.define(item_ref, res);

ast_addr.item_ref = Some(item_ref);
}
}


Ok(())
}
}
13 changes: 5 additions & 8 deletions src/asm/defs/align.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use crate::*;


#[derive(Debug)]
pub struct AlignDirective
{
pub item_ref: util::ItemRef<Self>,
pub align_size: usize,
}


pub fn define(
_report: &mut diagn::Report,
ast: &mut asm::AstTopLevel,
_decls: &mut asm::ItemDecls,
defs: &mut asm::ItemDefs)
-> Result<(), ()>
defs: &mut asm::ItemDefs,
) -> Result<(), ()>
{
for any_node in &mut ast.nodes
{
Expand All @@ -26,13 +24,12 @@ pub fn define(
item_ref,
align_size: 0,
};

defs.align_directives.define(item_ref, res);

ast_align.item_ref = Some(item_ref);
}
}


Ok(())
}
}
Loading

0 comments on commit 4bef7d8

Please sign in to comment.