From 6d559eac7095682eb431b4457ede9098a9fb67bc Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 9 Aug 2008 16:45:06 +0200 Subject: Add a simplistic, Perl-based LLVM binding generator. --- parse-llvm-c-core-header.pl | 139 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 parse-llvm-c-core-header.pl diff --git a/parse-llvm-c-core-header.pl b/parse-llvm-c-core-header.pl new file mode 100755 index 0000000..1f8be9d --- /dev/null +++ b/parse-llvm-c-core-header.pl @@ -0,0 +1,139 @@ +#! /usr/bin/env perl + +# Used to be a one-liner: +# +# perl -0777pe ... +# + +open (INPUT, "<$ARGV[0]") or die; +@input = ; +close (INPUT); +$text = join ("", @input); + +# Kill uninteresting code sections. +$text =~ s/#define.*//g; +$text =~ s/#include.*//g; +$text =~ s/#ifndef.*((.|[\r\n])*)#endif/\1/g; +$text =~ s/#if DEBUG(.|[\r\n])*?#endif//g; +$text =~ s/#ifdef __cplusplus(.|[\r\n])*?#endif//g; + +# Kill comments. +$text =~ s{/\*(.|[\r\n])*?\*/}{}g; + +# Convert type specifiers. +$text =~ s/(LLVM[^(\n\r]+?Ref)(?=[^(])/:pointer/g; +$text =~ s/(const )?char \*/:string /g; +$text =~ s/(\w|-|:)+ \*/:pointer /g; +$text =~ s/unsigned long long/:unsigned-long-long/g; +$text =~ s/($ARGV[1]") or die "Couldn't open file for writing: $ARGV[1]"; + print (OUTPUT "$text\n"); + close (OUTPUT); + } -- cgit v1.2.3