Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for dumping variables using 'printf' for testing scenarios where std is not avalible. #3

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b15c412
Draft version of formatting using printf(does not support enums yet, …
FractalFir Jan 31, 2024
cd79ada
Printf dumper is now toglable from the command line, and can display …
FractalFir Jan 31, 2024
293bc43
Added support for formatting larger tuples.
FractalFir Jan 31, 2024
864d04b
Cleanup, comments, small fixes for large tuples
FractalFir Jan 31, 2024
7119f94
Added implementations of the formatting trait for even larger tuples
FractalFir Jan 31, 2024
1dc3061
Fixed a small issue with array formatting
FractalFir Jan 31, 2024
345ce26
made debug_printf an unsafe function. Implemented the PrintFDebug tra…
FractalFir Jan 31, 2024
97ce8ec
Small fix to generated printf formatting
FractalFir Feb 5, 2024
6d60354
Small fix to generated printf formatting
FractalFir Feb 5, 2024
120bf6d
Small fix to 128 bit int formatting
FractalFir Feb 12, 2024
38e581b
Fixed a couple of typos
FractalFir Feb 12, 2024
dc8c0ff
Merge branch 'cbeuw:master' into master
FractalFir Feb 18, 2024
25ec83d
Fixed missing null terminators in enum display
FractalFir Apr 28, 2024
eaf5b10
Fixed printing of NaN values using printf printing the sign of a NaN.…
FractalFir May 11, 2024
c843fb6
Small fix
FractalFir May 11, 2024
350b556
Update CITATION.cff
cbeuw Oct 14, 2024
644e14b
Merge branch 'master' into master
FractalFir Nov 12, 2024
8183b5a
FIxed issues with dumper caused by the merge.
FractalFir Nov 12, 2024
87cb1c4
Some initial work on generating source files compatible with rust-gpu
FractalFir Dec 1, 2024
b3726ac
Misc fixes to the rustgpu support.
FractalFir Dec 1, 2024
e47e1cc
Fixes to formatting code for 'rust-gpu'
FractalFir Dec 2, 2024
bdce6d4
Started working on supporting disabling fuzzing enums and 128 bit int…
FractalFir Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions generate/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use mir::syntax::{
SwitchTargets, Terminator, TyId, TyKind, UnOp, VariantIdx,
};
use mir::tyctxt::TyCtxt;
use mir::VarDumper;
use rand::seq::SliceRandom;
use rand::{seq::IteratorRandom, Rng, RngCore, SeedableRng};
use rand_distr::{Distribution, WeightedError, WeightedIndex};
Expand Down Expand Up @@ -921,7 +922,7 @@ impl GenerationCtx {
for vars in dumpped.chunks(Program::DUMPER_ARITY) {
let new_bb = self.add_new_bb();

let args = if self.program.use_debug_dumper {
let args = if self.program.var_dumper == VarDumper::StdVarDumper || self.program.var_dumper == VarDumper::PrintfVarDumper{
let mut args = Vec::with_capacity(1 + Program::DUMPER_ARITY * 2);
args.push(Operand::Constant(
self.cursor.function.index().try_into().unwrap(),
Expand Down Expand Up @@ -1166,7 +1167,7 @@ impl GenerationCtx {
}
}

pub fn new(seed: u64, debug_dump: bool) -> Self {
pub fn new(seed: u64, debug_dump: VarDumper) -> Self {
let rng = RefCell::new(Box::new(rand::rngs::SmallRng::seed_from_u64(seed)));
let tcx = Rc::new(seed_tys(&mut *rng.borrow_mut()));
let ty_weights = TySelect::new(&tcx);
Expand Down
14 changes: 11 additions & 3 deletions generate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::time::Instant;

use clap::{arg, command, value_parser};
use log::{debug, info};
use mir::serialize::Serialize;
use mir::{serialize::Serialize, VarDumper};

use crate::generation::GenerationCtx;

Expand All @@ -27,6 +27,7 @@ fn main() {
let matches = command!()
.args(&[
arg!(-d --debug "generate a program where values are printed instead of hashed (slow)"),
arg!(-p --printf_debug "generate a program where values are printed using the C 'printf' function instead of hashed (slow)"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI stability is not a concern. So you could replace -d with a single enum flag with 3 options, defaulting to HashDumper

arg!(<seed> "generation seed").value_parser(value_parser!(u64)),
])
.get_matches();
Expand All @@ -35,12 +36,19 @@ fn main() {
.get_one::<u64>("seed")
.expect("need an integer as seed");
let debug_dump = matches.get_one::<bool>("debug").copied().unwrap_or(false);
let printf_dump = matches.get_one::<bool>("printf_debug").copied().unwrap_or(false);
let dumper = match (debug_dump,printf_dump){
(false,false)=>VarDumper::HashDumper,
(true,false)=>VarDumper::StdVarDumper,
(false,true)=>VarDumper::PrintfVarDumper,
(true,true)=>panic!("You can only choose either the `debug` dumper or `printf_debug` dumper, but both of them have been selected."),
};
info!("Generating a program with seed {seed}");
let genctxt = GenerationCtx::new(seed, debug_dump);
let genctxt = GenerationCtx::new(seed, dumper);
let time = Instant::now();
let (program, tcx) = genctxt.generate();
println!("{}", program.serialize(&tcx));
println!("{}", tcx.serialize());
println!("{}", tcx.serialize(dumper));
let dur = time.elapsed();
debug!("took {}s to generate", dur.as_secs_f32());
}
4 changes: 3 additions & 1 deletion generate/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ impl TySelect {
.unwrap();
}
trace!("Typing context with weights:\n{s}");
trace!("{}", tcx.serialize());
// FractalFir: serialization requires info about which dumper(printf-based one or not) is used. I pass `StdVarDumper` here to preserve
// previous behaviour.
trace!("{}", tcx.serialize(mir::VarDumper::StdVarDumper));
}

WeightedIndex::new(tcx.iter_enumerated().map(|(tyid, _)| weights[&tyid]))
Expand Down
10 changes: 10 additions & 0 deletions mir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
pub mod serialize;
pub mod syntax;
pub mod tyctxt;
pub const ENABLE_PRINTF_DEBUG:bool = true;
#[derive(Clone,Copy,PartialEq, Eq)]
pub enum VarDumper{
/// Print variable hashes
HashDumper,
/// Print variables using standard rust formatting
StdVarDumper,
/// Print variables using the c `printf` function
PrintfVarDumper,
}
14 changes: 7 additions & 7 deletions mir/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{syntax::*, tyctxt::TyCtxt};
use crate::{syntax::*, tyctxt::TyCtxt, VarDumper};

pub trait Serialize {
fn serialize(&self, tcx: &TyCtxt) -> String;
Expand Down Expand Up @@ -316,11 +316,11 @@ impl Serialize for Body {
impl Serialize for Program {
fn serialize(&self, tcx: &TyCtxt) -> String {
let mut program = Program::HEADER.to_string();
if self.use_debug_dumper {
program += Program::DEBUG_DUMPER;
} else {
program += Program::DUMPER;
}
program += match self.var_dumper{
VarDumper::HashDumper=>Program::DUMPER,
VarDumper::StdVarDumper=>Program::DEBUG_DUMPER,
VarDumper::PrintfVarDumper=>Program::PRINTF_DUMPER,
};
program.extend(self.functions.iter_enumerated().map(|(idx, body)| {
let args_list: String = body
.args_iter()
Expand Down Expand Up @@ -359,7 +359,7 @@ impl Serialize for Program {
.expect("program has functions")
.identifier();

let hash_printer = if self.use_debug_dumper {
let hash_printer = if self.var_dumper != VarDumper::HashDumper {
""
} else {
r#"
Expand Down
Loading