2
0

mk68kins.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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..64] 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-imm>';
  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. OT_PC_DISP16,OT_PC_IDX_DISP8,OT_IMMEDIATE];
  242. flags: []),
  243. (id: '<ea-data-alter>';
  244. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  245. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  246. flags: []),
  247. (id: '<ea-data-alter-bf>';
  248. modes: [OT_DATA,OT_ADDR_INDIR,
  249. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  250. flags: [OF_BITFIELD]),
  251. (id: '<ea-data-control-bf>';
  252. modes: [OT_DATA,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: [OF_BITFIELD]),
  256. (id: '<ea-control>';
  257. modes: [OT_ADDR_INDIR,
  258. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG,
  259. OT_PC_DISP16,OT_PC_IDX_DISP8];
  260. flags: []),
  261. (id: '<ea-control-alter>';
  262. modes: [OT_ADDR_INDIR,
  263. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  264. flags: []),
  265. (id: '<ea-alter>';
  266. modes: [OT_DATA,OT_ADDR,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  267. OT_ADDR_DISP16,OT_ADDR_IDX_DISP8,OT_ABS_SHORT,OT_ABS_LONG];
  268. flags: []),
  269. (id: '<ea-movep>';
  270. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16];
  271. flags: []),
  272. (id: '<cf-ea-mem-alter>';
  273. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  274. OT_ADDR_DISP16];
  275. flags: []),
  276. (id: '<cf-ea-data-alter>';
  277. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  278. OT_ADDR_DISP16];
  279. flags: []),
  280. (id: '<cf-ea-float>';
  281. modes: [OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  282. OT_ADDR_DISP16,OT_PC_DISP16];
  283. flags: []),
  284. (id: '<cf-ea-data-float>';
  285. modes: [OT_DATA,OT_ADDR_INDIR,OT_ADDR_INDIR_POSTINC,OT_ADDR_INDIR_PREDEC,
  286. OT_ADDR_DISP16,OT_PC_DISP16];
  287. flags: []),
  288. (id: '<cf-ea-movem>';
  289. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16];
  290. flags: []),
  291. (id: '<cf-ea-fmovem-src>';
  292. modes: [OT_ADDR_INDIR,OT_ADDR_DISP16,OT_PC_DISP16];
  293. flags: [])
  294. );
  295. function OpTypeStr(idx: integer): string;
  296. var
  297. optyp: TOperandType;
  298. begin
  299. result:='';
  300. for optyp in ParamTypes[idx].modes do
  301. if result='' then
  302. WriteStr(result,optyp)
  303. else
  304. WriteStr(result,result,', ',optyp);
  305. end;
  306. function FlagsToStr(idx: integer): string;
  307. var
  308. flagtyp: TOperandFlags;
  309. begin
  310. result:='';
  311. for flagtyp in ParamTypes[idx].flags do
  312. if result='' then
  313. WriteStr(result,flagtyp)
  314. else
  315. WriteStr(result,result,', ',flagtyp);
  316. end;
  317. function OpSizeStr(idx: integer): string;
  318. var
  319. opsizeflag: TOpsizeFlag;
  320. begin
  321. result:='';
  322. for opsizeflag in Opsizes[idx].flags do
  323. if result='' then
  324. WriteStr(result,opsizeflag)
  325. else
  326. WriteStr(result,result,', ',opsizeflag);
  327. end;
  328. function OpSupportStr(const sa: TStringArray): string;
  329. var
  330. i: integer;
  331. s: string;
  332. flag: TOpSupported;
  333. idx: integer;
  334. begin
  335. result:='';
  336. for s in sa do
  337. begin
  338. idx:=-1;
  339. for I:=Low(OpSupport) to High(OpSupport) do
  340. if OpSupport[I].id=s then
  341. begin
  342. idx:=i;
  343. flag:=OpSupport[i].flag;
  344. break;
  345. end;
  346. if idx < 0 then
  347. raise Exception.Create('Invalid support type: '''+s+'''');
  348. if result='' then
  349. WriteStr(result,flag)
  350. else
  351. WriteStr(result,result,', ',flag);
  352. end;
  353. end;
  354. type
  355. { T68kInsDatOutputFiles }
  356. T68kInsDatOutputFiles = class
  357. public
  358. OpFile: TextFile;
  359. NOpFile: TextFile;
  360. StdOpNames: TextFile;
  361. InsTabFile: TextFile;
  362. constructor Create;
  363. destructor Destroy;override;
  364. end;
  365. constructor T68kInsDatOutputFiles.Create;
  366. begin
  367. AssignFile(OpFile,'m68kop.inc');
  368. Rewrite(OpFile);
  369. Writeln(OpFile,HeaderStr);
  370. Writeln(OpFile,'(');
  371. AssignFile(NOpFile,'m68knop.inc');
  372. Rewrite(NOpFile);
  373. Writeln(NOpFile,HeaderStr);
  374. AssignFile(StdOpNames,'m68kstd.inc');
  375. Rewrite(StdOpNames);
  376. Writeln(StdOpNames,HeaderStr);
  377. Writeln(StdOpNames,'(');
  378. AssignFile(InsTabFile,'m68ktab.inc');
  379. Rewrite(InsTabFile);
  380. Writeln(InsTabFile,HeaderStr);
  381. Writeln(InsTabFile,'(');
  382. end;
  383. destructor T68kInsDatOutputFiles.Destroy;
  384. begin
  385. CloseFile(OpFile);
  386. CloseFile(NOpFile);
  387. CloseFile(StdOpNames);
  388. CloseFile(InsTabFile);
  389. inherited Destroy;
  390. end;
  391. function FindParamType(const ParamTypeStr: string): Integer;
  392. var
  393. I: Integer;
  394. begin
  395. for I:=Low(ParamTypes) to High(ParamTypes) do
  396. if ParamTypes[I].id=ParamTypeStr then
  397. exit(I);
  398. raise Exception.Create('Invalid param type: '''+ParamTypeStr+'''');
  399. end;
  400. function FindOpsize(const SizeStr: string): Integer;
  401. var
  402. I: Integer;
  403. begin
  404. for I:=Low(Opsizes) to High(Opsizes) do
  405. if Opsizes[I].id=SizeStr then
  406. exit(I);
  407. raise Exception.Create('Invalid size: '''+SizeStr+'''');
  408. end;
  409. var
  410. InsDatFile: TextFile;
  411. OutputFiles: T68kInsDatOutputFiles=nil;
  412. S, op, ParamsStr: string;
  413. FirstIns: Boolean=true;
  414. OpCount: Integer=0;
  415. S_Split, S_Params, S_Support: TStringArray;
  416. ParamIdx: Integer;
  417. begin
  418. writeln('FPC m68k Instruction Table Converter Version ',Version);
  419. AssignFile(InsDatFile,'./m68kins.dat');
  420. Reset(InsDatFile);
  421. try
  422. OutputFiles:=T68kInsDatOutputFiles.Create;
  423. while not EoF(InsDatFile) do
  424. begin
  425. Readln(InsDatFile,S);
  426. S:=Trim(S);
  427. if AnsiStartsStr(';',S) then
  428. continue
  429. else if AnsiStartsStr('[',S) then
  430. begin
  431. op:=Copy(S,2,Length(S)-2);
  432. if not FirstIns then
  433. begin
  434. Writeln(OutputFiles.OpFile,',');
  435. Writeln(OutputFiles.StdOpNames,',');
  436. end;
  437. FirstIns:=False;
  438. Write(OutputFiles.OpFile,'A_'+op);
  439. Write(OutputFiles.StdOpNames,''''+LowerCase(op)+'''');
  440. end
  441. else if S<>'' then
  442. begin
  443. Inc(OpCount);
  444. if OpCount<>1 then
  445. Writeln(OutputFiles.InsTabFile,',');
  446. S_Split:=S.Split(' ',TStringSplitOptions.ExcludeEmpty);
  447. S_Params:=S_Split[0].Split(',',TStringSplitOptions.ExcludeEmpty);
  448. S_Support:=S_Split[4].Split(',',TStringSplitOptions.ExcludeEmpty);
  449. if (Length(S_Params)=1) and (S_Params[0]='void') then
  450. SetLength(S_Params,0);
  451. Writeln(OutputFiles.InsTabFile,' (');
  452. Writeln(OutputFiles.InsTabFile,' opcode : A_',op,';');
  453. Writeln(OutputFiles.InsTabFile,' ops : ',Length(S_Params),';');
  454. Write(OutputFiles.InsTabFile, ' optypes : (');
  455. if Length(S_Params)>max_operands then
  456. raise Exception.Create('Too many operands');
  457. for ParamIdx:=0 to max_operands-1 do
  458. begin
  459. if ParamIdx<>0 then
  460. Write(OutputFiles.InsTabFile,',');
  461. if ParamIdx<=High(S_Params) then
  462. Write(OutputFiles.InsTabFile,'[',OpTypeStr(FindParamType(S_Params[ParamIdx])),']')
  463. else
  464. Write(OutputFiles.InsTabFile,'[]');
  465. end;
  466. Writeln(OutputFiles.InsTabFile, ');');
  467. Write(OutputFiles.InsTabFile, ' opflags : (');
  468. if Length(S_Params)>max_operands then
  469. raise Exception.Create('Too many operands');
  470. for ParamIdx:=0 to max_operands-1 do
  471. begin
  472. if ParamIdx<>0 then
  473. Write(OutputFiles.InsTabFile,',');
  474. if ParamIdx<=High(S_Params) then
  475. Write(OutputFiles.InsTabFile,'[',FlagsToStr(FindParamType(S_Params[ParamIdx])),']')
  476. else
  477. Write(OutputFiles.InsTabFile,'[]');
  478. end;
  479. Writeln(OutputFiles.InsTabFile, ');');
  480. Writeln(OutputFiles.InsTabFile, ' codelen : ',S_Split[2],';');
  481. Writeln(OutputFiles.InsTabFile, ' code : (',S_Split[1],');');
  482. Writeln(OutputFiles.InsTabFile, ' support : [',OpSupportStr(S_Support),'];');
  483. Writeln(OutputFiles.InsTabFile, ' sizes : [',OpsizeStr(FindOpsize(S_Split[3])),'];');
  484. Write(OutputFiles.InsTabFile, ' )');
  485. end;
  486. end;
  487. Writeln(OutputFiles.OpFile,');');
  488. Writeln(OutputFiles.StdOpNames,');');
  489. Writeln(OutputFiles.NOpFile,OpCount,';');
  490. Writeln(OutputFiles.InsTabFile);
  491. Writeln(OutputFiles.InsTabFile,');');
  492. finally
  493. FreeAndNil(OutputFiles);
  494. CloseFile(InsDatFile);
  495. end;
  496. end.