diff --git a/.gitignore b/.gitignore index 01c49fd..b934256 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target *.zip rustfmt.toml **/*.rs.bk +csmith diff --git a/src/ir/dtype.rs b/src/ir/dtype.rs index 1d89086..f769483 100644 --- a/src/ir/dtype.rs +++ b/src/ir/dtype.rs @@ -86,9 +86,11 @@ pub enum Dtype { /// TODO(document) Struct { /// TODO(document) + // FIXME: Why is this an option? name: Option, /// TODO(document) + // FIXME: Just use vec for empty set of fields, no need for option? fields: Option>>, /// TODO(document) diff --git a/src/ir/visualize.rs b/src/ir/visualize.rs index 6ea095f..9b6286c 100644 --- a/src/ir/visualize.rs +++ b/src/ir/visualize.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::ir::*; -use crate::{some_or, Translate}; +use crate::Translate; #[derive(Default, Debug)] pub struct Visualizer { @@ -29,7 +29,9 @@ impl Translate for Visualizer { signature, definition, } => { - let definition = some_or!(definition, continue); + let Some(definition) = definition else { + continue; + }; let subgraph = self.translate_function(name, signature, definition)?; subgraphs.push(subgraph); } @@ -41,7 +43,9 @@ impl Translate for Visualizer { // Add edges between subgraphs for (name, decl) in &source.decls { if let Declaration::Function { definition, .. } = decl { - let definition = some_or!(definition, continue); + let Some(definition) = definition else { + continue; + }; for (bid, block) in &definition.blocks { for (iid, instruction) in block.instructions.iter().enumerate() { diff --git a/src/ir/write_ir.rs b/src/ir/write_ir.rs index 77c1777..b20a328 100644 --- a/src/ir/write_ir.rs +++ b/src/ir/write_ir.rs @@ -2,7 +2,6 @@ use std::io::{Result, Write}; use crate::ir::*; use crate::write_base::*; -use crate::*; impl WriteLine for TranslationUnit { fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> { @@ -36,14 +35,16 @@ impl WriteLine for TranslationUnit { } for (name, decl) in &self.decls { - let _ = some_or!(decl.get_variable(), continue); - (name, decl).write_line(indent, write)?; + if decl.get_variable().is_some() { + (name, decl).write_line(indent, write)?; + } } for (name, decl) in &self.decls { - let _ = some_or!(decl.get_function(), continue); - writeln!(write)?; - (name, decl).write_line(indent, write)?; + if decl.get_function().is_some() { + writeln!(write)?; + (name, decl).write_line(indent, write)?; + } } Ok(()) diff --git a/src/irgen/mod.rs b/src/irgen/mod.rs index a7746c4..d32ad9f 100644 --- a/src/irgen/mod.rs +++ b/src/irgen/mod.rs @@ -725,7 +725,7 @@ fn name_of_params_from_derived_declarators( #[inline] fn name_of_parameter_declaration(parameter_declaration: &ParameterDeclaration) -> Option { - let declarator = some_or!(parameter_declaration.declarator.as_ref(), return None); + let declarator = parameter_declaration.declarator.as_ref()?; Some(name_of_declarator(&declarator.node)) } diff --git a/src/opt/mod.rs b/src/opt/mod.rs index cb3c7ad..ed53684 100644 --- a/src/opt/mod.rs +++ b/src/opt/mod.rs @@ -77,7 +77,7 @@ where T: Optimize, { fn optimize(&mut self, code: &mut ir::Declaration) -> bool { - let (_fsig, fdef) = some_or!(code.get_function_mut(), return false); + let (_, fdef) = some_or!(code.get_function_mut(), return false); let fdef = some_or!(fdef, return false); self.inner.optimize(fdef) } diff --git a/src/utils.rs b/src/utils.rs index 4088ad2..e9fe130 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,14 +1,3 @@ -#[macro_export] -/// Ok or executing the given expression. -macro_rules! ok_or { - ($e:expr_2021, $err:expr_2021) => {{ - match $e { - Ok(r) => r, - Err(_) => $err, - } - }}; -} - #[macro_export] /// Some or executing the given expression. macro_rules! some_or { diff --git a/tests/test_examples.rs b/tests/test_examples.rs index dc541a7..6ef08cd 100644 --- a/tests/test_examples.rs +++ b/tests/test_examples.rs @@ -8,8 +8,7 @@ where F: Fn(&Path), { let dir = path.read_dir().expect("read_dir call failed"); - for entry in dir { - let entry = ok_or!(entry, continue); + for entry in dir.filter_map(Result::ok) { let path = entry.path(); if !(path.is_file() && path.extension() == Some(ext)) { @@ -24,8 +23,7 @@ where fn test_opt_between_dirs>(from: &Path, to: &Path, opt: &mut O) { let from_dir = from.read_dir().expect("read_dir call failed"); - for entry in from_dir { - let entry = ok_or!(entry, continue); + for entry in from_dir.filter_map(Result::ok) { let from_file_path = entry.path(); if !(from_file_path.is_file() && from_file_path.extension() == Some(OsStr::new("ir"))) { @@ -34,7 +32,7 @@ fn test_opt_between_dirs>(from: &Path, to: &Pat let file_name = from_file_path .strip_prefix(from) - .expect("`from_file _path` must have file name"); + .expect("`from_file_path` must have file name"); let to_file_path = to.join(file_name); assert!(from_file_path.is_file());