1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
use std
use bio
use "types"
pkg =
const emitaout : (lnk : lnk# -> void)
;;
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")
;;
}
|