]> git.mdlowis.com Git - proto/aas.git/commitdiff
added bash wrapper script
authorMike Lowis <mike.lowis@gentex.com>
Mon, 6 Nov 2023 21:25:57 +0000 (16:25 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 6 Nov 2023 21:25:57 +0000 (16:25 -0500)
aas [new file with mode: 0755]
aas.rb

diff --git a/aas b/aas
new file mode 100755 (executable)
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 c0a4a87f933ea5ba0df90cb226657666b6c46ec8..43f473cb4b46892e24951b4123386d592c757e86 100755 (executable)
--- 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