summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-12-19 19:48:48 -0800
committerOri Bernstein <ori@eigenstate.org>2016-12-19 19:48:48 -0800
commit0b779653fa6d233b344fb07a3ff2bfe393b8d9aa (patch)
tree8edda3a43b63fd1c7882b2684f29204a21cf995a
parentf5db4655fcb8ef9c0fe034490692544f70b48ce5 (diff)
download6as-0b779653fa6d233b344fb07a3ff2bfe393b8d9aa.tar.gz
Maybe if it actually compiled...
-rw-r--r--encode.myr41
-rw-r--r--gen.awk1
2 files changed, 42 insertions, 0 deletions
diff --git a/encode.myr b/encode.myr
new file mode 100644
index 0000000..87ae334
--- /dev/null
+++ b/encode.myr
@@ -0,0 +1,41 @@
+use std
+
+use "types"
+use "tables-gen"
+
+pkg assem =
+ const encode : (as : assem#, op : byte[:], args : arg[:] -> void)
+;;
+
+var instrmap : std.htab(byte[:], variant[:])#
+
+const encode = {as, op : byte[:], args : arg[:]
+ var variants, best
+
+ match std.htget(instrmap, op)
+ | `std.Some vl: variants = vl
+ | `std.None: std.fatal("unknown opcode {}\n", op)
+ ;;
+
+ match bestvariant(variants, args)
+ | `std.Some v: best = v
+ | `std.None:
+ ;;
+
+ writeenc(as, op, best)
+}
+
+const bestvariant = {variants, args
+ -> `std.Some variants[0]
+}
+
+const writeenc = {as, op, desc
+ std.put("encoding {}: {}\n", op, desc)
+}
+
+const __init__ = {
+ instrmap = std.mkht(std.strhash, std.streq)
+ for o in instrtab[:]
+ std.htput(instrmap, o.name, o.vlist)
+ ;;
+}
diff --git a/gen.awk b/gen.awk
index 816b0c7..0e4cf13 100644
--- a/gen.awk
+++ b/gen.awk
@@ -50,6 +50,7 @@ $4 == "ignore" {next}
END {
print "use std"
print "use \"types\""
+ print "use \"regs-gen\""
print ""
print "pkg assem ="
print "\tconst instrtab : insn[" nop "]"