1 use bigint_presentation_code_register_allocator::{function::Function, interned::GlobalState};
5 use serde_json::{Deserializer, Value};
6 use std::io::{BufWriter, Write};
8 #[derive(Parser, Debug)]
9 #[command(version, about, long_about)]
17 #[derive(Serialize, Debug)]
19 DumpInput(&'a Function),
22 #[derive(Serialize, Debug)]
30 fn write_to_stdout(&self, pretty: bool) -> Result<()> {
31 let mut stdout = BufWriter::new(std::io::stdout().lock());
33 serde_json::to_writer_pretty(&mut stdout, self)?;
35 serde_json::to_writer(&mut stdout, self)?;
41 fn from_err(e: impl Into<eyre::Report>) -> Self {
42 Self::Error(format!("{:?}", e.into()))
46 fn main() -> Result<()> {
47 let Args { dump_input, pretty } = Args::parse();
48 let stdin = std::io::stdin().lock();
49 for input in Deserializer::from_reader(stdin).into_iter::<Value>() {
50 GlobalState::scope(|| -> Result<()> {
51 let function = match serde_json::from_value::<Function>(input?) {
54 Output::from_err(e).write_to_stdout(pretty)?;
59 Output::Info(Info::DumpInput(&function)).write_to_stdout(pretty)?;