mk68kins.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. {
  2. Copyright (c) 2020 by Karoly Balogh
  3. Convert m68kins.dat to a set of .inc files for the m68k backend
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. program mk68kins;
  11. {$mode objfpc}{$H+}
  12. uses
  13. SysUtils,StrUtils;
  14. const
  15. Version = '1.0.0';
  16. HeaderStr = '{ don''t edit, this file is generated from m68kins.dat; to regenerate, run ''make insdat'' in the compiler directory }';
  17. max_operands = 6;
  18. type
  19. TOperandType = (
  20. OT_DATA,
  21. OT_ADDR,
  22. OT_ADDR_INDIR,
  23. OT_ADDR_INDIR_POSTINC,
  24. OT_ADDR_INDIR_PREDEC,
  25. OT_ADDR_DISP16,
  26. OT_ADDR_IDX_DISP8,
  27. OT_ABS_SHORT,
  28. OT_ABS_LONG,
  29. OT_PC_DISP16,
  30. OT_PC_IDX_DISP8,
  31. OT_IMMEDIATE,
  32. OT_REG_LIST,
  33. OT_FPUREG_LIST,
  34. OT_FPUREG,
  35. OT_SPECIALREG
  36. );
  37. TOperandFlags = (
  38. OF_IMM_QUICK,
  39. OF_IMM_FLOAT,
  40. OF_IMM_64BIT,
  41. OF_SPECREG,
  42. OF_SPECREG_CCR,
  43. OF_SPECREG_SR,
  44. OF_SPECREG_USP,
  45. OF_SPECREG_FPIAR,
  46. OF_SPECREG_FPU,
  47. OF_BITFIELD,
  48. OF_BRANCH,
  49. OF_DOUBLE_REG,
  50. OF_KFACTOR,
  51. OF_NOSIZE
  52. );
  53. TOpSizeFlag = (
  54. OPS_UNSIZED,
  55. OPS_SHORT,
  56. OPS_BYTE,
  57. OPS_WORD,
  58. OPS_LONG,
  59. OPS_QUAD,
  60. OPS_SINGLE,
  61. OPS_DOUBLE,
  62. OPS_EXTENDED,
  63. OPS_PACKED,
  64. OPS_COLDFIRE
  65. );
  66. TOpSupported = (
  67. OS_M68000,
  68. OS_M68000UP,
  69. OS_M68010UP,
  70. OS_M68020,
  71. OS_M68020UP,
  72. OS_M68030,
  73. OS_M68040,
  74. OS_M68040UP,
  75. OS_M68060,
  76. OS_M68881,
  77. OS_M68851,
  78. OS_CPU32,
  79. OS_CF,
  80. OS_CF_ISA_A,
  81. OS_CF_ISA_APL,
  82. OS_CF_ISA_B,
  83. OS_CF_ISA_C,
  84. OS_CF_HWDIV,
  85. OS_CF_FPU,
  86. OS_CF_USP,
  87. OS_GNU_AS
  88. );
  89. TParamType = record
  90. id: string[32];
  91. modes: set of TOperandType;
  92. flags: set of TOperandFlags;
  93. end;
  94. TFlagsType = record
  95. id: string[32];
  96. flags: set of TOpSizeFlag;
  97. end;
  98. TSupportType = record
  99. id: string[32];
  100. flag: TOPSupported;
  101. end;
  102. const
  103. OpSizes: array[0..16] of TFlagsType = (
  104. (id: 'UNS'; flags: [OPS_UNSIZED]),
  105. (id: 'B'; flags: [OPS_BYTE]),
  106. (id: 'W'; flags: [OPS_WORD]),
  107. (id: 'L'; flags: [OPS_LONG]),
  108. (id: 'Q'; flags: [OPS_QUAD]),
  109. (id: 'BW'; flags: [OPS_BYTE,OPS_WORD]),
  110. (id: 'BWL'; flags: [OPS_BYTE,OPS_WORD,OPS_LONG]),
  111. (id: 'WL'; flags: [OPS_WORD,OPS_LONG]),
  112. (id: 'SBW'; flags: [OPS_SHORT,OPS_BYTE,OPS_WORD]),
  113. (id: 'SBWL'; flags: [OPS_SHORT,OPS_BYTE,OPS_WORD,OPS_LONG]),
  114. (id: 'CFWL'; flags: [OPS_WORD,OPS_LONG,OPS_COLDFIRE]),
  115. (id: 'CFBWL'; flags: [OPS_BYTE,OPS_WORD,OPS_LONG,OPS_COLDFIRE]),
  116. (id: 'FD'; flags: [OPS_DOUBLE]),
  117. (id: 'FX'; flags: [OPS_EXTENDED]),
  118. (id: 'FP'; flags: [OPS_PACKED]),
  119. (id: 'ANY'; flags: [OPS_BYTE,OPS_WORD,OPS_LONG,OPS_SINGLE,OPS_DOUBLE,OPS_EXTENDED,OPS_PACKED]),
  120. (id: 'CFANY'; flags: [OPS_BYTE,OPS_WORD,OPS_LONG,OPS_SINGLE,OPS_DOUBLE,OPS_COLDFIRE])
  121. );
  122. const
  123. OpSupport: array[0..19] of TSupportType = (
  124. (id: 'm68000up'; flag: OS_M68000UP),
  125. (id: 'm68010up'; flag: OS_M68010UP),
  126. (id: 'm68020'; flag: OS_M68020),
  127. (id: 'm68020up'; flag: OS_M68020UP),
  128. (id: 'm68030'; flag: OS_M68030),
  129. (id: 'm68040'; flag: OS_M68040),
  130. (id: 'm68040up'; flag: OS_M68040UP),
  131. (id: 'm68060'; flag: OS_M68060),
  132. (id: 'm68881'; flag: OS_M68881),
  133. (id: 'm68851'; flag: OS_M68851),
  134. (id: 'cpu32'; flag: OS_CPU32),
  135. (id: 'cf'; flag: OS_CF),
  136. (id: 'cf_isa_a'; flag: OS_CF_ISA_A),
  137. (id: 'cf_isa_apl'; flag: OS_CF_ISA_APL),
  138. (id: 'cf_isa_b'; flag: OS_CF_ISA_B),
  139. (id: 'cf_isa_c'; flag: OS_CF_ISA_C),
  140. (id: 'cf_hwdiv'; flag: OS_CF_HWDIV),
  141. (id: 'cf_fpu'; flag: OS_CF_FPU),
  142. (id: 'cf_usp'; flag: OS_CF_USP),
  143. (id: 'gnu_as'; flag: OS_GNU_AS)
  144. );
  145. const
  146. ParamTypes: array [0..63] of TParamType = (
  147. (id: 'void'; modes: []; flags: []),
  148. (id: '#imm'; modes: [OT_IMMEDIATE]; flags: []),
  149. (id: '#immq'; modes: [OT_IMMEDIATE]; flags: [OF_NOSIZE,OF_IMM_QUICK]),
  150. (id: '#immregs'; modes: [OT_IMMEDIATE]; flags: [OF_NOSIZE]),
  151. (id: 'Dx'; modes: [OT_DATA]; flags: []),
  152. (id: 'Dx:Dx'; modes: [OT_DATA]; flags: [OF_DOUBLE_REG]),
  153. (id: 'Rx'; modes: [OT_DATA, OT_ADDR]; flags: []),
  154. (id: 'Ax'; modes: [OT_ADDR]; flags: []),
  155. (id: '(Ax)'; modes: [OT_ADDR_INDIR]; flags: []),
  156. (id: '-(Ax)'; modes: [OT_ADDR_INDIR_PREDEC]; flags: []),
  157. (id: '(Ax)+'; modes: [OT_ADDR_INDIR_POSTINC]; flags: []),
  158. (id: 'd16(Ax)'; modes: [OT_ADDR_DISP16]; flags: []),
  159. (id: 'Dx-Ax'; modes: [OT_REG_LIST]; flags: []),
  160. (id: 'FPx'; modes: [OT_FPUREG]; flags: []),
  161. (id: 'FPx:FPx'; modes: [OT_FPUREG]; flags: [OF_DOUBLE_REG]),
  162. (id: 'FPx-FPx'; modes: [OT_FPUREG_LIST]; flags: []),
  163. (id: 'FPspec-list'; modes: [OT_FPUREG_LIST]; flags: [OF_SPECREG, OF_SPECREG_FPU]),
  164. (id: 'CCR'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG, OF_SPECREG_CCR]),
  165. (id: 'SR'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG, OF_SPECREG_SR]),
  166. (id: 'USP'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG, OF_SPECREG_USP]),
  167. (id: 'CTRL'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  168. (id: 'FC'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  169. (id: 'RP_030'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  170. (id: 'RP_851'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  171. (id: 'TC'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  172. (id: 'AC'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  173. (id: 'M1_B'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  174. (id: 'BAD'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  175. (id: 'BAC'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  176. (id: 'PSR'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  177. (id: 'PCSR'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  178. (id: 'TT'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  179. (id: 'VAL'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  180. (id: 'FPIAR'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG, OF_SPECREG_FPIAR]),
  181. (id: 'FPspec'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG, OF_SPECREG_FPU]),
  182. (id: '<caches>'; modes: [OT_SPECIALREG]; flags: [OF_SPECREG]),
  183. (id: '<addr>'; modes: [OT_ABS_LONG]; flags: []),
  184. (id: '<dest>'; modes: [OT_ABS_LONG]; flags: [OF_BRANCH]),
  185. (id: '<value>'; modes: [OT_ABS_LONG]; flags: [OF_NOSIZE]),
  186. (id: '(Rx):(Rx)'; modes: [OT_ADDR_INDIR]; flags: [OF_DOUBLE_REG]),
  187. (id: '<ea-any>';
  188. modes: [OT_DATA,OT_ADDR,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  189. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  190. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  191. flags: []),
  192. (id: '<ea-mem>';
  193. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  194. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  195. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  196. flags: []),
  197. (id: '<ea-mem-alter>';
  198. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  199. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  200. flags: []),
  201. (id: '<ea-mem-noimm>';
  202. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  203. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  204. OT_PC_DISP16,OT_PC_IDX_DISP8];
  205. flags: []),
  206. (id: '<ea-mem-fpuimm>';
  207. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  208. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  209. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  210. flags: [OF_IMM_FLOAT]),
  211. (id: '<ea-mem-alter-kf>';
  212. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  213. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  214. flags: [OF_KFACTOR]),
  215. (id: '<ea-mem-save>';
  216. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_PREDEC,
  217. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  218. flags: []),
  219. (id: '<ea-mem-restore>';
  220. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,
  221. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  222. flags: []),
  223. (id: '<ea-mem-imm64>';
  224. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  225. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  226. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  227. flags: [OF_IMM_64BIT]),
  228. (id: '<ea-data>';
  229. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  230. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  231. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  232. flags: []),
  233. (id: '<ea-data-noimm>';
  234. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  235. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  236. OT_PC_DISP16,OT_PC_IDX_DISP8];
  237. flags: []),
  238. (id: '<ea-data-alter>';
  239. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  240. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  241. flags: []),
  242. (id: '<ea-data-alter-bf>';
  243. modes: [OT_DATA,OT_ADDR_INDIR,
  244. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  245. flags: [OF_BITFIELD]),
  246. (id: '<ea-data-control-bf>';
  247. modes: [OT_DATA,OT_ADDR_INDIR,
  248. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  249. OT_PC_DISP16,OT_PC_IDX_DISP8];
  250. flags: [OF_BITFIELD]),
  251. (id: '<ea-control>';
  252. modes: [OT_ADDR_INDIR,
  253. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  254. OT_PC_DISP16,OT_PC_IDX_DISP8];
  255. flags: []),
  256. (id: '<ea-control-alter>';
  257. modes: [OT_ADDR_INDIR,
  258. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  259. flags: []),
  260. (id: '<ea-alter>';
  261. modes: [OT_DATA,OT_ADDR,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  262. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  263. flags: []),
  264. (id: '<ea-movep>';
  265. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16];
  266. flags: []),
  267. (id: '<cf-ea-mem-alter>';
  268. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  269. OT_ADDR_DISP16];
  270. flags: []),
  271. (id: '<cf-ea-data-alter>';
  272. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  273. OT_ADDR_DISP16];
  274. flags: []),
  275. (id: '<cf-ea-float>';
  276. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  277. OT_ADDR_DISP16,OT_PC_DISP16];
  278. flags: []),
  279. (id: '<cf-ea-data-float>';
  280. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  281. OT_ADDR_DISP16,OT_PC_DISP16];
  282. flags: []),
  283. (id: '<cf-ea-movem>';
  284. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16];
  285. flags: []),
  286. (id: '<cf-ea-fmovem-src>';
  287. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16,OT_PC_DISP16];
  288. flags: [])
  289. );
  290. function OpTypeStr(idx: integer): string;
  291. var
  292. optyp: TOperandType;
  293. begin
  294. result:='';
  295. for optyp in ParamTypes[idx].modes do
  296. if result='' then
  297. WriteStr(result,optyp)
  298. else
  299. WriteStr(result,result,', ',optyp);
  300. end;
  301. function FlagsToStr(idx: integer): string;
  302. var
  303. flagtyp: TOperandFlags;
  304. begin
  305. result:='';
  306. for flagtyp in ParamTypes[idx].flags do
  307. if result='' then
  308. WriteStr(result,flagtyp)
  309. else
  310. WriteStr(result,result,', ',flagtyp);
  311. end;
  312. function OpSizeStr(idx: integer): string;
  313. var
  314. opsizeflag: TOpsizeFlag;
  315. begin
  316. result:='';
  317. for opsizeflag in Opsizes[idx].flags do
  318. if result='' then
  319. WriteStr(result,opsizeflag)
  320. else
  321. WriteStr(result,result,', ',opsizeflag);
  322. end;
  323. function OpSupportStr(const sa: TStringArray): string;
  324. var
  325. i: integer;
  326. s: string;
  327. flag: TOpSupported;
  328. idx: integer;
  329. begin
  330. result:='';
  331. for s in sa do
  332. begin
  333. idx:=-1;
  334. for I:=Low(OpSupport) to High(OpSupport) do
  335. if OpSupport[I].id=s then
  336. begin
  337. idx:=i;
  338. flag:=OpSupport[i].flag;
  339. break;
  340. end;
  341. if idx < 0 then
  342. raise Exception.Create('Invalid support type: '''+s+'''');
  343. if result='' then
  344. WriteStr(result,flag)
  345. else
  346. WriteStr(result,result,', ',flag);
  347. end;
  348. end;
  349. type
  350. { T68kInsDatOutputFiles }
  351. T68kInsDatOutputFiles = class
  352. public
  353. OpFile: TextFile;
  354. NOpFile: TextFile;
  355. StdOpNames: TextFile;
  356. InsTabFile: TextFile;
  357. constructor Create;
  358. destructor Destroy;override;
  359. end;
  360. constructor T68kInsDatOutputFiles.Create;
  361. begin
  362. AssignFile(OpFile,'m68kop.inc');
  363. Rewrite(OpFile);
  364. Writeln(OpFile,HeaderStr);
  365. Writeln(OpFile,'(');
  366. AssignFile(NOpFile,'m68knop.inc');
  367. Rewrite(NOpFile);
  368. Writeln(NOpFile,HeaderStr);
  369. AssignFile(StdOpNames,'m68kstd.inc');
  370. Rewrite(StdOpNames);
  371. Writeln(StdOpNames,HeaderStr);
  372. Writeln(StdOpNames,'(');
  373. AssignFile(InsTabFile,'m68ktab.inc');
  374. Rewrite(InsTabFile);
  375. Writeln(InsTabFile,HeaderStr);
  376. Writeln(InsTabFile,'(');
  377. end;
  378. destructor T68kInsDatOutputFiles.Destroy;
  379. begin
  380. CloseFile(OpFile);
  381. CloseFile(NOpFile);
  382. CloseFile(StdOpNames);
  383. CloseFile(InsTabFile);
  384. inherited Destroy;
  385. end;
  386. function FindParamType(const ParamTypeStr: string): Integer;
  387. var
  388. I: Integer;
  389. begin
  390. for I:=Low(ParamTypes) to High(ParamTypes) do
  391. if ParamTypes[I].id=ParamTypeStr then
  392. exit(I);
  393. raise Exception.Create('Invalid param type: '''+ParamTypeStr+'''');
  394. end;
  395. function FindOpsize(const SizeStr: string): Integer;
  396. var
  397. I: Integer;
  398. begin
  399. for I:=Low(Opsizes) to High(Opsizes) do
  400. if Opsizes[I].id=SizeStr then
  401. exit(I);
  402. raise Exception.Create('Invalid size: '''+SizeStr+'''');
  403. end;
  404. var
  405. InsDatFile: TextFile;
  406. OutputFiles: T68kInsDatOutputFiles=nil;
  407. S, op, ParamsStr: string;
  408. FirstIns: Boolean=true;
  409. OpCount: Integer=0;
  410. S_Split, S_Params, S_Support: TStringArray;
  411. ParamIdx: Integer;
  412. begin
  413. writeln('FPC m68k Instruction Table Converter Version ',Version);
  414. AssignFile(InsDatFile,'./m68kins.dat');
  415. Reset(InsDatFile);
  416. try
  417. OutputFiles:=T68kInsDatOutputFiles.Create;
  418. while not EoF(InsDatFile) do
  419. begin
  420. Readln(InsDatFile,S);
  421. S:=Trim(S);
  422. if AnsiStartsStr(';',S) then
  423. continue
  424. else if AnsiStartsStr('[',S) then
  425. begin
  426. op:=Copy(S,2,Length(S)-2);
  427. if not FirstIns then
  428. begin
  429. Writeln(OutputFiles.OpFile,',');
  430. Writeln(OutputFiles.StdOpNames,',');
  431. end;
  432. FirstIns:=False;
  433. Write(OutputFiles.OpFile,'A_'+op);
  434. Write(OutputFiles.StdOpNames,''''+LowerCase(op)+'''');
  435. end
  436. else if S<>'' then
  437. begin
  438. Inc(OpCount);
  439. if OpCount<>1 then
  440. Writeln(OutputFiles.InsTabFile,',');
  441. S_Split:=S.Split(' ',TStringSplitOptions.ExcludeEmpty);
  442. S_Params:=S_Split[0].Split(',',TStringSplitOptions.ExcludeEmpty);
  443. S_Support:=S_Split[4].Split(',',TStringSplitOptions.ExcludeEmpty);
  444. if (Length(S_Params)=1) and (S_Params[0]='void') then
  445. SetLength(S_Params,0);
  446. Writeln(OutputFiles.InsTabFile,' (');
  447. Writeln(OutputFiles.InsTabFile,' opcode : A_',op,';');
  448. Writeln(OutputFiles.InsTabFile,' ops : ',Length(S_Params),';');
  449. Write(OutputFiles.InsTabFile, ' optypes : (');
  450. if Length(S_Params)>max_operands then
  451. raise Exception.Create('Too many operands');
  452. for ParamIdx:=0 to max_operands-1 do
  453. begin
  454. if ParamIdx<>0 then
  455. Write(OutputFiles.InsTabFile,',');
  456. if ParamIdx<=High(S_Params) then
  457. Write(OutputFiles.InsTabFile,'[',OpTypeStr(FindParamType(S_Params[ParamIdx])),']')
  458. else
  459. Write(OutputFiles.InsTabFile,'[]');
  460. end;
  461. Writeln(OutputFiles.InsTabFile, ');');
  462. Write(OutputFiles.InsTabFile, ' opflags : (');
  463. if Length(S_Params)>max_operands then
  464. raise Exception.Create('Too many operands');
  465. for ParamIdx:=0 to max_operands-1 do
  466. begin
  467. if ParamIdx<>0 then
  468. Write(OutputFiles.InsTabFile,',');
  469. if ParamIdx<=High(S_Params) then
  470. Write(OutputFiles.InsTabFile,'[',FlagsToStr(FindParamType(S_Params[ParamIdx])),']')
  471. else
  472. Write(OutputFiles.InsTabFile,'[]');
  473. end;
  474. Writeln(OutputFiles.InsTabFile, ');');
  475. Writeln(OutputFiles.InsTabFile, ' codelen : ',S_Split[2],';');
  476. Writeln(OutputFiles.InsTabFile, ' code : (',S_Split[1],');');
  477. Writeln(OutputFiles.InsTabFile, ' support : [',OpSupportStr(S_Support),'];');
  478. Writeln(OutputFiles.InsTabFile, ' sizes : [',OpsizeStr(FindOpsize(S_Split[3])),'];');
  479. Write(OutputFiles.InsTabFile, ' )');
  480. end;
  481. end;
  482. Writeln(OutputFiles.OpFile,');');
  483. Writeln(OutputFiles.StdOpNames,');');
  484. Writeln(OutputFiles.NOpFile,OpCount,';');
  485. Writeln(OutputFiles.InsTabFile);
  486. Writeln(OutputFiles.InsTabFile,');');
  487. finally
  488. FreeAndNil(OutputFiles);
  489. CloseFile(InsDatFile);
  490. end;
  491. end.