tblgen: Factor out common code.