ir: Add getClass function.
semantic: Rewrite object casts to calls to __castTo.