Merge remote-tracking branch 'gop/main' into q

This commit is contained in:
xushiwei
2024-04-30 08:27:57 +08:00
5 changed files with 46 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
package main
const c = 100
var a float64 = 1
func main() {
if c > 100 {
a = 0
}
}

View File

@@ -0,0 +1,32 @@
; ModuleID = 'main'
source_filename = "main"
@main.a = global ptr null
@"main.init$guard" = global ptr null
define void @main.init() {
_llgo_0:
%0 = load i1, ptr @"main.init$guard", align 1
br i1 %0, label %_llgo_2, label %_llgo_1
_llgo_1: ; preds = %_llgo_0
store i1 true, ptr @"main.init$guard", align 1
store double 1.000000e+00, ptr @main.a, align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}
define void @main() {
_llgo_0:
call void @main.init()
br i1 false, label %_llgo_1, label %_llgo_2
_llgo_1: ; preds = %_llgo_0
store double 0.000000e+00, ptr @main.a, align 8
br label %_llgo_2
_llgo_2: ; preds = %_llgo_1, %_llgo_0
ret void
}

View File

@@ -484,7 +484,7 @@ func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr {
g := p.varOf(v)
return g.Expr
case *ssa.Const:
t := v.Type()
t := types.Default(v.Type())
return b.Const(v.Value, p.prog.Type(t))
}
panic(fmt.Sprintf("compileValue: unknown value - %T\n", v))

View File

@@ -140,7 +140,7 @@ func (b Builder) Const(v constant.Value, typ Type) Expr {
if v == nil {
return prog.Null(typ)
}
switch t := types.Default(typ.t).(type) {
switch t := typ.t.(type) {
case *types.Basic:
kind := t.Kind()
switch {

View File

@@ -212,7 +212,7 @@ func (p Program) tyInt64() llvm.Type {
}
func (p Program) toLLVMType(typ types.Type) Type {
switch t := types.Default(typ).(type) {
switch t := typ.(type) {
case *types.Basic:
switch t.Kind() {
case types.Int: