Rustc cross-checker compiler plugin

This is a simple cross-check inserter for Rust code that is implemented as a Rust compiler plugin.

Usage

To use the compiler plugin, you need to take several steps.First, add the plugin as a Cargo dependency to your Cargo.toml file:

  1. [dependencies]
  2. c2rust-xcheck-plugin = { path = ".../C2Rust/cross-checks/rust-checks/rustc-plugin" }
  3. c2rust-xcheck-derive = { path = ".../C2Rust/cross-checks/rust-checks/derive-macros" }
  4. c2rust-xcheck-runtime = { path = ".../C2Rust/cross-checks/rust-checks/runtime" }

with as the full path to the C2Rust repository.Next, add the following preamble to your main.rs or lib.rs file:

  1. #![allow(unused_variables)]
  2. #![feature(plugin)]
  3. #![plugin(c2rust_xcheck_plugin)]
  4. fn main() {
  5. #[macro_use]
  6. extern crate c2rust_xcheck_derive;
  7. #[macro_use]
  8. extern crate c2rust_xcheck_runtime;
  9. }

Cross-checker options

Cross-checking is enabled and configured using the #[cross_check] directive,which can either be enabled globally (using #![cross_check] at the beginning of main.rs or lib.rs) or individuallyper function (the per-function settings override the global ones).

The directive optionally takes the following options:

  • yes and enabled enable cross-checking for the current scope (crateor function).
  • none and disabled disable cross-checking for the current scope.
  • entry(djb2="foo") sets the cross-checking name for the current function entry point to the DJB2 hash of foo.
  • entry(fixed=NNN) sets the cross-checking ID for the current function entry point to NNN.

Example:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. #[cross_check(yes, entry(djb2="foo"))]
  4. fn bar() { }
  5. #[cross_check(yes, entry(fixed=0x1234))]
  6. fn baz() { }
  7. #[cross_check(no)]
  8. fn foo() { }
  9. }