A couple more primitives now working. In the process I ran into an issue
with some buffer filling up when running ntranslate. Isolating it to survey.subx
was straightforward, but --trace ran out of RAM, and --trace --dump ran
out of (7GB of) disk. In the end what helped was just repeatedly inserting
exits at different points, and I realized there was a magic number that
hadn't been turned into a named constant.
This commit is contained in:
Kartik Agaram 2019-11-26 22:11:23 -08:00
parent 55628fb693
commit 70187b1c01
13 changed files with 119 additions and 3 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
apps/hex

Binary file not shown.

BIN
apps/mu

Binary file not shown.

View File

@ -2176,6 +2176,118 @@ test-add-reg-to-reg:
5d/pop-to-ebp
c3/return
test-add-reg-to-mem:
# add-to var1 var2/reg
# =>
# 01 *(ebp+__) var2
#
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp
# setup
(clear-stream _test-output-stream)
(clear-stream _test-output-buffered-file->buffer)
# var-var1/ecx : var
68/push 0/imm32/no-register
68/push 8/imm32/stack-offset
68/push 1/imm32/block-depth
68/push 1/imm32/type-int
68/push "var1"/imm32
89/<- %ecx 4/r32/esp
# var-var2/edx : var in ecx
68/push "ecx"/imm32/register
68/push 0/imm32/no-stack-offset
68/push 1/imm32/block-depth
68/push 1/imm32/type-int
68/push "var2"/imm32
89/<- %edx 4/r32/esp
# inouts/esi : (list var2)
68/push 0/imm32/next
52/push-edx/var-var2
89/<- %esi 4/r32/esp
# inouts = (list var1 var2)
56/push-esi/next
51/push-ecx/var-var1
89/<- %esi 4/r32/esp
# stmt/esi : statement
68/push 0/imm32/next
68/push 0/imm32/outputs
56/push-esi/inouts
68/push "add-to"/imm32/operation
68/push 1/imm32
89/<- %esi 4/r32/esp
# convert
(emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
(flush _test-output-buffered-file)
#? # dump _test-output-stream {{{
#? (write 2 "^")
#? (write-stream 2 _test-output-stream)
#? (write 2 "$\n")
#? (rewind-stream _test-output-stream)
#? # }}}
# check output
(check-next-stream-line-equal _test-output-stream "01 *(ebp+0x00000008) 0x00000001/r32" "F - test-add-reg-to-mem")
# . epilogue
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return
test-add-mem-to-reg:
# var1/reg <- add var2
# =>
# 03 *(ebp+__) var1
#
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp
# setup
(clear-stream _test-output-stream)
(clear-stream _test-output-buffered-file->buffer)
# var-var1/ecx : var in eax
68/push "eax"/imm32/register
68/push 0/imm32/no-stack-offset
68/push 1/imm32/block-depth
68/push 1/imm32/type-int
68/push "var1"/imm32
89/<- %ecx 4/r32/esp
# var-var2/edx : var
68/push 0/imm32/no-register
68/push 8/imm32/stack-offset
68/push 1/imm32/block-depth
68/push 1/imm32/type-int
68/push "var2"/imm32
89/<- %edx 4/r32/esp
# inouts/esi : (list var2)
68/push 0/imm32/next
52/push-edx/var-var2
89/<- %esi 4/r32/esp
# outputs/edi : (list var1)
68/push 0/imm32/next
51/push-ecx/var-var1
89/<- %edi 4/r32/esp
# stmt/esi : statement
68/push 0/imm32/next
57/push-edi/outputs
56/push-esi/inouts
68/push "add"/imm32/operation
68/push 1/imm32
89/<- %esi 4/r32/esp
# convert
(emit-subx-statement _test-output-buffered-file %esi 0 Primitives 0)
(flush _test-output-buffered-file)
#? # dump _test-output-stream {{{
#? (write 2 "^")
#? (write-stream 2 _test-output-stream)
#? (write 2 "$\n")
#? (rewind-stream _test-output-stream)
#? # }}}
# check output
(check-next-stream-line-equal _test-output-stream "03 *(ebp+0x00000008) 0x00000000/r32" "F - test-add-mem-to-reg")
# . epilogue
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return
test-add-literal-to-reg:
# var1/eax <- add 0x34
# =>

BIN
apps/pack

Binary file not shown.

Binary file not shown.

View File

@ -13,3 +13,7 @@ Input-size:
# number of labels we can translate to addresses
Max-labels:
0x10000/imm32/4K-labels/64KB
# capacity of trace-stream
Trace-size:
0x80000/imm32/512KB

Binary file not shown.

View File

@ -23,7 +23,7 @@
# The output is the stream of bytes without segment headers or label definitions,
# and with label references replaced with numeric values/displacements.
#
# $ cat x |./subx run apps/assort
# $ cat x |./subx run apps/survey
# ...ELF header bytes...
# # ELF header above will specify that code segment begins at this offset
# aa bb nn # some computed address
@ -53,9 +53,9 @@ Entry: # run tests if necessary, convert stdin if not
e8/call new-segment/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp
# initialize-trace-stream(256KB)
# initialize-trace-stream(Trace-size)
# . . push args
68/push 0x40000/imm32/256KB
68/push Trace-size/imm32
# . . call
e8/call initialize-trace-stream/disp32
# . . discard args

Binary file not shown.