func (gi *globalInit) update(typ llvm.Type, indices []uint32, val llvm.Value) { if len(indices) == 0 { gi.val = val return } if gi.val.C != nil { gi.val = llvm.ConstInsertValue(gi.val, val, indices) } tk := typ.TypeKind() if len(gi.elems) == 0 { switch tk { case llvm.StructTypeKind: gi.elems = make([]globalInit, typ.StructElementTypesCount()) case llvm.ArrayTypeKind: gi.elems = make([]globalInit, typ.ArrayLength()) default: panic("unexpected type") } } var eltyp llvm.Type switch tk { case llvm.StructTypeKind: eltyp = typ.StructElementTypes()[indices[0]] case llvm.ArrayTypeKind: eltyp = typ.ElementType() default: panic("unexpected type") } gi.elems[indices[0]].update(eltyp, indices[1:], val) }
func (c *Codegen) getUnderlyingType(t llvm.Type) llvm.Type { for t.TypeKind() == llvm.PointerTypeKind { t = t.ElementType() } return t }
func (fr *frame) createZExtOrTrunc(v llvm.Value, t llvm.Type, name string) llvm.Value { switch n := v.Type().IntTypeWidth() - t.IntTypeWidth(); { case n < 0: v = fr.builder.CreateZExt(v, fr.target.IntPtrType(), name) case n > 0: v = fr.builder.CreateTrunc(v, fr.target.IntPtrType(), name) } return v }
func (gi *globalInit) build(typ llvm.Type) llvm.Value { if gi.val.C != nil { return gi.val } if len(gi.elems) == 0 { return llvm.ConstNull(typ) } switch typ.TypeKind() { case llvm.StructTypeKind: eltypes := typ.StructElementTypes() elems := make([]llvm.Value, len(eltypes)) for i, eltyp := range eltypes { elems[i] = gi.elems[i].build(eltyp) } return llvm.ConstStruct(elems, false) case llvm.ArrayTypeKind: eltyp := typ.ElementType() elems := make([]llvm.Value, len(gi.elems)) for i := range gi.elems { elems[i] = gi.elems[i].build(eltyp) } return llvm.ConstArray(eltyp, elems) default: panic("unexpected type") } }