Created
April 3, 2018 03:25
-
-
Save migueldeicaza/592905022620c58f938e7b6b70cb7028 to your computer and use it in GitHub Desktop.
Brute force sccript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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