Esempio n. 1
0
func sysVClassifyType(typ types.Type) []sysVParameterClass {
	switch typ := typ.(type) {
	case *types.Struct:
		return sysVClassifyStructType(typ)

	case *types.Array:
		return sysVClassifyArrayType(typ)

	case *types.Int:
		switch typ.Width() {
		case 1, 8, 16, 32, 64, 128:
			return []sysVParameterClass{sysVClassINTEGER}
		default:
			panic("unim")
		}

	case *types.Pointer:
		return []sysVParameterClass{sysVClassINTEGER}

	case *types.Float:
		switch typ.Type() {
		case types.Float32, types.Float64:
			return []sysVParameterClass{sysVClassSSE}
		default:
			panic("unim")
		}

	case types.Void:
		return []sysVParameterClass{sysVClassNO_CLASS}

	default:
		panic("amd64.classifyType: unim: " + reflect.TypeOf(typ).String())
	}
}
Esempio n. 2
0
func TypeSizeInBits(typ types.Type) int {
	switch typ := typ.(type) {
	case *types.Int:
		w := typ.Width()
		for w%8 != 0 {
			w++
		}
		return w

	case *types.Float:
		return typ.Type().Width()

	case *types.Pointer:
		return 64

	case *types.Array:
		return TypeSizeInBits(typ.Element()) * typ.Length()

	case *types.Struct:
		return newStructLayout(typ).size

	default:
		panic("unim")
	}
}
Esempio n. 3
0
func checkTypeSupported(typ types.Type) {
	switch typ := typ.(type) {
	case *types.Int:
		switch typ.Width() {
		case 1, 8, 16, 32, 64:
			// all good
		default:
			goto unsupported
		}

	case *types.Array:
		checkTypeSupported(typ.Element())

	case *types.Struct:
		for _, field := range typ.Fields() {
			checkTypeSupported(field)
		}
	}

	return

unsupported:
	panic(fmt.Sprintf("unsupported type: %s", typ))
}