fixnasm.pp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. Convert insns.dat from Nasm to an i386ins.dat for usage with
  4. the Free pascal compiler
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. program fixnasm;
  12. {$ifndef FPC}
  13. procedure readln(var t:text;var s:string);
  14. var
  15. c : char;
  16. i : longint;
  17. begin
  18. c:=#0;
  19. i:=0;
  20. while (not eof(t)) and (c<>#10) do
  21. begin
  22. read(t,c);
  23. if c<>#10 then
  24. begin
  25. inc(i);
  26. s[i]:=c;
  27. end;
  28. end;
  29. if (i>0) and (s[i]=#13) then
  30. dec(i);
  31. s[0]:=chr(i);
  32. end;
  33. {$endif}
  34. const
  35. spaces=' ';
  36. var
  37. t,f : text;
  38. para,bytes,flags,
  39. opcode,lastop,
  40. s : string;
  41. i,j : longint;
  42. begin
  43. writeln('Fixing insns.dat -> i386ins.dat');
  44. assign(t,'insns.dat');
  45. reset(t);
  46. assign(f,'insns.new');
  47. rewrite(f);
  48. lastop:='';
  49. while not eof(t) do
  50. begin
  51. readln(t,s);
  52. if (s<>'') and (s[1]<>';') then
  53. begin
  54. i:=pos(' ',s);
  55. j:=pos(',',s);
  56. if (j>0) and (j<i) then
  57. opcode:=Copy(s,1,j-1)
  58. else
  59. opcode:=Copy(s,1,i-1);
  60. if opcode<>lastop then
  61. begin
  62. writeln(f,'');
  63. writeln(f,'[',Copy(s,1,i-1),']');
  64. writeln(f,'(Ch_All, Ch_None, Ch_None)');
  65. lastop:=opcode;
  66. end;
  67. while (i<length(s)) and (s[i+1]=' ') do
  68. inc(i);
  69. Delete(s,1,i);
  70. i:=pos(' ',s);
  71. para:=Copy(s,1,i-1);
  72. para:=para+Copy(spaces,1,22-length(para));
  73. while (i<length(s)) and (s[i+1]=' ') do
  74. inc(i);
  75. Delete(s,1,i);
  76. i:=pos(' ',s);
  77. bytes:=Copy(s,1,i-1);
  78. bytes:=bytes+Copy(spaces,1,32-length(bytes));
  79. while (i<length(s)) and (s[i+1]=' ') do
  80. inc(i);
  81. Delete(s,1,i);
  82. i:=pos(' ',s);
  83. if i=0 then
  84. i:=255;
  85. flags:=Copy(s,1,i-1);
  86. writeln(f,para,bytes,flags);
  87. end
  88. else
  89. writeln(f,s);
  90. end;
  91. close(f);
  92. close(t);
  93. end.