Skip to content

Commit

Permalink
Merge pull request #884 from cpunion/unify-build
Browse files Browse the repository at this point in the history
Unify cltest, llgen, gentests to build.Do
  • Loading branch information
xushiwei authored Nov 26, 2024
2 parents 25bc848 + 43c4a3b commit e93d579
Show file tree
Hide file tree
Showing 36 changed files with 162 additions and 469 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/cleanup.sh

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install embedme
run: npm install -g embedme

- name: Verify README.md embedded code
run: npx embedme --verify README.md

Expand All @@ -32,7 +32,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
Expand All @@ -43,7 +43,6 @@ jobs:
run: |
set -e
set -x
bash .github/workflows/cleanup.sh
source doc/_readme/scripts/install_macos.sh
- name: Install dependencies on Ubuntu
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ jobs:
- name: Install dependencies
if: startsWith(matrix.os, 'macos')
run: |
bash .github/workflows/cleanup.sh
brew update
brew install llvm@${{matrix.llvm}} pkg-config bdw-gc openssl libffi
brew install llvm@${{matrix.llvm}} bdw-gc openssl libffi
brew link --force libffi
echo "$(brew --prefix llvm@${{matrix.llvm}})/bin" >> $GITHUB_PATH
echo "PKG_CONFIG_PATH=/opt/homebrew/opt/libffi/lib/pkgconfig" >> $GITHUB_ENV
# Install optional deps for demos.
#
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_demo.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
set -e

# llgo run subdirectories under _demo and _pydemo
# llgo run subdirectories under _demo and _pydemo that contain *.go files
total=0
failed=0
failed_cases=""
for d in ./_demo/* ./_pydemo/*; do
total=$((total+1))
if [ -d "$d" ]; then
if [ -d "$d" ] && [ -n "$(ls "$d"/*.go 2>/dev/null)" ]; then
total=$((total+1))
echo "Testing $d"
if ! (cd "$d" && llgo run .); then
echo "FAIL"
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ Follow these steps to generate the `llgo` command (its usage is the same as the

```sh
brew update
brew install llvm@18 pkg-config bdw-gc openssl cjson
brew install llvm@18 bdw-gc openssl cjson libffi
brew install [email protected] # optional
brew link --force libffi
go install -v github.com/goplus/llgo/cmd/llgo@latest

```

### on Linux (Debian/Ubuntu)
Expand All @@ -371,7 +373,7 @@ go install -v github.com/goplus/llgo/cmd/llgo@latest
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y llvm-18-dev clang-18 libclang-18-dev lld-18 pkg-config libgc-dev libssl-dev zlib1g-dev libcjson-dev python3.12-dev
sudo apt-get install -y llvm-18-dev clang-18 libclang-18-dev lld-18 pkg-config libgc-dev libssl-dev zlib1g-dev libcjson-dev libsqlite3-dev
sudo apt-get install -y python3.12-dev # optional
go install -v github.com/goplus/llgo/cmd/llgo@latest
```
Expand Down
30 changes: 4 additions & 26 deletions chore/gentests/gentests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,23 @@ import (
"os"
"strings"

"github.com/goplus/llgo/cl"
"github.com/goplus/llgo/internal/llgen"
"github.com/goplus/llgo/ssa"
"github.com/goplus/mod"
)

func main() {
dir, _, err := mod.FindGoMod(".")
check(err)

ssa.Initialize(ssa.InitAll | ssa.InitNative)
llgen.Verbose = false

llgenDir(dir + "/cl/_testlibc")
llgenDir(dir + "/cl/_testlibgo")
llgenDir(dir + "/cl/_testrt")
llgenDir(dir + "/cl/_testgo")
llgenDir(dir+"/cl/_testpy", "")
llgenDir(dir+"/cl/_testdata", "")
}

func isDbgSymEnabled(flagsFile string) bool {
data, err := os.ReadFile(flagsFile)
if err != nil {
return false
}
toks := strings.Split(strings.Join(strings.Split(string(data), "\n"), " "), " ")
for _, tok := range toks {
if tok == "-dbg" {
return true
}
}
return false
llgenDir(dir + "/cl/_testpy")
llgenDir(dir + "/cl/_testdata")
}

func llgenDir(dir string, pkgPath ...string) {
func llgenDir(dir string) {
fis, err := os.ReadDir(dir)
check(err)
for _, fi := range fis {
Expand All @@ -67,10 +48,7 @@ func llgenDir(dir string, pkgPath ...string) {
testDir := dir + "/" + name
fmt.Fprintln(os.Stderr, "llgen", testDir)
check(os.Chdir(testDir))
dbg := isDbgSymEnabled("flags.txt")
cl.EnableDebugSymbols(dbg)

llgen.SmartDoFile("in.go", pkgPath...)
llgen.SmartDoFile(testDir)
}
}

Expand Down
10 changes: 5 additions & 5 deletions chore/llgen/llgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/goplus/llgo/internal/llgen"
)

func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "Usage: llgen [flags] <pkg> [pkgPath]")
flag.Parse()
if len(flag.Args()) != 1 {
fmt.Fprintln(os.Stderr, "Usage: llgen [flags] <pkg>")
return
}
llgen.Init()
args := os.Args[1:]
llgen.SmartDoFile(args[0], args[1:]...)
llgen.SmartDoFile(flag.Args()[0])
}
14 changes: 7 additions & 7 deletions cl/_testdata/apkg/out.ll
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
; ModuleID = 'apkg'
source_filename = "apkg"
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/apkg'
source_filename = "github.com/goplus/llgo/cl/_testdata/apkg"

@"apkg.init$guard" = global i1 false, align 1
@"github.com/goplus/llgo/cl/_testdata/apkg.init$guard" = global i1 false, align 1

define double @apkg.Max(double %0, double %1) {
define double @"github.com/goplus/llgo/cl/_testdata/apkg.Max"(double %0, double %1) {
_llgo_0:
%2 = fcmp ogt double %0, %1
br i1 %2, label %_llgo_1, label %_llgo_2
Expand All @@ -15,13 +15,13 @@ _llgo_2: ; preds = %_llgo_0
ret double %1
}

define void @apkg.init() {
define void @"github.com/goplus/llgo/cl/_testdata/apkg.init"() {
_llgo_0:
%0 = load i1, ptr @"apkg.init$guard", align 1
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/apkg.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1

_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"apkg.init$guard", align 1
store i1 true, ptr @"github.com/goplus/llgo/cl/_testdata/apkg.init$guard", align 1
br label %_llgo_2

_llgo_2: ; preds = %_llgo_1, %_llgo_0
Expand Down
14 changes: 7 additions & 7 deletions cl/_testdata/llgotag/out.ll
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
; ModuleID = 'llgotag'
source_filename = "llgotag"
; ModuleID = 'github.com/goplus/llgo/cl/_testdata/llgotag'
source_filename = "github.com/goplus/llgo/cl/_testdata/llgotag"

@"llgotag.init$guard" = global i1 false, align 1
@"github.com/goplus/llgo/cl/_testdata/llgotag.init$guard" = global i1 false, align 1

define void @llgotag.Foo() {
define void @"github.com/goplus/llgo/cl/_testdata/llgotag.Foo"() {
_llgo_0:
ret void
}

define void @llgotag.init() {
define void @"github.com/goplus/llgo/cl/_testdata/llgotag.init"() {
_llgo_0:
%0 = load i1, ptr @"llgotag.init$guard", align 1
%0 = load i1, ptr @"github.com/goplus/llgo/cl/_testdata/llgotag.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1

_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"llgotag.init$guard", align 1
store i1 true, ptr @"github.com/goplus/llgo/cl/_testdata/llgotag.init$guard", align 1
br label %_llgo_2

_llgo_2: ; preds = %_llgo_1, %_llgo_0
Expand Down
10 changes: 5 additions & 5 deletions cl/_testdata/print/out.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ source_filename = "main"
@_llgo_int16 = linkonce global ptr null, align 8
@_llgo_int64 = linkonce global ptr null, align 8
@_llgo_int = linkonce global ptr null, align 8
@_llgo_uint8 = linkonce global ptr null, align 8
@_llgo_byte = linkonce global ptr null, align 8
@_llgo_uint16 = linkonce global ptr null, align 8
@_llgo_uint32 = linkonce global ptr null, align 8
@_llgo_uint64 = linkonce global ptr null, align 8
Expand Down Expand Up @@ -243,7 +243,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_3,
%78 = insertvalue %"github.com/goplus/llgo/internal/runtime.eface" %77, ptr inttoptr (i64 5 to ptr), 1
store %"github.com/goplus/llgo/internal/runtime.eface" %78, ptr %75, align 8
%79 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.eface", ptr %38, i64 10
%80 = load ptr, ptr @_llgo_uint8, align 8
%80 = load ptr, ptr @_llgo_byte, align 8
%81 = insertvalue %"github.com/goplus/llgo/internal/runtime.eface" undef, ptr %80, 0
%82 = insertvalue %"github.com/goplus/llgo/internal/runtime.eface" %81, ptr inttoptr (i64 1 to ptr), 1
store %"github.com/goplus/llgo/internal/runtime.eface" %82, ptr %79, align 8
Expand Down Expand Up @@ -389,7 +389,7 @@ _llgo_14: ; preds = %_llgo_55

_llgo_15: ; preds = %_llgo_55
%25 = extractvalue %"github.com/goplus/llgo/internal/runtime.eface" %0, 0
%26 = load ptr, ptr @_llgo_uint8, align 8
%26 = load ptr, ptr @_llgo_byte, align 8
%27 = icmp eq ptr %25, %26
br i1 %27, label %_llgo_56, label %_llgo_57

Expand Down Expand Up @@ -1273,13 +1273,13 @@ _llgo_17: ; preds = %_llgo_16
br label %_llgo_18

_llgo_18: ; preds = %_llgo_17, %_llgo_16
%27 = load ptr, ptr @_llgo_uint8, align 8
%27 = load ptr, ptr @_llgo_byte, align 8
%28 = icmp eq ptr %27, null
br i1 %28, label %_llgo_19, label %_llgo_20

_llgo_19: ; preds = %_llgo_18
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.Basic"(i64 40)
store ptr %29, ptr @_llgo_uint8, align 8
store ptr %29, ptr @_llgo_byte, align 8
br label %_llgo_20

_llgo_20: ; preds = %_llgo_19, %_llgo_18
Expand Down
11 changes: 2 additions & 9 deletions cl/_testgo/goroutine/out.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source_filename = "main"

%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/c/pthread.RoutineFunc" = type { ptr, ptr }

@"main.init$guard" = global i1 false, align 1
@__llgo_argc = global i32 0, align 4
Expand Down Expand Up @@ -41,7 +40,7 @@ _llgo_0:
%8 = getelementptr inbounds { { ptr, ptr }, %"github.com/goplus/llgo/internal/runtime.String" }, ptr %6, i32 0, i32 1
store %"github.com/goplus/llgo/internal/runtime.String" { ptr @0, i64 16 }, ptr %8, align 8
%9 = alloca i8, i64 8, align 1
%10 = call i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr %9, ptr null, %"github.com/goplus/llgo/c/pthread.RoutineFunc" { ptr @"__llgo_stub.main._llgo_routine$1", ptr null }, ptr %6)
%10 = call i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr %9, ptr null, ptr @"main._llgo_routine$1", ptr %6)
br label %_llgo_3

_llgo_1: ; preds = %_llgo_3
Expand Down Expand Up @@ -88,13 +87,7 @@ _llgo_0:

declare void @free(ptr)

declare i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr, ptr, %"github.com/goplus/llgo/c/pthread.RoutineFunc", ptr)

define linkonce ptr @"__llgo_stub.main._llgo_routine$1"(ptr %0, ptr %1) {
_llgo_0:
%2 = tail call ptr @"main._llgo_routine$1"(ptr %1)
ret ptr %2
}
declare i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr, ptr, ptr, ptr)

declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String")

Expand Down
11 changes: 2 additions & 9 deletions cl/_testgo/selects/out.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
; ModuleID = 'main'
source_filename = "main"

%"github.com/goplus/llgo/c/pthread.RoutineFunc" = type { ptr, ptr }
%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 }
%"github.com/goplus/llgo/internal/runtime.ChanOp" = type { ptr, ptr, i32, i1 }
%"github.com/goplus/llgo/internal/runtime.Slice" = type { ptr, i64, i64 }
Expand Down Expand Up @@ -61,7 +60,7 @@ _llgo_0:
%15 = getelementptr inbounds { { ptr, ptr } }, ptr %14, i32 0, i32 0
store { ptr, ptr } %13, ptr %15, align 8
%16 = alloca i8, i64 8, align 1
%17 = call i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr %16, ptr null, %"github.com/goplus/llgo/c/pthread.RoutineFunc" { ptr @"__llgo_stub.main._llgo_routine$1", ptr null }, ptr %14)
%17 = call i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr %16, ptr null, ptr @"main._llgo_routine$1", ptr %14)
%18 = load ptr, ptr %2, align 8
%19 = alloca {}, align 8
call void @llvm.memset(ptr %19, i8 0, i64 0, i1 false)
Expand Down Expand Up @@ -230,13 +229,7 @@ _llgo_0:

declare void @free(ptr)

declare i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr, ptr, %"github.com/goplus/llgo/c/pthread.RoutineFunc", ptr)

define linkonce ptr @"__llgo_stub.main._llgo_routine$1"(ptr %0, ptr %1) {
_llgo_0:
%2 = tail call ptr @"main._llgo_routine$1"(ptr %1)
ret ptr %2
}
declare i32 @"github.com/goplus/llgo/internal/runtime.CreateThread"(ptr, ptr, ptr, ptr)

declare i1 @"github.com/goplus/llgo/internal/runtime.ChanSend"(ptr, ptr, i64)

Expand Down
Loading

0 comments on commit e93d579

Please sign in to comment.