76 lines
1.3 KiB
Go
76 lines
1.3 KiB
Go
package types
|
|
|
|
import (
|
|
"git.gammaspectra.live/WeebDataHoarder/compute-go/assembler/obj"
|
|
)
|
|
|
|
func Offset(a Addressable, offset int64) Address {
|
|
switch a.Addr().Type {
|
|
case obj.TYPE_REG:
|
|
return Address{
|
|
Type: obj.TYPE_MEM,
|
|
Reg: a.Addr().Reg,
|
|
Offset: offset,
|
|
}
|
|
case obj.TYPE_MEM:
|
|
return Address{
|
|
Type: obj.TYPE_MEM,
|
|
Reg: a.Addr().Reg,
|
|
Offset: a.Addr().Offset + offset,
|
|
}
|
|
default:
|
|
panic("not supported")
|
|
}
|
|
}
|
|
|
|
func Memory(r Registerable, offset int64) Address {
|
|
return Address{
|
|
Type: obj.TYPE_MEM,
|
|
Reg: r.Reg(),
|
|
Offset: offset,
|
|
}
|
|
}
|
|
|
|
func IndexMemory(r Registerable, offset int64, scale int16) Address {
|
|
return Address{
|
|
Index: r.Reg(),
|
|
Scale: scale,
|
|
Type: obj.TYPE_MEM,
|
|
Offset: offset,
|
|
}
|
|
}
|
|
|
|
func LocationPC(offset int64) Address {
|
|
return Address{
|
|
Type: obj.TYPE_BRANCH,
|
|
Offset: offset,
|
|
}
|
|
}
|
|
|
|
func Location(p *obj.Prog) Address {
|
|
return Address{
|
|
Type: obj.TYPE_BRANCH,
|
|
Val: p,
|
|
}
|
|
}
|
|
|
|
func Immediate[T ~int | ~uint | ~int8 | ~uint8 | ~int16 | ~uint16 | ~int32 | ~uint32 | ~int64 | ~uint64](i T) Address {
|
|
return Address{
|
|
Type: obj.TYPE_CONST,
|
|
Offset: int64(i),
|
|
}
|
|
}
|
|
|
|
func ImmediateString[T ~string](s T) Address {
|
|
return Address{
|
|
Type: obj.TYPE_SCONST,
|
|
Val: string(s),
|
|
}
|
|
}
|
|
|
|
func ImmediateFloat64[T ~float64](f T) Address {
|
|
return Address{
|
|
Type: obj.TYPE_FCONST,
|
|
Val: float64(f),
|
|
}
|
|
}
|