From f8230328065eb4049292b15d109b369e2e89746a Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 2 Feb 2026 23:25:15 +0100 Subject: nasm: add the --prelude flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This flag prints to the standard output some helper code that bridges nasm-exclusive features with ca65. Signed-off-by: Miquel Sabaté Solà --- crates/nasm/src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/nasm/src') diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 64e88ed..923f89e 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -32,6 +32,7 @@ fn print_help() { println!(" -D (=VALUE)\tDefine an 8-bit variable on the global scope (default: 1)"); println!(" -h, --help\t\tPrint this message."); println!(" -o, --out \tFile path where the output should be located after execution."); + println!(" --prelude\t\tPrint the 'prelude' file; a file that can be used for defining default implementations for nasm-only features."); println!(" -s, --stats\t\tPrint the statistics on the final layout of segments and memory."); println!(" --stdout\t\tPrint the output binary to the standard output."); println!(" -v, --version\t\tPrint the version of this program."); @@ -42,6 +43,22 @@ fn print_help() { std::process::exit(0); } +// Print the 'prelude' file, which is a file that provides default +// implementations for nasm-only control statements. These implementations do +// not strive to make things complete in all ways, but at least with this +// another compiler will produce the same binary as nasm. +fn print_prelude() { + println!( + r#";; The __fallthrough__ special statement allows developers to explicitly tell +;; the assembler that a "fall through" situation does not happen by mistake. +.macro __fallthrough__ arg + ;; NOTE: nothing to do :) +.endmacro"# + ); + + std::process::exit(0); +} + // Parse a value from the '-D' flag which is expected to be 'NAME(=VALUE)'. fn parse_define(arg: &str) -> (String, u8) { let mut key_value = arg.split('='); @@ -99,6 +116,7 @@ fn parse_arguments() -> Args { None => die("you need to provide a value for the '-D' flag".to_string()), }, "-h" | "--help" => print_help(), + "--prelude" => print_prelude(), "-o" | "--out" => match res.out { Some(_) => die("only specify the '-o/--out' flag once".to_string()), None => { -- cgit v1.2.3