Modify the return type value of generate function

Return 0 represents codegen successfully, return -1 otherwise.