genbindings: add helper arguments to dump wip json

This commit is contained in:
mappu 2024-08-07 18:51:30 +12:00
parent 60d5aa55d1
commit 0514866d23
2 changed files with 23 additions and 8 deletions

View File

@ -11,14 +11,6 @@ func parseHeader(inner []interface{}) (*parsedHeader, error) {
var ret parsedHeader var ret parsedHeader
/*
jb, err := json.MarshalIndent(inner, "", "\t")
if err != nil {
panic(err)
}
fmt.Println(string(jb))
*/
fmt.Printf("package miqt\n\n") fmt.Printf("package miqt\n\n")
for _, node := range inner { for _, node := range inner {

View File

@ -2,9 +2,12 @@ package main
import ( import (
"context" "context"
"encoding/json"
"flag" "flag"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
) )
@ -16,6 +19,8 @@ func main() {
inputHeader := flag.String("inputHeader", `/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qpushbutton.h`, "Input file") inputHeader := flag.String("inputHeader", `/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qpushbutton.h`, "Input file")
cflags := flag.String("cflags", `-DQT_WIDGETS_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtCore -DQT_GUI_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtGui -DQT_CORE_LIB`, "Cflags to pass to clang (e.g. `pkg-config --cflags Qt5Widgets`)") cflags := flag.String("cflags", `-DQT_WIDGETS_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtCore -DQT_GUI_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtGui -DQT_CORE_LIB`, "Cflags to pass to clang (e.g. `pkg-config --cflags Qt5Widgets`)")
outDir := flag.String("outdir", "..", "Output directory for generated gen_** files") outDir := flag.String("outdir", "..", "Output directory for generated gen_** files")
dumpClang := flag.Bool("dumpclang", false, "Dump clang JSON to stdout and exit")
dumpIL := flag.Bool("dumpil", false, "Dump intermediate IL JSON to stdout and exit")
flag.Parse() flag.Parse()
@ -25,12 +30,30 @@ func main() {
panic(err) panic(err)
} }
if *dumpClang {
jb, err := json.MarshalIndent(astInner, "", "\t")
if err != nil {
panic(err)
}
fmt.Println(string(jb))
os.Exit(0)
}
// Convert it to our intermediate format // Convert it to our intermediate format
parsed, err := parseHeader(astInner) parsed, err := parseHeader(astInner)
if err != nil { if err != nil {
panic(err) panic(err)
} }
if *dumpIL {
jb, err := json.MarshalIndent(parsed, "", "\t")
if err != nil {
panic(err)
}
fmt.Println(string(jb))
os.Exit(0)
}
// Emit 3 code files from the intermediate format // Emit 3 code files from the intermediate format
outputName := filepath.Join(*outDir, "gen_"+strings.TrimSuffix(filepath.Base(*inputHeader), `.h`)) outputName := filepath.Join(*outDir, "gen_"+strings.TrimSuffix(filepath.Base(*inputHeader), `.h`))