github.com/goplus/llgo@v0.8.3/ssa/cl_test.go (about) 1 /* 2 * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package ssa_test 18 19 import ( 20 "testing" 21 22 "github.com/goplus/llgo/cl/cltest" 23 ) 24 25 func TestFromTestpy(t *testing.T) { 26 cltest.FromDir(t, "", "../cl/_testpy", false) 27 } 28 29 func TestFromTestrt(t *testing.T) { 30 cltest.FromDir(t, "", "../cl/_testrt", true) 31 } 32 33 func TestFromTestdata(t *testing.T) { 34 cltest.FromDir(t, "", "../cl/_testdata", false) 35 } 36 37 func TestRuntime(t *testing.T) { 38 cltest.Pkg(t, "github.com/goplus/llgo/internal/runtime", "../internal/runtime/llgo_autogen.ll") 39 cltest.Pkg(t, "github.com/goplus/llgo/internal/abi", "../internal/abi/llgo_autogen.ll") 40 } 41 42 /* 43 func TestCallback(t *testing.T) { 44 ctx := llvm.NewContext() 45 mod := ctx.NewModule("foo/bar") 46 47 tc := llvm.FunctionType(ctx.VoidType(), nil, false) 48 callback := llvm.PointerType(tc, 0) 49 params := []llvm.Type{callback} 50 51 tfn := llvm.FunctionType(ctx.VoidType(), params, false) 52 f := llvm.AddFunction(mod, "fn", tfn) 53 b := ctx.NewBuilder() 54 blk := llvm.AddBasicBlock(f, "") 55 b.SetInsertPointAtEnd(blk) 56 57 arg := f.Param(0) 58 // arg = b.CreateLoad(tc, arg, "") 59 b.CreateCall(tc, arg, nil, "") 60 b.CreateRetVoid() 61 62 expected := `; ModuleID = 'foo/bar' 63 ` 64 if v := mod.String(); v != expected { 65 t.Fatalf("\n==> got:\n%s\n==> expected:\n%s\n", v, expected) 66 } 67 } 68 69 /* 70 func TestMap(t *testing.T) { 71 var m typeutil.Map 72 sig := types.NewSignatureType(nil, nil, nil, nil, nil, false) 73 m.Set(sig, 1) 74 csig := (*ssa.CFuncPtr)(sig) 75 m.Set(csig, 2) 76 if v := m.At(sig); v.(int) != 1 { 77 t.Fatal("At(sig):", v) 78 } 79 if v := m.At(csig); v.(int) != 2 { 80 t.Fatal("At(csig):", v) 81 } 82 } 83 */