Begin to refactor ir generation code in ir writer module