rubyx/lib/rubyx/execute.rb

28 lines
1.1 KiB
Ruby

class RubyXC < Thor
desc "execute FILE" , "Compile given FILE and execute resulting binary"
long_desc <<-LONGDESC
Just like the compile task, this compiles the file to an object/binary file.
Then rubyxc will link and run the resulting object file. For this to work,
qemu needs to be set up correctly on the system. Specifically, because of
bug #13, arm-linux-gnueabihf-ld needs to exist (it's part of the cross compiled
arm binutils).
The resulting a.out will be run via qemu-arm. This is part of the qemu "linux" package
and interprets the arm binary on the host, assuming a linux os.
This whole approach should only be used for preliminary checking that no core-dumps
are generated by the program, or when no benchmarking (as the times will be whatever).
For simple functional test though, it is a much much quicker way to run the binary
than transferring it to another machine. The a.out is left in place to be run again.
LONGDESC
def execute(file)
outfile = compile(file)
puts "Running #{outfile}\n\n"
system "qemu-arm ./a.out ;echo $?"
end
end