-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstddef.go
47 lines (40 loc) · 882 Bytes
/
stddef.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
package libs
import (
"fmt"
"strings"
"github.com/gotranspile/cxgo/types"
)
// TODO: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html
const (
stddefH = "stddef.h"
)
func init() {
RegisterLibrary(stddefH, func(c *Env) *Library {
return &Library{
Header: incStdDef(c.Env),
Types: typesStdDef(c.Env),
}
})
}
func incStdDef(e *types.Env) string {
var buf strings.Builder
buf.WriteString(`
#include <` + stdintH + `>
#define NULL 0
typedef intptr_t ptrdiff_t;
typedef uintptr_t size_t;
`)
sz := e.C().WCharSize()
signed := e.C().WCharSigned()
_, _ = fmt.Fprintf(&buf, "typedef %s wchar_t;\n",
buildinFixedIntName(sz*8, !signed),
)
return buf.String()
}
func typesStdDef(e *types.Env) map[string]types.Type {
return map[string]types.Type{
"wchar_t": e.C().WChar(),
"size_t": e.UintPtrT(),
"ptrdiff_t": e.IntPtrT(),
}
}