forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
- Loading branch information
1 parent
19adf79
commit 6040814
Showing
9 changed files
with
421 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
//! This module contains code related to the MIR-to-MIR pass that performs the | ||
//! stubbing of functions and methods. | ||
use crate::kani_middle::codegen_units::Stubs; | ||
use crate::kani_middle::stubbing::{contract_host_param, validate_stub_const}; | ||
use crate::kani_middle::transform::body::{MutMirVisitor, MutableBody}; | ||
use crate::kani_middle::transform::{TransformPass, TransformationType}; | ||
use crate::kani_queries::QueryDb; | ||
use rustc_middle::ty::TyCtxt; | ||
use rustc_smir::rustc_internal; | ||
use stable_mir::mir::mono::Instance; | ||
use stable_mir::mir::visit::{Location, MirVisitor}; | ||
use stable_mir::mir::{Body, ConstOperand, LocalDecl, Operand, Terminator, TerminatorKind}; | ||
use stable_mir::ty::{FnDef, MirConst, RigidTy, TyKind}; | ||
use stable_mir::CrateDef; | ||
use std::collections::HashMap; | ||
use std::fmt::Debug; | ||
use tracing::{debug, trace}; | ||
use crate::kani_middle::find_fn_def; | ||
|
||
/// Replace the body of a function that is stubbed by the other. | ||
/// | ||
/// This pass will replace the entire body, and it should only be applied to stubs | ||
/// that have a body. | ||
#[derive(Debug)] | ||
pub struct QuantifiersPass { | ||
forall: Option<FnDef>, | ||
} | ||
|
||
impl TransformPass for QuantifiersPass { | ||
fn transformation_type() -> TransformationType | ||
where | ||
Self: Sized, | ||
{ | ||
TransformationType::Instrumentation | ||
} | ||
|
||
fn is_enabled(&self, query_db: &QueryDb) -> bool | ||
where | ||
Self: Sized, | ||
{ | ||
true | ||
} | ||
|
||
/// Transform the function body by replacing it with the stub body. | ||
fn transform(&mut self, tcx: TyCtxt, body: Body, instance: Instance) -> (bool, Body) { | ||
trace!(function=?instance.name(), "transform"); | ||
println!("transform {:?}", self.forall); | ||
/*let ty = instance.ty(); | ||
if let TyKind::RigidTy(RigidTy::FnDef(fn_def, mut args)) = ty.kind() { | ||
if let Some(replace) = self.stubs.get(&fn_def) { | ||
if let Some(idx) = contract_host_param(tcx, fn_def, *replace) { | ||
debug!(?idx, "FnStubPass::transform remove_host_param"); | ||
args.0.remove(idx); | ||
} | ||
let new_instance = Instance::resolve(*replace, &args).unwrap(); | ||
debug!(from=?instance.name(), to=?new_instance.name(), "FnStubPass::transform"); | ||
if let Some(body) = FnStubValidator::validate(tcx, (fn_def, *replace), new_instance) | ||
{ | ||
return (true, body); | ||
} | ||
} | ||
}*/ | ||
(false, body) | ||
} | ||
} | ||
|
||
impl QuantifiersPass { | ||
/// Build the pass with non-extern function stubs. | ||
pub fn new(tcx: TyCtxt, ) -> QuantifiersPass { | ||
let forall = find_fn_def(tcx, "KaniForall"); | ||
QuantifiersPass { forall } | ||
} | ||
} |
Oops, something went wrong.