aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/utils
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-07-06 16:00:50 +0200
committerBjörn Gustavsson <[email protected]>2017-08-08 09:49:42 +0200
commite1be82aba88fd01926bcfc88757ae3257eadaf16 (patch)
treed9473374ef1bd584f1ff316486709022bea2e773 /erts/emulator/utils
parent426af3250c3f1bdb121413b8b054b63c1bc60fa6 (diff)
downloadotp-e1be82aba88fd01926bcfc88757ae3257eadaf16.tar.gz
otp-e1be82aba88fd01926bcfc88757ae3257eadaf16.tar.bz2
otp-e1be82aba88fd01926bcfc88757ae3257eadaf16.zip
beam_makeops: Pretty-print the generated code
Diffstat (limited to 'erts/emulator/utils')
-rwxr-xr-xerts/emulator/utils/beam_makeops35
1 files changed, 29 insertions, 6 deletions
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).
#