| @@ -0,0 +1,68 @@ |
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import sys |
| 4 | + |
| 5 | +import dis |
| 6 | +import opcodes |
| 7 | +from opcodes import Imm, LOfp, LOmp, NoOp, SOfp, SOmp, SOSOfp, SOSOmp |
| 8 | +from utils import hash_signature |
| 9 | + |
| 10 | +if __name__ == "__main__": |
| 11 | + |
| 12 | + if len(sys.argv) != 2: |
| 13 | + sys.stderr.write("Usage: %s <output file>\n" % sys.argv[0]) |
| 14 | + sys.exit(1) |
| 15 | + |
| 16 | + d = dis.Dis() |
| 17 | + d.runtime_flag = dis.RuntimeFlag(dis.RuntimeFlag.HASLDT) |
| 18 | + d.stack_extent = 560 |
| 19 | + d.data_size = 8 |
| 20 | + d.entry_pc = 0 |
| 21 | + d.entry_type = 1 |
| 22 | + |
| 23 | + """ |
| 24 | + implement count; |
| 25 | + |
| 26 | + include "sys.m"; |
| 27 | + include "draw.m"; |
| 28 | + |
| 29 | + count: module |
| 30 | + { |
| 31 | + init: fn(ctxt: ref Draw->Context, args: list of string); |
| 32 | + }; |
| 33 | + |
| 34 | + init(ctxt: ref Draw->Context, args: list of string) |
| 35 | + { |
| 36 | + sys := load Sys Sys->PATH; |
| 37 | + for (i := 0; i < 123; i++) |
| 38 | + ; |
| 39 | + } |
| 40 | + """ |
| 41 | + |
| 42 | + d.code = [ |
| 43 | + opcodes.load(LOmp(0), Imm(0), LOfp(48)), |
| 44 | + opcodes.movw(Imm(0), LOfp(40)), |
| 45 | + opcodes.blew(Imm(123), SOfp(40), Imm(5)), |
| 46 | + opcodes.addw(Imm(1), NoOp(), LOfp(40)), |
| 47 | + opcodes.jmp(Imm(2)), |
| 48 | + opcodes.ret() |
| 49 | + ] |
| 50 | + |
| 51 | + d.types = [ |
| 52 | + dis.Type(0, 8, "\xc0"), |
| 53 | + dis.Type(1, 56, "\x00\xc8") |
| 54 | + ] |
| 55 | + |
| 56 | + d.data = { |
| 57 | + 0: dis.Data(0, 0, 0x03, array = "$Sys"), |
| 58 | + } |
| 59 | + |
| 60 | + d.module_name = "count" |
| 61 | + d.link = [dis.Link(0, 1, 0x4244b354, "init")] |
| 62 | + d.initialised_globals = 1 |
| 63 | + d.ldt = [] |
| 64 | + d.path = sys.argv[0] |
| 65 | + |
| 66 | + d.write(open(sys.argv[1], "w")) |
| 67 | + |
| 68 | + sys.exit() |