github.com/axw/llgo@v0.0.0-20160805011314-95b5fe4dca20/irgen/println.go (about) 1 //===- println.go - IR generation for print and println -------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements IR generation for the print and println built-in 11 // functions. 12 // 13 //===----------------------------------------------------------------------===// 14 15 package irgen 16 17 import ( 18 "fmt" 19 20 "llvm.org/llgo/third_party/gotools/go/types" 21 ) 22 23 func (fr *frame) printValues(println_ bool, values ...*govalue) { 24 for i, value := range values { 25 llvm_value := value.value 26 27 typ := value.Type().Underlying() 28 if name, isname := typ.(*types.Named); isname { 29 typ = name.Underlying() 30 } 31 32 if println_ && i > 0 { 33 fr.runtime.printSpace.call(fr) 34 } 35 switch typ := typ.(type) { 36 case *types.Basic: 37 switch typ.Kind() { 38 case types.Uint8, types.Uint16, types.Uint32, types.Uintptr, types.Uint, types.Uint64: 39 i64 := fr.llvmtypes.ctx.Int64Type() 40 zext := fr.builder.CreateZExt(llvm_value, i64, "") 41 fr.runtime.printUint64.call(fr, zext) 42 43 case types.Int, types.Int8, types.Int16, types.Int32, types.Int64: 44 i64 := fr.llvmtypes.ctx.Int64Type() 45 sext := fr.builder.CreateSExt(llvm_value, i64, "") 46 fr.runtime.printInt64.call(fr, sext) 47 48 case types.Float32: 49 llvm_value = fr.builder.CreateFPExt(llvm_value, fr.llvmtypes.ctx.DoubleType(), "") 50 fallthrough 51 case types.Float64: 52 fr.runtime.printDouble.call(fr, llvm_value) 53 54 case types.Complex64: 55 llvm_value = fr.convert(value, types.Typ[types.Complex128]).value 56 fallthrough 57 case types.Complex128: 58 fr.runtime.printComplex.call(fr, llvm_value) 59 60 case types.String, types.UntypedString: 61 fr.runtime.printString.call(fr, llvm_value) 62 63 case types.Bool: 64 fr.runtime.printBool.call(fr, llvm_value) 65 66 case types.UnsafePointer: 67 fr.runtime.printPointer.call(fr, llvm_value) 68 69 default: 70 panic(fmt.Sprint("Unhandled Basic Kind: ", typ.Kind)) 71 } 72 73 case *types.Interface: 74 if typ.Empty() { 75 fr.runtime.printEmptyInterface.call(fr, llvm_value) 76 } else { 77 fr.runtime.printInterface.call(fr, llvm_value) 78 } 79 80 case *types.Slice: 81 fr.runtime.printSlice.call(fr, llvm_value) 82 83 case *types.Pointer, *types.Map, *types.Chan, *types.Signature: 84 fr.runtime.printPointer.call(fr, llvm_value) 85 86 default: 87 panic(fmt.Sprintf("Unhandled type kind: %s (%T)", typ, typ)) 88 } 89 } 90 if println_ { 91 fr.runtime.printNl.call(fr) 92 } 93 }