foundry_common_fmt/
eof.rs
1use comfy_table::{modifiers::UTF8_ROUND_CORNERS, ContentArrangement, Table};
2use revm_primitives::{
3 eof::{EofBody, EofHeader},
4 Eof,
5};
6use std::fmt::{self, Write};
7
8pub fn pretty_eof(eof: &Eof) -> Result<String, fmt::Error> {
9 let Eof {
10 header:
11 EofHeader {
12 types_size,
13 code_sizes,
14 container_sizes,
15 data_size,
16 sum_code_sizes: _,
17 sum_container_sizes: _,
18 },
19 body:
20 EofBody { types_section, code_section, container_section, data_section, is_data_filled: _ },
21 raw: _,
22 } = eof;
23
24 let mut result = String::new();
25
26 let mut table = Table::new();
27 table.apply_modifier(UTF8_ROUND_CORNERS);
28 table.add_row(vec!["type_size", &types_size.to_string()]);
29 table.add_row(vec!["num_code_sections", &code_sizes.len().to_string()]);
30 if !code_sizes.is_empty() {
31 table.add_row(vec!["code_sizes", &format!("{code_sizes:?}")]);
32 }
33 table.add_row(vec!["num_container_sections", &container_sizes.len().to_string()]);
34 if !container_sizes.is_empty() {
35 table.add_row(vec!["container_sizes", &format!("{container_sizes:?}")]);
36 }
37 table.add_row(vec!["data_size", &data_size.to_string()]);
38
39 write!(result, "Header:\n{table}")?;
40
41 if !code_section.is_empty() {
42 let mut table = Table::new();
43 table.apply_modifier(UTF8_ROUND_CORNERS);
44 table.set_content_arrangement(ContentArrangement::Dynamic);
45 table.set_header(vec!["", "Inputs", "Outputs", "Max stack height", "Code"]);
46 for (idx, (code, type_section)) in code_section.iter().zip(types_section).enumerate() {
47 table.add_row(vec![
48 &idx.to_string(),
49 &type_section.inputs.to_string(),
50 &type_section.outputs.to_string(),
51 &type_section.max_stack_size.to_string(),
52 &code.to_string(),
53 ]);
54 }
55
56 write!(result, "\n\nCode sections:\n{table}")?;
57 }
58
59 if !container_section.is_empty() {
60 let mut table = Table::new();
61 table.apply_modifier(UTF8_ROUND_CORNERS);
62 table.set_content_arrangement(ContentArrangement::Dynamic);
63 for (idx, container) in container_section.iter().enumerate() {
64 table.add_row(vec![&idx.to_string(), &container.to_string()]);
65 }
66
67 write!(result, "\n\nContainer sections:\n{table}")?;
68 }
69
70 if !data_section.is_empty() {
71 let mut table = Table::new();
72 table.apply_modifier(UTF8_ROUND_CORNERS);
73 table.set_content_arrangement(ContentArrangement::Dynamic);
74 table.add_row(vec![&data_section.to_string()]);
75 write!(result, "\n\nData section:\n{table}")?;
76 }
77
78 Ok(result)
79}