Files
compiler-explorer/etc/scripts/disasms/moarvm_disasm.raku
timo bd80d171de Add raku language and rakudo compiler (#7784)
This relies on https://github.com/compiler-explorer/infra/pull/1658 to
put rakudo release versions in the right spot.


![image](https://github.com/user-attachments/assets/30ba7c2b-389a-4d3f-895b-c13da5b5f072)

There are more things that can be added, such as opcode tooltips,
suggested options for `--target=parse`, `--target=ast`,
`--target=optimize`, and probably other things I haven't thought of yet.
But this pull request should be a good starting point, and fine to merge
without waiting for further features.
2025-06-09 12:39:53 -05:00

37 lines
1.1 KiB
Raku

sub tempname {
my $lastex;
for ^1000 {
my $name = $*TMPDIR.child("rakudo_disassembly_" ~ (|("a".."z"),|("A".."Z"),|("0".."9")).roll(8).join("") ~ ".moarvm");
try {
$name.IO.open(:create, :exclusive).close();
CATCH { default { $lastex = $!; next } }
}
return $name;
}
die "Could not come up with a free temp name file? $lastex.Str()";
}
sub MAIN($rakudoexe, $outputfile, *@extra_args) {
my $code = @extra_args.pop;
# If the user passes --target, we don't want to run the output through
# the moar --dump program.
if @extra_args && @extra_args.any.starts-with("--target=") {
my $output = qqx/ $rakudoexe @extra_args[0] $code /;
$outputfile.IO.spurt($output);
return;
}
# Store the moar bytecode result
my $tempfile = tempname;
my $moarexe = $rakudoexe.IO.sibling("moar");
qqx/ $rakudoexe --target=mbc --output=$tempfile $code /;
my $output = qqx[ $moarexe --dump $tempfile ];
$outputfile.IO.spurt($output);
LEAVE { .IO.unlink with $tempfile }
}