예제 #1
0
func newFunction(typ *types.Signature, name string) *Function {
	var parameters []*Parameter

	for _, parType := range typ.Parameters() {
		parameters = append(parameters, newParameter(parType, ""))
	}

	return &Function{
		typ:         typ,
		NameHandler: NameHandler{name: name},
		parameters:  parameters,
	}
}
예제 #2
0
파일: win.go 프로젝트: MovingtoMars/nnvm
func (v Target) winLoadCallArguments(a *allocator, vals []ssa.Value, sig *types.Signature) {
	numVals := len(vals)

	v.wop("andq $-16, #rsp")

	if numVals > 4 && numVals%2 != 0 {
		v.wop("pushq $0")
	}

	totalMem := winTotalMemSizeBits(sig.Parameters())
	if totalMem > 0 {
		v.wop("subq $%d, #rsp", totalMem/8)
	}
	v.wop("movq #rsp, #r11")

	for i, arg := range vals {
		v.winLoadCallArgument(a, arg, i)
	}

	v.wop("subq $32, #rsp")
}
예제 #3
0
파일: sysv.go 프로젝트: MovingtoMars/nnvm
// warning: this function sucks
//
// If reverse is false, move parameters to values
// If reverse is true, move values to call arguments
func (v Target) sysVCopyFunctionVals(a *allocator, vals []ssa.Value, sig *types.Signature, reverse bool) {
	regSeqIndex := 0
	nextReg := func() string {
		if regSeqIndex >= len(sysVParameterRegSeq) {
			return ""
		}
		regSeqIndex++
		return sysVParameterRegSeq[regSeqIndex-1]
	}

	if sysVClassifyType(sig.ReturnType())[0] == sysVClassMEMORY {
		regSeqIndex++
	}

	curStackEightbyteIndex := 0

	if reverse {
		v.wop("andq $-16, #rsp")
	}

	for _, val := range vals {
		classList := sysVClassifyType(val.Type())

		switch val.Type().(type) {
		case *types.Struct, *types.Array:
			panic("unim")
		}

		if len(classList) != 1 {
			panic("internal error: non-aggregate type has ABI classList of length > 1")
		}

		class := classList[0]

		switch class {
		case sysVClassINTEGER:
			storesz := TypeStoreSizeInBits(val.Type())
			if storesz > 64 {
				panic("unim")
			}
			if !isPow2(storesz) {
				panic("unim")
			}

			if reg := nextReg(); reg != "" {
				if !reverse {
					v.wop("mov%s #%s, %s", sizeSuffixBits(storesz), regToSize(reg, storesz), a.valStr(val))
				} else {
					if storesz != 64 {
						v.wop("xorq #%s, #%s", reg, reg)
					}
					v.wop("mov%s %s, #%s", sizeSuffixBits(storesz), a.valStr(val), regToSize(reg, storesz))
				}
			} else {
				if !reverse {
					v.wop("movq $%d, #r11", curStackEightbyteIndex)
					v.wop("movq 16(#rbp, #r11, 8), #r11")
					v.wop("mov%s #%s, %s", sizeSuffixBits(storesz), regToSize("r11", storesz), a.valStr(val))
				} else {
					panic("f**k")
				}

				curStackEightbyteIndex++
			}
		default:
			panic("unim")
		}
	}
}