diff --git a/cl/compile.go b/cl/compile.go index c76baa8b..04064580 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -83,13 +83,19 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock) llssa.Bas return ret } -func (p *context) compileInstrAndValue(b llssa.Builder, iv instrAndValue) llssa.Expr { +func (p *context) compileInstrAndValue(b llssa.Builder, iv instrAndValue) (ret llssa.Expr) { + if v, ok := p.vals[iv]; ok { + return v + } switch v := iv.(type) { case *ssa.UnOp: x := p.compileValue(b, v.X) - return b.UnOp(v.Op, x) + ret = b.UnOp(v.Op, x) + default: + panic(fmt.Sprintf("compileInstrAndValue: unknown instr - %T\n", iv)) } - panic(fmt.Sprintf("compileInstrAndValue: unknown instr - %T\n", iv)) + p.vals[iv] = ret + return ret } func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) { @@ -128,25 +134,19 @@ func (p *context) compileInstr(b llssa.Builder, instr ssa.Instruction) { } } -func (p *context) compileValue(b llssa.Builder, v ssa.Value) (ret llssa.Expr) { - if e, ok := p.vals[v]; ok { - return e - } +func (p *context) compileValue(b llssa.Builder, v ssa.Value) llssa.Expr { if iv, ok := v.(instrAndValue); ok { - ret = p.compileInstrAndValue(b, iv) - } else { - switch v := v.(type) { - case *ssa.Global: - g := p.compileGlobal(p.pkg, v) - ret = g.Expr - case *ssa.Const: - ret = b.Const(v.Value, v.Type()) - default: - panic(fmt.Sprintf("compileValue: unknown value - %T\n", v)) - } + return p.compileInstrAndValue(b, iv) + } + switch v := v.(type) { + case *ssa.Global: + g := p.compileGlobal(p.pkg, v) + return g.Expr + case *ssa.Const: + return b.Const(v.Value, v.Type()) + default: + panic(fmt.Sprintf("compileValue: unknown value - %T\n", v)) } - p.vals[v] = ret - return ret } // ----------------------------------------------------------------------------- diff --git a/cl/compile_test.go b/cl/compile_test.go index b8a45a7f..01773069 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -72,8 +72,7 @@ source_filename = "foo" define void @init() { _llgo_0: %0 = load i1, ptr @"init$guard", align 1 - %1 = load i1, ptr @"init$guard", align 1 - br i1 %1, label %_llgo_2, label %_llgo_1 + br i1 %0, label %_llgo_2, label %_llgo_1 _llgo_1: ; preds = %_llgo_0 store i1 true, ptr @"init$guard", align 1 diff --git a/cl/symbol.go b/cl/symbol.go deleted file mode 100644 index 89662863..00000000 --- a/cl/symbol.go +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2023 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 cl - -/* -import ( - "go/types" - - "github.com/goplus/llgo/loader" - "golang.org/x/tools/go/ssa" - llvm "tinygo.org/x/go-llvm" -) - -// functionInfo contains some information about a function or method. In -// particular, it contains information obtained from pragmas. -// -// The linkName value contains a valid link name, even if //go:linkname is not -// present. -type functionInfo struct { - /* - wasmModule string // go:wasm-module - wasmName string // wasm-export-name or wasm-import-name in the IR - linkName string // go:linkname, go:export - the IR function name - section string // go:section - object file section name - exported bool // go:export, CGo - interrupt bool // go:interrupt - nobounds bool // go:nobounds - variadic bool // go:variadic (CGo only) - inline inlineType // go:inline -*/ -/* - linkName string // go:linkname, go:export - the IR function name -} - -/* -type inlineType int - -// How much to inline. -const ( - // Default behavior. The compiler decides for itself whether any given - // function will be inlined. Whether any function is inlined depends on the - // optimization level. - inlineDefault inlineType = iota - - // Inline hint, just like the C inline keyword (signalled using - // //go:inline). The compiler will be more likely to inline this function, - // but it is not a guarantee. - inlineHint - - // Don't inline, just like the GCC noinline attribute. Signalled using - // //go:noinline. - inlineNone -) -*/ -/* -// getFunctionInfo returns information about a function that is not directly -// present in *ssa.Function, such as the link name and whether it should be -// exported. -func (c *context) getFunctionInfo(f *ssa.Function) functionInfo { - panic("todo") -} - -// globalInfo contains some information about a specific global. By default, -// linkName is equal to .RelString(nil) on a global and extern is false, but for -// some symbols this is different (due to //go:extern for example). -type globalInfo struct { - /* - linkName string // go:extern - align int // go:align -*/ -/* - section string // go:section - extern bool // go:extern -} - -func (c *context) loadASTComments(loader.Package) { - panic("todo") -} - -// getGlobal returns a LLVM IR global value for a Go SSA global. It is added to -// the LLVM IR if it has not been added already. -func (c *context) getGlobal(g *ssa.Global) llvm.Value { - panic("todo") -} - -// getGlobalInfo returns some information about a specific global. -func (c *context) getGlobalInfo(g *ssa.Global) globalInfo { - panic("todo") -} - -// Get all methods of a type. -func getAllMethods(prog *ssa.Program, typ types.Type) []*types.Selection { - panic("todo") -} -*/