Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Brute force sccript.
$next = 0;
while (<>){
if (/DllImport/){
$import = $_;
$next = 1;
} elsif ($next){
($prefix, $func, $args) = $_ =~ /(.*) (TF_[A-Za-z0-9]*) (\(.*)/;
#print "Got [$prefix][$func][$args] - $_\n";
$res = $import;
$res =~ s/Library/Library, EntryPoint="$func"/;
print $res;
print "$prefix _CPU_$func $args\n";
$res = $import;
$res =~ s/Library/LibraryGPU, EntryPoint="$func"/;
print $res;
print "$prefix _GPU_$func $args\n";
#
# Remove the () around the arguments
$args =~ s/;$//;
$cargs = $args;
$cargs =~ s/\(//;
$cargs =~ s/\)//;
#
# Split the arguments in the indivudal "type value" groups
# and generate a list of value1, value2, value3
@individual = split (/,/, $cargs);
$pass = "";
foreach $n (@individual){
if (!($pass eq "")){
$pass .= ", ";
}
($arg) = $n =~ /\w+\**(\[\])* (\w+)/;
$pass = $pass . $arg;
}
# Remove the extern
if ($nprefix =~ /void/){
$ret = "return ";
} else {
$ret = "";
}
$nprefix = $prefix;
$nprefix =~ s/ extern//;
print "$nprefix $func $args\n";
print "\t\t{\n";
print "\t\t\tif (TFCore.UseCPU)\n";
print "\t\t\t\t${return}_CPU_$func ($pass);\n";
print "\t\t\telse\n";
print "\t\t\t\t${return}_GPU_$func ($pass);\n";
print "\t\t}\n";
$next = 0;
} else {
print;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment