mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
Nits
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ target
|
|||||||
*.zip
|
*.zip
|
||||||
rustfmt.toml
|
rustfmt.toml
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
csmith
|
||||||
|
|||||||
@@ -86,9 +86,11 @@ pub enum Dtype {
|
|||||||
/// TODO(document)
|
/// TODO(document)
|
||||||
Struct {
|
Struct {
|
||||||
/// TODO(document)
|
/// TODO(document)
|
||||||
|
// FIXME: Why is this an option?
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
/// TODO(document)
|
/// TODO(document)
|
||||||
|
// FIXME: Just use vec for empty set of fields, no need for option?
|
||||||
fields: Option<Vec<Named<Dtype>>>,
|
fields: Option<Vec<Named<Dtype>>>,
|
||||||
|
|
||||||
/// TODO(document)
|
/// TODO(document)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::ir::*;
|
use crate::ir::*;
|
||||||
use crate::{some_or, Translate};
|
use crate::Translate;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct Visualizer {
|
pub struct Visualizer {
|
||||||
@@ -29,7 +29,9 @@ impl Translate<TranslationUnit> for Visualizer {
|
|||||||
signature,
|
signature,
|
||||||
definition,
|
definition,
|
||||||
} => {
|
} => {
|
||||||
let definition = some_or!(definition, continue);
|
let Some(definition) = definition else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
let subgraph = self.translate_function(name, signature, definition)?;
|
let subgraph = self.translate_function(name, signature, definition)?;
|
||||||
subgraphs.push(subgraph);
|
subgraphs.push(subgraph);
|
||||||
}
|
}
|
||||||
@@ -41,7 +43,9 @@ impl Translate<TranslationUnit> for Visualizer {
|
|||||||
// Add edges between subgraphs
|
// Add edges between subgraphs
|
||||||
for (name, decl) in &source.decls {
|
for (name, decl) in &source.decls {
|
||||||
if let Declaration::Function { definition, .. } = decl {
|
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 (bid, block) in &definition.blocks {
|
||||||
for (iid, instruction) in block.instructions.iter().enumerate() {
|
for (iid, instruction) in block.instructions.iter().enumerate() {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::io::{Result, Write};
|
|||||||
|
|
||||||
use crate::ir::*;
|
use crate::ir::*;
|
||||||
use crate::write_base::*;
|
use crate::write_base::*;
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
impl WriteLine for TranslationUnit {
|
impl WriteLine for TranslationUnit {
|
||||||
fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()> {
|
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 {
|
for (name, decl) in &self.decls {
|
||||||
let _ = some_or!(decl.get_variable(), continue);
|
if decl.get_variable().is_some() {
|
||||||
(name, decl).write_line(indent, write)?;
|
(name, decl).write_line(indent, write)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, decl) in &self.decls {
|
for (name, decl) in &self.decls {
|
||||||
let _ = some_or!(decl.get_function(), continue);
|
if decl.get_function().is_some() {
|
||||||
writeln!(write)?;
|
writeln!(write)?;
|
||||||
(name, decl).write_line(indent, write)?;
|
(name, decl).write_line(indent, write)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -725,7 +725,7 @@ fn name_of_params_from_derived_declarators(
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn name_of_parameter_declaration(parameter_declaration: &ParameterDeclaration) -> Option<String> {
|
fn name_of_parameter_declaration(parameter_declaration: &ParameterDeclaration) -> Option<String> {
|
||||||
let declarator = some_or!(parameter_declaration.declarator.as_ref(), return None);
|
let declarator = parameter_declaration.declarator.as_ref()?;
|
||||||
Some(name_of_declarator(&declarator.node))
|
Some(name_of_declarator(&declarator.node))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ where
|
|||||||
T: Optimize<ir::FunctionDefinition>,
|
T: Optimize<ir::FunctionDefinition>,
|
||||||
{
|
{
|
||||||
fn optimize(&mut self, code: &mut ir::Declaration) -> bool {
|
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);
|
let fdef = some_or!(fdef, return false);
|
||||||
self.inner.optimize(fdef)
|
self.inner.optimize(fdef)
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/utils.rs
11
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]
|
#[macro_export]
|
||||||
/// Some or executing the given expression.
|
/// Some or executing the given expression.
|
||||||
macro_rules! some_or {
|
macro_rules! some_or {
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ where
|
|||||||
F: Fn(&Path),
|
F: Fn(&Path),
|
||||||
{
|
{
|
||||||
let dir = path.read_dir().expect("read_dir call failed");
|
let dir = path.read_dir().expect("read_dir call failed");
|
||||||
for entry in dir {
|
for entry in dir.filter_map(Result::ok) {
|
||||||
let entry = ok_or!(entry, continue);
|
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if !(path.is_file() && path.extension() == Some(ext)) {
|
if !(path.is_file() && path.extension() == Some(ext)) {
|
||||||
@@ -24,8 +23,7 @@ where
|
|||||||
fn test_opt_between_dirs<O: Optimize<ir::TranslationUnit>>(from: &Path, to: &Path, opt: &mut O) {
|
fn test_opt_between_dirs<O: Optimize<ir::TranslationUnit>>(from: &Path, to: &Path, opt: &mut O) {
|
||||||
let from_dir = from.read_dir().expect("read_dir call failed");
|
let from_dir = from.read_dir().expect("read_dir call failed");
|
||||||
|
|
||||||
for entry in from_dir {
|
for entry in from_dir.filter_map(Result::ok) {
|
||||||
let entry = ok_or!(entry, continue);
|
|
||||||
let from_file_path = entry.path();
|
let from_file_path = entry.path();
|
||||||
|
|
||||||
if !(from_file_path.is_file() && from_file_path.extension() == Some(OsStr::new("ir"))) {
|
if !(from_file_path.is_file() && from_file_path.extension() == Some(OsStr::new("ir"))) {
|
||||||
@@ -34,7 +32,7 @@ fn test_opt_between_dirs<O: Optimize<ir::TranslationUnit>>(from: &Path, to: &Pat
|
|||||||
|
|
||||||
let file_name = from_file_path
|
let file_name = from_file_path
|
||||||
.strip_prefix(from)
|
.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);
|
let to_file_path = to.join(file_name);
|
||||||
|
|
||||||
assert!(from_file_path.is_file());
|
assert!(from_file_path.is_file());
|
||||||
|
|||||||
Reference in New Issue
Block a user