summaryrefslogtreecommitdiff
path: root/etc/tosail2.perl
diff options
context:
space:
mode:
authorRobert Norton2018-02-08 17:05:07 +0000
committerRobert Norton2018-02-08 17:10:23 +0000
commitb7e9ebcbbd660285e781b6912bf72751fa6b2b4e (patch)
tree59e442046f54637e621e37548404f25ce0a5cc17 /etc/tosail2.perl
parent579cd897d7873436ba6cfb3469b185bf6b321dac (diff)
Some perl for automating some of sail->sail2 porting. Does not even attempt to get everything right but does manage some of the simpler and more tedious stuff. Health warning: may cause bleeding of eyes.
Diffstat (limited to 'etc/tosail2.perl')
-rw-r--r--etc/tosail2.perl64
1 files changed, 64 insertions, 0 deletions
diff --git a/etc/tosail2.perl b/etc/tosail2.perl
new file mode 100644
index 00000000..893e2be8
--- /dev/null
+++ b/etc/tosail2.perl
@@ -0,0 +1,64 @@
+#!/usr/bin/env perl
+
+use strict;
+my $in_enum = 0;
+my $in_bitfield = 0;
+
+while (<>) {
+ my $line = $_;
+
+ # fix bitfield declaration, assumes zero based
+ if (s/typedef\s+(\w+)\s+=\s+register\s+bits\s+\[\s*([\d]+)\s*:\s*0\s*\]/bitfield $1 : bits(@{[$2 + 1]}) =/) {
+ $in_bitfield = 1;
+ }
+ if ($in_bitfield) {
+ if (/\}/) { $in_bitfield = 0; }
+ # fix fields of bitfields
+ s!(\d+)\s*(\.\.\s*\d+)?\s*:\s*(\w+\s*);!$3 : $1$2,!;
+ }
+ # sail2 does not have != at all
+ s!:=!=!;
+ # fix comment style
+ s!\(\*!\/\*!g;
+ s!\*\)!\*\/!g;
+ # fix register declarations
+ s!register \(([^\)]+)\)\W+(\w+)!register $2 : $1!;
+
+ # fix enumerations.
+ if (s!typedef\s+(\w+)\s+=\s+enumerate!enum $1 =!) {
+ $in_enum = 1;
+ }
+ if ($in_enum) {
+ s/;/,/g;
+ if (/\}/) {$in_enum = 0};
+ }
+
+ # fix type aliases
+ s!typedef\s+(\w+)\s+=\s+(.*)!type $1 = $2!;
+
+ # fix switch -> match
+ s!switch\s*\((.*)\)!match $1!;
+ # fix switch cases, need to add commas at end of lines
+ s!case\s+(.*)->!$1 =>!;
+
+ # fix lets with type
+ s!let \(([^\)]+)\)\W+(\w+)!let $2 : $1!;
+
+ # fix val declarations
+ s!val (.*) (\w+)!val $2 : $1!;
+
+ # attempt to decode pattern matches
+ if (/clause decode/) {
+ s/:/@/g;
+ s!\((\w+)\) (\w+)!$2 : $1!g;
+ }
+
+ # fix any bits[n]
+ s!bit\s*\[([^\]]+)\]!bits\($1\)!g;
+
+ # fix option types
+ s!option<([^>]+)>!option($1)!;
+
+ # drop extern, Nat?
+ print;
+}