llgo gen: todo
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 The GoPlus Authors (goplus.org). All rights reserved.
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
95
cmd/internal/gen/gen.go
Normal file
95
cmd/internal/gen/gen.go
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Package build implements the “llgo gen command.
|
||||||
|
package gen
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo"
|
||||||
|
"github.com/goplus/llgo/cl"
|
||||||
|
"github.com/goplus/llgo/cmd/internal/base"
|
||||||
|
"github.com/goplus/llgo/internal/projs"
|
||||||
|
"github.com/goplus/llgo/ssa"
|
||||||
|
"github.com/qiniu/x/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// llgo gen
|
||||||
|
var Cmd = &base.Command{
|
||||||
|
UsageLine: "llgo gen [-v] [packages|files]",
|
||||||
|
Short: "Convert Go code into LLVM ir (*.ll) code",
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
flag = &Cmd.Flag
|
||||||
|
flagVerbose = flag.Bool("v", false, "print verbose information")
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Cmd.Run = runCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCmd(cmd *base.Command, args []string) {
|
||||||
|
err := flag.Parse(args)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicln("parse input arguments failed:", err)
|
||||||
|
}
|
||||||
|
pattern := flag.Args()
|
||||||
|
if len(pattern) == 0 {
|
||||||
|
pattern = []string{"."}
|
||||||
|
}
|
||||||
|
|
||||||
|
projects, err := projs.ParseAll(pattern...)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicln("gopprojs.ParseAll:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ssa.Initialize(ssa.InitAll)
|
||||||
|
if *flagVerbose {
|
||||||
|
ssa.SetDebug(ssa.DbgFlagAll)
|
||||||
|
cl.SetDebug(cl.DbgFlagAll)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, proj := range projects {
|
||||||
|
switch v := proj.(type) {
|
||||||
|
case *projs.DirProj:
|
||||||
|
_, _, err = llgo.Gen(v.Dir, nil, true, 0)
|
||||||
|
case *projs.PkgPathProj:
|
||||||
|
_, _, err = llgo.GenPkgPath("", v.Path, nil, true, 0)
|
||||||
|
case *projs.FilesProj:
|
||||||
|
_, err = llgo.GenFiles("", v.Files, nil)
|
||||||
|
default:
|
||||||
|
log.Panicln("`llgo gen` doesn't support", reflect.TypeOf(v))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "llgo gen failed: %d errors.\n", errorNum(err))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func errorNum(err error) int {
|
||||||
|
if e, ok := err.(errors.List); ok {
|
||||||
|
return len(e)
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goplus/llgo/cmd/internal/base"
|
"github.com/goplus/llgo/cmd/internal/base"
|
||||||
"github.com/goplus/llgo/cmd/internal/build"
|
"github.com/goplus/llgo/cmd/internal/build"
|
||||||
|
"github.com/goplus/llgo/cmd/internal/gen"
|
||||||
"github.com/goplus/llgo/cmd/internal/help"
|
"github.com/goplus/llgo/cmd/internal/help"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ func init() {
|
|||||||
flag.Usage = mainUsage
|
flag.Usage = mainUsage
|
||||||
base.Llgo.Commands = []*base.Command{
|
base.Llgo.Commands = []*base.Command{
|
||||||
build.Cmd,
|
build.Cmd,
|
||||||
|
gen.Cmd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
gen.go
Normal file
34
gen.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package llgo
|
||||||
|
|
||||||
|
type GenFlags int
|
||||||
|
|
||||||
|
// Gen generates llgo_autogen.ll for a Go package directory.
|
||||||
|
func Gen(dir string, conf *Config, genTestPkg bool, flags GenFlags) (string, bool, error) {
|
||||||
|
panic("todo")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenPkgPath generates llgo_autogen.ll for a Go package.
|
||||||
|
func GenPkgPath(workDir, pkgPath string, conf *Config, allowExtern bool, flags GenFlags) (localDir string, recursively bool, err error) {
|
||||||
|
panic("todo")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenFiles generates llgo_autogen.ll for specified Go files.
|
||||||
|
func GenFiles(autogen string, files []string, conf *Config) (outFiles []string, err error) {
|
||||||
|
panic("todo")
|
||||||
|
}
|
||||||
9
load.go
9
load.go
@@ -16,9 +16,18 @@
|
|||||||
|
|
||||||
package llgo
|
package llgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/goplus/llgo/ssa"
|
||||||
|
)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadDir loads Go packages from a specified directory.
|
||||||
|
func LoadDir(dir string, conf *Config, genTestPkg, promptGen bool) (out, test *ssa.Package, err error) {
|
||||||
|
panic("todo")
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user