move FormalMode to crate::testing and add to prelude

This commit is contained in:
Jacob Lifshay 2025-10-24 00:14:04 -07:00
parent 3e5b2f126a
commit b6e4cd0614
Signed by: programmerjake
SSH key fingerprint: SHA256:HnFTLGpSm4Q4Fj502oCFisjZSoakwEuTsJJMSke63RQ
5 changed files with 41 additions and 52 deletions

View file

@ -13,9 +13,10 @@ use crate::{
}, },
intern::{Intern, InternSlice, Interned}, intern::{Intern, InternSlice, Interned},
module::NameId, module::NameId,
testing::FormalMode,
util::job_server::AcquiredJob, util::job_server::AcquiredJob,
}; };
use clap::{Args, ValueEnum}; use clap::Args;
use eyre::Context; use eyre::Context;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
@ -24,33 +25,6 @@ use std::{
path::Path, path::Path,
}; };
#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq, Hash, Default, Deserialize, Serialize)]
#[non_exhaustive]
pub enum FormalMode {
#[default]
BMC,
Prove,
Live,
Cover,
}
impl FormalMode {
pub fn as_str(self) -> &'static str {
match self {
FormalMode::BMC => "bmc",
FormalMode::Prove => "prove",
FormalMode::Live => "live",
FormalMode::Cover => "cover",
}
}
}
impl fmt::Display for FormalMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Args, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Args, Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub struct FormalArgs { pub struct FormalArgs {

View file

@ -37,7 +37,7 @@ pub use crate::{
value::{SimOnly, SimOnlyValue, SimValue, ToSimValue, ToSimValueWithType}, value::{SimOnly, SimOnlyValue, SimValue, ToSimValue, ToSimValueWithType},
}, },
source_location::SourceLocation, source_location::SourceLocation,
testing::assert_formal, testing::{FormalMode, assert_formal},
ty::{AsMask, CanonicalType, Type}, ty::{AsMask, CanonicalType, Type},
util::{ConstUsize, GenericConstUsize}, util::{ConstUsize, GenericConstUsize},
wire::Wire, wire::Wire,

View file

@ -6,7 +6,7 @@ use crate::{
NoArgs, RunBuild, NoArgs, RunBuild,
external::{ExternalCommandArgs, ExternalCommandJobKind}, external::{ExternalCommandArgs, ExternalCommandJobKind},
firrtl::{FirrtlArgs, FirrtlJobKind}, firrtl::{FirrtlArgs, FirrtlJobKind},
formal::{Formal, FormalAdditionalArgs, FormalArgs, FormalMode, WriteSbyFileJobKind}, formal::{Formal, FormalAdditionalArgs, FormalArgs, WriteSbyFileJobKind},
verilog::{UnadjustedVerilogArgs, VerilogJobArgs, VerilogJobKind}, verilog::{UnadjustedVerilogArgs, VerilogJobArgs, VerilogJobKind},
}, },
bundle::BundleType, bundle::BundleType,
@ -14,14 +14,43 @@ use crate::{
module::Module, module::Module,
util::HashMap, util::HashMap,
}; };
use serde::Deserialize; use serde::{Deserialize, Serialize};
use std::{ use std::{
fmt::Write, fmt::{self, Write},
path::{Path, PathBuf}, path::{Path, PathBuf},
process::Command, process::Command,
sync::{Mutex, OnceLock}, sync::{Mutex, OnceLock},
}; };
#[derive(
clap::ValueEnum, Copy, Clone, Debug, PartialEq, Eq, Hash, Default, Deserialize, Serialize,
)]
#[non_exhaustive]
pub enum FormalMode {
#[default]
BMC,
Prove,
Live,
Cover,
}
impl FormalMode {
pub fn as_str(self) -> &'static str {
match self {
FormalMode::BMC => "bmc",
FormalMode::Prove => "prove",
FormalMode::Live => "live",
FormalMode::Cover => "cover",
}
}
}
impl fmt::Display for FormalMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Deserialize)] #[derive(Deserialize)]
struct CargoMetadata { struct CargoMetadata {
target_directory: String, target_directory: String,

View file

@ -212,9 +212,7 @@ pub fn queue<T: Type>(
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use crate::{
build::formal::FormalMode, firrtl::ExportOptions, firrtl::ExportOptions, module::transform::simplify_enums::SimplifyEnumsKind, ty::StaticType,
module::transform::simplify_enums::SimplifyEnumsKind, testing::assert_formal,
ty::StaticType,
}; };
use std::num::NonZero; use std::num::NonZero;

View file

@ -2,19 +2,7 @@
// See Notices.txt for copyright information // See Notices.txt for copyright information
//! Formal tests in Fayalite //! Formal tests in Fayalite
use fayalite::{ use fayalite::prelude::*;
build::formal::FormalMode,
clock::{Clock, ClockDomain},
expr::{CastTo, HdlPartialEq},
firrtl::ExportOptions,
formal::{any_const, any_seq, formal_reset, hdl_assert, hdl_assume},
hdl, hdl_module,
int::{Bool, DynSize, Size, UInt, UIntType},
module::{connect, connect_any, instance, memory, reg_builder, wire},
reset::ToReset,
testing::assert_formal,
ty::StaticType,
};
/// Test hidden state /// Test hidden state
/// ///
@ -119,7 +107,7 @@ mod hidden_state {
FormalMode::Prove, FormalMode::Prove,
16, 16,
None, None,
ExportOptions::default(), Default::default(),
); );
// here a couple of cycles is enough // here a couple of cycles is enough
assert_formal( assert_formal(
@ -128,7 +116,7 @@ mod hidden_state {
FormalMode::Prove, FormalMode::Prove,
2, 2,
None, None,
ExportOptions::default(), Default::default(),
); );
} }
} }
@ -242,7 +230,7 @@ mod memory {
#[hdl] #[hdl]
let wr: WritePort<DynSize> = wire(WritePort[n]); let wr: WritePort<DynSize> = wire(WritePort[n]);
connect(wr.addr, any_seq(UInt[n])); connect(wr.addr, any_seq(UInt[n]));
connect(wr.data, any_seq(UInt::<8>::TYPE)); connect(wr.data, any_seq(UInt::<8>::new_static()));
connect(wr.en, any_seq(Bool)); connect(wr.en, any_seq(Bool));
#[hdl] #[hdl]
let dut = instance(example_sram(n)); let dut = instance(example_sram(n));
@ -289,7 +277,7 @@ mod memory {
FormalMode::Prove, FormalMode::Prove,
2, 2,
None, None,
ExportOptions::default(), Default::default(),
); );
} }
} }