Skip to content

Commit

Permalink
NCI thunk stuff:
Browse files Browse the repository at this point in the history
bin/ncithunker.pl script to generate src/GMP/thunks.nci
the script reads Parrot's available thunks and my NCI definition and then
outputs which thunks I need in the proper format
  • Loading branch information
bubaflub committed Jul 14, 2011
1 parent 8654374 commit d039693
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
70 changes: 70 additions & 0 deletions bin/ncithunker.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/perl

use strict;
use warnings;

use File::Spec;

if (scalar @ARGV != 2 || ! -d $ARGV[0] || ! -e $ARGV[1]) {
die "Usage: perl $0 /path/to/parrot /path/to/definition.nci\n";
}

my $parrot_dir = $ARGV[0];
my $nci_def = $ARGV[1];

my $available_signatures;
my $needed_signatures;

my @parrot_nci_files;
push @parrot_nci_files, File::Spec->catfile($parrot_dir, 'src', 'nci', 'core_thunks.nci');
push @parrot_nci_files, File::Spec->catfile($parrot_dir, 'src', 'nci', 'extra_thunks.nci');

# read in all available thunks
# read in custom definition file
# if there isn't an available thunk throw it in needed_signatures
# print out properly formatted NCI definition file for parrot_nci_thunk_gen

foreach my $parrot_nci_file (@parrot_nci_files) {
if (! -e $parrot_nci_file) {
die "Cannot read $parrot_nci_file\n";
}

open(my $fh, '<', $parrot_nci_file);
while(<$fh>) {
next if $_ =~ m/^$/;
next if $_ =~ m/^#/;
$_ =~ s/#.*$//;
$_ =~ s/\s+//g;
$available_signatures->{$_} = 1;
}

close $fh;
}

open(my $fh, '<', $nci_def);

my $section;

while(<$fh>) {
next if $_ =~ m/^$/;
if ($_ =~ m/\[(\w+)\]/) {
$section = $1;
next;
}

if ($section eq 'defs') {
my ($return_type, $func_name, $params) = split /\s+/, $_, 4;
my $nci_sig = $return_type . $params;
if (!exists $available_signatures->{$nci_sig}) {
$needed_signatures->{$nci_sig} = 1;
}
} else {
next;
}
}

foreach(keys %{$needed_signatures}) {
my $return_type = substr($_, 0, 1);
my $params = substr($_, 1, length($_) - 1);
print "$return_type\t$params\n";
}
16 changes: 16 additions & 0 deletions src/GMP/thunks.nci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
v pppl
d p
v ppll
l pl
v ppl
p pip
v pd
l pp
d pp
v pppp
v plp
v ppppp
l ppp
v pplp
v pll
i pd

0 comments on commit d039693

Please sign in to comment.