ssa: impl builtin alignof offsetof
This commit is contained in:
16
ssa/expr.go
16
ssa/expr.go
@@ -1257,7 +1257,23 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
|
||||
case "Add":
|
||||
return b.Advance(args[0], args[1])
|
||||
case "Sizeof":
|
||||
// instance of generic function
|
||||
return b.Prog.Val(int(b.Prog.SizeOf(args[0].Type)))
|
||||
case "Alignof":
|
||||
// instance of generic function
|
||||
return b.Prog.Val(int(b.Prog.td.ABITypeAlignment(args[0].ll)))
|
||||
case "Offsetof":
|
||||
// instance of generic function
|
||||
if load := args[0].impl.IsALoadInst(); !load.IsNil() {
|
||||
if gep := load.Operand(0).IsAGetElementPtrInst(); !gep.IsNil() {
|
||||
typ := gep.GEPSourceElementType()
|
||||
offset := gep.Operand(2).IsAConstantInt()
|
||||
if typ.TypeKind() == llvm.StructTypeKind && !offset.IsNil() {
|
||||
return b.Prog.Val(int(b.Prog.td.ElementOffset(typ, int(offset.SExtValue()))))
|
||||
}
|
||||
}
|
||||
}
|
||||
panic("invalid argument for unsafe.Offsetof: must be a selector expression")
|
||||
}
|
||||
panic("todo: " + fn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user