runtime: c.Argc, c.Argv, c.Getopt

This commit is contained in:
xushiwei
2024-05-07 10:16:03 +08:00
parent 1136526e4c
commit a8ead2543d
39 changed files with 684 additions and 450 deletions

View File

@@ -5,6 +5,8 @@ source_filename = "main"
%main.generator = type { i32 }
@"main.init$guard" = global ptr null
@__llgo_argc = global ptr null
@__llgo_argv = global ptr null
@0 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@1 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@2 = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
@@ -61,90 +63,92 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
define void @main(i32 %0, ptr %1) {
_llgo_0:
store i32 %0, ptr @__llgo_argc, align 4
store ptr %1, ptr @__llgo_argv, align 8
call void @"github.com/goplus/llgo/internal/runtime.init"()
call void @main.init()
%0 = alloca { ptr, ptr }, align 8
%1 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 0
store ptr @__llgo_stub.rand, ptr %1, align 8
%2 = getelementptr inbounds { ptr, ptr }, ptr %0, i32 0, i32 1
store ptr null, ptr %2, align 8
%3 = load { ptr, ptr }, ptr %0, align 8
%4 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %3)
%5 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
%2 = alloca { ptr, ptr }, align 8
%3 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 0
store ptr @__llgo_stub.rand, ptr %3, align 8
%4 = getelementptr inbounds { ptr, ptr }, ptr %2, i32 0, i32 1
store ptr null, ptr %4, align 8
%5 = load { ptr, ptr }, ptr %2, align 8
%6 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %5)
%7 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %6)
br label %_llgo_1
_llgo_1: ; preds = %_llgo_2, %_llgo_0
%6 = phi i64 [ -1, %_llgo_0 ], [ %7, %_llgo_2 ]
%7 = add i64 %6, 1
%8 = icmp slt i64 %7, %5
br i1 %8, label %_llgo_2, label %_llgo_3
%8 = phi i64 [ -1, %_llgo_0 ], [ %9, %_llgo_2 ]
%9 = add i64 %8, 1
%10 = icmp slt i64 %9, %7
br i1 %10, label %_llgo_2, label %_llgo_3
_llgo_2: ; preds = %_llgo_1
%9 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %4)
%10 = getelementptr inbounds i32, ptr %9, i64 %7
%11 = load i32, ptr %10, align 4
%12 = call i32 (ptr, ...) @printf(ptr @0, i32 %11)
%11 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %6)
%12 = getelementptr inbounds i32, ptr %11, i64 %9
%13 = load i32, ptr %12, align 4
%14 = call i32 (ptr, ...) @printf(ptr @0, i32 %13)
br label %_llgo_1
_llgo_3: ; preds = %_llgo_1
%13 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
store i32 1, ptr %13, align 4
%14 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%15 = getelementptr inbounds { ptr }, ptr %14, i32 0, i32 0
store ptr %13, ptr %15, align 8
%16 = alloca { ptr, ptr }, align 8
%17 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 0
store ptr @"main.main$1", ptr %17, align 8
%18 = getelementptr inbounds { ptr, ptr }, ptr %16, i32 0, i32 1
store ptr %14, ptr %18, align 8
%19 = load { ptr, ptr }, ptr %16, align 8
%20 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %19)
%21 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %20)
%15 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
store i32 1, ptr %15, align 4
%16 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%17 = getelementptr inbounds { ptr }, ptr %16, i32 0, i32 0
store ptr %15, ptr %17, align 8
%18 = alloca { ptr, ptr }, align 8
%19 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 0
store ptr @"main.main$1", ptr %19, align 8
%20 = getelementptr inbounds { ptr, ptr }, ptr %18, i32 0, i32 1
store ptr %16, ptr %20, align 8
%21 = load { ptr, ptr }, ptr %18, align 8
%22 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %21)
%23 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %22)
br label %_llgo_4
_llgo_4: ; preds = %_llgo_5, %_llgo_3
%22 = phi i64 [ -1, %_llgo_3 ], [ %23, %_llgo_5 ]
%23 = add i64 %22, 1
%24 = icmp slt i64 %23, %21
br i1 %24, label %_llgo_5, label %_llgo_6
%24 = phi i64 [ -1, %_llgo_3 ], [ %25, %_llgo_5 ]
%25 = add i64 %24, 1
%26 = icmp slt i64 %25, %23
br i1 %26, label %_llgo_5, label %_llgo_6
_llgo_5: ; preds = %_llgo_4
%25 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %20)
%26 = getelementptr inbounds i32, ptr %25, i64 %23
%27 = load i32, ptr %26, align 4
%28 = call i32 (ptr, ...) @printf(ptr @1, i32 %27)
%27 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %22)
%28 = getelementptr inbounds i32, ptr %27, i64 %25
%29 = load i32, ptr %28, align 4
%30 = call i32 (ptr, ...) @printf(ptr @1, i32 %29)
br label %_llgo_4
_llgo_6: ; preds = %_llgo_4
%29 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
%30 = getelementptr inbounds %main.generator, ptr %29, i32 0, i32 0
store i32 1, ptr %30, align 4
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%32 = getelementptr inbounds { ptr }, ptr %31, i32 0, i32 0
store ptr %29, ptr %32, align 8
%33 = alloca { ptr, ptr }, align 8
%34 = getelementptr inbounds { ptr, ptr }, ptr %33, i32 0, i32 0
store ptr @"main.next$bound", ptr %34, align 8
%35 = getelementptr inbounds { ptr, ptr }, ptr %33, i32 0, i32 1
store ptr %31, ptr %35, align 8
%36 = load { ptr, ptr }, ptr %33, align 8
%37 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %36)
%38 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %37)
%31 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocZ"(i64 4)
%32 = getelementptr inbounds %main.generator, ptr %31, i32 0, i32 0
store i32 1, ptr %32, align 4
%33 = call ptr @"github.com/goplus/llgo/internal/runtime.AllocU"(i64 8)
%34 = getelementptr inbounds { ptr }, ptr %33, i32 0, i32 0
store ptr %31, ptr %34, align 8
%35 = alloca { ptr, ptr }, align 8
%36 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 0
store ptr @"main.next$bound", ptr %36, align 8
%37 = getelementptr inbounds { ptr, ptr }, ptr %35, i32 0, i32 1
store ptr %33, ptr %37, align 8
%38 = load { ptr, ptr }, ptr %35, align 8
%39 = call %"github.com/goplus/llgo/internal/runtime.Slice" @main.genInts(i64 5, { ptr, ptr } %38)
%40 = call i64 @"github.com/goplus/llgo/internal/runtime.SliceLen"(%"github.com/goplus/llgo/internal/runtime.Slice" %39)
br label %_llgo_7
_llgo_7: ; preds = %_llgo_8, %_llgo_6
%39 = phi i64 [ -1, %_llgo_6 ], [ %40, %_llgo_8 ]
%40 = add i64 %39, 1
%41 = icmp slt i64 %40, %38
br i1 %41, label %_llgo_8, label %_llgo_9
%41 = phi i64 [ -1, %_llgo_6 ], [ %42, %_llgo_8 ]
%42 = add i64 %41, 1
%43 = icmp slt i64 %42, %40
br i1 %43, label %_llgo_8, label %_llgo_9
_llgo_8: ; preds = %_llgo_7
%42 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %37)
%43 = getelementptr inbounds i32, ptr %42, i64 %40
%44 = load i32, ptr %43, align 4
%45 = call i32 (ptr, ...) @printf(ptr @2, i32 %44)
%44 = call ptr @"github.com/goplus/llgo/internal/runtime.SliceData"(%"github.com/goplus/llgo/internal/runtime.Slice" %39)
%45 = getelementptr inbounds i32, ptr %44, i64 %42
%46 = load i32, ptr %45, align 4
%47 = call i32 (ptr, ...) @printf(ptr @2, i32 %46)
br label %_llgo_7
_llgo_9: ; preds = %_llgo_7