|
| 1 | +use comfy_table::{ContentArrangement, Table}; |
| 2 | +use revm_primitives::{ |
| 3 | + eof::{EofBody, EofHeader}, |
| 4 | + Eof, |
| 5 | +}; |
| 6 | +use std::fmt::{self, Write}; |
| 7 | + |
| 8 | +pub 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.add_row(vec!["type_size", &types_size.to_string()]); |
| 28 | + table.add_row(vec!["num_code_sections", &code_sizes.len().to_string()]); |
| 29 | + if !code_sizes.is_empty() { |
| 30 | + table.add_row(vec!["code_sizes", &format!("{code_sizes:?}")]); |
| 31 | + } |
| 32 | + table.add_row(vec!["num_container_sections", &container_sizes.len().to_string()]); |
| 33 | + if !container_sizes.is_empty() { |
| 34 | + table.add_row(vec!["container_sizes", &format!("{container_sizes:?}")]); |
| 35 | + } |
| 36 | + table.add_row(vec!["data_size", &data_size.to_string()]); |
| 37 | + |
| 38 | + write!(result, "Header:\n{table}")?; |
| 39 | + |
| 40 | + if !code_section.is_empty() { |
| 41 | + let mut table = Table::new(); |
| 42 | + table.set_content_arrangement(ContentArrangement::Dynamic); |
| 43 | + table.set_header(vec!["", "Inputs", "Outputs", "Max stack height", "Code"]); |
| 44 | + for (idx, (code, type_section)) in code_section.iter().zip(types_section).enumerate() { |
| 45 | + table.add_row(vec![ |
| 46 | + &idx.to_string(), |
| 47 | + &type_section.inputs.to_string(), |
| 48 | + &type_section.outputs.to_string(), |
| 49 | + &type_section.max_stack_size.to_string(), |
| 50 | + &code.to_string(), |
| 51 | + ]); |
| 52 | + } |
| 53 | + |
| 54 | + write!(result, "\n\nCode sections:\n{table}")?; |
| 55 | + } |
| 56 | + |
| 57 | + if !container_section.is_empty() { |
| 58 | + let mut table = Table::new(); |
| 59 | + table.set_content_arrangement(ContentArrangement::Dynamic); |
| 60 | + for (idx, container) in container_section.iter().enumerate() { |
| 61 | + table.add_row(vec![&idx.to_string(), &container.to_string()]); |
| 62 | + } |
| 63 | + |
| 64 | + write!(result, "\n\nContainer sections:\n{table}")?; |
| 65 | + } |
| 66 | + |
| 67 | + if !data_section.is_empty() { |
| 68 | + let mut table = Table::new(); |
| 69 | + table.set_content_arrangement(ContentArrangement::Dynamic); |
| 70 | + table.add_row(vec![&data_section.to_string()]); |
| 71 | + write!(result, "\n\nData section:\n{table}")?; |
| 72 | + } |
| 73 | + |
| 74 | + Ok(result) |
| 75 | +} |
0 commit comments