Update skeleton

This commit is contained in:
Jeehoon Kang
2020-05-02 07:52:40 +00:00
parent 3bef06455e
commit f4dc5e426c
11 changed files with 142 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ use core::ops::{Deref, DerefMut};
use hexf::{parse_hexf32, parse_hexf64};
use lang_c::ast;
use ordered_float::OrderedFloat;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::hash::{Hash, Hasher};
pub use dtype::{Dtype, DtypeError, HasDtype};
@@ -18,7 +18,7 @@ pub use parse::Parse;
#[derive(Debug, Clone, PartialEq)]
pub struct TranslationUnit {
pub decls: HashMap<String, Declaration>,
pub decls: BTreeMap<String, Declaration>,
pub structs: HashMap<String, Option<Dtype>>,
}
@@ -161,7 +161,7 @@ pub struct FunctionDefinition {
pub allocations: Vec<Named<Dtype>>,
/// Basic blocks.
pub blocks: HashMap<BlockId, Block>,
pub blocks: BTreeMap<BlockId, Block>,
/// The initial block id.
pub bid_init: BlockId,

View File

@@ -16,7 +16,7 @@ peg::parser! {
pub rule translation_unit() -> TranslationUnit
= _ ds:(named_decl() ** __) _ {
let mut decls = HashMap::new();
let mut decls = BTreeMap::new();
for decl in ds {
let result = decls.insert(decl.name.unwrap(), decl.inner);
assert!(result.is_none());

View File

@@ -1,7 +1,7 @@
use crate::opt::FunctionPass;
use crate::*;
pub type Gvn = FunctionPass<Repeat<GvnInner>>;
pub type Gvn = FunctionPass<GvnInner>;
#[derive(Default)]
pub struct GvnInner {}

View File

@@ -0,0 +1,3 @@
//! Utilities for implementing optimizations.
//!
//! You can add here utilities commonly used in the implementation of multiple optimizations.

View File

@@ -1,6 +1,6 @@
use lang_c::ast::*;
use std::fs::{self, File};
use std::io::{stderr, Write};
use std::io::{stderr, Read, Write};
use std::path::Path;
use std::process::{Command, Stdio};
use tempfile::tempdir;
@@ -41,7 +41,14 @@ pub fn test_irgen(unit: &TranslationUnit, path: &Path) {
// Compile c file: If fails, test is vacuously success
if !Command::new("gcc")
.args(&["-O1", &file_path, "-o", &bin_path])
.args(&[
"-fsanitize=undefined",
"-fno-sanitize-recover=all",
"-O1",
&file_path,
"-o",
&bin_path,
])
.stderr(Stdio::null())
.status()
.unwrap()
@@ -52,6 +59,7 @@ pub fn test_irgen(unit: &TranslationUnit, path: &Path) {
// Execute compiled executable
let mut child = Command::new(fs::canonicalize(bin_path.clone()).unwrap())
.stderr(Stdio::piped())
.spawn()
.expect("failed to execute the compiled executable");
@@ -71,6 +79,18 @@ pub fn test_irgen(unit: &TranslationUnit, path: &Path) {
::std::process::exit(SKIP_TEST);
}
);
if child
.stderr
.expect("`stderr` of `child` must be `Some`")
.bytes()
.next()
.is_some()
{
println!("error occurs");
::std::process::exit(SKIP_TEST);
}
let status = some_or_exit!(status.code(), SKIP_TEST);
let ir = match Irgen::default().translate(unit) {