From b4f4366ff3e5b76a69888b706e4c71da75b036e1 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 27 May 2008 14:43:14 -0700 Subject: regs.pl: add include guards to generated header files Add include guards to generated header files, and make sure the appropriate prerequisite headers are included if necessary. --- regs.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'regs.pl') diff --git a/regs.pl b/regs.pl index a56fa01..3a43ef0 100755 --- a/regs.pl +++ b/regs.pl @@ -79,6 +79,9 @@ close(REGS); if ( $fmt eq 'h' ) { # Output regs.h print "/* automatically generated from $file - do not edit */\n\n"; + print "#ifndef NASM_REGS_H\n"; + print "#define NASM_REGS_H\n\n"; + $expr_regs = 1; printf "#define EXPR_REG_START %d\n\n", $expr_regs; print "enum reg_enum {\n"; @@ -98,7 +101,7 @@ if ( $fmt eq 'h' ) { foreach $reg ( sort(keys(%regs)) ) { printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg}; } - print "\n"; + print "\n\n#endif /* NASM_REGS_H */\n"; } elsif ( $fmt eq 'c' ) { # Output regs.c print "/* automatically generated from $file - do not edit */\n\n"; @@ -137,7 +140,6 @@ if ( $fmt eq 'h' ) { } elsif ( $fmt eq 'dc' ) { # Output regdis.c print "/* automatically generated from $file - do not edit */\n\n"; - print "#include \"regs.h\"\n"; print "#include \"regdis.h\"\n\n"; foreach $class ( sort(keys(%disclass)) ) { printf "const enum reg_enum nasm_rd_%-8s[%2d] = {", @@ -155,11 +157,15 @@ if ( $fmt eq 'h' ) { } } elsif ( $fmt eq 'dh' ) { # Output regdis.h - print "/* automatically generated from $file - do not edit */\n"; + print "/* automatically generated from $file - do not edit */\n\n"; + print "#ifndef NASM_REGDIS_H\n"; + print "#define NASM_REGDIS_H\n\n"; + print "#include \"regs.h\"\n\n"; foreach $class ( sort(keys(%disclass)) ) { printf "extern const enum reg_enum nasm_rd_%-8s[%2d];\n", $class, scalar @{$disclass{$class}}; } + print "\n#endif /* NASM_REGDIS_H */\n"; } else { die "$0: Unknown output format\n"; } -- cgit v1.2.3