--- /dev/null
+#!/bin/sh
+
+output="a.out"
+objects=""
+
+# Parse command line options
+while :; do
+ case $1 in
+ -o|--output)
+ if [ -n "$2" ]; then
+ output=$2
+ shift
+ else
+ printf 'ERROR: "--output" requires a non-empty option argument.\n' >&2
+ exit 1
+ fi
+ ;;
+ --output=?*)
+ output=${1#*=}
+ ;;
+ --output=)
+ printf 'ERROR: "--file" requires a non-empty option argument.\n' >&2
+ exit 1
+ ;;
+ *)
+ break
+ esac
+ shift
+done
+
+# Now assemble all the files
+for f in "$@"; do
+ PATH="$PWD:$PATH" aas.rb "$f" | as - -o "$f.o"
+ objects="$objects $f.o"
+done
+
+# And link them altogether
+ld --gc-sections -o "$output" $objects
\ No newline at end of file
module Targets
module X86_64
class << self
+ #############
+ # Literals
+ #############
def int(value)
# TODO: optimize this based on size of operand
emit "mov $#{value}, %rax"
emit "pushq %rax"
end
+# def string(value)
+# end
+
#############
# ARITHMETIC
#############
def byte(value)
emit ".byte 0x#{"%02x" % value.to_i}"
end
+
+ def string(value)
+ emit ".ascii #{value.to_s.inspect}"
+ end
end
class Function
$main_obj = false
$syscalls = [false, false, false, false, false, false, false]
$target = Targets::X86_64
-$out_name = ARGV[0]
$asm_out = Tempfile.new("aas")
# Process all the input files
-ARGV[1..-1].each do |f|
+ARGV.each do |f|
load f
end
$syscalls.each_with_index do |used, n|
# Now run it through the system assembler
$asm_out.close
puts File.read($asm_out.path)
-system "as -o #{$out_name} #{$asm_out.path}"
+#system "as -o #{$out_name} #{$asm_out.path}"
$asm_out.unlink