func (d *debugInfo) setLocation(b llvm.Builder, pos token.Pos) { position := d.Fset.Position(pos) b.SetCurrentDebugLocation(llvm.MDNode([]llvm.Value{ llvm.ConstInt(llvm.Int32Type(), uint64(position.Line), true), llvm.ConstInt(llvm.Int32Type(), uint64(position.Column), true), d.MDNode(d.context()), llvm.Value{}, })) }
// declare creates an llvm.dbg.declare call for the specified function // parameter or local variable. func (d *debugInfo) declare(b llvm.Builder, v ssa.Value, llv llvm.Value, paramIndex int) { tag := tagAutoVariable if paramIndex >= 0 { tag = tagArgVariable } ld := debug.NewLocalVariableDescriptor(tag) ld.Argument = uint32(paramIndex + 1) ld.Name = llv.Name() if file := d.Fset.File(v.Pos()); file != nil { ld.Line = uint32(file.Position(v.Pos()).Line) ld.File = &d.getCompileUnit(file).Path } ld.Type = d.TypeDebugDescriptor(deref(v.Type())) ld.Context = d.context() b.InsertDeclare(d.module, llvm.MDNode([]llvm.Value{llv}), d.MDNode(ld)) }
// coerce yields a value of the the type specified, initialised // to the exact bit pattern as in the specified value. // // Note: the value's type and the specified target type must have // the same size. If the source is an aggregate, then the target // must also be an aggregate with the same number of fields, each // of which must have the same size. func coerce(b llvm.Builder, v llvm.Value, t llvm.Type) llvm.Value { // FIXME don't do this with alloca switch t.TypeKind() { case llvm.ArrayTypeKind, llvm.StructTypeKind: ptr := b.CreateAlloca(t, "") ptrv := b.CreateBitCast(ptr, llvm.PointerType(v.Type(), 0), "") b.CreateStore(v, ptrv) return b.CreateLoad(ptr, "") } vt := v.Type() switch vt.TypeKind() { case llvm.ArrayTypeKind, llvm.StructTypeKind: ptr := b.CreateAlloca(vt, "") b.CreateStore(v, ptr) ptrt := b.CreateBitCast(ptr, llvm.PointerType(t, 0), "") return b.CreateLoad(ptrt, "") } return b.CreateBitCast(v, t, "") }