<[email protected]> writes:
> From: Kyrylo Tkachov <[email protected]>
>
> genemit and genrecog use the same size-based output selection, but each
> generator owns its file names, opens files during option parsing, and closes
> them separately. Adding more partitioned generators would copy this logic.
>
> Put the common output record and lifecycle helpers in gensupport. The helpers
> validate names, delay file opening until option parsing is complete, select
> only partition outputs by current size, and close every output with a useful
> diagnostic. Fixed outputs, such as headers, use the same record but do not
> participate in selection.
>
> Convert genemit and genrecog to the common interface. Also remove the unused
> output index and disabled round-robin code from choose_output, and remove a
> genrecog selection whose result is discarded. Diagnose missing or repeated
> genrecog -H options, remove its fixed header-name limit, and stop printing
> parsed output options to standard output.
>
> Robin added the shared choose_output helper for PR111600, following the
> size-based policy that Tamar used in genmatch.
>
> The 20 normal emit and recog partition files are identical before and after
> this change. One-output files also match. Duplicate name, cross-role alias,
> missing option, open failure, and close failure tests pass.
>
> Bootstrapped on aarch64-none-linux-gnu. Ok for trunk?
>
> gcc/ChangeLog:
>
> * gensupport.h (generator_output): New structure.
> (add_generator_output, open_generator_outputs): Declare.
> (close_generator_outputs): Likewise.
> (choose_output): Accept generator_output records. Remove the output
> index parameter.
> * gensupport.cc (add_generator_output): New function.
> (open_generator_outputs, close_generator_outputs): Likewise.
> (choose_output): Select only partition records. Remove the output index
> and disabled round-robin implementation.
> * genemit.cc (output_files): Use generator_output records.
> (handle_arg): Register output names.
> (main): Use the common open, selection, and close helpers.
> * genrecog.cc (print_subroutine_group): Accept generator_output records.
> (header_name): Change to a pointer.
> (header): Remove global variable.
> (output_files): Use generator_output records.
> (handle_arg): Register output names and validate -H.
> (main): Validate and register the header output. Use the common open,
> selection, and close helpers. Remove an unused output selection.
>
> [...]
> +/* Close all files in OUTPUTS. Return true if every close succeeds. */
> +
> +bool
> +close_generator_outputs (const vec<generator_output> &outputs)
> +{
> + bool ok = true;
> + for (const generator_output &output : outputs)
> + {
> + if (fclose (output.file) != 0)
> + {
> + error ("cannot close output %s: %s",
> + output.name ? output.name : "<stdout>", xstrerror (errno));
> + ok = false;
> + }
> + }
Nit: redundant outer { ... }.
OK with that change, thanks.
Richard
> + return ok;
> }
> diff --git a/gcc/gensupport.h b/gcc/gensupport.h
> index 86dd1103436..880505355b2 100644
> --- a/gcc/gensupport.h
> +++ b/gcc/gensupport.h
> @@ -232,6 +232,20 @@ extern void compute_test_codes (rtx, file_location, char
> *);
> extern file_location get_file_location (rtx);
> extern const char *get_emit_function (rtx);
> extern bool find_optab (optab_pattern *, const char *);
> -extern FILE *choose_output (const vec<FILE *> &, unsigned &);
> +
> +/* An output file produced by a machine-description generator. Partition
> + files participate in size-based output selection. */
> +struct generator_output
> +{
> + const char *name;
> + FILE *file;
> + bool partition_p;
> +};
> +
> +extern unsigned int add_generator_output (vec<generator_output> &,
> + const char *, bool);
> +extern void open_generator_outputs (vec<generator_output> &);
> +extern FILE *choose_output (const vec<generator_output> &);
> +extern bool close_generator_outputs (const vec<generator_output> &);
>
> #endif /* GCC_GENSUPPORT_H */