diff options
Diffstat (limited to 'aout.myr')
-rw-r--r-- | aout.myr | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -1,4 +1,5 @@ use std +use bio use "types" @@ -7,5 +8,35 @@ pkg = ;; const emitaout = {lnk + match bio.create(lnk.outf, bio.Wr, 0o755) + | `std.Err e: + std.fatal("could not open output: {}\n", e) + | `std.Ok f: + w32(f, magic(26)) + w32(f, lnk.text.len) + w32(f, lnk.data.len) + w32(f, (lnk.bss : uint32)) + w32(f, 0) /* syms */ + w32(f, (lnk.entry : uint32)) + w32(f, 0) /* pc/sp offset tab */ + w32(f, 0) /* pc/lnum tab */ + wstr(f, lnk.text) + wstr(f, lnk.data) + bio.close(f) + ;; } +const magic = {arch + -> 0x00008000 | 4*arch*arch+7 +} + +const wstr = {f, s; check(bio.write(f, s))} +const w32 = {f, v : uint32; check(bio.putbe32(f, v))} + +generic check = {st : bio.status(@a) + match st + | `bio.Ok _: /* nothing */ + | `bio.Err e: std.fatal("i/o error: {}\n", e) + | `bio.Eof: std.fatal("i/o error: eof\n") + ;; +} |