def __init__(self, parent, ptr, cmp, val, ordering, failordering, name): outtype = types.LiteralStructType([val.type, types.IntType(1)]) super(CmpXchg, self).__init__( parent, outtype, "cmpxchg", (ptr, cmp, val), name=name ) self.ordering = ordering self.failordering = failordering
def wrapped(self, lhs, rhs, name=""): if lhs.type != rhs.type: raise ValueError( "Operands must be the same type, got (%s, %s)" % (lhs.type, rhs.type)) ty = lhs.type if not isinstance(ty, types.IntType): raise TypeError("expected an integer type, got %s" % (ty, )) bool_ty = types.IntType(1) mod = self.module fnty = types.FunctionType(types.LiteralStructType([ty, bool_ty]), [ty, ty]) fn = mod.declare_intrinsic("llvm.%s.with.overflow" % (opname, ), [ty], fnty) ret = self.call(fn, [lhs, rhs], name=name) return ret
def literal_struct(cls, elems): """ Construct a literal structure constant made of the given members. """ tys = [el.type for el in elems] return cls(types.LiteralStructType(tys), elems)