Example #1
0
File: types.go Project: minux/llgo
func (m *TypeMap) descriptorBasic(t *types.Basic, name string) TypeDebugDescriptor {
	switch t.Kind() {
	case types.String:
		return m.descriptorStruct(types.NewStruct([]*types.Var{
			types.NewVar(0, nil, "ptr", types.NewPointer(types.Typ[types.Uint8])),
			types.NewVar(0, nil, "len", types.Typ[types.Int]),
		}, nil), name)
	case types.UnsafePointer:
		return &BasicTypeDescriptor{
			TypeDescriptorCommon: TypeDescriptorCommon{
				Name:      name,
				Size:      uint64(m.Sizes.Sizeof(t) * 8),
				Alignment: uint64(m.Sizes.Alignof(t) * 8),
			},
			TypeEncoding: DW_ATE_unsigned,
		}
	default:
		bt := &BasicTypeDescriptor{
			TypeDescriptorCommon: TypeDescriptorCommon{
				Name:      t.String(),
				Size:      uint64(m.Sizes.Sizeof(t) * 8),
				Alignment: uint64(m.Sizes.Alignof(t) * 8),
			},
		}
		switch bi := t.Info(); {
		case bi&types.IsBoolean != 0:
			bt.TypeEncoding = DW_ATE_boolean
		case bi&types.IsUnsigned != 0:
			bt.TypeEncoding = DW_ATE_unsigned
		case bi&types.IsInteger != 0:
			bt.TypeEncoding = DW_ATE_signed
		case bi&types.IsFloat != 0:
			bt.TypeEncoding = DW_ATE_float
		case bi&types.IsComplex != 0:
			bt.TypeEncoding = DW_ATE_imaginary_float
		case bi&types.IsUnsigned != 0:
			bt.TypeEncoding = DW_ATE_unsigned
		default:
			panic(fmt.Sprintf("unhandled: %#v", t))
		}
		return bt
	}
}