Newer
Older

Mark Wheelhouse
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/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']
Mark Wheelhouse
committed
puts "---------------------------------------------------------------"
puts "The exit code is: #{exit_code}."

Mark Wheelhouse
committed
puts ""
end
end
end