Skip to content

Commit

Permalink
assembler refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippRados committed Dec 19, 2024
1 parent b313622 commit 261deb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
33 changes: 12 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,18 @@ fn output_path(
fn assemble(options: &CliOptions, file: &Path, asm_file: OutFile) -> Result<OutFile, WreccError> {
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)
Expand Down
4 changes: 3 additions & 1 deletion wrecc_compiler/src/compiler/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
Expand Down

0 comments on commit 261deb7

Please sign in to comment.