|
4 | 4 | //! This file contains functions related to codegenning MIR functions into gotoc
|
5 | 5 |
|
6 | 6 | use crate::codegen_cprover_gotoc::GotocCtx;
|
| 7 | +use crate::kani_middle::attributes::{extract_integer_argument, partition_kanitool_attributes}; |
7 | 8 | use cbmc::goto_program::{Expr, Stmt, Symbol};
|
8 | 9 | use cbmc::InternString;
|
9 | 10 | use kani_metadata::HarnessMetadata;
|
10 |
| -use rustc_ast::ast; |
11 |
| -use rustc_ast::{Attribute, LitKind}; |
| 11 | +use rustc_ast::Attribute; |
12 | 12 | use rustc_hir::def::DefKind;
|
13 | 13 | use rustc_hir::def_id::DefId;
|
14 | 14 | use rustc_middle::mir::{HasLocalDecls, Local};
|
@@ -436,59 +436,3 @@ impl<'tcx> GotocCtx<'tcx> {
|
436 | 436 | }
|
437 | 437 | }
|
438 | 438 | }
|
439 |
| - |
440 |
| -/// If the attribute is named `kanitool::name`, this extracts `name` |
441 |
| -fn kanitool_attr_name(attr: &ast::Attribute) -> Option<String> { |
442 |
| - match &attr.kind { |
443 |
| - ast::AttrKind::Normal(normal) => { |
444 |
| - let segments = &normal.item.path.segments; |
445 |
| - if (!segments.is_empty()) && segments[0].ident.as_str() == "kanitool" { |
446 |
| - Some(segments[1].ident.as_str().to_string()) |
447 |
| - } else { |
448 |
| - None |
449 |
| - } |
450 |
| - } |
451 |
| - _ => None, |
452 |
| - } |
453 |
| -} |
454 |
| - |
455 |
| -/// Partition all the attributes into two buckets, proof_attributes and other_attributes |
456 |
| -fn partition_kanitool_attributes( |
457 |
| - all_attributes: &[Attribute], |
458 |
| -) -> (Vec<&Attribute>, Vec<(String, &Attribute)>) { |
459 |
| - let mut proof_attributes = vec![]; |
460 |
| - let mut other_attributes = vec![]; |
461 |
| - |
462 |
| - for attr in all_attributes { |
463 |
| - // Get the string the appears after "kanitool::" in each attribute string. |
464 |
| - // Ex - "proof" | "unwind" etc. |
465 |
| - if let Some(attribute_string) = kanitool_attr_name(attr).as_deref() { |
466 |
| - if attribute_string == "proof" { |
467 |
| - proof_attributes.push(attr); |
468 |
| - } else { |
469 |
| - other_attributes.push((attribute_string.to_string(), attr)); |
470 |
| - } |
471 |
| - } |
472 |
| - } |
473 |
| - |
474 |
| - (proof_attributes, other_attributes) |
475 |
| -} |
476 |
| - |
477 |
| -/// Extracts the integer value argument from the attribute provided |
478 |
| -/// For example, `unwind(8)` return `Some(8)` |
479 |
| -fn extract_integer_argument(attr: &Attribute) -> Option<u128> { |
480 |
| - // Vector of meta items , that contain the arguments given the attribute |
481 |
| - let attr_args = attr.meta_item_list()?; |
482 |
| - // Only extracts one integer value as argument |
483 |
| - if attr_args.len() == 1 { |
484 |
| - let x = attr_args[0].literal()?; |
485 |
| - match x.kind { |
486 |
| - LitKind::Int(y, ..) => Some(y), |
487 |
| - _ => None, |
488 |
| - } |
489 |
| - } |
490 |
| - // Return none if there are no attributes or if there's too many attributes |
491 |
| - else { |
492 |
| - None |
493 |
| - } |
494 |
| -} |
0 commit comments