chiark / gitweb /
realtime: movpos: debug output: exclude some more stuff from the default movpos output
[trains.git] / hostside / debug-extractor
1 #!/usr/bin/perl -w
2
3 use strict qw(vars);
4
5 print <<END
6 /* autogenerated - do not edit */
7
8 #ifndef DEBUG_FLAGS_H
9 #define DEBUG_FLAGS_H
10
11 typedef struct {
12   unsigned long active, nondefault;
13 } DebugSelectorKindFlags;
14
15 typedef struct {
16   const char *name;
17   unsigned long bit;
18 } DebugSelectorKindInfo;
19
20 typedef struct {
21   const char *name;
22   const DebugSelectorKindInfo *kinds;
23   unsigned long *dflags, *userset;
24   unsigned long defdflags;
25 } DebugSelectorAreaInfo;
26
27 END
28     or die $!;
29
30 our (%count);
31 our ($decls)='';
32 our ($defs)='';
33
34 our ($shift,$decl,$ma,$mar,$mk);
35
36 while (<>) {
37     next unless m/\bDPRINTF1?\((\w+),(\w+),/;
38     $count{$1}{$2}++;
39 }
40
41 foreach $ma (sort keys %count) {
42     $mar= $count{$ma};
43     $decl= "unsigned long dflags_$ma";
44     $decls.= "extern $decl;\n";
45     our $ddf= "DEFDFLAGS_${ma}";
46     $defs .= ("\n".
47               "#ifndef $ddf\n".
48               "# define $ddf ~0UL\n".
49               "#endif\n");
50     $defs .= "static const DebugSelectorKindInfo dsiks_${ma}[]= {\n";
51     $shift= 0;
52     foreach $mk (sort { $mar->{$a} <=> $mar->{$b} or $a cmp $b } keys %$mar) {
53         next unless length $mk;
54         our $db= "DBIT_${ma}_${mk}";
55         our $v= 1<<$shift;
56         $shift++;
57         $defs.= sprintf "  { %-20s %-25s },\n", "\"$mk\",", $db;
58         printf "#define %-30s %0#10x /* %3d */\n", $db, $v, $mar->{$mk};
59     }
60     $defs.= "  { 0 }\n".
61         "};\n";
62     $defs.= "$decl;\n";
63     $defs.= "static unsigned long dflags_userset_$ma;\n";
64 }
65 $defs.= <<END;
66 static const DebugSelectorAreaInfo dsais[]= {
67 #define DSAI(x) \\
68   { #x, dsiks_##x, &dflags_##x, &dflags_userset_##x, DEFDFLAGS_##x }
69 END
70 foreach $ma (sort keys %count) {
71     $defs.= "DSAI($ma),\n"
72 }
73 $defs.= "  { 0 }\n".
74     "#undef DSAI\n".
75         "};\n";
76
77 print <<END
78
79 $decls
80 #endif /*DEBUG_FLAGS_H*/
81
82 #ifdef DEBUG_FLAGS_H_DEFINE
83 $defs
84 #endif /*DEBUG_FLAGS_H_DEFINE*/
85
86 END
87     or die $!;