-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnstcc.go
76 lines (64 loc) · 1.3 KB
/
nstcc.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
//go:generate go run gen.go
package nstcc
import (
"io"
)
type Context struct {
Arch Arch
// TODO: add something about how to resolve and read filenames like
// "foo.h" and <stdio.h>.
}
func Compile(ctx *Context, dst io.Writer, src []byte) error {
// TODO.
return nil
}
func Preprocess(ctx *Context, dst io.Writer, src []byte) error {
c := newCompiler(ctx, dst, src)
c.parseFlags = parseFlagPreprocess | parseFlagLineFeed | parseFlagAsmComments | parseFlagSpaces
for {
if err := c.next(); err != nil {
return err
}
if c.tok == tokEOF {
break
}
}
return nil
}
type tokenSym struct {
hashNext *tokenSym
symDefine *sym
symLabel *sym
symStruct *sym
symIdentifier *sym
tok token
str []byte
}
const symFirstAnon = 0x10000000 // First anonymous sym.
type sym struct {
tok token
// TODO: asmLabel []byte
// TODO: r for register.
c int32 // TODO: int64?
defineTokStr []tokenValue
cType cType
// TODO: jnext for jump-next.
next *sym
stackPrev *sym
tokPrev *sym
}
func (c *compiler) symPush2(ps **sym, tok token, typ macroType, cc int32) *sym {
if ps == &c.localStack {
// TODO: look for incompatible types for redefinition.
}
s := &sym{
tok: tok,
cType: cType{
typ: typ,
},
c: cc,
stackPrev: *ps,
}
*ps = s
return s
}