]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
tools/ocaml: abi-check: Improve output and error messages
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 10 Sep 2019 11:34:38 +0000 (12:34 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Tue, 10 Sep 2019 13:16:37 +0000 (14:16 +0100)
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>
Acked-by: Andrew Cooper <Andrew.Cooper3@citrix.com>
tools/ocaml/libs/xc/abi-check

index a470c05e0b39bcd078518988666fb31e80f08167..94506764291f8af6486cdc756ce69cc1188ef8a3 100755 (executable)
@@ -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;