mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-30 02:31:53 +08:00
Update generator.go.
modified: generator.go modified: main.c
This commit is contained in:
40
generator.go
40
generator.go
@@ -77,8 +77,6 @@ func ftrace(s string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, "# %%s:%%d: %%v\n", path.Base(fn), fl, fmt.Sprintf(s, args...))
|
||||
os.Stderr.Sync()
|
||||
}
|
||||
|
||||
func Xsqlite3PendingByte() int32 { return _sqlite3PendingByte }
|
||||
`
|
||||
|
||||
prologueTest = `// Code generated by ccgo. DO NOT EDIT.
|
||||
@@ -118,7 +116,6 @@ func main() {
|
||||
#define SQLITE_WITHOUT_MSIZE 1
|
||||
|
||||
int sqlite3PendingByte;
|
||||
|
||||
`
|
||||
)
|
||||
|
||||
@@ -170,7 +167,7 @@ func errStr(err error) string {
|
||||
}
|
||||
}
|
||||
|
||||
func build(predef string, tus [][]string, qualifiers []string, opts ...cc.Opt) ([]*cc.TranslationUnit, []byte) {
|
||||
func build(predef string, tus [][]string, ccgoOpts []ccgo.Option, opts ...cc.Opt) ([]*cc.TranslationUnit, []byte) {
|
||||
ndbg := ""
|
||||
if *ndebug {
|
||||
ndbg = "#define NDEBUG 1"
|
||||
@@ -231,7 +228,7 @@ func build(predef string, tus [][]string, qualifiers []string, opts ...cc.Opt) (
|
||||
}
|
||||
|
||||
var out buffer.Bytes
|
||||
if err := ccgo.New(build, &out, ccgo.Packages(qualifiers)); err != nil {
|
||||
if err := ccgo.New(build, &out, ccgoOpts...); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -265,7 +262,7 @@ func macros(buf io.Writer, ast *cc.TranslationUnit) {
|
||||
switch t := m.Type; t.Kind() {
|
||||
case
|
||||
cc.Int, cc.UInt, cc.Long, cc.ULong, cc.LongLong, cc.ULongLong,
|
||||
cc.Float, cc.LongDouble, cc.Bool:
|
||||
cc.Float, cc.Double, cc.LongDouble, cc.Bool:
|
||||
fmt.Fprintf(buf, "X%s = %v\n", v, m.Value)
|
||||
case cc.Ptr:
|
||||
switch t := t.Element(); t.Kind() {
|
||||
@@ -406,14 +403,24 @@ func sqlite() {
|
||||
}
|
||||
|
||||
pth := filepath.Join(repo, "sqlite-amalgamation-"+version)
|
||||
sqlite3 := filepath.Join(pth, "sqlite3.c")
|
||||
asta, src := build(
|
||||
ast, _ := build(
|
||||
defines,
|
||||
[][]string{
|
||||
{filepath.Join(pth, "sqlite3.h")},
|
||||
{"main.c"},
|
||||
{sqlite3},
|
||||
},
|
||||
nil,
|
||||
[]ccgo.Option{ccgo.Library()},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{pth}),
|
||||
)
|
||||
sqlite3 := filepath.Join(pth, "sqlite3.c")
|
||||
_, src := build(
|
||||
defines,
|
||||
[][]string{
|
||||
{sqlite3},
|
||||
{"main.c"},
|
||||
},
|
||||
[]ccgo.Option{ccgo.Library()},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{pth}),
|
||||
)
|
||||
@@ -425,7 +432,7 @@ func sqlite() {
|
||||
}
|
||||
|
||||
fmt.Fprintf(&b, prologueSqlite, lic, strings.TrimSpace(tidyComments(header(sqlite3))))
|
||||
macros(&b, asta[0])
|
||||
macros(&b, ast[0])
|
||||
b.Write(src)
|
||||
b2, err := format.Source(b.Bytes())
|
||||
if err != nil {
|
||||
@@ -436,6 +443,7 @@ func sqlite() {
|
||||
}
|
||||
|
||||
dst := fmt.Sprintf(filepath.Join("internal", "bin", "bin_%s_%s.go"), runtime.GOOS, runtime.GOARCH)
|
||||
b2 = bytes.Replace(b2, []byte("var Xsqlite3PendingByte int32"), []byte("func Xsqlite3PendingByte() int32 { return _sqlite3PendingByte }"), 1)
|
||||
if err := ioutil.WriteFile(dst, b2, 0664); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -460,7 +468,7 @@ func mpTest() {
|
||||
{filepath.Join(sqlitePth, "sqlite3.c")},
|
||||
{test},
|
||||
},
|
||||
[]string{"bin"},
|
||||
[]ccgo.Option{ccgo.Packages([]string{"bin"})},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{sqlitePth}),
|
||||
)
|
||||
@@ -506,7 +514,7 @@ func threadTest1() {
|
||||
{filepath.Join(sqlitePth, "sqlite3.c")},
|
||||
{test},
|
||||
},
|
||||
[]string{"bin"},
|
||||
[]ccgo.Option{ccgo.Packages([]string{"bin"})},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
|
||||
)
|
||||
@@ -551,7 +559,7 @@ func threadTest2() {
|
||||
{filepath.Join(sqlitePth, "sqlite3.c")},
|
||||
{test},
|
||||
},
|
||||
[]string{"bin"},
|
||||
[]ccgo.Option{ccgo.Packages([]string{"bin"})},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
|
||||
)
|
||||
@@ -598,7 +606,7 @@ func threadTest3() {
|
||||
{filepath.Join(repo, "sqlite-src-"+version, "src", "test_multiplex.c")},
|
||||
{test},
|
||||
},
|
||||
[]string{"bin"},
|
||||
[]ccgo.Option{ccgo.Packages([]string{"bin"})},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
|
||||
)
|
||||
@@ -643,7 +651,7 @@ func threadTest4() {
|
||||
{filepath.Join(sqlitePth, "sqlite3.c")},
|
||||
{test},
|
||||
},
|
||||
[]string{"bin"},
|
||||
[]ccgo.Option{ccgo.Packages([]string{"bin"})},
|
||||
cc.EnableAnonymousStructFields(),
|
||||
cc.IncludePaths([]string{".", sqlitePth, filepath.Join(repo, "sqlite-src-"+version, "src")}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user