add code rewrite phase to codegen