From 512c4ad6c0fc30d6830c59e7cafdc1c2f57a2b8a Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Mon, 6 Nov 2023 16:25:57 -0500 Subject: [PATCH] added bash wrapper script --- aas | 38 ++++++++++++++++++++++++++++++++++++++ aas.rb | 15 ++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100755 aas diff --git a/aas b/aas new file mode 100755 index 0000000..faa5f3a --- /dev/null +++ b/aas @@ -0,0 +1,38 @@ +#!/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 diff --git a/aas.rb b/aas.rb index c0a4a87..43f473c 100755 --- a/aas.rb +++ b/aas.rb @@ -22,12 +22,18 @@ eos 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 ############# @@ -274,6 +280,10 @@ class Variable def byte(value) emit ".byte 0x#{"%02x" % value.to_i}" end + + def string(value) + emit ".ascii #{value.to_s.inspect}" + end end class Function @@ -360,11 +370,10 @@ end $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| @@ -375,6 +384,6 @@ $asm_out.write START_CODE if $main_obj # 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 -- 2.54.0