mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-24 00:06:09 +00:00
Ensure that parse errors cause non-zero exit.
Also, avoid creating output file when a parse error occurs
This commit is contained in:
parent
2d4d401d70
commit
b81aca4948
@ -30,24 +30,30 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "gen4asm.h"
|
#include "gen4asm.h"
|
||||||
|
|
||||||
extern FILE *yyin;
|
extern FILE *yyin;
|
||||||
|
|
||||||
|
extern int errors;
|
||||||
|
|
||||||
|
char *input_filename = "<stdin>";
|
||||||
|
|
||||||
struct brw_program compiled_program;
|
struct brw_program compiled_program;
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: intel-gen4asm [-o outputfile] inputfile\n");
|
fprintf(stderr, "usage: intel-gen4asm [-o outputfile] inputfile\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
char *output_file = NULL;
|
||||||
FILE *output = stdout;
|
FILE *output = stdout;
|
||||||
struct brw_program_instruction *entry;
|
struct brw_program_instruction *entry;
|
||||||
int err;
|
int err;
|
||||||
@ -56,13 +62,8 @@ int main(int argc, char **argv)
|
|||||||
while ((o = getopt_long(argc, argv, "o:", longopts, NULL)) != -1) {
|
while ((o = getopt_long(argc, argv, "o:", longopts, NULL)) != -1) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case 'o':
|
case 'o':
|
||||||
if (strcmp(optarg, "-") != 0) {
|
if (strcmp(optarg, "-") != 0)
|
||||||
output = fopen(optarg, "w");
|
output_file = optarg;
|
||||||
if (output == NULL) {
|
|
||||||
perror("Couldn't open output file");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -77,7 +78,8 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[0], "-") != 0) {
|
if (strcmp(argv[0], "-") != 0) {
|
||||||
yyin = fopen(argv[0], "r");
|
input_filename = argv[0];
|
||||||
|
yyin = fopen(input_filename, "r");
|
||||||
if (yyin == NULL) {
|
if (yyin == NULL) {
|
||||||
perror("Couldn't open input file");
|
perror("Couldn't open input file");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -86,6 +88,16 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
err = yyparse();
|
err = yyparse();
|
||||||
|
|
||||||
|
if (err || errors)
|
||||||
|
exit (1);
|
||||||
|
|
||||||
|
if (output_file) {
|
||||||
|
output = fopen(output_file, "w");
|
||||||
|
if (output == NULL) {
|
||||||
|
perror("Couldn't open output file");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (entry = compiled_program.first;
|
for (entry = compiled_program.first;
|
||||||
entry != NULL;
|
entry != NULL;
|
||||||
entry = entry->next) {
|
entry = entry->next) {
|
||||||
@ -96,5 +108,12 @@ int main(int argc, char **argv)
|
|||||||
((int *)(&entry->instruction))[3]);
|
((int *)(&entry->instruction))[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fflush (output);
|
||||||
|
if (ferror (output)) {
|
||||||
|
perror ("Could not flush output file");
|
||||||
|
if (output_file)
|
||||||
|
unlink (output_file);
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user