2011-08-03 14:34:09 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# vim:set ts=4 sw=4:
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $DIR="l0dable";
|
2012-01-23 23:18:36 +00:00
|
|
|
my $memcpy;
|
2011-08-03 14:34:09 +00:00
|
|
|
|
|
|
|
if( -d "../$DIR"){
|
|
|
|
chdir("..");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! -d $DIR ){
|
|
|
|
die "Can't find $DIR?";
|
|
|
|
};
|
|
|
|
|
|
|
|
my @symb;
|
|
|
|
open(Q,"<","l0dable/EXPORTS") || die "$!";
|
|
|
|
while(<Q>){
|
|
|
|
chomp;s/\r$//;
|
2011-08-03 15:11:50 +00:00
|
|
|
next if /^#/;
|
|
|
|
next if /^\s*$/;
|
2011-08-03 14:34:09 +00:00
|
|
|
push @symb,$_;
|
|
|
|
};
|
|
|
|
close(Q);
|
|
|
|
|
|
|
|
$\="\n";
|
|
|
|
|
|
|
|
open (C,">","table.c")||die;
|
|
|
|
print C '#include "table.h"';
|
|
|
|
|
|
|
|
open (H,">","table.h")||die;
|
|
|
|
print H "#include <sysdefs.h>";
|
|
|
|
|
|
|
|
open (I,">","$DIR/usetable.h")||die;
|
|
|
|
print I "extern const void * TheTable[];";
|
|
|
|
|
|
|
|
print I "";
|
|
|
|
|
|
|
|
my %types;
|
|
|
|
my %files;
|
|
|
|
my %variable;
|
|
|
|
|
|
|
|
use File::Find ();
|
|
|
|
|
|
|
|
sub wanted {
|
|
|
|
my $id;
|
|
|
|
next unless /\.h$/;
|
|
|
|
open(F,"<",$_) || die;
|
|
|
|
while(<F>){
|
|
|
|
chomp;s/\r$//;
|
2011-08-03 15:10:52 +00:00
|
|
|
if(m!^[^(]* ([\w]+)\s*\(.*\);\s*(//.*)?(/\*[^/]*\*/)?$!){
|
2011-08-03 14:34:09 +00:00
|
|
|
$id=$1;
|
|
|
|
s/$id/(*)/;
|
|
|
|
s/;//;
|
|
|
|
s!//.*!!;
|
|
|
|
$types{$id}="*($_)";
|
|
|
|
$files{$id}=$File::Find::name;
|
2011-08-03 17:13:20 +00:00
|
|
|
}elsif (m!^\s*extern\s[^(]* ([\w]+)\s*(\[[^]]*\]\s*)?;\s*(//.*)?(/\*[^/]*\*/)?$!){
|
2011-08-03 14:34:09 +00:00
|
|
|
$id=$1;
|
|
|
|
s/extern //;
|
|
|
|
my $star="*";
|
2011-08-03 17:13:20 +00:00
|
|
|
if( s/\[.*\]//){
|
2011-08-03 14:34:09 +00:00
|
|
|
$star="";
|
|
|
|
};
|
|
|
|
s/$id/*/;
|
|
|
|
s/;//;
|
|
|
|
s!//.*!!;
|
|
|
|
$types{$id}="$star($_)";
|
|
|
|
$variable{$id}=1;
|
|
|
|
$files{$id}=$File::Find::name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
close(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
File::Find::find({wanted => \&wanted}, '.');
|
|
|
|
|
|
|
|
print C "";
|
2011-08-05 12:23:27 +00:00
|
|
|
print C <<EOF;
|
2011-08-12 18:24:56 +00:00
|
|
|
#ifndef SIMULATOR
|
2011-08-05 12:23:27 +00:00
|
|
|
__attribute__ ((used, section("table")))
|
2011-08-12 18:24:56 +00:00
|
|
|
#endif /* SIMULATOR */
|
2011-08-05 12:23:27 +00:00
|
|
|
const void * TheTable[]={
|
|
|
|
EOF
|
2011-08-03 14:34:09 +00:00
|
|
|
|
|
|
|
my %defs;
|
|
|
|
|
|
|
|
for my $idx (0..$#symb){
|
|
|
|
$_=$symb[$idx];
|
|
|
|
if(!$types{$_}){
|
2011-08-03 14:44:46 +00:00
|
|
|
warn "Couldn't find $symb[$idx] - ignoring it.";
|
|
|
|
print C "NULL,";
|
|
|
|
print I "#define $_ (NULL)";
|
|
|
|
next;
|
2011-08-03 14:34:09 +00:00
|
|
|
};
|
|
|
|
if(!$defs{$files{$_}}){
|
|
|
|
print H qq!#include "$files{$_}"!;
|
|
|
|
$defs{$files{$_}}++;
|
|
|
|
};
|
|
|
|
|
|
|
|
if($variable{$_}){
|
|
|
|
print C "\&$_,";
|
|
|
|
}else{
|
|
|
|
print C "$_,";
|
|
|
|
};
|
|
|
|
print I "#define $_ ($types{$_}(TheTable[$idx]))";
|
2012-01-23 23:18:36 +00:00
|
|
|
if($_ eq "memcpy" || $_ eq "memmove"){
|
|
|
|
$memcpy=$idx
|
|
|
|
};
|
2011-08-03 14:34:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
print C "};";
|
|
|
|
|
2012-01-23 23:18:36 +00:00
|
|
|
if (defined($memcpy)){
|
|
|
|
print I "#define _memcpy_nr $memcpy";
|
|
|
|
};
|
2011-08-03 14:34:09 +00:00
|
|
|
close(I);
|
|
|
|
close(H);
|
|
|
|
close(C);
|
|
|
|
|
2011-08-03 14:44:46 +00:00
|
|
|
print "done.";
|
|
|
|
|