Re: [patch][arm] (respin) Improve error checking in parsecpu.awk

2017-09-22 Thread Ramana Radhakrishnan

On 9/22/17 4:58 PM, Vidya Praveen wrote:

Hello,

This patch by Richard Earnshaw was reverted along with the commit that preceded
it as the preceding commit was causing  cross-native builds  to fail and I
presumed this patch was related too.  Now I am respinning as the issue that
caused the cross-native failure have been fixed. This patch however is simply
rebased and has no other changes.

For reference, the ChangeLog of the preceding patch that broke cross-native 
build.

 [arm] auto-generate arm-isa.h from CPU descriptions

 This patch autogenerates arm-isa.h from new entries in arm-cpus.in.
 This has the primary advantage that it makes the description file more
 self-contained, but it also solves the 'array dimensioning' problem
 that Tamar recently encountered.  It adds two new constructs to
 arm-cpus.in: features and fgroups.  Fgroups are simply a way of naming
 a group of feature bits so that they can be referenced together.  We
 follow the convention that feature bits are all lower case, while
 fgroups are (predominantly) upper case.  This is helpful as in some
 contexts they share the same namespace.  Most of the minor changes in
 this patch are related to adopting this new naming convention.

 * config.gcc (arm*-*-*): Don't add arm-isa.h to tm_p_file.
 * config/arm/arm-isa.h: Delete.  Move definitions to ...
 * arm-cpus.in: ... here.  Use new feature and fgroup values.
 * config/arm/arm.c (arm_option_override): Use lower case for feature
 bit names.
 * config/arm/arm.h (TARGET_HARD_FLOAT): Likewise.
 (TARGET_VFP3, TARGET_VFP5, TARGET_FMA): Likewise.
 * config/arm/parsecpu.awk (END): Add new command 'isa'.
 (isa_pfx): Delete.
 (print_isa_bits_for): New function.
 (gen_isa): New function.
 (gen_comm_data): Use print_isa_bits_for.
 (define feature): New keyword.
 (define fgroup): New keyword.
 * config/arm/t-arm (OPTIONS_H_EXTRA): Add arm-isa.h
 (arm-isa.h): Add rule to generate file.
 * common/config/arm/arm-common.c: (arm_canon_arch_option): Use lower
 case for feature bit names.

Tested by building cross/cross-native arm-none-linux-gnueabihf and baremetal
cross build (arm-none-eabi) on x86_64.

OK for trunk?



Ok, please apply.

Ramana


Regards
VP.

gcc/ChangeLog:

[arm] Improve error checking in parsecpu.awk

This patch adds a bit more error checking to parsecpu.awk to ensure
that statements are not missing arguments or have excess arguments
beyond those permitted.  It also slightly improves the handling of
errors so that we terminate properly if parsing fails and be as
helpful as we can while in the parsing phase.

2017-09-22  Richard Earnshaw  

* config/arm/parsecpu.awk (fatal): Note that we've encountered an
error.  Only quit immediately if parsing is complete.
(BEGIN): Initialize fatal_err and parse_done.
(begin fpu, end fpu): Check number of arguments.
(begin arch, end arch): Likewise.
(begin cpu, end cpu): Likewise.
(cname, tune for, tune flags, architecture, fpu, option): Likewise.
(optalias): Likewise.





[patch][arm] (respin) Improve error checking in parsecpu.awk

2017-09-22 Thread Vidya Praveen
Hello,

This patch by Richard Earnshaw was reverted along with the commit that preceded
it as the preceding commit was causing  cross-native builds  to fail and I
presumed this patch was related too.  Now I am respinning as the issue that
caused the cross-native failure have been fixed. This patch however is simply
rebased and has no other changes.

For reference, the ChangeLog of the preceding patch that broke cross-native 
build.

[arm] auto-generate arm-isa.h from CPU descriptions

This patch autogenerates arm-isa.h from new entries in arm-cpus.in.
This has the primary advantage that it makes the description file more
self-contained, but it also solves the 'array dimensioning' problem
that Tamar recently encountered.  It adds two new constructs to
arm-cpus.in: features and fgroups.  Fgroups are simply a way of naming
a group of feature bits so that they can be referenced together.  We
follow the convention that feature bits are all lower case, while
fgroups are (predominantly) upper case.  This is helpful as in some
contexts they share the same namespace.  Most of the minor changes in
this patch are related to adopting this new naming convention.

* config.gcc (arm*-*-*): Don't add arm-isa.h to tm_p_file.
* config/arm/arm-isa.h: Delete.  Move definitions to ...
* arm-cpus.in: ... here.  Use new feature and fgroup values.
* config/arm/arm.c (arm_option_override): Use lower case for feature
bit names.
* config/arm/arm.h (TARGET_HARD_FLOAT): Likewise.
(TARGET_VFP3, TARGET_VFP5, TARGET_FMA): Likewise.
* config/arm/parsecpu.awk (END): Add new command 'isa'.
(isa_pfx): Delete.
(print_isa_bits_for): New function.
(gen_isa): New function.
(gen_comm_data): Use print_isa_bits_for.
(define feature): New keyword.
(define fgroup): New keyword.
* config/arm/t-arm (OPTIONS_H_EXTRA): Add arm-isa.h
(arm-isa.h): Add rule to generate file.
* common/config/arm/arm-common.c: (arm_canon_arch_option): Use lower
case for feature bit names.

Tested by building cross/cross-native arm-none-linux-gnueabihf and baremetal
cross build (arm-none-eabi) on x86_64.

OK for trunk?

Regards
VP.

gcc/ChangeLog:

[arm] Improve error checking in parsecpu.awk

This patch adds a bit more error checking to parsecpu.awk to ensure
that statements are not missing arguments or have excess arguments
beyond those permitted.  It also slightly improves the handling of
errors so that we terminate properly if parsing fails and be as
helpful as we can while in the parsing phase.

2017-09-22  Richard Earnshaw  

* config/arm/parsecpu.awk (fatal): Note that we've encountered an
error.  Only quit immediately if parsing is complete.
(BEGIN): Initialize fatal_err and parse_done.
(begin fpu, end fpu): Check number of arguments.
(begin arch, end arch): Likewise.
(begin cpu, end cpu): Likewise.
(cname, tune for, tune flags, architecture, fpu, option): Likewise.
(optalias): Likewise.
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5b9217c..4885746 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -2154,6 +2154,17 @@
 
 2017-09-06  Richard Earnshaw  
 
+	* config/arm/parsecpu.awk (fatal): Note that we've encountered an
+	error.  Only quit immediately if parsing is complete.
+	(BEGIN): Initialize fatal_err and parse_done.
+	(begin fpu, end fpu): Check number of arguments.
+	(begin arch, end arch): Likewise.
+	(begin cpu, end cpu): Likewise.
+	(cname, tune for, tune flags, architecture, fpu, option): Likewise.
+	(optalias): Likewise.
+
+2017-09-06  Richard Earnshaw  
+
 	* config.gcc (arm*-*-*): Don't add arm-isa.h to tm_p_file.
 	* config/arm/arm-isa.h: Delete.  Move definitions to ...
 	* arm-cpus.in: ... here.  Use new feature and fgroup values.
diff --git a/gcc/config/arm/parsecpu.awk b/gcc/config/arm/parsecpu.awk
index d07d3fc..0b4fc68 100644
--- a/gcc/config/arm/parsecpu.awk
+++ b/gcc/config/arm/parsecpu.awk
@@ -32,7 +32,8 @@
 
 function fatal (m) {
 print "error ("lineno"): " m > "/dev/stderr"
-exit 1
+fatal_err = 1
+if (parse_done) exit 1
 }
 
 function toplevel () {
@@ -502,14 +503,18 @@ BEGIN {
 arch_name = ""
 fpu_name = ""
 lineno = 0
+fatal_err = 0
+parse_done = 0
 if (cmd == "") fatal("Usage parsecpu.awk -v cmd=")
 }
 
+# New line.  Reset parse status and increment line count for error messages
 // {
 lineno++
 parse_ok = 0
 }
 
+# Comments must be on a line on their own.
 /^#/ {
 parse_ok = 1
 }
@@ -552,12 +557,14 @@ BEGIN {
 }
 
 /^begin fpu / {
+if (NF != 3) fatal("syntax: begin fpu ")
 toplevel()
 fpu_name = $3
 parse_ok = 1
 }
 
 /^end fpu / {
+if (NF != 3) fatal("syntax: end fpu ")
 if (fpu_name != $3) fatal("mimatched end fpu")
 if (! (fpu_name in fpu_isa)) {