taddset.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondadd() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondsetelement() }
  9. {****************************************************************}
  10. { DEFINES: }
  11. { FPC = Target is FreePascal compiler }
  12. {****************************************************************}
  13. { REMARKS: }
  14. { }
  15. { }
  16. { }
  17. {****************************************************************}
  18. Program tneg;
  19. var
  20. Err : boolean;
  21. type
  22. { DO NOT CHANGE THE VALUES OF THESE ENUMERATIONS! }
  23. tsmallenum = (dA,dB,dC,dd,de,df,dg,dh,di,dj,dk,dl,dm,dn,dop,dp,dq,dr);
  24. tasmop = (A_ABCD,
  25. A_ADD,A_ADDA,A_ADDI,A_ADDQ,A_ADDX,A_AND,A_ANDI,
  26. A_ASL,A_ASR,A_BCC,A_BCS,A_BEQ,A_BGE,A_BGT,A_BHI,
  27. A_BLE,A_BLS,A_BLT,A_BMI,A_BNE,A_BPL,A_BVC,A_BVS,
  28. A_BCHG,A_BCLR,A_BRA,A_BSET,A_BSR,A_BTST,A_CHK,
  29. A_CLR,A_CMP,A_CMPA,A_CMPI,A_CMPM,A_DBCC,A_DBCS,A_DBEQ,A_DBGE,
  30. A_DBGT,A_DBHI,A_DBLE,A_DBLS,A_DBLT,A_DBMI,A_DBNE,A_DBRA,
  31. A_DBPL,A_DBT,A_DBVC,A_DBVS,A_DBF,A_DIVS,A_DIVU,
  32. A_EOR,A_EORI,A_EXG,A_ILLEGAL,A_EXT,A_JMP,A_JSR,
  33. A_LEA,A_LINK,A_LSL,A_LSR,A_MOVE,A_MOVEA,A_MOVEI,A_MOVEQ,
  34. A_MOVEM,A_MOVEP,A_MULS,A_MULU,A_NBCD,A_NEG,A_NEGX,
  35. A_NOP,A_NOT,A_OR,A_ORI,A_PEA,A_ROL,A_ROR,A_ROXL,
  36. A_ROXR,A_RTR,A_RTS,A_SBCD,A_SCC,A_SCS,A_SEQ,A_SGE,
  37. A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,A_SNE,
  38. A_SPL,A_ST,A_SVC,A_SVS,A_SF,A_SUB,A_SUBA,A_SUBI,A_SUBQ,
  39. A_SUBX,A_SWAP,A_TAS,A_TRAP,A_TRAPV,A_TST,A_UNLK,
  40. A_RTE,A_RESET,A_STOP,
  41. { MC68010 instructions }
  42. A_BKPT,A_MOVEC,A_MOVES,A_RTD,
  43. { MC68020 instructions }
  44. A_BFCHG,A_BFCLR,A_BFEXTS,A_BFEXTU,A_BFFFO,
  45. A_BFINS,A_BFSET,A_BFTST,A_CALLM,A_CAS,A_CAS2,
  46. A_CHK2,A_CMP2,A_DIVSL,A_DIVUL,A_EXTB,A_PACK,A_RTM,
  47. A_TRAPCC,A_TRACS,A_TRAPEQ,A_TRAPF,A_TRAPGE,A_TRAPGT,
  48. A_TRAPHI,A_TRAPLE,A_TRAPLS,A_TRAPLT,A_TRAPMI,A_TRAPNE,
  49. A_TRAPPL,A_TRAPT,A_TRAPVC,A_TRAPVS,A_UNPK,
  50. { FPU Processor instructions - directly supported only. }
  51. { IEEE aware and misc. condition codes not supported }
  52. A_FABS,A_FADD,
  53. A_FBEQ,A_FBNE,A_FBNGT,A_FBGT,A_FBGE,A_FBNGE,
  54. A_FBLT,A_FBNLT,A_FBLE,A_FBGL,A_FBNGL,A_FBGLE,A_FBNGLE,
  55. A_FDBEQ,A_FDBNE,A_FDBGT,A_FDBNGT,A_FDBGE,A_FDBNGE,
  56. A_FDBLT,A_FDBNLT,A_FDBLE,A_FDBGL,A_FDBNGL,A_FDBGLE,A_FBDNGLE,
  57. A_FSEQ,A_FSNE,A_FSGT,A_FSNGT,A_FSGE,A_FSNGE,
  58. A_FSLT,A_FSNLT,A_FSLE,A_FSGL,A_FSNGL,A_FSGLE,A_FSNGLE,
  59. A_FCMP,A_FDIV,A_FMOVE,A_FMOVEM,
  60. A_FMUL,A_FNEG,A_FNOP,A_FSQRT,A_FSUB,A_FSGLDIV,
  61. A_FSFLMUL,A_FTST,
  62. A_FTRAPEQ,A_FTRAPNE,A_FTRAPGT,A_FTRAPNGT,A_FTRAPGE,A_FTRAPNGE,
  63. A_FTRAPLT,A_FTRAPNLT,A_FTRAPLE,A_FTRAPGL,A_FTRAPNGL,A_FTRAPGLE,A_FTRAPNGLE,
  64. { Protected instructions }
  65. A_CPRESTORE,A_CPSAVE,
  66. { FPU Unit protected instructions }
  67. { and 68030/68851 common MMU instructions }
  68. { (this may include 68040 MMU instructions) }
  69. A_FRESTORE,A_FSAVE,A_PFLUSH,A_PFLUSHA,A_PLOAD,A_PMOVE,A_PTEST,
  70. { Useful for assembly langage output }
  71. A_LABEL,A_NONE);
  72. type
  73. topset = set of tasmop;
  74. tsmallset = set of tsmallenum;
  75. const
  76. { NORMAL SETS }
  77. constset1 : array[1..3] of topset =
  78. (
  79. { 66 } { 210 } { 225 }
  80. ([A_MOVE, { 66 : LONG 2 - BIT 2 }
  81. A_FTST, { 210 : LONG 6 - BIT 18 }
  82. A_CPSAVE]),{ 225 : LONG 7 - BIT 1 }
  83. { 1..8 }
  84. ([A_ADD..A_ASL]),
  85. { 134 }
  86. ([A_CHK2])
  87. );
  88. constset2 : array[1..3] of topset =
  89. (
  90. ([A_MOVE,A_FTST,A_CPSAVE]),
  91. ([A_ADD..A_ASL]),
  92. ([A_CHK2])
  93. );
  94. { SMALL SETS }
  95. constset3 : array[1..3] of tsmallset =
  96. (
  97. ([DA, { 0 : LONG 0 : bit 0 }
  98. DD, { 3 : LONG 0 : bit 3 }
  99. DM]), { 12 : LONG 0 : bit 12 }
  100. ([DB..DI]), { 1..8 : LONG 0 : bits 1-8 }
  101. ([DR]) { 17 : LONG 0 : bit 17 }
  102. );
  103. constset4 : array[1..3] of tsmallset =
  104. (
  105. ([DA,DD,DM]),
  106. ([DB..DI]),
  107. ([DR])
  108. );
  109. procedure CheckPassed(passed:boolean);
  110. begin
  111. if passed then
  112. WriteLn('Success.')
  113. else
  114. begin
  115. WriteLn('Failure.');
  116. Halt(1);
  117. Err:=true;
  118. end;
  119. end;
  120. procedure SetTestEqual;
  121. { FPC_SET_COMP_SETS }
  122. var
  123. op2list :set of tasmop;
  124. oplist: set of tasmop;
  125. passed : boolean;
  126. Begin
  127. Write('Normal Set == Normal Set test...');
  128. passed := true;
  129. op2list:=[];
  130. oplist:=[];
  131. if not (oplist=op2list) then
  132. passed := false;
  133. if not (constset1[2] = constset2[2]) then
  134. passed := false;
  135. if (constset1[1] = constset2[2]) then
  136. passed := false;
  137. if not (constset1[1] = [A_MOVE,A_FTST,A_CPSAVE]) then
  138. passed := false;
  139. CheckPassed(passed);
  140. end;
  141. procedure SetTestNotEqual;
  142. { FPC_SET_COMP_SETS }
  143. var
  144. op2list :set of tasmop;
  145. oplist: set of tasmop;
  146. passed : boolean;
  147. Begin
  148. Write('Normal Set <> Normal Set test...');
  149. passed := true;
  150. op2list:=[];
  151. oplist:=[];
  152. if not (oplist=op2list) then
  153. passed := false;
  154. if (constset1[2] <> constset2[2]) then
  155. passed := false;
  156. if not (constset1[1] <> constset2[2]) then
  157. passed := false;
  158. { if ( [A_ADD] <> [A_ADD] ) then optimized out.
  159. passed := false;
  160. if ( [A_BLE..A_BPL] <> [A_BLE..A_BPL] ) then
  161. passed := false; }
  162. if (constset1[1] <> [A_MOVE,A_FTST,A_CPSAVE]) then
  163. passed := false;
  164. CheckPassed(passed);
  165. end;
  166. procedure SetTestLt;
  167. var
  168. op2list :set of tasmop;
  169. oplist: set of tasmop;
  170. passed : boolean;
  171. begin
  172. Write('Normal Set <= Normal Set test...');
  173. passed := true;
  174. if constset1[1] <= constset2[2] then
  175. passed := false;
  176. oplist := [];
  177. op2list := [A_MOVE];
  178. if op2list <= oplist then
  179. passed := false;
  180. oplist := [A_MOVE,A_CPRESTORE..A_CPSAVE];
  181. if oplist <= op2list then
  182. passed := false;
  183. CheckPassed(passed);
  184. end;
  185. Procedure SetTestAddOne;
  186. { FPC_SET_SET_BYTE }
  187. { FPC_SET_ADD_SETS }
  188. var
  189. op : tasmop;
  190. oplist: set of tasmop;
  191. Begin
  192. Write('Set + Set element testing...');
  193. op:=A_LABEL;
  194. oplist:=[];
  195. oplist:=oplist+[op];
  196. CheckPassed(oplist = [A_LABEL]);
  197. end;
  198. Procedure SetTestAddTwo;
  199. { SET_ADD_SETS }
  200. var
  201. op2list :set of tasmop;
  202. oplist: set of tasmop;
  203. Begin
  204. Write('Complex Set + Set element testing...');
  205. op2list:=[];
  206. oplist:=[];
  207. oplist:=[A_MOVE]+[A_JSR];
  208. op2list:=[A_LABEL];
  209. oplist:=op2list+oplist;
  210. CheckPassed(oplist = [A_MOVE,A_JSR,A_LABEL]);
  211. end;
  212. Procedure SetTestSubOne;
  213. { SET_SUB_SETS }
  214. var
  215. op2list :set of tasmop;
  216. oplist: set of tasmop;
  217. op :tasmop;
  218. passed : boolean;
  219. Begin
  220. Write('Set - Set element testing...');
  221. passed := true;
  222. op2list:=[];
  223. oplist:=[];
  224. op := A_TRACS;
  225. oplist:=[A_MOVE]+[A_JSR]+[op];
  226. op2list:=[A_MOVE]+[A_JSR];
  227. oplist:=oplist-op2list;
  228. if oplist <> [A_TRACS] then
  229. passed := false;
  230. oplist:=[A_MOVE]+[A_JSR]+[op];
  231. op2list:=[A_MOVE]+[A_JSR];
  232. oplist:=op2list-oplist;
  233. if oplist <> [] then
  234. passed := false;
  235. CheckPassed(passed);
  236. end;
  237. Procedure SetTestSubTwo;
  238. { FPC_SET_SUB_SETS }
  239. const
  240. b: tasmop = (A_BSR);
  241. var
  242. op2list :set of tasmop;
  243. oplist: set of tasmop;
  244. op : tasmop;
  245. passed : boolean;
  246. Begin
  247. Write('Complex Set - Set element testing...');
  248. op := A_BKPT;
  249. passed := true;
  250. oplist:=[A_MOVE]+[A_JSR]-[op];
  251. op2list:=[A_MOVE]+[A_JSR];
  252. if oplist <> op2list then
  253. passed := false;
  254. oplist := [A_MOVE];
  255. oplist := oplist - [A_MOVE];
  256. if oplist <> [] then
  257. passed := false;
  258. oplist := oplist + [b];
  259. if oplist <> [b] then
  260. passed := false;
  261. oplist := oplist - [b];
  262. if oplist <> [] then
  263. passed := false;
  264. CheckPassed(passed);
  265. end;
  266. Procedure SetTestMulSets;
  267. { FPC_SET_MUL_SETS }
  268. var
  269. op2list :set of tasmop;
  270. oplist: set of tasmop;
  271. passed : boolean;
  272. Begin
  273. passed := true;
  274. Write('Set * Set element testing...');
  275. op2list:=[];
  276. oplist:=[];
  277. oplist:=[A_MOVE]+[A_JSR];
  278. op2list:=[A_MOVE];
  279. oplist:=oplist*op2list;
  280. if oplist <> [A_JSR] then
  281. passed := false;
  282. oplist := [A_MOVE,A_FTST];
  283. op2list := [A_MOVE,A_FTST];
  284. oplist := oplist * op2list;
  285. if oplist <> [A_MOVE,A_FTST] then
  286. passed := false;
  287. CheckPassed(passed);
  288. end;
  289. procedure SetTestRange;
  290. var
  291. op2list :set of tasmop;
  292. oplist: set of tasmop;
  293. passed : boolean;
  294. op1 : tasmop;
  295. op2 : tasmop;
  296. begin
  297. passed := true;
  298. Write('Range Set + element testing...');
  299. op1 := A_ADD;
  300. op2 := A_ASL;
  301. oplist := [];
  302. oplist := [op1..op2];
  303. if oplist <> constset1[2] then
  304. passed := false;
  305. CheckPassed(passed);
  306. end;
  307. procedure SetTestByte;
  308. var
  309. op2list :set of tasmop;
  310. oplist: set of tasmop;
  311. passed : boolean;
  312. op1 : tasmop;
  313. op2 : tasmop;
  314. op : tasmop;
  315. begin
  316. Write('Simple Set + element testing...');
  317. passed := true;
  318. op := A_LABEL;
  319. oplist := [A_MOVE,op,A_JSR];
  320. if oplist <> [A_MOVE,A_LABEL,A_JSR] then
  321. passed := false;
  322. CheckPassed(passed);
  323. end;
  324. {------------------------------ TESTS FOR SMALL VALUES ---------------------}
  325. procedure SmallSetTestEqual;
  326. var
  327. op2list :set of tsmallenum;
  328. oplist: set of tsmallenum;
  329. passed : boolean;
  330. Begin
  331. Write('Small Set == Small Set test...');
  332. passed := true;
  333. op2list:=[];
  334. oplist:=[];
  335. if not (oplist=op2list) then
  336. passed := false;
  337. if not (constset3[2] = constset4[2]) then
  338. passed := false;
  339. if (constset3[1] = constset4[2]) then
  340. passed := false;
  341. if not (constset3[1] = [DA,DD,DM]) then
  342. passed := false;
  343. CheckPassed(passed);
  344. end;
  345. procedure SmallSetTestNotEqual;
  346. var
  347. op2list :set of tsmallenum;
  348. oplist: set of tsmallenum;
  349. passed : boolean;
  350. Begin
  351. Write('Small Set <> Small Set test...');
  352. passed := true;
  353. op2list:=[];
  354. oplist:=[];
  355. if not (oplist=op2list) then
  356. passed := false;
  357. if (constset3[2] <> constset4[2]) then
  358. passed := false;
  359. if not (constset3[1] <> constset4[2]) then
  360. passed := false;
  361. { if ( [A_ADD] <> [A_ADD] ) then optimized out.
  362. passed := false;
  363. if ( [A_BLE..A_BPL] <> [A_BLE..A_BPL] ) then
  364. passed := false; }
  365. if (constset3[1] <> [DA,DD,DM]) then
  366. passed := false;
  367. CheckPassed(passed);
  368. end;
  369. procedure SmallSetTestLt;
  370. var
  371. op2list :set of tsmallenum;
  372. oplist: set of tsmallenum;
  373. passed : boolean;
  374. begin
  375. Write('Small Set <= Small Set test...');
  376. passed := true;
  377. if constset3[1] <= constset4[2] then
  378. passed := false;
  379. oplist := [];
  380. op2list := [DC];
  381. if op2list <= oplist then
  382. passed := false;
  383. oplist := [DC,DF..DM];
  384. if oplist <= op2list then
  385. passed := false;
  386. CheckPassed(passed);
  387. end;
  388. Procedure SmallSetTestAddOne;
  389. var
  390. op : tsmallenum;
  391. oplist: set of tsmallenum;
  392. Begin
  393. Write('Small Set + Small Set element testing...');
  394. op:=DG;
  395. oplist:=[];
  396. oplist:=oplist+[op];
  397. CheckPassed( oplist = [DG] );
  398. end;
  399. Procedure SmallSetTestAddTwo;
  400. var
  401. op2list :set of tsmallenum;
  402. oplist: set of tsmallenum;
  403. Begin
  404. Write('Small Complex Set + Small Set element testing...');
  405. op2list:=[];
  406. oplist:=[];
  407. oplist:=[DG]+[DI];
  408. op2list:=[DM];
  409. oplist:=op2list+oplist;
  410. CheckPassed( oplist = [DG,DI,DM] );
  411. end;
  412. Procedure SmallSetTestSubOne;
  413. var
  414. op2list :set of tsmallenum;
  415. oplist: set of tsmallenum;
  416. op :tsmallenum;
  417. passed : boolean;
  418. Begin
  419. Write('Small Set - Small Set element testing...');
  420. passed := true;
  421. op2list:=[];
  422. oplist:=[];
  423. op := DL;
  424. oplist:=[DG]+[DI]+[op];
  425. op2list:=[DG]+[DI];
  426. oplist:=oplist-op2list;
  427. if oplist <> [DL] then
  428. passed := false;
  429. oplist:=[DG]+[DI]+[op];
  430. op2list:=[DG]+[DI];
  431. oplist:=op2list-oplist;
  432. if oplist <> [] then
  433. passed := false;
  434. CheckPassed(passed);
  435. end;
  436. Procedure SmallSetTestSubTwo;
  437. const
  438. b: tsmallenum = (DH);
  439. var
  440. op2list :set of tsmallenum;
  441. oplist: set of tsmallenum;
  442. op : tsmallenum;
  443. passed : boolean;
  444. Begin
  445. Write('Small Complex Set - Small Set element testing...');
  446. op := DL;
  447. passed := true;
  448. oplist:=[DG]+[DI]-[op];
  449. op2list:=[DG]+[DI];
  450. if oplist <> op2list then
  451. passed := false;
  452. oplist := [DG];
  453. oplist := oplist - [DG];
  454. if oplist <> [] then
  455. passed := false;
  456. oplist := oplist + [b];
  457. if oplist <> [b] then
  458. passed := false;
  459. oplist := oplist - [b];
  460. if oplist <> [] then
  461. passed := false;
  462. CheckPassed(passed);
  463. end;
  464. Procedure SmallSetTestMulSets;
  465. var
  466. op2list : set of tsmallenum;
  467. oplist: set of tsmallenum;
  468. passed : boolean;
  469. Begin
  470. passed := true;
  471. Write('Small Set * Small Set element testing...');
  472. op2list:=[];
  473. oplist:=[];
  474. oplist:=[DG]+[DI];
  475. op2list:=[DG];
  476. oplist:=oplist*op2list;
  477. if oplist <> [DI] then
  478. passed := false;
  479. oplist := [DG,DK];
  480. op2list := [DG,DK];
  481. oplist := oplist * op2list;
  482. if oplist <> [DG,DK] then
  483. passed := false;
  484. CheckPassed(passed);
  485. end;
  486. procedure SmallSetTestRange;
  487. var
  488. op2list :set of tsmallenum;
  489. oplist: set of tsmallenum;
  490. passed : boolean;
  491. op1 : tsmallenum;
  492. op2 : tsmallenum;
  493. begin
  494. passed := true;
  495. Write('Small Range Set + element testing...');
  496. op1 := DB;
  497. op2 := DI;
  498. oplist := [];
  499. oplist := [op1..op2];
  500. if oplist <> constset3[2] then
  501. passed := false;
  502. CheckPassed(passed);
  503. end;
  504. procedure SmallSetTestByte;
  505. var
  506. op2list : set of tsmallenum;
  507. oplist: set of tsmallenum;
  508. passed : boolean;
  509. op1 : tsmallenum;
  510. op2 : tsmallenum;
  511. op : tsmallenum;
  512. begin
  513. Write('Small Simple Set + element testing...');
  514. passed := true;
  515. op := DD;
  516. oplist := [DG,op,DI];
  517. if oplist <> [DG,DD,DI] then
  518. passed := false;
  519. CheckPassed(passed);
  520. end;
  521. (*
  522. const
  523. b: myenum = (dA);
  524. var
  525. enum: set of myenum;
  526. oplist: set of tasmop;
  527. l : word;
  528. Begin
  529. SetTestEqual;
  530. SetTestNotEqual;
  531. { small sets }
  532. enum:=[];
  533. { add }
  534. enum:=enum+[da];
  535. { subtract }
  536. enum:=enum-[da];
  537. if DA in enum then
  538. WriteLn('Found A_LABEL');
  539. { very large sets }
  540. { copy loop test }
  541. WRITELN('LARGE SETS:');
  542. oplist := [A_LABEL];
  543. { secondin test }
  544. if A_LABEL in oplist then
  545. WriteLn('TESTING SIMPLE SECOND_IN: PASSED.');
  546. { }
  547. oplist:=[];
  548. if A_LABEL in oplist then
  549. WriteLn('SECOND IN FAILED.');
  550. { SecondinSets;}
  551. SetSetByte;
  552. SetAddSets;
  553. SetSubSets;
  554. SetCompSets;
  555. SetMulSets;
  556. WRITELN('SMALL SETS:');
  557. SmallInSets;
  558. SmallAddSets;
  559. SmallSubSets;
  560. SmallCompSets;
  561. SmallMulSets;
  562. l:=word(A_CPRESTORE);
  563. if l = word(A_CPRESTORE) then
  564. Begin
  565. end;
  566. *)
  567. Begin
  568. WriteLn('----------------------- Normal sets -----------------------');
  569. { Normal sets }
  570. SetTestEqual;
  571. SetTestNotEqual;
  572. SetTestAddOne;
  573. SetTestAddTwo;
  574. SetTestSubOne;
  575. SetTestSubTwo;
  576. SetTestRange;
  577. SetTestLt;
  578. SetTestByte;
  579. { Small sets }
  580. WriteLn('----------------------- Small sets -----------------------');
  581. SmallSetTestEqual;
  582. SmallSetTestNotEqual;
  583. SmallSetTestAddOne;
  584. SmallSetTestAddTwo;
  585. SmallSetTestSubOne;
  586. SmallSetTestSubTwo;
  587. SmallSetTestRange;
  588. SmallSetTestLt;
  589. SmallSetTestByte;
  590. if Err then
  591. Halt(1);
  592. end.