From c1adc216fe29a15d888d5ff7b3118ccecb3cdbec Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Tue, 16 Sep 2025 18:48:11 +0000 Subject: [PATCH] Allow ZOC to ignore errors --- compiler/src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/src/main.rs b/compiler/src/main.rs index 9d1a5d1..a58ad98 100644 --- a/compiler/src/main.rs +++ b/compiler/src/main.rs @@ -21,9 +21,14 @@ pub struct Options { output_dir: Option, #[bpaf(long("arch"))] - /// Target architecture + /// Target GPU architecture arch: Option, + #[bpaf(long("ignore-errors"))] + /// Try to ignore errors. This will try and produce output even if there are + /// parsing errors (e.g. an unimplemented instruction) + ignore_errors: bool, + #[bpaf(positional("filename"))] /// PTX file ptx_path: String, @@ -48,7 +53,10 @@ fn main_core() -> Result<(), CompilerError> { .unwrap_or("output"); let mut output_path = match opts.output_dir { - Some(value) => value, + Some(value) => { + std::fs::create_dir_all(&value)?; + value + } None => match ptx_path.parent() { Some(dir) => dir.to_path_buf(), None => env::current_dir()?, @@ -68,7 +76,7 @@ fn main_core() -> Result<(), CompilerError> { let ptx = fs::read(&ptx_path).map_err(CompilerError::from)?; let ptx = str::from_utf8(&ptx).map_err(CompilerError::from)?; - let llvm = ptx_to_llvm(ptx).map_err(CompilerError::from)?; + let llvm = ptx_to_llvm(opts.ignore_errors, ptx).map_err(CompilerError::from)?; write_to_file(&llvm.llvm_ir, output_path.with_extension("ll").as_path())?; @@ -92,8 +100,12 @@ fn main_core() -> Result<(), CompilerError> { Ok(()) } -fn ptx_to_llvm(ptx: &str) -> Result { - let ast = ptx_parser::parse_module_checked(ptx).map_err(CompilerError::from)?; +fn ptx_to_llvm(ignore_errors: bool, ptx: &str) -> Result { + let ast = if ignore_errors { + ptx_parser::parse_module_unchecked(ptx) + } else { + ptx_parser::parse_module_checked(ptx).map_err(CompilerError::from)? + }; let mut start = Instant::now(); let module = ptx::to_llvm_module( ast,