5 # usage: gen-gupc-inline-lib template.in [input-file ...]
7 # Create a file from template.in that implements selectively inline'd
8 # GUPC runtime routines.
10 # The files are read first. This processes lines with the
11 # following syntax. Note, the '//' sequence must begin in column one.
13 # The following lines are processed in the input files.
15 # //begin <name> Collect the following lines up to the matching 'end'
16 # and append them to an internal buffer named <name>
17 # Nested Begin ... end brackets are _not_ supported.
19 # //end <name> End the collection of items into the buffer named <name>.
21 # The following lines are processed in the template file.
23 # //include <name> Expands into the contents of the buffer named <name>.
25 # //inline Expands into:
26 # "__attribute__((__always_inline__)) static inline".
27 # May appear inside a begin ... end bracket.
29 # The expanded text is written to stdout.
31 my $nargs = scalar @ARGV;
32 die "missing first (template file) arg" if $nargs < 1;
35 die "file not found: $_" if ! -f
;
37 my $tfile = shift @ARGV;
38 open TEMPLATE
, "<$tfile" or die "can't open template file: $tfile";
42 # Read the input files listed in @ARGV
45 if ($input_file ne $ARGV)
48 or die "missing '//end ${buf}': $input_file\n";
52 if (m{^//begin\s+(\w+)\s*$})
54 die "nested buffers not supported,"
55 . " last buffer is '$buf': $input_file\n"
60 elsif (m{^//end\s+(\w+)\s*$})
63 die "no matching begin for buffer '$endbuf': $input_file\n"
65 die "buffer mismatch, '$buf' != '$endbuf': $input_file\n"
72 $bufs{$buf} .= "$_\n";
76 or die "missing '//end ${buf}': $input_file\n";
77 my $inline_attr = "__attribute__((__always_inline__))\nstatic inline";
80 $bufs{$buf} =~ s
{^//inline\s
*$}{$inline_attr}mg
;
85 if (m{^//include\s+(\w+)\s*$})
88 die "unknown buffer: $buf" if !exists ($bufs{$buf});
92 elsif (m{^//inline\s*$})
94 print "$inline_attr\n";