From e1be82aba88fd01926bcfc88757ae3257eadaf16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 6 Jul 2017 16:00:50 +0200 Subject: beam_makeops: Pretty-print the generated code --- erts/emulator/utils/beam_makeops | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'erts/emulator') diff --git a/erts/emulator/utils/beam_makeops b/erts/emulator/utils/beam_makeops index fca596e4e5..da69b13e87 100755 --- a/erts/emulator/utils/beam_makeops +++ b/erts/emulator/utils/beam_makeops @@ -825,7 +825,7 @@ sub emulator_output { my $name = "$outdir/$key"; open(STDOUT, ">$name") || die "Failed to open $name for writing: $!\n"; comment('C'); - print @{$combined_code{$key}}; + print_indented_code(@{$combined_code{$key}}); } } @@ -865,18 +865,41 @@ sub print_code { $code .= "OpCase($label):\n"; $sort_key = $label; } - foreach (split("\n", $key)) { - $code .= " $_\n"; - } - $code .= "\n"; + $code .= "$key\n"; $sorted{$sort_key} = $code; } foreach (sort keys %sorted) { - print $sorted{$_}; + print_indented_code($sorted{$_}); + } +} + +sub print_indented_code { + my(@code) = @_; + + foreach my $chunk (@code) { + my $indent = 0; + foreach (split "\n", $chunk) { + s/^\s*//; + if (/\}/) { + $indent -= 2; + } + if ($_ eq '') { + print "\n"; + } elsif (/^#/) { + print $_, "\n"; + } else { + print ' ' x $indent, $_, "\n"; + } + if (/\{/) { + $indent += 2; + } + } + print "\n"; } } + # # Produce output needed by the compiler back-end (assembler). # -- cgit v1.2.3