3 # Copyright (C) 2003-2007, Parrot Foundation.
8 tools/dev/ncidef2asm.pl - Turn an NCI library definition file into PASM
12 perl tools/dev/ncidef2asm.pl path/to/from_file [ path/to/to_file ]
16 This program takes an NCI library definition file and turns it into PASM.
18 An NCI library definition file provides the information needed to
19 generate a parrot wrapper for the named library (or libraries). Its
20 format is simple, and looks like:
29 p new_field i i i i i i
37 Note that the assembly file is generated in the order you specify, so
38 if there are library dependencies, make sure you have them in the
43 Declares the package that all subsequent sub PMCs will be put
44 into. The name is a simple concatenation of the package name, double
45 colon, and the routine name, with no preceding punctuation.
49 The name of the library to be loaded. Should be as qualified as
50 necessary for your platform--generally the full filename is required,
51 though the directory generally isn't.
53 You may load multiple libraries here, but only the last one loaded
54 will be exposed to subsequent defs.
58 This section holds the definitions of functions. Each function is
59 assumed to be in the immediate preceding library. The definition of
62 return_type name [param [param [param ...]]]
64 The param and return_type parameters use the NCI standard, which for
71 Parameter is a void pointer, taken from the PMC's data pointer. PMC is
72 assumed to be an unmanagedstruct or child class.
74 Taken from a P register
78 Parameter is a character.
80 Taken from an I register
86 Taken from an I register
92 Taken from an I register
98 Taken from an I register
104 Taken from an N register.
108 Parameter is a double.
110 Taken from an N register.
114 Paramter is a char *, presumably a C string
116 Taken from an S register
120 Void. Only valid as a return type, noting that the function returns no data.
124 Interpreter pointer. The current interpreter pointer is passed in
134 Taken from an I register.
140 Taken from an I register
146 Taken from an I register
155 my ( $from_file, $to_file ) = @ARGV;
157 # If there is no destination file, strip off the extension of the
158 # source file and add a .pasm to it
159 if ( !defined $to_file ) {
160 $to_file = $from_file;
161 $to_file =~ s/\..*$//;
165 open my $INPUT, '<', "$from_file" or die "Can't open up $from_file, error $!";
166 open my $OUTPUT, '>', "$to_file" or die "Can't open up $to_file, error $!";
168 # To start, save all the registers, just in case
169 print $OUTPUT "saveall\n";
172 my ( $cur_package, $line, $cur_section );
176 package => \
&package_line
,
181 while ( $line = <$INPUT> ) {
183 # Throw away trailing newlines, comments, and whitespace. If the
184 # line's empty, then off to the next line
190 # Is it a section line? If so, extract the section and set it.
191 if ( $line =~ /\[(\w+)\]/ ) {
196 # Everything else goes to the handler
197 $dispatch{$cur_section}->($line);
201 # Put the registers back and end
202 print $OUTPUT "restoreall\n";
203 print $OUTPUT "end\n";
209 # Trim leading and trailing spaces
213 # Set the global current package
214 $cur_package = $line;
220 print $OUTPUT "loadlib P1, '$line'\n";
225 my ( $return_type, $name, @params ) = split ' ', $line;
226 unshift @params, $return_type;
227 my $signature = join( "", @params );
228 print $OUTPUT "dlfunc P2, P1, '$name', '$signature'\n";
229 print $OUTPUT "store_global '${cur_package}::${name}', P2\n";
234 # cperl-indent-level: 4
237 # vim: expandtab shiftwidth=4: