diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-09-07 22:44:03 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-09-07 22:44:03 -0700 |
| commit | 92b8da05981328c2d4b106d9de008625b6895620 (patch) | |
| tree | b5c834b61f47b5a8403997a1c6d583d910fb8eb4 /transform.e | |
| parent | 08d58db689cac50ef582340e93047273f7759a37 (diff) | |
add magic hex-transform comments in all the amd64 instruction words
also add logic to output newlines at the start of these comments Force-Push: yes Change-Id: I4c3ce99c264e7d02150cdf2b40d486e925b5fb72
Diffstat (limited to 'transform.e')
| -rw-r--r-- | transform.e | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/transform.e b/transform.e index eb8e8bf..3086968 100644 --- a/transform.e +++ b/transform.e @@ -2720,7 +2720,8 @@ allocate-transformation-state s" transformation-state" variable : hex-output-metadata-label-loop-buffer-start ; : hex-output-metadata-label-loop-buffer-length 8 + ; : hex-output-metadata-latest-output-point 2 8 * + ; -: hex-output-metadata-first-entry 3 8 * + ; +: hex-output-metadata-is-fresh-line 3 8 * + ; +: hex-output-metadata-first-entry 4 8 * + ; : hex-output-metadata-entry-data-start ; : hex-output-metadata-entry-data-length 8 + ; : hex-output-metadata-entry-type 2 8 * + ; @@ -2742,6 +2743,7 @@ allocate-transformation-state s" transformation-state" variable dup hex-output-metadata-label-loop-buffer-start 0 swap ! dup hex-output-metadata-label-loop-buffer-length 0 swap ! dup hex-output-metadata-latest-output-point 0 swap ! + dup hex-output-metadata-is-fresh-line 1 swap ! dup hex-output-metadata-first-entry 0 swap ! ; ~ (pointer -- boolean) @@ -2937,11 +2939,28 @@ allocate-transformation-state s" transformation-state" variable s" swap" find entry-to-execution-token , ; +: is-fresh-line@ + transformation-state transformation-state-output-metadata @ + hex-output-metadata-is-fresh-line @ ; + +: is-fresh-line! + transformation-state transformation-state-output-metadata @ + hex-output-metadata-is-fresh-line ! ; + +: fresh-line is-fresh-line@ not { newline } if ; + ~ This "replacement" is a little different from an alternate: When the code ~ under transformation attempts to compile its own version of sys-write, it ~ gets a stub that calls this word instead. It's swapped out by ~ hex-colon-alternate, whereas the regular alternates are swapped out by ~ hex-transform-one. +~ +~ In the programs we're actually running the transform on, there's only ever +~ a single call to sys-write which is the whole binary in one go, but we don't +~ want to require that, so we keep all the formatting state in the output +~ metadata. In particular, hex-output-metadata-entry-is-fresh-line is kept +~ there. +~ ~ (length to write, base address --) : hex-sys-write-replacement { over } { @@ -2956,12 +2975,15 @@ allocate-transformation-state s" transformation-state" variable dup hex-output-metadata-entry-type @ hex-output-metadata-entry-type-line-comment = { + fresh-line dup hex-output-metadata-entry-string @ ." ~ " emitstring newline + 1 is-fresh-line! } if dup hex-output-metadata-entry-type @ hex-output-metadata-entry-type-line-break = { newline + 1 is-fresh-line! } if dup hex-output-metadata-entry-type @ @@ -2972,6 +2994,7 @@ allocate-transformation-state s" transformation-state" variable dup hex-output-metadata-entry-string @ emitstring 0x22 value@ emitstring drop newline + 1 is-fresh-line! } if dup hex-output-metadata-entry-type @ @@ -2980,6 +3003,7 @@ allocate-transformation-state s" transformation-state" variable ." ~ Alignment padding to width " dup hex-output-metadata-entry-string @ . newline + 1 is-fresh-line! } if } if @@ -2988,6 +3012,8 @@ allocate-transformation-state s" transformation-state" variable drop dup 8@ .hex8 space + 0 is-fresh-line! + 1+ swap 1- swap } while ; |