about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-04-10 01:24:47 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-18 00:44:46 -0700
commit4ad59882c35cb433dbd7cbf850a1333d114ae721 (patch)
tree69c3682ddd4725a7fc13e6ec448329e3145a9095
parent33171ec595d4e7a2c87c7bf6b6a091c822d9f2a6 (diff)
downloadmu-4ad59882c35cb433dbd7cbf850a1333d114ae721.tar.gz
emit-segments in survey.subx now working
-rw-r--r--apps/survey.subx176
1 files changed, 104 insertions, 72 deletions
diff --git a/apps/survey.subx b/apps/survey.subx
index f6979dea..d09f1f1d 100644
--- a/apps/survey.subx
+++ b/apps/survey.subx
@@ -1917,7 +1917,7 @@ test-compute-addresses-large-segments:
     # . . push labels
     52/push-edx
     # . . call
-    e8/call  stream-add5/disp32
+    e8/call  stream-add6/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x1c/imm32        # add to esp
     # component under test
@@ -2059,8 +2059,8 @@ emit-segments:  # in: (addr stream byte), out: (addr buffered-file), labels: (ad
     #         write-slice-buffered(out, word-slice)
     #         write-buffered(out, " ")
     #         continue
-    #       datum = next-token-from-slice(word-slice->start, word-slice->end, "/")
-    #       info = get-slice(labels, datum)
+    #       var datum: (addr slice) = next-token-from-slice(word-slice->start, word-slice->end, "/")
+    #       var info: (addr label-info) = get-slice(labels, datum)
     #       var curr-segment-name: (addr array byte) = lookup(info->segment-name)
     #       if !string-equal?(info->segment-name, "code")
     #         if has-metadata?(word-slice, "disp8")
@@ -2307,7 +2307,7 @@ $emit-segments:check-metadata:
     e8/call  next-token-from-slice/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # add to esp
-#?     # dump word-slice {{{
+#?     # dump datum {{{
 #?     # . write(2/stderr, "datum: ")
 #?     # . . push args
 #?     68/push  "datum: "/imm32
@@ -2316,7 +2316,7 @@ $emit-segments:check-metadata:
 #?     e8/call  write/disp32
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-#?     # . write-slice-buffered(Stderr, word-slice)
+#?     # . write-slice-buffered(Stderr, datum)
 #?     # . . push args
 #?     57/push-edi
 #?     68/push  Stderr/imm32
@@ -2340,11 +2340,11 @@ $emit-segments:check-metadata:
 #?     # . . discard args
 #?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
 #?     # }}}
-    # info/esi = get-slice(labels, datum, row-size=16, "label table")
-    # . eax = get-slice(labels, datum, row-size=16, "label table")
+    # info/esi = get-slice(labels, datum, row-size=24, "label table")
+    # . eax = get-slice(labels, datum, row-size=24, "label table")
     # . . push args
     68/push  "label table"/imm32
-    68/push  0x10/imm32/row-size
+    68/push  0x18/imm32/row-size
     57/push-edi
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0x10/disp8      .                 # push *(ebp+16)
     # . . call
@@ -2354,38 +2354,20 @@ $emit-segments:check-metadata:
     # . esi = eax
     89/copy                         3/mod/direct    6/rm32/esi    .           .             .           0/r32/eax   .               .                 # copy eax to esi
 $emit-segments:check-global-variable:
-#?     # dump info->segment-name {{{
-#?     # . write(2/stderr, "aa: label segment: ")
-#?     # . . push args
-#?     68/push  "aa: label segment: "/imm32
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-#?     # . write(2/stderr, info->segment-name)
-#?     # . . push args
-#?     ff          6/subop/push        0/mod/indirect  6/rm32/esi    .           .             .           .           .               .                 # push *esi
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-#?     # . write(2/stderr, "$\n")
-#?     # . . push args
-#?     68/push  "$\n"/imm32
-#?     68/push  2/imm32/stderr
-#?     # . . call
-#?     e8/call  write/disp32
-#?     # . . discard args
-#?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-#?     # }}}
     # if string-equal?(info->segment-name, "code") goto code label checks
-    # . eax = string-equal?(info->segment-name, "code")
+    # . eax = lookup(info->segment-name)
     # . . push args
-    68/push  "code"/imm32
+    ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           4/disp8         .                 # push *(esi+4)
     ff          6/subop/push        0/mod/indirect  6/rm32/esi    .           .             .           .           .               .                 # push *esi
     # . . call
+    e8/call  lookup/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+    # . eax = string-equal?(eax, "code")
+    # . . push args
+    68/push  "code"/imm32
+    50/push-eax
+    # . . call
     e8/call  string-equal?/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
@@ -2422,7 +2404,7 @@ $emit-segments:emit-global-variable:
     # emit-hex(out, info->address, 4)
     # . . push args
     68/push  4/imm32
-    ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           8/disp8         .                 # push *(esi+8)
+    ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           0xc/disp8       .                 # push *(esi+12)
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
     # . . call
     e8/call  emit-hex/disp32
@@ -2467,7 +2449,7 @@ $emit-segments:check-code-label-for-imm32:
 #?     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
 #?     # . print-int32-buffered(Stderr, info->address)
 #?     # . . push args
-#?     ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           8/disp8         .                 # push *(esi+8)
+#?     ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           0xc/disp8       .                 # push *(esi+12)
 #?     68/push  Stderr/imm32
 #?     # . . call
 #?     e8/call  print-int32-buffered/disp32
@@ -2493,7 +2475,7 @@ $emit-segments:emit-code-label-imm32:
     # emit-hex(out, info->address, 4)
     # . . push args
     68/push  4/imm32
-    ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           8/disp8         .                 # push *(esi+8)
+    ff          6/subop/push        1/mod/*+disp8   6/rm32/esi    .           .             .           .           0xc/disp8       .                 # push *(esi+12)
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
     # . . call
     e8/call  emit-hex/disp32
@@ -2518,7 +2500,7 @@ $emit-segments:emit-code-label-disp8:
     # emit-hex(out, info->offset - offset-of-next-instruction, 1)
     # . . push args
     68/push  1/imm32
-    8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   4/disp8         .                 # copy *(esi+4) to eax
+    8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   8/disp8         .                 # copy *(esi+8) to eax
     29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           3/r32/ebx   .               .                 # subtract ebx from eax
     50/push-eax
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
@@ -2545,7 +2527,7 @@ $emit-segments:emit-code-label-disp32:
     # emit-hex(out, info->offset - offset-of-next-instruction, 4)
     # . . push args
     68/push  4/imm32
-    8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   4/disp8         .                 # copy *(esi+4) to eax
+    8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   8/disp8         .                 # copy *(esi+8) to eax
     29/subtract                     3/mod/direct    0/rm32/eax    .           .             .           3/r32/ebx   .               .                 # subtract ebx from eax
     50/push-eax
     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
@@ -2654,9 +2636,6 @@ test-emit-segments-global-variable:
     #     00
     #     x:
     #       34
-    #   segments:
-    #     - 'code': {0x1074, 0, 9}
-    #     - 'data': {0x2079, 5, 2}
     #   labels:
     #     - 'x': {'data', 1, 0x207a}
     #
@@ -2691,12 +2670,16 @@ test-emit-segments-global-variable:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-    # . var labels/edx: (stream byte 512*16)
-    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x2000/imm32      # subtract from esp
-    68/push  0x2000/imm32/size
+    # . var labels/edx: (stream byte 8*24)
+    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc0/imm32        # subtract from esp
+    68/push  0xc0/imm32/size
     68/push  0/imm32/read
     68/push  0/imm32/write
     89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
+    # . var h/ebx: (handle array byte)
+    68/push  0/imm32
+    68/push  0/imm32
+    89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           4/r32/esp   .               .                 # copy esp to ebx
     # initialize input
     # . write(_test-input-stream, "== code 0x1000\n")
     # . . push args
@@ -2754,16 +2737,31 @@ test-emit-segments-global-variable:
     e8/call  write/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    # . stream-add5(labels, "x", "data", 1, 0x207a)
+    # . stream-add6(labels, "x", "data", 1, 0x207a)
     68/push  0x207a/imm32/label-address
     68/push  1/imm32/segment-offset
-    68/push  "data"/imm32/segment-name
-    68/push  "x"/imm32/label-name
+    # . . push "data"
+    53/push-ebx
+    68/push  "data"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push "l1"
+    53/push-ebx
+    68/push  "x"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push labels
     52/push-edx
     # . . call
-    e8/call  stream-add5/disp32
+    e8/call  stream-add6/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x14/imm32        # add to esp
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x1c/imm32        # add to esp
     # component under test
     # . emit-segments(_test-input-stream, _test-output-buffered-file, labels)
     # . . push args
@@ -2866,8 +2864,6 @@ test-emit-segments-code-label:
     #     l1:
     #       ef gh
     #       ij l1/disp32
-    #   segments:
-    #     - 'code': {0x1054, 0, 9}
     #   labels:
     #     - 'l1': {'code', 2, 0x1056}
     #
@@ -2901,12 +2897,16 @@ test-emit-segments-code-label:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-    # . var labels/edx: (stream byte 512*16)
-    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x2000/imm32      # subtract from esp
-    68/push  0x2000/imm32/size
+    # . var labels/edx: (stream byte 8*24)
+    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc0/imm32        # subtract from esp
+    68/push  0xc0/imm32/size
     68/push  0/imm32/read
     68/push  0/imm32/write
     89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
+    # . var h/ebx: (handle array byte)
+    68/push  0/imm32
+    68/push  0/imm32
+    89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           4/r32/esp   .               .                 # copy esp to ebx
     # initialize input
     # . write(_test-input-stream, "== code 0x1000\n")
     # . . push args
@@ -2948,16 +2948,31 @@ test-emit-segments-code-label:
     e8/call  write/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    # . stream-add5(labels, "l1", "code", 2, 0x1056)
+    # . stream-add6(labels, "l1", "code", 2, 0x1056)
     68/push  0x1056/imm32/label-address
     68/push  2/imm32/segment-offset
-    68/push  "code"/imm32/segment-name
-    68/push  "l1"/imm32/label-name
+    # . . push "data"
+    53/push-ebx
+    68/push  "code"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push "l1"
+    53/push-ebx
+    68/push  "l1"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push labels
     52/push-edx
     # . . call
-    e8/call  stream-add5/disp32
+    e8/call  stream-add6/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x14/imm32        # add to esp
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x1c/imm32        # add to esp
     # component under test
     # . emit-segments(_test-input-stream, _test-output-buffered-file, labels)
     # . . push args
@@ -3051,8 +3066,6 @@ test-emit-segments-code-label-absolute:
     #     l1:
     #       ef gh
     #       ij l1/imm32
-    #   segments:
-    #     - 'code': {0x1054, 0, 9}
     #   labels:
     #     - 'l1': {'code', 2, 0x1056}
     #
@@ -3086,12 +3099,16 @@ test-emit-segments-code-label-absolute:
     e8/call  clear-stream/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               4/imm32           # add to esp
-    # . var labels/edx: (stream byte 512*16)
-    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0x2000/imm32      # subtract from esp
-    68/push  0x2000/imm32/size
+    # . var labels/edx: (stream byte 8*24)
+    81          5/subop/subtract    3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc0/imm32        # subtract from esp
+    68/push  0xc0/imm32/size
     68/push  0/imm32/read
     68/push  0/imm32/write
     89/copy                         3/mod/direct    2/rm32/edx    .           .             .           4/r32/esp   .               .                 # copy esp to edx
+    # . var h/ebx: (handle array byte)
+    68/push  0/imm32
+    68/push  0/imm32
+    89/copy                         3/mod/direct    3/rm32/ebx    .           .             .           4/r32/esp   .               .                 # copy esp to ebx
     # initialize input
     # . write(_test-input-stream, "== code 0x1000\n")
     # . . push args
@@ -3133,16 +3150,31 @@ test-emit-segments-code-label-absolute:
     e8/call  write/disp32
     # . . discard args
     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    # . stream-add5(labels, "l1", "code", 2, 0x1056)
+    # . stream-add6(labels, "l1", "code", 2, 0x1056)
     68/push  0x1056/imm32/label-address
     68/push  2/imm32/segment-offset
-    68/push  "code"/imm32/segment-name
-    68/push  "l1"/imm32/label-name
+    # . . push "data"
+    53/push-ebx
+    68/push  "code"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push "l1"
+    53/push-ebx
+    68/push  "l1"/imm32
+    68/push  Heap/imm32
+    e8/call  copy-array/disp32
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+    ff          6/subop/push        1/mod/*+disp8   3/rm32/ebx    .           .             .           .           4/disp8         .                 # push *(ebx+4)
+    ff          6/subop/push        0/mod/indirect  3/rm32/ebx    .           .             .           .           .               .                 # push *ebx
+    # . . push labels
     52/push-edx
     # . . call
-    e8/call  stream-add5/disp32
+    e8/call  stream-add6/disp32
     # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x14/imm32        # add to esp
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x1c/imm32        # add to esp
     # component under test
     # . emit-segments(_test-input-stream, _test-output-buffered-file, labels)
     # . . push args