codegen logic