[v3,07/12] tools/ocaml: abi-check: Improve output and error messages
diff mbox series

Message ID 20190910120207.10358-8-ian.jackson@eu.citrix.com
State New
Headers show
Series
  • ocaml abi fixes
Related show

Commit Message

Ian Jackson Sept. 10, 2019, 12:02 p.m. UTC
In the generated C, add some comments saying where we found the ocaml
type.  This helps with debugging.  (I considered emitting #line
directives but decided this would be more confusing than helpful.)

Improve two dies.

Use better-named filehandles (perl prints thier names when it dies).

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/ocaml/libs/xc/abi-check | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/tools/ocaml/libs/xc/abi-check b/tools/ocaml/libs/xc/abi-check
index a470c05e0b..9450676429 100755
--- a/tools/ocaml/libs/xc/abi-check
+++ b/tools/ocaml/libs/xc/abi-check
@@ -15,7 +15,7 @@  our %enums;
 @ARGV == 2 or die;
 our ($c, $o) = @ARGV;
 
-open STDIN, "<", $c or die $!;
+open C_FILE, "<", $c or die $!;
 
 our $cline = -1;
 our $ei;
@@ -29,7 +29,7 @@  our $ei;
 #   /* ! CPrefix CFinal CFinalHow */
 #
 # The function definitions use /* ! */ which simply skips that instance.
-while (<>) {
+while (<C_FILE>) {
     if ($cline == -1) {
         if (m/c_bitmap_to_ocaml_list|ocaml_list_to_c_bitmap/) {
             $cline = 0;
@@ -37,7 +37,8 @@  while (<>) {
         }
     } else {
         $cline++;
-        m{^\s+/\* \s+ ! \s+ (.*?) \s* \*/\s*$}x or die "$cline $_ ?";
+        m{^\s+/\* \s+ ! \s+ (.*?) \s* \*/\s*$}x or
+            die "at line $cline of annotation, did not expect $_ ?";
         my @vals = split /\s+/, $1;
         if ($cline == 1 && !@vals) {
             $cline = -1;
@@ -45,7 +46,7 @@  while (<>) {
             $ei->{$_} = shift @vals foreach qw(OType OPrefix Mangle);
         } elsif ($cline == 2 && @vals == 3) {
             $ei->{$_} = shift @vals foreach qw(CPrefix CFinal CFinalHow);
-            die if $enums{ $ei->{OType} };
+            die "redefining OType $ei->{OType}" if $enums{ $ei->{OType} };
             $enums{ $ei->{OType} } = $ei;
             $cline = -1;
         } else {
@@ -58,13 +59,14 @@  sub expect ($$) {
     printf "BUILD_BUG_ON( %-30s != %-10s );\n", @_ or die $!;
 }
 
-open STDIN, "<", $o or die $!;
+open OCAML_FILE, "<", $o or die $!;
 my $cval;
 $ei = undef;
 my $bitnum = 0;
-while (<>) {
+while (<OCAML_FILE>) {
     if (!$ei) {
         if (m{^type \s+ (\w+) \s* \= \s* $/}x && $enums{$1}) {
+            print "// found ocaml type $1 at $o:$.\n" or die $!;
             $ei = $enums{$1};
             $cval = '';
             $bitnum = 0;