mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
This relies on https://github.com/compiler-explorer/infra/pull/1658 to put rakudo release versions in the right spot.  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.
37 lines
1.1 KiB
Raku
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 }
|
|
}
|