Skip to content

Commit

Permalink
[basm] Add some option to individually deactivate chunks in snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty/Benediction committed Jan 7, 2024
1 parent 0de3384 commit ea83d2a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cpclib-asm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ chardetng = {workspace = true, optional = true}
aho-corasick = "1.1.2"
compact_str = "0.7.1"
beef = "0.5.2"
enumflags2 = "0.7.8"


[build-dependencies]
Expand Down
29 changes: 21 additions & 8 deletions cpclib-asm/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ impl Env {

// Add the symbols in the snapshot
fn handle_sna_symbols(&mut self) -> Result<(), AssemblerError> {
if ! self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaSymb) {
return Ok(());
}


let ace_chunk = self.symbols_output.build_ace_snapshot_chunk(self.symbols());
self.sna.add_chunk(ace_chunk);

Expand All @@ -964,8 +969,15 @@ impl Env {
/// as they are stored inside a chunk of the snapshot:
/// If one day another export is coded, we could export the others too.
fn handle_breakpoints(&mut self) -> Result<(), AssemblerError> {
let mut winape_chunk = WinapeBreakPointChunk::empty();
let mut ace_chunk = AceBreakPointChunk::empty();
let mut winape_chunk = if self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaBrks) {
Some(WinapeBreakPointChunk::empty())
} else {
None
};
let mut ace_chunk = if self.options().assemble_options().get_flag(crate::AssemblingOptionFlags::SnaBrkc) {
Some(AceBreakPointChunk::empty())
}
else {None};

let pages_mmr = MMR_PAGES_SELECTION;
for (activepage, _page) in pages_mmr[0..self.pages_info_sna.len()].iter().enumerate() {
Expand All @@ -978,17 +990,18 @@ impl Env {
};
eprint!("{}", info);

winape_chunk.add_breakpoint(brk.winape());
ace_chunk.add_breakpoint(brk.ace());
winape_chunk.as_mut().map(|chunk| chunk.add_breakpoint(brk.winape()));
ace_chunk.as_mut().map(|chunk| chunk.add_breakpoint(brk.ace()));
}
}

if winape_chunk.nb_breakpoints() > 0 {
self.sna.add_chunk(winape_chunk);

if let Some(chunk) = winape_chunk && chunk.nb_breakpoints() > 0 {
self.sna.add_chunk(chunk);
}

if ace_chunk.nb_breakpoints() > 0 {
self.sna.add_chunk(ace_chunk);
if let Some(chunk) = ace_chunk && chunk.nb_breakpoints() > 0 {
self.sna.add_chunk(chunk);
}

Ok(())
Expand Down
51 changes: 44 additions & 7 deletions cpclib-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,52 @@ use preamble::processed_token::ProcessedToken;
use preamble::*;

use self::listing_output::ListingOutput;
use enumflags2::{bitflags, make_bitflags, BitFlags};

#[bitflags]
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum AssemblingOptionFlags {
/// Set to consider that the assembler pay attention to the case of the labels
CaseSensitive,
// Set to include SYMB in sna chunks
SnaSymb,
// Set to include BRKS in sna chunks
SnaBrks,
// Set to include BRKC in sna chunks
SnaBrkc
}


impl AssemblingOptionFlags {
pub fn from_chunk(chunk: &str) -> Option<Self> {
match chunk {
"SYMB" => Some(Self::SnaSymb),
"BRKS" => Some(Self::SnaBrks),
"BRKC" => Some(Self::SnaBrkc),
_ => None
}
}
}

/// Configuration of the assembler. By default the assembler is case sensitive and has no symbol
#[derive(Debug, Clone)]
pub struct AssemblingOptions {
/// Set to true to consider that the assembler pay attention to the case of the labels
case_sensitive: bool,

flags: BitFlags<AssemblingOptionFlags>,

/// Contains some symbols that could be used during assembling
symbols: cpclib_tokens::symbols::SymbolsTable,
output_builder: Option<Arc<RwLock<ListingOutput>>>,
/// The snapshot may be prefiled with a dedicated snapshot
snapshot_model: Option<Snapshot>,
amsdos_behavior: AmsdosAddBehavior
amsdos_behavior: AmsdosAddBehavior,
}

impl Default for AssemblingOptions {
fn default() -> Self {
Self {
case_sensitive: true,
flags: AssemblingOptionFlags::CaseSensitive | AssemblingOptionFlags::SnaBrkc | AssemblingOptionFlags::SnaBrks | AssemblingOptionFlags::SnaSymb,
symbols: cpclib_tokens::symbols::SymbolsTable::default(),
output_builder: None,
snapshot_model: None,
Expand All @@ -77,7 +105,7 @@ impl AssemblingOptions {

pub fn new_case_insensitive() -> Self {
let mut options = Self::new_case_sensitive();
options.case_sensitive = false;
options.set_case_sensitive(false);
options
}

Expand All @@ -88,9 +116,18 @@ impl AssemblingOptions {
options
}

pub fn set_flag(&mut self, flag: AssemblingOptionFlags, val: bool) -> &mut Self {
self.flags.set(flag, val);
self
}

pub fn get_flag(&self, flag: AssemblingOptionFlags) -> bool {
self.flags.contains(flag)
}

/// Specify if the assembler must be case sensitive or not
pub fn set_case_sensitive(&mut self, val: bool) -> &mut Self {
self.case_sensitive = val;
self.set_flag(AssemblingOptionFlags::CaseSensitive, val);
self
}

Expand Down Expand Up @@ -120,7 +157,7 @@ impl AssemblingOptions {
}

pub fn case_sensitive(&self) -> bool {
self.case_sensitive
self.get_flag(AssemblingOptionFlags::CaseSensitive)
}

pub fn snapshot_model(&self) -> Option<&Snapshot> {
Expand Down
20 changes: 19 additions & 1 deletion cpclib-basm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::str::FromStr;
use cpclib_asm::assembler::file::get_filename;
use cpclib_asm::preamble::file::read_source;
use cpclib_asm::preamble::symbols_output::SymbolOutputFormat;
use cpclib_asm::preamble::*;
use cpclib_asm::{preamble::*, AssemblingOptionFlags};
use cpclib_asm::progress::{normalize, Progress};
use cpclib_common::clap::builder::{PossibleValue, PossibleValuesParser};
use cpclib_common::clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command, ValueHint};
Expand Down Expand Up @@ -196,7 +196,9 @@ pub fn assemble<'arg>(
let _show_progress = matches.get_flag("PROGRESS");

let mut assemble_options = AssemblingOptions::default();

assemble_options.set_case_sensitive(!matches.get_flag("CASE_INSENSITIVE"));

if matches.get_flag("OVERRIDE") {
assemble_options
.set_save_behavior(cpclib_disc::amsdos::AmsdosAddBehavior::ReplaceAndEraseIfPresent);
Expand All @@ -208,6 +210,14 @@ pub fn assemble<'arg>(
assemble_options.set_save_behavior(cpclib_disc::amsdos::AmsdosAddBehavior::FailIfPresent);
}

if let Some(chunks) = matches.get_many::<String>("NO_SNA_CHUNK") {
for chunk in chunks {
let flag = AssemblingOptionFlags::from_chunk(chunk).unwrap();
assemble_options.set_flag(flag, false);
}
}


// TODO add symbols if any
if let Some(files) = matches.get_many::<String>("LOAD_SYMBOLS") {
for path in files {
Expand Down Expand Up @@ -626,6 +636,14 @@ pub fn build_args_parser() -> clap::Command {
.long("snapshot")
.alias("sna")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("NO_SNA_CHUNK")
.help("Deactivate some snapshot chunks (comma separated)")
.long("nochunk")
.value_delimiter(',')
.value_names(["CODE"])
.value_parser(["BRKC", "BRKS", "SYMB"])
)
.arg(
Arg::new("CASE_INSENSITIVE")
Expand Down

0 comments on commit ea83d2a

Please sign in to comment.