move out c/cpp/py

This commit is contained in:
Li Jie
2025-04-03 15:52:18 +08:00
parent 0a8a4eb6a6
commit ed366568b4
777 changed files with 4608 additions and 139122 deletions

34
chore/llgen/llgen.go Normal file
View 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 main
import (
"flag"
"fmt"
"os"
"github.com/goplus/llgo/internal/llgen"
)
func main() {
flag.Parse()
if len(flag.Args()) != 1 {
fmt.Fprintln(os.Stderr, "Usage: llgen [flags] <pkg>")
return
}
llgen.SmartDoFile(flag.Args()[0])
}

65
chore/llgen/llgen_test.go Normal file
View File

@@ -0,0 +1,65 @@
//go:build !llgo
// +build !llgo
package main
import (
"log"
"os"
"path/filepath"
"strings"
"testing"
)
func TestMain(t *testing.T) {
// Create test package in current module
testPkg := filepath.Join(".testdata_dont_commit", "hello")
err := os.MkdirAll(testPkg, 0755)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(filepath.Join(".testdata_dont_commit"))
helloFile := filepath.Join(testPkg, "hello.go")
err = os.WriteFile(helloFile, []byte(`package hello
func Hello() string {
return "Hello, World!"
}
`), 0644)
if err != nil {
t.Fatal(err)
}
// Save original args and restore them after test
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
// Get absolute path to test package
absTestPkg, err := filepath.Abs(testPkg)
if err != nil {
t.Fatal(err)
}
// Set test arguments
os.Args = []string{"llgen", absTestPkg}
// Run main
main()
// Check if the output file exists
outputFile := filepath.Join(testPkg, "llgo_autogen.ll")
log.Printf("Generated file: %s", filepath.Join(absTestPkg, "llgo_autogen.ll"))
if _, err = os.Stat(outputFile); err != nil {
t.Fatalf("Generated file should exist: %v", err)
}
// Read and verify file content
content, err := os.ReadFile(outputFile)
if err != nil {
t.Fatalf("Should be able to read generated file: %v", err)
}
if !strings.Contains(string(content), "define") {
t.Error("Generated file should contain LLVM IR code")
}
}