From 261deb722eed943b4209b6a25ed0266b65a86cec Mon Sep 17 00:00:00 2001 From: Philipp Rados Date: Thu, 19 Dec 2024 17:18:27 +0100 Subject: [PATCH] assembler refactor --- src/main.rs | 33 ++++++++++---------------- wrecc_compiler/src/compiler/scanner.rs | 4 +++- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/main.rs b/src/main.rs index 73cbc1d..fe2a6d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,27 +96,18 @@ fn output_path( fn assemble(options: &CliOptions, file: &Path, asm_file: OutFile) -> Result { let output_path = output_path(file, &options.output_path, options.no_link, "o"); - let output = match std::env::consts::OS { - "linux" => { - Command::new("as") - .arg(asm_file.get()) - .arg("-o") - .arg(output_path.get()) - .output() - .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))? - } - "macos" => { - Command::new("as") - .arg(asm_file.get()) - .arg("-o") - .arg(output_path.get()) - .arg("-arch") - .arg("x86_64") - .output() - .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))? - } - _ => return Err(WreccError::Sys(String::from("only supports linux and macos"))), - }; + let mut cmd = Command::new("as"); + cmd.arg(asm_file.get()).arg("-o").arg(output_path.get()); + + // Specify target architecture for macos + // so that apple silicon chips can run x86-64 binary through rosetta + if std::env::consts::OS == "macos" { + cmd.arg("-arch").arg("x86_64"); + } + + let output = cmd + .output() + .map_err(|_| WreccError::Sys("could not invoke assembler 'as'".to_string()))?; if output.status.success() { Ok(output_path) diff --git a/wrecc_compiler/src/compiler/scanner.rs b/wrecc_compiler/src/compiler/scanner.rs index 1949f31..26c59f9 100644 --- a/wrecc_compiler/src/compiler/scanner.rs +++ b/wrecc_compiler/src/compiler/scanner.rs @@ -353,10 +353,12 @@ impl<'a> Scanner<'a> { .ok_or(Error::new(pp_token, ErrorKind::Eof("expected character literal")))?; self.escape_char(char_to_escape, char_iter) .ok_or(Error::new(pp_token, ErrorKind::InvalidEscape(char_string))) - // strings can contain non-ascii chars } else if c.is_ascii() || is_string { + // strings can contain non-ascii chars Ok(c) } else { + // doesn't apply to escaped chars since they can are in + // range [0;255] which is valid while valid ascii is only [0;127] Err(Error::new(pp_token, ErrorKind::CharLiteralAscii(c))) } }