about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-02-17 07:39:20 -0800
committerKartik Agaram <vc@akkartik.com>2019-02-17 07:39:20 -0800
commitead24155ca2cebcba94a9c8d5906d6142d286a01 (patch)
treee16a860587c47c175899b1b2c7bcf7603d261f0d
parenta6079569ccc993ee456d5206867ef60b1d556453 (diff)
downloadmu-ead24155ca2cebcba94a9c8d5906d6142d286a01.tar.gz
4978 - maybe we need another phase
Phase 1: coalesce different instances/fragments for each segment, correctly
prepending later fragments.

Phase 2: pack bitfields into bytes.

Phase 3: compute addresses for labels, compute the ELF header.

Phase 4: convert hex bytes to binary.

But ugh, phase 1 involves linked lists and I'll have to go down a rabbit
hole building up more standard library functions.
-rw-r--r--subx/apps/merge.subx36
1 files changed, 36 insertions, 0 deletions
diff --git a/subx/apps/merge.subx b/subx/apps/merge.subx
new file mode 100644
index 00000000..a5ecc987
--- /dev/null
+++ b/subx/apps/merge.subx
@@ -0,0 +1,36 @@
+# Read a text file of SubX segment 'fragments' with duplicate names, and emit
+# a list of 'merged' segments.
+#
+# Example input:
+#   == A
+#   a
+#   b
+#   c
+#   == B
+#   d
+#   e
+#   == A
+#   f
+#   g
+#   == A
+#   h
+#
+# Output:
+#   == A
+#   h
+#   f
+#   g
+#   a
+#   b
+#   c
+#   == B
+#   d
+#   e
+#
+# The output gives each segment the contents of all its fragments, with later
+# fragments *prepended* to earlier ones.
+#
+# Prepending necessitates buffering output until the end. We'll convert
+# fragments to distinct streams, maintain each segment as a linked list of
+# fragments that's easy to prepend to, and finally emit the linked lists in
+# order.