From 4535b2ef6f48c0de9a6d680a3eb61ba0a15120b7 Mon Sep 17 00:00:00 2001 From: Jeehoon Kang Date: Mon, 21 Jun 2021 18:45:39 +0000 Subject: [PATCH] Update --- .github/bors.toml | 2 + .github/workflows/ci.yml | 36 +++ .gitlab-ci.yml | 47 ++++ Cargo.lock | 535 +++++++++++++++++++++++++-------------- Cargo.toml | 23 +- Jenkinsfile | 48 ---- README.md | 31 ++- bench/Makefile | 4 +- bench/remote.sh | 7 + bin/fuzz.rs | 6 +- bin/kecc.rs | 13 +- bors.toml | 2 - rust-toolchain | 2 +- src/asm/mod.rs | 16 +- src/asm/write_asm.rs | 4 +- src/c/ast_equiv.rs | 9 +- src/c/parse.rs | 13 +- src/ir/dtype.rs | 95 ++++++- src/ir/equiv.rs | 7 +- src/ir/interp.rs | 30 +-- src/ir/mod.rs | 25 +- src/ir/parse.rs | 2 +- src/lib.rs | 37 ++- src/opt/mod.rs | 6 +- src/tests.rs | 47 ++-- src/utils.rs | 9 + src/write_base.rs | 8 + tests/fuzz.py | 2 +- 28 files changed, 696 insertions(+), 370 deletions(-) create mode 100644 .github/bors.toml create mode 100644 .github/workflows/ci.yml create mode 100644 .gitlab-ci.yml delete mode 100644 Jenkinsfile create mode 100755 bench/remote.sh delete mode 100644 bors.toml diff --git a/.github/bors.toml b/.github/bors.toml new file mode 100644 index 0000000..e52aa08 --- /dev/null +++ b/.github/bors.toml @@ -0,0 +1,2 @@ +delete_merged_branches = true +status = ["ci"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5eb6024 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + pull_request: + push: + branches: + - master + - staging + - trying + +defaults: + run: + shell: bash + +jobs: + ci: + name: ci + runs-on: [self-hosted, ubuntu-20.04] + steps: + - uses: actions/checkout@v2 + - name: Install latest + uses: actions-rs/toolchain@v1 + with: + profile: minimal + override: true + components: rust-src, rustfmt, clippy + - name: Rustfmt + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy --all + - name: Check + run: cargo check --all + - name: Test (Debug) + run: RUST_MIN_STACK=8388608 cargo test -- --skip test_examples_asmgen + - name: Test (Release) + run: RUST_MIN_STACK=8388608 cargo test --release -- --skip test_examples_asmgen diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..46244e8 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +# Setup a cache to cache job parts between jobs to ensure faster builds +cache: + key: "$CI_JOB_NAME" + untracked: true + paths: + - $HOME/.cargo/ + - target/ + +# Set any required environment variables here +variables: + RUST_BACKTRACE: "FULL" + +image: "rust:latest" + +stages: +- install +- test + +install: + stage: install + script: + - rustup default stable + +check: + stage: test + before_script: + - rustup component add rustfmt clippy + - cargo install cargo-audit + script: + - cargo check --verbose + - cargo fmt -- --check + - cargo clippy -- -D warnings + - cargo audit + +debug: + stage: test + before_script: + - apt update && apt install -yy gcc-riscv64-linux-gnu g++-riscv64-linux-gnu qemu-user-static + script: + - RUST_MIN_STACK=8388608 cargo test + +release: + stage: test + before_script: + - apt update && apt install -yy gcc-riscv64-linux-gnu g++-riscv64-linux-gnu qemu-user-static + script: + - RUST_MIN_STACK=8388608 cargo test --release diff --git a/Cargo.lock b/Cargo.lock index c8ec49c..2d3a9e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,489 +1,638 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] -name = "ansi_term" -version = "0.11.0" +name = "addr2line" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a2e47a1fbe209ee101dd6d61285226744c6c8d3c21c8dc878ba6cb9f467f3a" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "gimli", ] +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi", ] [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.46" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7815ea54e4d821e791162e078acbebfd6d8c8939cd559c9335dceb1c8ca7282" dependencies = [ - "backtrace-sys 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cc" -version = "1.0.52" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" -version = "0.1.10" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.33.0" +version = "3.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", + "unicode-width", + "vec_map", + "yaml-rust", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] name = "either" -version = "1.5.3" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "failure" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" dependencies = [ - "backtrace 0.3.46 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace", + "failure_derive", ] [[package]] name = "failure_derive" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote 1.0.9", + "syn 1.0.73", + "synstructure", ] [[package]] name = "getrandom" -version = "0.1.14" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189" + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "hexf" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54653cc32d838771a36532647afad59c4bf7155745eeeec406f71fd5d7e7538" dependencies = [ - "hexf-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hexf-parse 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hexf-impl", + "hexf-parse", + "proc-macro-hack", ] [[package]] name = "hexf-impl" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22eadcfadba76a730b2764eaa577d045f35e0ef5174b9c5b46adf1ee42b85e12" dependencies = [ - "hexf-parse 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "hexf-parse", + "proc-macro-hack", + "syn 0.11.11", ] [[package]] name = "hexf-parse" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296f72d53a89096cbc9a88c9547ee8dfe793388674620e2207593d370550ac" + +[[package]] +name = "indexmap" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +dependencies = [ + "autocfg", + "hashbrown", +] [[package]] name = "itertools" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" dependencies = [ - "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "either", ] [[package]] name = "kecc" version = "0.1.0" dependencies = [ - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "hexf 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lang-c 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "peg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap", + "failure", + "hexf", + "itertools", + "lang-c", + "ordered-float", + "peg", + "rand", + "tempfile", + "wait-timeout", ] [[package]] name = "lang-c" -version = "0.8.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a597343db6f9affec95665270028e3113864b48a1a0ba9257c1553ade3840207" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.69" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" + +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", +] + +[[package]] +name = "object" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" +dependencies = [ + "memchr", ] [[package]] name = "ordered-float" -version = "1.0.2" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f100fcfb41e5385e0991f74981732049f9b896821542a219420491046baafdc2" dependencies = [ - "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits", ] [[package]] -name = "peg" -version = "0.6.2" +name = "os_str_bytes" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" + +[[package]] +name = "peg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07c0b841ea54f523f7aa556956fbd293bcbe06f2e67d2eb732b7278aaf1d166a" dependencies = [ - "peg-macros 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "peg-runtime 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "peg-macros", + "peg-runtime", ] [[package]] name = "peg-macros" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" dependencies = [ - "peg-runtime 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "peg-runtime", + "proc-macro2", + "quote 1.0.9", ] [[package]] name = "peg-runtime" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c719dcf55f09a3a7e764c6649ab594c18a177e3599c467983cdf644bfc0a4088" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote 1.0.9", + "syn 1.0.73", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote 1.0.9", + "version_check", +] [[package]] name = "proc-macro-hack" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b773f824ff2a495833f85fcdddcf85e096949971decada2e93249fa2c6c3d32f" dependencies = [ - "proc-macro-hack-impl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack-impl", ] [[package]] name = "proc-macro-hack-impl" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f674ccc446da486175527473ec8aa064f980b0966bbf767ee743a5dff6244a7" [[package]] name = "proc-macro2" -version = "1.0.10" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.2", ] [[package]] name = "quote" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.3" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "rand" -version = "0.7.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] name = "rand_chacha" -version = "0.2.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ppv-lite86", + "rand_core", ] [[package]] name = "rand_core" -version = "0.5.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", ] [[package]] name = "rand_hc" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core", ] [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +dependencies = [ + "bitflags", +] [[package]] name = "remove_dir_all" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.15", + "synom", + "unicode-xid 0.0.4", ] [[package]] name = "syn" -version = "1.0.18" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote 1.0.9", + "unicode-xid 0.2.2", ] [[package]] name = "synom" version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4", ] [[package]] name = "synstructure" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ - "proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote 1.0.9", + "syn 1.0.73", + "unicode-xid 0.2.2", ] [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", ] [[package]] name = "textwrap" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789" dependencies = [ - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] -name = "unicode-width" -version = "0.1.7" +name = "unicode-segmentation" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "vec_map" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "wait-timeout" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" dependencies = [ - "libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "yaml-rust" -version = "0.3.5" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" -"checksum backtrace 0.3.46 (registry+https://github.com/rust-lang/crates.io-index)" = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e" -"checksum backtrace-sys 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "78848718ee1255a2485d1309ad9cdecfc2e7d0362dd11c6829364c6b35ae1bc7" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" -"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" -"checksum failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b" -"checksum failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" -"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" -"checksum hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" -"checksum hexf 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e54653cc32d838771a36532647afad59c4bf7155745eeeec406f71fd5d7e7538" -"checksum hexf-impl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "22eadcfadba76a730b2764eaa577d045f35e0ef5174b9c5b46adf1ee42b85e12" -"checksum hexf-parse 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "79296f72d53a89096cbc9a88c9547ee8dfe793388674620e2207593d370550ac" -"checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -"checksum lang-c 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2554b3a7a324e3d8ad63603fe6729c4c144bab2ab36742c45a72788bff50e8ec" -"checksum libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)" = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" -"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" -"checksum peg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9075875c14bb21f25f11cad4b6ad2e4dd443b8fb83900b2fbdd6ebd744b82e97" -"checksum peg-macros 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c24c165fd39e995246140cc78df55c56c6733ba87e6658cb3e197b8856c62852" -"checksum peg-runtime 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1a2897e69d986c7986747ebad425cf03746ec5e3e09bb3b2600f91301ba864" -"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" -"checksum proc-macro-hack 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b773f824ff2a495833f85fcdddcf85e096949971decada2e93249fa2c6c3d32f" -"checksum proc-macro-hack-impl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0f674ccc446da486175527473ec8aa064f980b0966bbf767ee743a5dff6244a7" -"checksum proc-macro2 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" -"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" -"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum syn 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" -"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/Cargo.toml b/Cargo.toml index 25fcb83..52ff9c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kecc" version = "0.1.0" -authors = ["Chunmyong Park ", "Jeehoon Kang ", "Hyunsu Kim "] +authors = ["Chunmyong Park ", "Jeehoon Kang "] edition = "2018" default-run = "kecc" @@ -18,19 +18,24 @@ path = "src/lib.rs" [[bin]] name = "kecc" path = "bin/kecc.rs" +required-features = ["build-bin"] [[bin]] name = "fuzz" path = "bin/fuzz.rs" +required-features = ["build-bin"] + +[features] +build-bin = ["clap"] [dependencies] -clap = { version = "2.33.0", features = ["yaml"] } -lang-c = "0.8.1" -itertools = "0.9.0" -failure = "0.1.7" -tempfile = "3.1.0" -ordered-float = "1.0" +clap = { version = "3.0.0-beta.2", features = ["yaml"], optional = true } +lang-c = "0.10.1" +itertools = "0.10.1" +failure = "0.1.8" +tempfile = "3.2.0" +ordered-float = "2.5.1" hexf = "0.1.0" wait-timeout = "0.2.0" -peg = "0.6.2" -rand = "0.7" +peg = "0.7.0" +rand = "0.8.4" diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index c54953e..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,48 +0,0 @@ -def setupRust() { - sh "rustup component add rustfmt clippy" - sh "rustup install nightly" - sh "cargo update" - sh "cargo" -} - -pipeline { - agent { - docker { - image 'rust:latest' - } - } - - stages { - stage('Rustfmt') { - steps { - setupRust() - sh "cargo fmt --all -- --check" - } - } - stage('Clippy') { - steps { - setupRust() - sh "cargo clippy --all" - } - } - stage('Build') { - steps { - setupRust() - sh "cargo build" - sh "cargo build --release" - } - } - stage('Test') { - steps { - setupRust() - // When `cargo test` runs, the function `it_works()` is called in a new thread. - // The stack size of a new thread is `2 MiB` on Linux, and this small stack size - // can cause `stack-overflow` error when testing stack-intensive code. - // For this reason, we need to increase the default size of stack to `8 MiB`. - // TODO: delete `--skip test_examples_asmgen` - sh "RUST_MIN_STACK=8388608 cargo test -- --skip test_examples_asmgen" - sh "RUST_MIN_STACK=8388608 cargo test --release -- --skip test_examples_asmgen" - } - } - } -} diff --git a/README.md b/README.md index 71d636a..8bc9689 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,15 @@ cargo build --release # release build ## Run ```sh -cargo run -- -h # print options -cargo run -- -p examples/c/fibonacci.c # parse -cargo run -- -i examples/c/fibonacci.c # irgen -cargo run -- -O --iroutput examples/c/fibonacci.c # optimize -cargo run -- examples/c/fibonacci.c # compile +cargo run --features=build-bin -- -h # print options +cargo run --features=build-bin -- -p examples/c/fibonacci.c # parse +cargo run --features=build-bin -- -i examples/c/fibonacci.c # irgen +cargo run --features=build-bin -- -O --iroutput examples/c/fibonacci.c # optimize +cargo run --features=build-bin -- examples/c/fibonacci.c # compile -cargo run -- --irrun examples/c/fibonacci.c # interprets the IR +cargo run --features=build-bin -- --irrun examples/c/fibonacci.c # interprets the IR -cargo run --release -- examples/c/fibonacci.c # compile with release build +cargo run --features=build-bin --release -- examples/c/fibonacci.c # compile with release build ``` @@ -73,9 +73,8 @@ cat tests/test_reduced.c ### Install ```sh -# Ubuntu 18.04 or higher -apt install -y make cmake python3 -apt install -y csmith libcsmith-dev creduce +# Ubuntu 20.04 +sudo apt install -y make cmake python3 csmith libcsmith-dev creduce ``` ### Run @@ -113,8 +112,8 @@ reduces the program; check if the reduced program still fails on the test, and i given program with the reduced one; repeat until you get a small enough buggy program. For more information, we refer to the [Creduce](https://embed.cs.utah.edu/creduce/) homepage. -**[NOTICE]** The fuzzer supports Ubuntu 18.04 or 20.04 only. It may work for other platforms, but if it -doesn't, please run the fuzzer in Ubuntu 18.04 or 20.04. +**[NOTICE]** The fuzzer supports Ubuntu 20.04 only. It may work for other platforms, but if it +doesn't, please run the fuzzer in Ubuntu 20.04. ## Running RISC-V Binaries @@ -122,18 +121,18 @@ doesn't, please run the fuzzer in Ubuntu 18.04 or 20.04. ### Install ```sh -# Ubuntu 20.04 or higher -apt install gcc-10-riscv64-linux-gnu g++-10-riscv64-linux-gnu qemu-user-static +# Ubuntu 20.04 +sudo apt install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu qemu-user-static ``` ### Cross-Compilation and Architecture-Emulation ```sh # Compile C source code into RISC-V assembly -riscv64-linux-gnu-gcc-10 hello.c -S -o hello.S +riscv64-linux-gnu-gcc hello.c -S -o hello.S # Link to an RISC-V executable -riscv64-linux-gnu-gcc-10 -static hello.S -o hello +riscv64-linux-gnu-gcc -static hello.S -o hello # Emulate the executable qemu-riscv64-static ./hello diff --git a/bench/Makefile b/bench/Makefile index d707aec..0ecbacd 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -1,5 +1,5 @@ -CC=riscv64-linux-gnu-gcc-10 -CXX=riscv64-linux-gnu-g++-10 +CC=riscv64-linux-gnu-gcc +CXX=riscv64-linux-gnu-g++ KECC=../target/release/kecc CFLAGS=-O RM=rm -f diff --git a/bench/remote.sh b/bench/remote.sh new file mode 100755 index 0000000..554cd49 --- /dev/null +++ b/bench/remote.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +sshpass -p 'sifive' scp bench-gcc hifiveu:/mnt/home/runner/cs420-final/bench-gcc +sshpass -p 'sifive' ssh hifiveu /usr/sbin/chroot /mnt "chown runner:runner /home/runner/cs420-final/bench-gcc" +sshpass -p 'sifive' ssh hifiveu /usr/sbin/chroot /mnt /bin/su - runner -c "/home/runner/cs420-final/bench-gcc" diff --git a/bin/fuzz.rs b/bin/fuzz.rs index 2caf8c9..8753bae 100644 --- a/bin/fuzz.rs +++ b/bin/fuzz.rs @@ -1,6 +1,4 @@ -#[macro_use] -extern crate clap; -use clap::{crate_authors, crate_description, crate_version, App}; +use clap::{crate_authors, crate_description, crate_version, load_yaml, App}; extern crate kecc; @@ -9,7 +7,7 @@ use std::path::Path; fn main() { let yaml = load_yaml!("fuzz_cli.yml"); #[allow(deprecated)] - let matches = App::from_yaml(yaml) + let matches = App::from(yaml) .version(crate_version!()) .about(crate_description!()) .author(crate_authors!(", ")) diff --git a/bin/kecc.rs b/bin/kecc.rs index 782b546..7a7179b 100644 --- a/bin/kecc.rs +++ b/bin/kecc.rs @@ -1,8 +1,7 @@ use std::ffi::OsStr; use std::path::Path; -#[macro_use] -extern crate clap; -use clap::{crate_authors, crate_description, crate_version, App}; + +use clap::{crate_authors, crate_description, crate_version, load_yaml, App}; use lang_c::ast::TranslationUnit; @@ -17,7 +16,7 @@ use kecc::{ fn main() { let yaml = load_yaml!("kecc_cli.yml"); #[allow(deprecated)] - let matches = App::from_yaml(yaml) + let matches = App::from(yaml) .version(crate_version!()) .about(crate_description!()) .author(crate_authors!(", ")) @@ -26,7 +25,7 @@ fn main() { let input = matches.value_of("INPUT").unwrap(); let input = Path::new(input); - let output = matches.value_of("output").unwrap_or_else(|| "-"); + let output = matches.value_of("output").unwrap_or("-"); let mut output: Box = if output == "-" { Box::new(::std::io::stdout()) } else { @@ -48,7 +47,7 @@ fn main() { fn compile_c( input: &TranslationUnit, output: &mut dyn ::std::io::Write, - matches: &clap::ArgMatches<'_>, + matches: &clap::ArgMatches, ) { if matches.is_present("parse") { return; @@ -78,7 +77,7 @@ fn compile_c( fn compile_ir( input: &mut ir::TranslationUnit, output: &mut dyn ::std::io::Write, - matches: &clap::ArgMatches<'_>, + matches: &clap::ArgMatches, ) { if matches.is_present("irparse") { return; diff --git a/bors.toml b/bors.toml deleted file mode 100644 index 2daddc9..0000000 --- a/bors.toml +++ /dev/null @@ -1,2 +0,0 @@ -status = [ "continuous-integration/jenkins/branch" ] -delete_merged_branches = true diff --git a/rust-toolchain b/rust-toolchain index 372cf40..3f48301 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.44.0 +1.53.0 diff --git a/src/asm/mod.rs b/src/asm/mod.rs index 024005d..278a33e 100644 --- a/src/asm/mod.rs +++ b/src/asm/mod.rs @@ -5,7 +5,7 @@ use crate::ir; use core::convert::TryFrom; #[derive(Debug, Clone, PartialEq)] -pub struct TODO {} +pub struct Todo {} /// TODO #[derive(Debug, Clone, PartialEq)] @@ -616,9 +616,9 @@ impl Immediate { #[derive(Debug, Clone, PartialEq)] pub enum RelocationFunction { /// %hi - HI20, + Hi20, /// %lo - LO12, + Lo12, } /// `Label` is used as branch, unconditional jump targets and symbol offsets. @@ -676,17 +676,11 @@ impl TryFrom for DataSize { impl DataSize { pub fn is_integer(&self) -> bool { - match self { - Self::Byte | Self::Half | Self::Word | Self::Double => true, - _ => false, - } + matches!(self, Self::Byte | Self::Half | Self::Word | Self::Double) } pub fn is_floating_point(&self) -> bool { - match self { - Self::SinglePrecision | Self::DoublePrecision => true, - _ => false, - } + matches!(self, Self::SinglePrecision | Self::DoublePrecision) } fn word(self) -> Option { diff --git a/src/asm/write_asm.rs b/src/asm/write_asm.rs index eef65f5..440205f 100644 --- a/src/asm/write_asm.rs +++ b/src/asm/write_asm.rs @@ -434,8 +434,8 @@ impl WriteString for Immediate { impl WriteString for RelocationFunction { fn write_string(&self) -> String { match self { - Self::HI20 => "%hi", - Self::LO12 => "%lo", + Self::Hi20 => "%hi", + Self::Lo12 => "%lo", } .to_string() } diff --git a/src/c/ast_equiv.rs b/src/c/ast_equiv.rs index a0cf56b..b063161 100644 --- a/src/c/ast_equiv.rs +++ b/src/c/ast_equiv.rs @@ -79,7 +79,7 @@ impl IsEquiv for DeclaratorKind { (Self::Identifier(identifier), Self::Identifier(other_identifier)) => { identifier.node.name == other_identifier.node.name } - (Self::Declarator(decl), Self::Declarator(other_decl)) => decl.is_equiv(&other_decl), + (Self::Declarator(decl), Self::Declarator(other_decl)) => decl.is_equiv(other_decl), _ => false, } } @@ -104,7 +104,7 @@ impl IsEquiv for DerivedDeclarator { params.is_equiv(other_params) } (Self::KRFunction(kr_func_decl), Self::KRFunction(other_kr_func_decl)) => { - kr_func_decl.is_equiv(&other_kr_func_decl) + kr_func_decl.is_equiv(other_kr_func_decl) } _ => false, } @@ -128,10 +128,10 @@ impl IsEquiv for ArraySize { (Self::Unknown, Self::Unknown) => true, (Self::VariableUnknown, Self::VariableUnknown) => true, (Self::VariableExpression(expr), Self::VariableExpression(other_expr)) => { - expr.is_equiv(&other_expr) + expr.is_equiv(other_expr) } (Self::StaticExpression(expr), Self::StaticExpression(other_expr)) => { - expr.is_equiv(&other_expr) + expr.is_equiv(other_expr) } _ => false, } @@ -492,6 +492,7 @@ impl IsEquiv for Enumerator { impl IsEquiv for TypeQualifier { fn is_equiv(&self, other: &Self) -> bool { + #[allow(clippy::match_like_matches_macro)] match (self, other) { (Self::Const, Self::Const) => true, _ => false, diff --git a/src/c/parse.rs b/src/c/parse.rs index e4630c6..411ff44 100644 --- a/src/c/parse.rs +++ b/src/c/parse.rs @@ -8,6 +8,7 @@ use lang_c::span::Node; use crate::utils::AssertSupported; use crate::Translate; +/// TODO(document) #[derive(Debug)] pub enum Error { ParseError(ParseError), @@ -15,7 +16,8 @@ pub enum Error { Unsupported, } -#[derive(Default)] +/// TODO(document) +#[derive(Default, Debug)] pub struct Parse {} impl> Translate

for Parse { @@ -182,7 +184,7 @@ impl AssertSupported for AlignmentSpecifier { fn assert_supported(&self) { match self { Self::Type(typename) => typename.assert_supported(), - Self::Constant(_) => panic!(AlignmentSpecifier::Constant), + Self::Constant(_) => std::panic::panic_any(AlignmentSpecifier::Constant), } } } @@ -225,7 +227,7 @@ impl AssertSupported for DerivedDeclarator { Self::Array(array_decl) => array_decl.assert_supported(), Self::Function(func_decl) => func_decl.assert_supported(), // Support when K&R function has no parameter - Self::KRFunction(kr_func_decl) => assert_eq!(true, kr_func_decl.is_empty()), + Self::KRFunction(kr_func_decl) => assert!(kr_func_decl.is_empty()), } } } @@ -513,6 +515,7 @@ impl AssertSupported for SpecifierQualifier { match self { Self::TypeSpecifier(type_specifier) => type_specifier.assert_supported(), Self::TypeQualifier(type_qualifier) => type_qualifier.assert_supported(), + Self::Extension(_) => panic!("SpecifierQualifier::Extension"), } } } @@ -551,14 +554,14 @@ impl AssertSupported for Constant { impl AssertSupported for Integer { fn assert_supported(&self) { - assert_eq!(false, self.suffix.imaginary); + assert!(!self.suffix.imaginary); } } impl AssertSupported for Float { fn assert_supported(&self) { self.suffix.format.assert_supported(); - assert_eq!(false, self.suffix.imaginary); + assert!(!self.suffix.imaginary); } } diff --git a/src/ir/dtype.rs b/src/ir/dtype.rs index d0ac24e..35e1ae0 100644 --- a/src/ir/dtype.rs +++ b/src/ir/dtype.rs @@ -12,14 +12,20 @@ use itertools::izip; use crate::ir::*; use crate::some_or; +/// TODO(document) #[derive(Debug, PartialEq, Fail)] pub enum DtypeError { /// For uncommon error #[fail(display = "{}", message)] - Misc { message: String }, + Misc { + /// TODO(document) + message: String, + }, } +/// TODO(document) pub trait HasDtype { + /// TODO(document) fn dtype(&self) -> Dtype; } @@ -34,40 +40,77 @@ struct BaseDtype { is_typedef: bool, } +/// TODO(document) #[derive(Debug, PartialEq, Eq, Hash, Clone)] pub enum Dtype { + /// TODO(document) Unit { + /// TODO(document) is_const: bool, }, + /// TODO(document) Int { + /// TODO(document) width: usize, + + /// TODO(document) is_signed: bool, + + /// TODO(document) is_const: bool, }, + /// TODO(document) Float { + /// TODO(document) width: usize, + + /// TODO(document) is_const: bool, }, + /// TODO(document) Pointer { + /// TODO(document) inner: Box, + + /// TODO(document) is_const: bool, }, + /// TODO(document) Array { + /// TODO(document) inner: Box, + + /// TODO(document) size: usize, }, + /// TODO(document) Struct { + /// TODO(document) name: Option, + + /// TODO(document) fields: Option>>, + + /// TODO(document) is_const: bool, + + /// TODO(document) size_align_offsets: Option<(usize, usize, Vec)>, }, + /// TODO(document) Function { + /// TODO(document) ret: Box, + + /// TODO(document) params: Vec, }, + /// TODO(document) Typedef { + /// TODO(document) name: String, + + /// TODO(document) is_const: bool, }, } @@ -201,6 +244,7 @@ impl BaseDtype { ast::SpecifierQualifier::TypeQualifier(type_qualifier) => { self.apply_type_qualifier(&type_qualifier.node)? } + ast::SpecifierQualifier::Extension(_) => panic!("unsupported specifier qualifier"), } Ok(()) @@ -464,40 +508,73 @@ impl TryFrom<&ast::ParameterDeclaration> for Dtype { } impl Dtype { + /// TODO(document) pub const BITS_OF_BYTE: usize = 8; + + /// TODO(document) pub const SIZE_OF_BYTE: usize = 1; + + /// TODO(document) // TODO: consider architecture dependency (current: 64-bit architecture) pub const SIZE_OF_POINTER: usize = 8; + /// TODO(document) pub const SIZE_OF_CHAR: usize = 1; + + /// TODO(document) pub const SIZE_OF_SHORT: usize = 2; + + /// TODO(document) pub const SIZE_OF_INT: usize = 4; + + /// TODO(document) pub const SIZE_OF_LONG: usize = 8; + + /// TODO(document) pub const SIZE_OF_LONGLONG: usize = 8; + /// TODO(document) pub const SIZE_OF_FLOAT: usize = 4; + + /// TODO(document) pub const SIZE_OF_DOUBLE: usize = 8; + /// TODO(document) // signed option cannot be applied to boolean value pub const BOOL: Self = Self::Int { width: 1, is_signed: false, is_const: false, }; + + /// TODO(document) pub const CHAR: Self = Self::int(Self::SIZE_OF_CHAR * Self::BITS_OF_BYTE); + + /// TODO(document) pub const SHORT: Self = Self::int(Self::SIZE_OF_SHORT * Self::BITS_OF_BYTE); + + /// TODO(document) pub const INT: Self = Self::int(Self::SIZE_OF_INT * Self::BITS_OF_BYTE); + + /// TODO(document) pub const LONG: Self = Self::int(Self::SIZE_OF_LONG * Self::BITS_OF_BYTE); + + /// TODO(document) pub const LONGLONG: Self = Self::int(Self::SIZE_OF_LONGLONG * Self::BITS_OF_BYTE); + /// TODO(document) pub const FLOAT: Self = Self::float(Self::SIZE_OF_FLOAT * Self::BITS_OF_BYTE); + + /// TODO(document) pub const DOUBLE: Self = Self::float(Self::SIZE_OF_DOUBLE * Self::BITS_OF_BYTE); + /// TODO(document) #[inline] pub const fn unit() -> Self { Self::Unit { is_const: false } } + /// TODO(document) #[inline] pub const fn int(width: usize) -> Self { Self::Int { @@ -507,6 +584,7 @@ impl Dtype { } } + /// TODO(document) #[inline] pub const fn float(width: usize) -> Self { Self::Float { @@ -515,6 +593,7 @@ impl Dtype { } } + /// TODO(document) #[inline] pub fn pointer(inner: Dtype) -> Self { Self::Pointer { @@ -523,9 +602,14 @@ impl Dtype { } } - // Suppose the C declaration is `int *a[2][3]`. Then `a`'s `ir::Dtype` should be `[2 x [3 x int*]]`. - // But in the AST, it is parsed as `Array(3, Array(2, Pointer(int)))`, reversing the order of `2` and `3`. - // In the recursive translation of declaration into Dtype, we need to insert `3` inside `[2 * int*]`. + /// TODO(document) + /// + /// # Examples + /// + /// Suppose the C declaration is `int *a[2][3]`. Then `a`'s `ir::Dtype` should be `[2 x [3 x + /// int*]]`. But in the AST, it is parsed as `Array(3, Array(2, Pointer(int)))`, reversing the + /// order of `2` and `3`. In the recursive translation of declaration into Dtype, we need to + /// insert `3` inside `[2 * int*]`. pub fn array(base_dtype: Dtype, size: usize) -> Self { match base_dtype { Self::Array { @@ -547,6 +631,7 @@ impl Dtype { } } + /// TODO(document) #[inline] pub fn structure(name: Option, fields: Option>>) -> Self { Self::Struct { @@ -1344,7 +1429,7 @@ fn check_no_duplicate_field(fields: &[Named], field_names: &mut HashSet bool { @@ -30,7 +29,7 @@ impl IsEquiv for TranslationUnit { } } -impl IsEquiv for ir::Declaration { +impl IsEquiv for Declaration { fn is_equiv(&self, other: &Self) -> bool { match (self, other) { ( @@ -328,7 +327,7 @@ fn is_equiv_arg(lhs: &JumpArg, rhs: &JumpArg, map: &HashMap) - true } -impl IsEquiv for ir::FunctionDefinition { +impl IsEquiv for FunctionDefinition { fn is_equiv(&self, other: &Self) -> bool { if self.allocations != other.allocations { return false; @@ -348,7 +347,7 @@ impl IsEquiv for ir::FunctionDefinition { let mut map = HashMap::new(); for (f, t) in izip!(&preorder, &preorder_other) { - map.insert(*f, *t); + let _ = map.insert(*f, *t); } if map.get(&self.bid_init) != Some(&other.bid_init) { diff --git a/src/ir/interp.rs b/src/ir/interp.rs index 44d3a7e..5c63fc0 100644 --- a/src/ir/interp.rs +++ b/src/ir/interp.rs @@ -703,7 +703,7 @@ mod calculator { let value = (-(value as i128)) as u128; trim_unnecessary_bits(value, width as u128) }; - Ok(Value::int(result as u128, width, is_signed)) + Ok(Value::int(result, width, is_signed)) } ast::UnaryOperator::Negate => { // Check if it is boolean @@ -781,11 +781,11 @@ mod calculator { if value == 0 { Ok(Value::pointer(None, 0, inner.deref().clone())) } else { - panic!(format!( + panic!( "calculate_typecast: not support case \ - typecast int to pointer when `value` is {}", + typecast int to pointer when `value` is {}", value - )) + ) } } ( @@ -1028,7 +1028,7 @@ impl Byte { let size = value.dtype().size_align_of(structs).unwrap().0; let value_bits: u128 = match size { Dtype::SIZE_OF_FLOAT => (float_value.into_inner() as f32).to_bits() as u128, - Dtype::SIZE_OF_DOUBLE => (float_value.into_inner() as f64).to_bits() as u128, + Dtype::SIZE_OF_DOUBLE => (float_value.into_inner()).to_bits() as u128, _ => panic!("value_to_bytes: {} is not a valid float size", size), }; @@ -1073,7 +1073,7 @@ impl Byte { izip!(fields, offsets).for_each(|(f, o)| { let result = Self::value_to_bytes(f.deref(), structs); let size_of_data = f.deref().dtype().size_align_of(structs).unwrap().0; - values.splice(*o..(*o + size_of_data), result.iter().cloned()); + let _ = values.splice(*o..(*o + size_of_data), result.iter().cloned()); }); values @@ -1143,7 +1143,7 @@ impl Memory { let block = self.inner[bid].as_mut().unwrap(); if 0 <= offset && end <= block.len() { - block.splice(offset as usize..end, bytes.iter().cloned()); + let _ = block.splice(offset as usize..end, bytes.iter().cloned()); Ok(()) } else { Err(()) @@ -1163,16 +1163,16 @@ struct State<'i> { } impl<'i> State<'i> { - fn new(ir: &'i TranslationUnit, args: Vec) -> Result { + fn new(ir: &'i TranslationUnit, args: Vec) -> Result, InterpreterError> { // Interpreter starts with the main function let func_name = String::from("main"); let func = ir .decls .get(&func_name) - .ok_or_else(|| InterpreterError::NoMainFunction)?; + .ok_or(InterpreterError::NoMainFunction)?; let (_, func_def) = func .get_function() - .ok_or_else(|| InterpreterError::NoMainFunction)?; + .ok_or(InterpreterError::NoMainFunction)?; let func_def = func_def .as_ref() .ok_or_else(|| InterpreterError::NoFunctionDefinition { @@ -1218,7 +1218,7 @@ impl<'i> State<'i> { }, )? } else { - Value::default_from_dtype(&dtype, &self.ir.structs) + Value::default_from_dtype(dtype, &self.ir.structs) .expect("default value must be derived from `dtype`") }; @@ -1244,7 +1244,7 @@ impl<'i> State<'i> { fn alloc_local_variables(&mut self) -> Result<(), InterpreterError> { // add alloc register for (id, allocation) in self.stack_frame.func_def.allocations.iter().enumerate() { - let bid = self.memory.alloc(&allocation, &self.ir.structs)?; + let bid = self.memory.alloc(allocation, &self.ir.structs)?; let ptr = Value::pointer(Some(bid), 0, allocation.deref().clone()); let rid = RegisterId::local(id); @@ -1407,7 +1407,7 @@ impl<'i> State<'i> { let lhs = self.interp_operand(lhs.clone())?; let rhs = self.interp_operand(rhs.clone())?; - calculator::calculate_binary_operator_expression(&op, lhs, rhs).map_err(|_| { + calculator::calculate_binary_operator_expression(op, lhs, rhs).map_err(|_| { InterpreterError::Misc { func_name: self.stack_frame.func_name.clone(), pc: self.stack_frame.pc, @@ -1418,7 +1418,7 @@ impl<'i> State<'i> { Instruction::UnaryOp { op, operand, .. } => { let operand = self.interp_operand(operand.clone())?; - calculator::calculate_unary_operator_expression(&op, operand).map_err(|_| { + calculator::calculate_unary_operator_expression(op, operand).map_err(|_| { InterpreterError::Misc { func_name: self.stack_frame.func_name.clone(), pc: self.stack_frame.pc, @@ -1517,7 +1517,7 @@ impl<'i> State<'i> { let offset = prev_offset + value as isize; assert!(0 <= offset); - Value::pointer(*bid, offset as isize, inner_dtype.clone()) + Value::pointer(*bid, offset, inner_dtype.clone()) } }; diff --git a/src/ir/mod.rs b/src/ir/mod.rs index 0325cc5..1973c88 100644 --- a/src/ir/mod.rs +++ b/src/ir/mod.rs @@ -1,6 +1,9 @@ +//! The intermediate representation. + mod dtype; mod equiv; mod interp; +#[allow(clippy::all)] mod parse; mod write_ir; @@ -247,11 +250,7 @@ impl HasDtype for Instruction { impl Instruction { pub fn is_pure(&self) -> bool { - match self { - Self::Store { .. } => false, - Self::Call { .. } => false, - _ => true, - } + !matches!(self, Self::Store { .. } | Self::Call { .. }) } } @@ -526,6 +525,7 @@ impl TryFrom<&ast::Constant> for Constant { ast::IntegerBase::Decimal => Self::DECIMAL, ast::IntegerBase::Octal => Self::OCTAL, ast::IntegerBase::Hexadecimal => Self::HEXADECIMAL, + ast::IntegerBase::Binary => Self::BINARY, }; let value = if integer.suffix.unsigned { @@ -636,14 +636,11 @@ impl Constant { const DECIMAL: u32 = 10; const OCTAL: u32 = 8; const HEXADECIMAL: u32 = 16; + const BINARY: u32 = 2; #[inline] pub fn is_integer_constant(&self) -> bool { - if let Self::Int { .. } = self { - true - } else { - false - } + matches!(self, Self::Int { .. }) } #[inline] @@ -730,17 +727,13 @@ impl Constant { } _ => panic!( "constant value generated by `Constant::from_ast_expression` \ - must be `Constant{{Int, Float}}`" + must be `Constant(Int, Float)`" ), } } pub fn is_undef(&self) -> bool { - if let Self::Undef { .. } = self { - true - } else { - false - } + matches!(self, Self::Undef { .. }) } pub fn typecast(self, target_dtype: Dtype) -> Self { diff --git a/src/ir/parse.rs b/src/ir/parse.rs index b150418..8a1332a 100644 --- a/src/ir/parse.rs +++ b/src/ir/parse.rs @@ -660,7 +660,7 @@ pub enum Error { ResolveError, } -#[derive(Default)] +#[derive(Default, Debug)] pub struct Parse {} impl> Translate

for Parse { diff --git a/src/lib.rs b/src/lib.rs index d55ede3..32f6036 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,44 @@ +//! KECC: KAIST Educational C Compiler. + +// Tries to deny all lints (`rustc -W help`). #![deny(warnings)] -// Neccessary for skeleton code. +#![deny(absolute_paths_not_starting_with_crate)] +#![deny(anonymous_parameters)] +// #![deny(box_pointers)] +#![deny(deprecated_in_future)] +#![deny(elided_lifetimes_in_paths)] +#![deny(explicit_outlives_requirements)] +#![deny(invalid_html_tags)] +#![deny(keyword_idents)] +#![deny(macro_use_extern_crate)] +#![deny(missing_debug_implementations)] +// #![deny(missing_docs)] TODO +#![deny(missing_doc_code_examples)] +#![deny(non_ascii_idents)] +#![deny(pointer_structural_match)] +// #![deny(single_use_lifetimes)] +#![deny(trivial_numeric_casts)] +#![deny(unaligned_references)] +// #![deny(unreachable_pub)] +#![deny(unstable_features)] +// Necessary for `build-bin` trick. +// #![deny(unused_crate_dependencies)] +#![deny(unused_extern_crates)] +#![deny(unused_import_braces)] +#![deny(unused_lifetimes)] +#![deny(unused_qualifications)] +#![deny(unused_results)] +// #![deny(variant_size_differences)] +#![deny(rust_2018_idioms)] +#![deny(rustdoc::all)] +// Necessary for skeleton code. #![allow(unreachable_code)] // Necessary to allow `iter.fold(false, |l, r| l || r)`. It's used when iteration should not be // short-circuited. #![allow(clippy::unnecessary_fold)] +#![allow(clippy::result_unit_err)] +#![allow(clippy::vec_init_then_push)] +#![allow(clippy::collapsible_match)] mod tests; mod utils; diff --git a/src/opt/mod.rs b/src/opt/mod.rs index 2be97fb..15563c3 100644 --- a/src/opt/mod.rs +++ b/src/opt/mod.rs @@ -22,15 +22,15 @@ pub trait Optimize { pub type O0 = Null; pub type O1 = Repeat<(SimplifyCfg, (Mem2reg, (Gvn, Deadcode)))>; -#[derive(Default)] +#[derive(Default, Debug)] pub struct Null {} -#[derive(Default)] +#[derive(Default, Debug)] pub struct Repeat { inner: O, } -#[derive(Default)] +#[derive(Default, Debug)] pub struct FunctionPass> { inner: T, } diff --git a/src/tests.rs b/src/tests.rs index 6fd6993..16ddadf 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -14,7 +14,8 @@ const NONCE_NAME: &str = "nonce"; fn modify_c(path: &Path, rand_num: i32) -> String { let mut src = File::open(path).expect("`path` must exist"); let mut data = String::new(); - src.read_to_string(&mut data) + let _ = src + .read_to_string(&mut data) .expect("`src` must be converted to string"); drop(src); @@ -69,8 +70,9 @@ fn modify_asm(unit: &mut asm::Asm, rand_num: i32) { // Rust sets an exit code of 101 when the process panicked. // So, we decide KECC sets an exit code of 102 after 101 when the test skipped. -pub const SKIP_TEST: i32 = 102; +const SKIP_TEST: i32 = 102; +/// Tests write_c. pub fn test_write_c(path: &Path) { // Check if the file has .c extension assert_eq!(path.extension(), Some(std::ffi::OsStr::new("c"))); @@ -82,7 +84,7 @@ pub fn test_write_c(path: &Path) { let temp_file_path = temp_dir.path().join("temp.c"); let mut temp_file = File::create(&temp_file_path).unwrap(); - crate::write(&unit, &mut temp_file).unwrap(); + write(&unit, &mut temp_file).unwrap(); let new_unit = c::Parse::default() .translate(&temp_file_path.as_path()) @@ -92,6 +94,7 @@ pub fn test_write_c(path: &Path) { temp_dir.close().expect("temp dir deletion failed"); } +/// Tests irgen. pub fn test_irgen(path: &Path) { // Check if the file has .c extension assert_eq!(path.extension(), Some(std::ffi::OsStr::new("c"))); @@ -103,7 +106,7 @@ pub fn test_irgen(path: &Path) { .translate(&unit) .unwrap_or_else(|irgen_error| panic!("{}", irgen_error)); - let rand_num = rand::thread_rng().gen_range(1, 100); + let rand_num = rand::thread_rng().gen_range(1..100); let new_c = modify_c(path, rand_num); modify_ir(&mut ir, rand_num); @@ -151,7 +154,7 @@ pub fn test_irgen(path: &Path) { { println!("timeout occurs"); child.kill().unwrap(); - child.wait().unwrap(); + let _ = child.wait().unwrap(); ::std::process::exit(SKIP_TEST); } ); @@ -187,6 +190,7 @@ pub fn test_irgen(path: &Path) { assert_eq!(status as u8, value as u8); } +/// Tests irparse. pub fn test_irparse(path: &Path) { // Check if the file has .c extension assert_eq!(path.extension(), Some(std::ffi::OsStr::new("c"))); @@ -195,7 +199,7 @@ pub fn test_irparse(path: &Path) { .unwrap_or_else(|_| panic!("parse failed {}", path.display())); // Test parse - c::Parse::default() + let _ = c::Parse::default() .translate(&path) .expect("failed to parse the given program"); @@ -207,7 +211,7 @@ pub fn test_irparse(path: &Path) { .unwrap_or_else(|irgen_error| panic!("{}", irgen_error)); let temp_file_path = temp_dir.path().join("ir0.ir"); let mut temp_file = File::create(&temp_file_path).unwrap(); - crate::write(&ir, &mut temp_file).unwrap(); + write(&ir, &mut temp_file).unwrap(); let ir0 = ir::Parse::default() .translate(&temp_file_path.as_path()) @@ -233,9 +237,9 @@ fn test_irparse_for_optimized_ir>( temp_file_path: &Path, mut opt: O, ) -> ir::TranslationUnit { - opt.optimize(&mut ir); + let _ = opt.optimize(&mut ir); let mut temp_file = File::create(temp_file_path).unwrap(); - crate::write(&ir, &mut temp_file).unwrap(); + write(&ir, &mut temp_file).unwrap(); let optimized_ir = ir::Parse::default() .translate(&temp_file_path) @@ -246,6 +250,7 @@ fn test_irparse_for_optimized_ir>( optimized_ir } +/// Tests optimizations. pub fn test_opt, P2: AsRef, O: Optimize>( from: &P1, to: &P2, @@ -258,7 +263,7 @@ pub fn test_opt, P2: AsRef, O: Optimize, P2: AsRef, O: Optimize { + /// TODO(document) type Target; + + /// TODO(document) type Error; + /// TODO(document) fn translate(&mut self, source: &S) -> Result; } +/// TODO(document) pub trait AssertSupported { + /// TODO(document) fn assert_supported(&self); } +/// TODO(document) pub trait IsEquiv { + /// TODO(document) fn is_equiv(&self, other: &Self) -> bool; } diff --git a/src/write_base.rs b/src/write_base.rs index 495bc4b..5361ecc 100644 --- a/src/write_base.rs +++ b/src/write_base.rs @@ -1,22 +1,30 @@ use std::io::{Result, Write}; +/// TODO(document) #[inline] pub fn write_indent(indent: usize, write: &mut dyn Write) -> Result<()> { write!(write, "{}", " ".repeat(indent)) } +/// TODO(document) pub trait WriteLine { + /// TODO(document) fn write_line(&self, indent: usize, write: &mut dyn Write) -> Result<()>; } +/// TODO(document) pub trait WriteString { + /// TODO(document) fn write_string(&self) -> String; } +/// TODO(document) pub trait WriteOp { + /// TODO(document) fn write_operation(&self) -> String; } +/// TODO(document) pub fn write(t: &T, write: &mut dyn Write) -> Result<()> { t.write_line(0, write) } diff --git a/tests/fuzz.py b/tests/fuzz.py index 24e383c..70820b8 100644 --- a/tests/fuzz.py +++ b/tests/fuzz.py @@ -224,7 +224,7 @@ def fuzz(tests_dir, fuzz_arg, num_iter): dst.write(src_polished) try: - args = ["cargo", "run", "--release", "--bin", "fuzz", "--", fuzz_arg, os.path.join(tests_dir, "test_polished.c")] + args = ["cargo", "run", "--features=build-bin", "--release", "--bin", "fuzz", "--", fuzz_arg, os.path.join(tests_dir, "test_polished.c")] proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=tests_dir) proc.communicate(timeout=60)