about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-09-10 09:22:12 -0700
committerIrene Knapp <ireneista@irenes.space>2026-09-10 09:22:12 -0700
commit2eb637e63a9e5d8f87391beb4af6019963a7c36c (patch)
treef27d9d2772bd49475a6af737507a930b424a3a40
parent7a0a28f4d8b738d305b826b5464b27255dd7def3 (diff)
add provide-hex, which varies its output width to fit the value
and amd64.e uses it for all the immediates, but not for other kinds of numeric parameter, which looks pretty slick and readable

Force-Push: yes
Change-Id: Ifb630a4dc172d7495b5458316266fe76b75e07af
-rw-r--r--amd64.e38
-rw-r--r--labels.e2
-rw-r--r--transform.e32
3 files changed, 45 insertions, 27 deletions
diff --git a/amd64.e b/amd64.e
index 1a5df04..e76f33a 100644
--- a/amd64.e
+++ b/amd64.e
@@ -656,7 +656,7 @@ s" :cc-greater" keyword
 : push-imm32-extended64
   ~ : 5 # push-imm32-extended64
   swap 0x68 pack8 swap
-  ~ : provide-hex32
+  ~ : provide-hex
   pack32 ;
 
 ~ (output point, source register, source displacement value, target register
@@ -711,19 +711,19 @@ s" :cc-greater" keyword
   rex-w 0xC7 pack8 swap
   0 swap addressing-reg64
   swap
-  ~ : provide-hex32
+  ~ : provide-hex
   pack32 ;
 : mov-reg64-imm64
   ~ : 8 # # mov-reg64-imm64
   3roll rex-w swap reg64 0xB8 opcodereg swap
-  ~ : provide-hex64
+  ~ : provide-hex
   pack64 ;
 : mov-extrareg64-imm64
   ~ : 8 # # mov-extrareg64-imm64
   ~   Note the use of the B rex bit here; this instruction puts the register
   ~ number in the opcode field, so it uses Table 3-1.
   3roll rex-wb swap extrareg64 0xB8 opcodereg swap
-  ~ : provide-hex64
+  ~ : provide-hex
   pack64 ;
 
 ~ (output point, source register, target register -- output point)
@@ -1086,7 +1086,7 @@ s" :cc-greater" keyword
   ~ : 2 # # add-reg64-imm8
   3roll rex-w 0x83 pack8 swap 0 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ See above re: parameter order.
@@ -1110,7 +1110,7 @@ s" :cc-greater" keyword
   ~ : 2 # # sub-reg64-imm8
   3roll rex-w 0x83 pack8 swap 5 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ See above re: parameter order.
@@ -1120,7 +1120,7 @@ s" :cc-greater" keyword
   ~ : 2 # # sbb-reg64-imm8
   3roll rex-w 0x83 pack8 swap 3 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~  The target register is always rax.
@@ -1174,7 +1174,7 @@ s" :cc-greater" keyword
   3roll rex-w 0x83 pack8 swap
   4 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, source register, target register -- output point)
@@ -1189,7 +1189,7 @@ s" :cc-greater" keyword
   3roll rex-w 0x83 pack8 swap
   1 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, source register, target register -- output point)
@@ -1210,7 +1210,7 @@ s" :cc-greater" keyword
   3roll rex-w 0xC1 pack8 swap
   0 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, bit count, target register -- output point)
@@ -1219,7 +1219,7 @@ s" :cc-greater" keyword
   3roll 0xC0 pack8 swap
   0 swap addressing-reg8
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, bit count, target register -- output point)
@@ -1228,7 +1228,7 @@ s" :cc-greater" keyword
   3roll rex-w 0xC1 swap
   1 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, bit count, target register -- output point)
@@ -1237,7 +1237,7 @@ s" :cc-greater" keyword
   3roll 0xC0 pack8 swap
   1 swap addressing-reg64
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 
@@ -1267,7 +1267,7 @@ s" :cc-greater" keyword
   swap 7 swap addressing-reg64
   ~ ( output point, immediate value)
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~   Pretend to bitwise-and left with right, and set the flags the same way as
@@ -1295,7 +1295,7 @@ s" :cc-greater" keyword
   ~ : 1 # # jmp-cc-rel-imm8
   3roll swap condition-code 0x70 opcodecc
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, address offset value, condition code -- output point)
@@ -1304,7 +1304,7 @@ s" :cc-greater" keyword
   3unroll 0x0F pack8
   swap condition-code 0x70 opcodecc
   swap
-  ~ : provide-hex32
+  ~ : provide-hex
   pack32 ;
 
 ~ (output point, register -- output point)
@@ -1318,7 +1318,7 @@ s" :cc-greater" keyword
   ~ : 2 # jmp-rel-imm8
   swap 0xEB pack8
   swap
-  ~ : provide-hex8
+  ~ : provide-hex
   pack8 ;
 
 ~ (output point, address offset value -- output point)
@@ -1326,7 +1326,7 @@ s" :cc-greater" keyword
   ~ : 5 # jmp-rel-imm32
   swap 0xE9 pack8
   swap
-  ~ : provide-hex32
+  ~ : provide-hex
   pack32 ;
 
 ~ This is technically a "near" call. The name intentionally doesn't say so.
@@ -1336,7 +1336,7 @@ s" :cc-greater" keyword
   ~ : 5 # call-rel-imm32
   swap 0xE8 pack8
   swap
-  ~ : provide-hex32
+  ~ : provide-hex
   pack32 ;
 
 ~ Similarly, this is a "near" return.
diff --git a/labels.e b/labels.e
index f0629a8..f528219 100644
--- a/labels.e
+++ b/labels.e
@@ -131,6 +131,8 @@
   ~ Mark it used. It's faster to just do this than to check if it's needed.
   dup label-status dup @ 0x01 | swap !
 
+  ~ TODO putting a provide-label magic comment command here would be lovely
+
   ~ Return the guessed value.
   label-value @ ;
 
diff --git a/transform.e b/transform.e
index 5bec117..b8afb1d 100644
--- a/transform.e
+++ b/transform.e
@@ -2780,6 +2780,7 @@ allocate-transformation-state s" transformation-state" variable
 ~   ~ : Do a thing with # and # ?
 ~   ~ : Do a different #swap # thing to # now.
 ~   ~ : provide-decimal
+~   ~ : provide-hex
 ~   ~ : provide-hex8
 ~   ~ : provide-hex16
 ~   ~ : provide-hex32
@@ -3204,14 +3205,15 @@ allocate-transformation-state s" transformation-state" variable
 : hex-output-metadata-entry-type-raw-string-literal 6 ;
 : hex-output-metadata-entry-type-alignment 7 ;
 : hex-output-metadata-entry-type-push-substring-decimal 8 ;
-: hex-output-metadata-entry-type-push-substring-hex8 9 ;
-: hex-output-metadata-entry-type-push-substring-hex16 10 ;
-: hex-output-metadata-entry-type-push-substring-hex32 11 ;
-: hex-output-metadata-entry-type-push-substring-hex64 12 ;
-: hex-output-metadata-entry-type-push-substring-string 13 ;
-: hex-output-metadata-entry-type-drop-substring 14 ;
-: hex-output-metadata-entry-type-swap-substrings 15 ;
-: hex-output-metadata-entry-type-roll-substrings 16 ;
+: hex-output-metadata-entry-type-push-substring-hex 9 ;
+: hex-output-metadata-entry-type-push-substring-hex8 10 ;
+: hex-output-metadata-entry-type-push-substring-hex16 11 ;
+: hex-output-metadata-entry-type-push-substring-hex32 12 ;
+: hex-output-metadata-entry-type-push-substring-hex64 13 ;
+: hex-output-metadata-entry-type-push-substring-string 14 ;
+: hex-output-metadata-entry-type-drop-substring 15 ;
+: hex-output-metadata-entry-type-swap-substrings 16 ;
+: hex-output-metadata-entry-type-roll-substrings 17 ;
 
 ~   Initialize the contents of the output metadata to all zeroes. This is
 ~ called from hex-transform at its top level, at the very start, to make sure
@@ -3263,6 +3265,7 @@ allocate-transformation-state s" transformation-state" variable
   ~ push-substring entries.
   hex-output-metadata-entry-type @
   dup hex-output-metadata-entry-type-push-substring-decimal = swap
+  dup hex-output-metadata-entry-type-push-substring-hex = 3roll || swap
   dup hex-output-metadata-entry-type-push-substring-hex8 = 3roll || swap
   dup hex-output-metadata-entry-type-push-substring-hex16 = 3roll || swap
   dup hex-output-metadata-entry-type-push-substring-hex32 = 3roll || swap
@@ -3796,6 +3799,12 @@ allocate-transformation-state s" transformation-state" variable
           } if
 
           dup hex-output-metadata-entry-type @
+          hex-output-metadata-entry-type-push-substring-hex = {
+            ." 0x"
+            dup hex-output-metadata-entry-string @ .hex
+          } if
+
+          dup hex-output-metadata-entry-type @
           hex-output-metadata-entry-type-push-substring-hex8 = {
             ." 0x"
             dup hex-output-metadata-entry-string @ .hex8
@@ -4935,6 +4944,13 @@ allocate-transformation-state s" transformation-state" variable
     add-hex-output-metadata-entry
     exit
   } if
+  dup s" provide-hex" stringcmp 0 = {
+    ~ Create a new "push substring hex" entry.
+    drop drop
+    2 pick hex-output-metadata-entry-type-push-substring-hex swap
+    add-hex-output-metadata-entry
+    exit
+  } if
   dup s" provide-hex8" stringcmp 0 = {
     ~ Create a new "push substring hex8" entry.
     drop drop