Skip to content
Snippets Groups Projects
Commit 29e2fbce authored by Mark Wheelhouse's avatar Mark Wheelhouse
Browse files

added a refEmulate script for command-line access to the ARM Emulator on...

added a refEmulate script for command-line access to the ARM Emulator on Teaching server (plus some minor refactors of refCompile script)
parent 3d0fbf6f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/ruby #!/usr/bin/ruby
# comand line script that sends an HTTPS request to the WACC compiler web interface and interprets the JSON response # command line script that sends an HTTPS request to the WACC compiler web interface and interprets the JSON response
require "rest-client" require "rest-client"
require "json" require "json"
...@@ -106,13 +106,14 @@ end ...@@ -106,13 +106,14 @@ end
files.each do |file_path| files.each do |file_path|
puts "calling the reference compiler on #{file_path}" puts "calling the reference compiler on #{file_path}"
#get stdin from the user to pass to the reference compiler # get stdin from the user to pass to the reference compiler
stdin = "" stdin = ""
if $options[:execute] then if $options[:execute] then
puts "please provide a stdin stream to use when executing the program:" puts "please provide a stdin stream to use when executing the program:"
stdin = STDIN.gets stdin = STDIN.gets
end end
# make the call to the reference compiler
RestClient.post("https://teaching.doc.ic.ac.uk/wacc_compiler/run.cgi", RestClient.post("https://teaching.doc.ic.ac.uk/wacc_compiler/run.cgi",
:stdin => stdin, :stdin => stdin,
:options => $opts, :options => $opts,
......
#!/usr/bin/ruby
# command line script that sends an HTTPS request to the WACC compiler web interface and interprets the JSON response
require "rest-client"
require "json"
require "optparse"
ARGV << "-h" if ARGV.empty?
$options = {}
$opts = []
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] <target.s> \n options:"
$options[:assemble_only] = false
opts.on("-a", "--assemble_only",
"Assemble only. Check the input file for assembly errors, but do not execute the generated binary file.") do
$opts << "-a"
$options[:assemble_only] = true
end
$options[:directory] = false
opts.on("-d", "--directory",
"Give directory of ARM assembly files." ) do
$options[:directory] = true
end
opts.on_tail("-h", "--help",
"Show this message") do
puts opts
puts ""
puts " target.s: path to ARM assembly program file to emulate (or target directory if -dir option set)"
exit
end
end.parse!
# set up empty array of file_paths to process
files = []
puts ARGV[0]
if $options[:directory] then
# add the results of a search to the array
files += Dir.glob(File.join(ARGV[0], "**", "*.s"))
else
# just add the target file to the array
files << ARGV[0]
end
# check that there is at least one file to process
if files == [] then
puts "Error: no file(s) targeted"
exit 1
end
# now process each target file
files.each do |file_path|
puts "calling the ARM emulator on #{file_path}"
# get stdin from the user to pass to the ARM emulator
stdin = ""
unless $options[:assemble_only] then
puts "please provide a stdin stream to use when emulating the program:"
stdin = STDIN.gets
end
# make the call to the ARM emulator
RestClient.post("https://teaching.doc.ic.ac.uk/wacc_compiler/emulate.cgi",
:stdin => stdin,
:options => $opts,
:testfile => File.new(file_path)
) do |response|
json = JSON.load(response)
puts "-- Test: #{json['test']}"
puts ""
puts "-- Uploaded file: "
puts "---------------------------------------------------------------"
puts json['upload']
puts "---------------------------------------------------------------"
puts ""
puts "-- Assembly Output:"
puts json['assemble_out']
puts ""
unless $options[:assemble_only] then
puts "-- Emulation Output:"
puts json['emulator_out']
puts ""
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment