-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompiler.go
103 lines (81 loc) · 1.51 KB
/
compiler.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package nstcc
import (
"bufio"
"io"
)
type Arch uint32
const (
ArchAMD64 Arch = 0
Arch386 Arch = 1
)
type macroType uint32
const (
macroObj macroType = 0
macroFunc macroType = 1
)
type tokFlags uint32
const (
tokFlagBOL tokFlags = 0x01
tokFlagBOF tokFlags = 0x02
tokFlagEndIf tokFlags = 0x04
tokFlagEOF tokFlags = 0x08
)
type parseFlags uint32
const (
parseFlagPreprocess parseFlags = 0x01
parseFlagTokNum parseFlags = 0x02
parseFlagLineFeed parseFlags = 0x04
parseFlagAsmComments parseFlags = 0x08
parseFlagSpaces parseFlags = 0x10
)
type cType struct {
typ macroType // TODO: s/macroType/token/?
sym *sym
}
type cValue struct {
int int64
str []byte
}
type compiler struct {
ctx *Context
dst *bufio.Writer
src []byte
s int
macroPtr []tokenValue
m int
tokFlags tokFlags
parseFlags parseFlags
tok token
tokc cValue
textSection *section
dataSection *section
bssSection *section
curTextSection *section
lastTextSection *section
globalStack *sym
localStack *sym
localLabelStack *sym
globalLabelStack *sym
defineStack *sym
rsym int32
anonSym int32
ind int32
loc int32
funcName []byte
idents idents
}
func newCompiler(ctx *Context, dst io.Writer, src []byte) *compiler {
bw, ok := dst.(*bufio.Writer)
if !ok {
bw = bufio.NewWriter(dst)
}
c := &compiler{
ctx: ctx,
dst: bw,
src: src,
tokFlags: tokFlagBOL | tokFlagBOF,
anonSym: symFirstAnon,
}
c.idents.init()
return c
}