read_file_nondiff32.pl 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use autodie; # die if problem reading or writing a file
  5. my $filein = "./agast.txt";
  6. my $fileout = "./agast_new.txt";
  7. my $i1=1;
  8. my $i2=1;
  9. my $i3=1;
  10. my $tmp;
  11. my $ifcount0=0;
  12. my $ifcount1=0;
  13. my $ifcount2=0;
  14. my $ifcount3=0;
  15. my $ifcount4=0;
  16. my $elsecount;
  17. my $myfirstline = $ARGV[0];
  18. my $mylastline = $ARGV[1];
  19. my $tablename = $ARGV[2];
  20. my @array0 = ();
  21. my @array1 = ();
  22. my @array2 = ();
  23. my @array3 = ();
  24. my $homogeneous;
  25. my $success_homogeneous;
  26. my $structured;
  27. my $success_structured;
  28. open(my $in1, "<", $filein) or die "Can't open $filein: $!";
  29. open(my $out, ">", $fileout) or die "Can't open $fileout: $!";
  30. $array0[0] = 0;
  31. $i1=1;
  32. while (my $line1 = <$in1>)
  33. {
  34. chomp $line1;
  35. $array0[$i1] = 0;
  36. if (($i1>=$myfirstline)&&($i1<=$mylastline))
  37. {
  38. if($line1=~/if\(ptr\[offset(\d+)/)
  39. {
  40. if($line1=~/if\(ptr\[offset(\d+).*\>.*cb/)
  41. {
  42. $tmp=$1;
  43. }
  44. else
  45. {
  46. if($line1=~/if\(ptr\[offset(\d+).*\<.*c\_b/)
  47. {
  48. $tmp=$1+128;
  49. }
  50. else
  51. {
  52. die "invalid array index!"
  53. }
  54. }
  55. $array1[$ifcount1] = $tmp;
  56. $array0[$ifcount1] = $i1;
  57. $ifcount1++;
  58. }
  59. else
  60. {
  61. }
  62. }
  63. $i1++;
  64. }
  65. $homogeneous=$ifcount1;
  66. $success_homogeneous=$ifcount1+1;
  67. $structured=$ifcount1+2;
  68. $success_structured=$ifcount1+3;
  69. close $in1 or die "Can't close $filein: $!";
  70. open($in1, "<", $filein) or die "Can't open $filein: $!";
  71. $i1=1;
  72. while (my $line1 = <$in1>)
  73. {
  74. chomp $line1;
  75. if (($i1>=$myfirstline)&&($i1<=$mylastline))
  76. {
  77. if ($array0[$ifcount2] == $i1)
  78. {
  79. $array2[$ifcount2]=0;
  80. $array3[$ifcount2]=0;
  81. if ($array0[$ifcount2+1] == ($i1+1))
  82. {
  83. $array2[$ifcount2]=($ifcount2+1);
  84. }
  85. else
  86. {
  87. open(my $in2, "<", $filein) or die "Can't open $filein: $!";
  88. $i2=1;
  89. while (my $line2 = <$in2>)
  90. {
  91. chomp $line2;
  92. if ($i2 == $i1)
  93. {
  94. last;
  95. }
  96. $i2++;
  97. }
  98. my $line2 = <$in2>;
  99. chomp $line2;
  100. if ($line2=~/goto (\w+)/)
  101. {
  102. $tmp=$1;
  103. if ($tmp eq "homogeneous")
  104. {
  105. $array2[$ifcount2]=$homogeneous;
  106. }
  107. if ($tmp eq "success_homogeneous")
  108. {
  109. $array2[$ifcount2]=$success_homogeneous;
  110. }
  111. if ($tmp eq "structured")
  112. {
  113. $array2[$ifcount2]=$structured;
  114. }
  115. if ($tmp eq "success_structured")
  116. {
  117. $array2[$ifcount2]=$success_structured;
  118. }
  119. }
  120. else
  121. {
  122. die "goto expected: $!";
  123. }
  124. close $in2 or die "Can't close $filein: $!";
  125. }
  126. #find next else and interpret it
  127. open(my $in3, "<", $filein) or die "Can't open $filein: $!";
  128. $i3=1;
  129. $ifcount3=0;
  130. $elsecount=0;
  131. while (my $line3 = <$in3>)
  132. {
  133. chomp $line3;
  134. $i3++;
  135. if ($i3 == $i1)
  136. {
  137. last;
  138. }
  139. }
  140. while (my $line3 = <$in3>)
  141. {
  142. chomp $line3;
  143. $ifcount3++;
  144. if (($elsecount==0)&&($i3>$i1))
  145. {
  146. if ($line3=~/goto (\w+)/)
  147. {
  148. $tmp=$1;
  149. if ($tmp eq "homogeneous")
  150. {
  151. $array3[$ifcount2]=$homogeneous;
  152. }
  153. if ($tmp eq "success_homogeneous")
  154. {
  155. $array3[$ifcount2]=$success_homogeneous;
  156. }
  157. if ($tmp eq "structured")
  158. {
  159. $array3[$ifcount2]=$structured;
  160. }
  161. if ($tmp eq "success_structured")
  162. {
  163. $array3[$ifcount2]=$success_structured;
  164. }
  165. }
  166. else
  167. {
  168. if ($line3=~/if\(ptr\[offset/)
  169. {
  170. $ifcount4=0;
  171. while ($array0[$ifcount4]!=$i3)
  172. {
  173. $ifcount4++;
  174. if ($ifcount4==$ifcount1)
  175. {
  176. die "if else match expected: $!";
  177. }
  178. $array3[$ifcount2]=$ifcount4;
  179. }
  180. }
  181. else
  182. {
  183. die "elseif or elsegoto match expected: $!";
  184. }
  185. }
  186. last;
  187. }
  188. else
  189. {
  190. if ($line3=~/if\(ptr\[offset/)
  191. {
  192. $elsecount++;
  193. }
  194. else
  195. {
  196. if ($line3=~/else/)
  197. {
  198. $elsecount--;
  199. }
  200. }
  201. }
  202. $i3++;
  203. }
  204. printf("%3d [%3d][0x%08x]\n", $array0[$ifcount2], $ifcount2, (($array1[$ifcount2]&15)<<28)|($array2[$ifcount2]<<16)|(($array1[$ifcount2]&128)<<5)|($array3[$ifcount2]));
  205. close $in3 or die "Can't close $filein: $!";
  206. $ifcount2++;
  207. }
  208. else
  209. {
  210. }
  211. }
  212. $i1++;
  213. }
  214. printf(" [%3d][0x%08x]\n", $homogeneous, 252);
  215. printf(" [%3d][0x%08x]\n", $success_homogeneous, 253);
  216. printf(" [%3d][0x%08x]\n", $structured, 254);
  217. printf(" [%3d][0x%08x]\n", $success_structured, 255);
  218. close $in1 or die "Can't close $filein: $!";
  219. $ifcount0=0;
  220. $ifcount2=0;
  221. printf $out " static const unsigned long %s[] = {\n ", $tablename;
  222. while ($ifcount0 < $ifcount1)
  223. {
  224. printf $out "0x%08x, ", (($array1[$ifcount0]&15)<<28)|($array2[$ifcount0]<<16)|(($array1[$ifcount0]&128)<<5)|($array3[$ifcount0]);
  225. $ifcount0++;
  226. $ifcount2++;
  227. if ($ifcount2==8)
  228. {
  229. $ifcount2=0;
  230. printf $out "\n";
  231. printf $out " ";
  232. }
  233. }
  234. printf $out "0x%08x, ", 252;
  235. $ifcount0++;
  236. $ifcount2++;
  237. if ($ifcount2==8)
  238. {
  239. $ifcount2=0;
  240. printf $out "\n";
  241. printf $out " ";
  242. }
  243. printf $out "0x%08x, ", 253;
  244. $ifcount0++;
  245. $ifcount2++;
  246. if ($ifcount2==8)
  247. {
  248. $ifcount2=0;
  249. printf $out "\n";
  250. printf $out " ";
  251. }
  252. printf $out "0x%08x, ", 254;
  253. $ifcount0++;
  254. $ifcount2++;
  255. if ($ifcount2==8)
  256. {
  257. $ifcount2=0;
  258. printf $out "\n";
  259. printf $out " ";
  260. }
  261. printf $out "0x%08x\n", 255;
  262. $ifcount0++;
  263. $ifcount2++;
  264. printf $out " };\n\n";
  265. $#array0 = -1;
  266. $#array1 = -1;
  267. $#array2 = -1;
  268. $#array3 = -1;
  269. close $out or die "Can't close $fileout: $!";