From: Rafael Antognolli Date: Tue, 16 Jul 2019 17:07:37 +0000 (-0700) Subject: intel/gen_decoder: Add gen_spec_load_filename() function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=69506cbb7434578eddc08a653fa41a0666abaf0c;p=mesa.git intel/gen_decoder: Add gen_spec_load_filename() function. Refactor the code from gen_spec_load_from_path() into a separate function, that can be used with a xml file that doesn't fit the genX.xml filename format. Will be used soon for implementing unit tests for gen_decoder. Reviewed-by: Lionel Landwerlin --- diff --git a/src/intel/common/gen_decoder.c b/src/intel/common/gen_decoder.c index 90b0f97965f..69c68ff85f0 100644 --- a/src/intel/common/gen_decoder.c +++ b/src/intel/common/gen_decoder.c @@ -649,23 +649,16 @@ gen_spec_load(const struct gen_device_info *devinfo) } struct gen_spec * -gen_spec_load_from_path(const struct gen_device_info *devinfo, - const char *path) +gen_spec_load_filename(const char *filename) { struct parser_context ctx; - size_t len, filename_len = strlen(path) + 20; - char *filename = malloc(filename_len); - void *buf; FILE *input; - - len = snprintf(filename, filename_len, "%s/gen%i.xml", - path, devinfo_to_gen(devinfo, false)); - assert(len < filename_len); + void *buf; + size_t len; input = fopen(filename, "r"); if (input == NULL) { fprintf(stderr, "failed to open xml description\n"); - free(filename); return NULL; } @@ -675,7 +668,6 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo, if (ctx.parser == NULL) { fprintf(stderr, "failed to create parser\n"); fclose(input); - free(filename); return NULL; } @@ -716,7 +708,6 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo, XML_ParserFree(ctx.parser); fclose(input); - free(filename); /* free ctx.spec if genxml is empty */ if (ctx.spec && @@ -731,6 +722,23 @@ gen_spec_load_from_path(const struct gen_device_info *devinfo, return ctx.spec; } +struct gen_spec * +gen_spec_load_from_path(const struct gen_device_info *devinfo, + const char *path) +{ + size_t len, filename_len = strlen(path) + 20; + char *filename = malloc(filename_len); + + len = snprintf(filename, filename_len, "%s/gen%i.xml", + path, devinfo_to_gen(devinfo, false)); + assert(len < filename_len); + + struct gen_spec *spec = gen_spec_load_filename(filename); + free(filename); + + return spec; +} + void gen_spec_destroy(struct gen_spec *spec) { ralloc_free(spec); diff --git a/src/intel/common/gen_decoder.h b/src/intel/common/gen_decoder.h index b4c85ab0c1d..2dba6f1898a 100644 --- a/src/intel/common/gen_decoder.h +++ b/src/intel/common/gen_decoder.h @@ -54,6 +54,7 @@ struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char *name); struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo); struct gen_spec *gen_spec_load_from_path(const struct gen_device_info *devinfo, const char *path); +struct gen_spec *gen_spec_load_filename(const char *filename); void gen_spec_destroy(struct gen_spec *spec); uint32_t gen_spec_get_gen(struct gen_spec *spec); struct gen_group *gen_spec_find_instruction(struct gen_spec *spec,