tset2.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. (*********************************************************************)
  2. (* Copyright (C) 1998, Carl Eric Codere *)
  3. (*********************************************************************)
  4. (* FPC (Free Pascal compiler) testsuite: SETS *)
  5. (* Tests the following: in, +, -, *, assignments. *)
  6. (* for small sets amd large sets, both with constants *)
  7. (* and variables. *)
  8. (*********************************************************************)
  9. const
  10. failed: boolean = false;
  11. type
  12. myenum = (dA,dB,dC,dd,dedf,dg,dh,di,dj,dk,dl,dm,dn);
  13. tasmop = (A_ABCD,
  14. A_ADD,A_ADDA,A_ADDI,A_ADDQ,A_ADDX,A_AND,A_ANDI,
  15. A_ASL,A_ASR,A_BCC,A_BCS,A_BEQ,A_BGE,A_BGT,A_BHI,
  16. A_BLE,A_BLS,A_BLT,A_BMI,A_BNE,A_BPL,A_BVC,A_BVS,
  17. A_BCHG,A_BCLR,A_BRA,A_BSET,A_BSR,A_BTST,A_CHK,
  18. A_CLR,A_CMP,A_CMPA,A_CMPI,A_CMPM,A_DBCC,A_DBCS,A_DBEQ,A_DBGE,
  19. A_DBGT,A_DBHI,A_DBLE,A_DBLS,A_DBLT,A_DBMI,A_DBNE,A_DBRA,
  20. A_DBPL,A_DBT,A_DBVC,A_DBVS,A_DBF,A_DIVS,A_DIVU,
  21. A_EOR,A_EORI,A_EXG,A_ILLEGAL,A_EXT,A_JMP,A_JSR,
  22. A_LEA,A_LINK,A_LSL,A_LSR,A_MOVE,A_MOVEA,A_MOVEI,A_MOVEQ,
  23. A_MOVEM,A_MOVEP,A_MULS,A_MULU,A_NBCD,A_NEG,A_NEGX,
  24. A_NOP,A_NOT,A_OR,A_ORI,A_PEA,A_ROL,A_ROR,A_ROXL,
  25. A_ROXR,A_RTR,A_RTS,A_SBCD,A_SCC,A_SCS,A_SEQ,A_SGE,
  26. A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,A_SNE,
  27. A_SPL,A_ST,A_SVC,A_SVS,A_SF,A_SUB,A_SUBA,A_SUBI,A_SUBQ,
  28. A_SUBX,A_SWAP,A_TAS,A_TRAP,A_TRAPV,A_TST,A_UNLK,
  29. A_RTE,A_RESET,A_STOP,
  30. { MC68010 instructions }
  31. A_BKPT,A_MOVEC,A_MOVES,A_RTD,
  32. { MC68020 instructions }
  33. A_BFCHG,A_BFCLR,A_BFEXTS,A_BFEXTU,A_BFFFO,
  34. A_BFINS,A_BFSET,A_BFTST,A_CALLM,A_CAS,A_CAS2,
  35. A_CHK2,A_CMP2,A_DIVSL,A_DIVUL,A_EXTB,A_PACK,A_RTM,
  36. A_TRAPCC,A_TRACS,A_TRAPEQ,A_TRAPF,A_TRAPGE,A_TRAPGT,
  37. A_TRAPHI,A_TRAPLE,A_TRAPLS,A_TRAPLT,A_TRAPMI,A_TRAPNE,
  38. A_TRAPPL,A_TRAPT,A_TRAPVC,A_TRAPVS,A_UNPK,
  39. { FPU Processor instructions - directly supported only. }
  40. { IEEE aware and misc. condition codes not supported }
  41. A_FABS,A_FADD,
  42. A_FBEQ,A_FBNE,A_FBNGT,A_FBGT,A_FBGE,A_FBNGE,
  43. A_FBLT,A_FBNLT,A_FBLE,A_FBGL,A_FBNGL,A_FBGLE,A_FBNGLE,
  44. A_FDBEQ,A_FDBNE,A_FDBGT,A_FDBNGT,A_FDBGE,A_FDBNGE,
  45. A_FDBLT,A_FDBNLT,A_FDBLE,A_FDBGL,A_FDBNGL,A_FDBGLE,A_FBDNGLE,
  46. A_FSEQ,A_FSNE,A_FSGT,A_FSNGT,A_FSGE,A_FSNGE,
  47. A_FSLT,A_FSNLT,A_FSLE,A_FSGL,A_FSNGL,A_FSGLE,A_FSNGLE,
  48. A_FCMP,A_FDIV,A_FMOVE,A_FMOVEM,
  49. A_FMUL,A_FNEG,A_FNOP,A_FSQRT,A_FSUB,A_FSGLDIV,
  50. A_FSFLMUL,A_FTST,
  51. A_FTRAPEQ,A_FTRAPNE,A_FTRAPGT,A_FTRAPNGT,A_FTRAPGE,A_FTRAPNGE,
  52. A_FTRAPLT,A_FTRAPNLT,A_FTRAPLE,A_FTRAPGL,A_FTRAPNGL,A_FTRAPGLE,A_FTRAPNGLE,
  53. { Protected instructions }
  54. A_CPRESTORE,A_CPSAVE,
  55. { FPU Unit protected instructions }
  56. { and 68030/68851 common MMU instructions }
  57. { (this may include 68040 MMU instructions) }
  58. A_FRESTORE,A_FSAVE,A_PFLUSH,A_PFLUSHA,A_PLOAD,A_PMOVE,A_PTEST,
  59. { Useful for assembly langage output }
  60. A_LABEL,A_NONE);
  61. Function X(y:myenum): myenum;
  62. Begin
  63. x:=y;
  64. end;
  65. Procedure SecondInSets;
  66. { SET_IN_BYTE TESTS }
  67. var
  68. op,op2 : tasmop;
  69. oplist: set of tasmop;
  70. Begin
  71. Write('TESTING SET_IN_BYTE:');
  72. oplist:=[];
  73. op:=A_JSR;
  74. if A_JSR in oplist then
  75. begin
  76. WriteLn('A_JSR in [] FAILED.');
  77. failed := true
  78. end
  79. else
  80. Writeln('A_JSR in [] PASSED.');
  81. if op in oplist then
  82. begin
  83. WriteLn('op(A_JSR) in [] FAILED.');
  84. failed := true
  85. end
  86. else
  87. Writeln('op (A_JSR) in [] PASSED.');
  88. op:=A_MOVE;
  89. oplist:=oplist+[A_MOVE];
  90. if A_MOVE in oplist then
  91. WriteLn('A_MOVE in ([]+[A_MOVE]) PASSED.')
  92. else
  93. begin
  94. Writeln('A_MOVE in ([]+[A_MOVE]) FAILED.');
  95. failed := true;
  96. end;
  97. if op in oplist then
  98. WriteLn('op(A_MOVE) in ([]+[A_MOVE]) PASSED.')
  99. else
  100. begin
  101. Writeln('op(A_MOVE) in ([]+[A_MOVE]) FAILED.');
  102. failed := true;
  103. end;
  104. op:=A_MOVE;
  105. oplist:=[];
  106. oplist:=[A_SUB]+[op];
  107. op2:=A_MOVE;
  108. if A_MOVE in oplist then
  109. WriteLn('A_MOVE in ([A_SUB]+[op(A_MOVE)]) PASSED.')
  110. else
  111. begin
  112. Writeln('A_MOVE in ([A_SUB]+[op(A_MOVE)]) FAILED.');
  113. failed := true
  114. end;
  115. if op2 in oplist then
  116. WriteLn('op2(A_MOVE) in ([A_SUB]+[op(A_MOVE)]) PASSED.')
  117. else
  118. begin
  119. Writeln('op2(A_MOVE) in ([A_SUB]+[op(A_MOVE)]) FAILED.');
  120. failed := true
  121. end;
  122. end;
  123. Procedure SetSetByte;
  124. { SET_SET_BYTE }
  125. var
  126. op : tasmop;
  127. oplist: set of tasmop;
  128. Begin
  129. Write('TESTING SET_SET_BYTE(1):');
  130. op:=A_LABEL;
  131. oplist:=[];
  132. oplist:=oplist+[op];
  133. if op in oplist then
  134. Begin
  135. WriteLn(' PASSED.');
  136. end
  137. else
  138. Begin
  139. WriteLn(' FAILED.');
  140. failed := true
  141. end;
  142. Write('TESTING INCLUDE:');
  143. op:=A_RTE;
  144. include(oplist,op);
  145. if op in oplist then
  146. Begin
  147. WriteLn(' PASSED.');
  148. end
  149. else
  150. Begin
  151. WriteLn(' FAILED.');
  152. failed := true;
  153. end;
  154. end;
  155. Procedure SetAddSets;
  156. { SET_ADD_SETS }
  157. var
  158. op2list :set of tasmop;
  159. oplist: set of tasmop;
  160. Begin
  161. op2list:=[];
  162. oplist:=[];
  163. oplist:=[A_MOVE]+[A_JSR];
  164. op2list:=[A_LABEL];
  165. oplist:=op2list+oplist;
  166. if A_MOVE in oplist then
  167. if A_LABEL in oplist then
  168. if A_JSR in oplist then
  169. WriteLn('TESTING SET_ADD_SETS: PASSED.')
  170. else
  171. begin
  172. WriteLn('TESTING SET_ADD_SETS: FAILED.');
  173. failed := true
  174. end
  175. else
  176. begin
  177. WriteLn('TESTING SET_ADD_SETS: FAILED.');
  178. failed := true
  179. end
  180. else
  181. begin
  182. WriteLn('TESTING SET_ADD_SETS: FAILED.');
  183. failed := true
  184. end;
  185. end;
  186. Procedure SetSubsets;
  187. { SET_SUB_SETS }
  188. var
  189. op2list :set of tasmop;
  190. oplist: set of tasmop;
  191. Begin
  192. op2list:=[];
  193. oplist:=[];
  194. oplist:=[A_MOVE]+[A_JSR];
  195. op2list:=[A_MOVE]+[A_JSR];
  196. oplist:=op2list-oplist;
  197. if (A_MOVE in oplist) or (A_LABEL in oplist) or (A_JSR in oplist) then
  198. begin
  199. WriteLn('TESTING SET_SUB_SETS: FAILED.');
  200. failed := true
  201. end
  202. else
  203. WriteLn('TESTING SET_SUB_SETS: PASSED.');
  204. oplist := [A_MOVE,A_RTE];
  205. exclude(oplist,A_MOVE);
  206. if (A_MOVE in oplist) then
  207. begin
  208. WriteLn('TESTING EXCLUDE: FAILED.');
  209. failed := true
  210. end
  211. else
  212. WriteLn('TESTING EXCLUDE: PASSED.')
  213. end;
  214. Procedure SetCompSets;
  215. { SET_COMP_SETS }
  216. var
  217. op2list :set of tasmop;
  218. oplist: set of tasmop;
  219. Begin
  220. op2list:=[];
  221. oplist:=[];
  222. oplist:=[A_MOVE]+[A_JSR];
  223. op2list:=[A_MOVE]+[A_JSR];
  224. if oplist=op2list then
  225. WriteLn('TESTING SET_COMP_SETS(1): PASSED.')
  226. else
  227. begin
  228. WriteLn('TESTING SET_COMP_SETS(1): FAILED.');
  229. failed := true
  230. end;
  231. oplist:=[A_MOVE];
  232. if oplist=op2list then
  233. begin
  234. WriteLn('TESTING SET_COMP_SETS(2): FAILED.');
  235. failed := true
  236. end
  237. else
  238. WriteLn('TESTING SET_COMP_SETS(2): PASSED.');
  239. end;
  240. Procedure SetMulSets;
  241. { SET_COMP_SETS }
  242. var
  243. op2list :set of tasmop;
  244. oplist: set of tasmop;
  245. Begin
  246. op2list:=[];
  247. oplist:=[];
  248. oplist:=[A_MOVE]+[A_JSR];
  249. op2list:=[A_MOVE];
  250. oplist:=oplist*op2list;
  251. if A_JSR in oplist then
  252. begin
  253. WriteLn('TESTING SET_MUL_SETS(1): FAILED.');
  254. failed := true
  255. end
  256. else
  257. WriteLn('TESTING SET_MUL_SETS(1): PASSED.');
  258. if A_MOVE in oplist then
  259. WriteLn('TESTING SET_MUL_SETS(2): PASSED.')
  260. else
  261. begin
  262. WriteLn('TESTING SET_MUL_SETS(2): FAILED.');
  263. failed := true
  264. end;
  265. end;
  266. {------------------------------ TESTS FOR SMALL VALUES ---------------------}
  267. Procedure SmallInSets;
  268. { SET_IN_BYTE TESTS }
  269. var
  270. op : myenum;
  271. oplist: set of myenum;
  272. Begin
  273. Write('TESTING IN_BYTE:');
  274. oplist:=[];
  275. op:=Dn;
  276. if op in oplist then
  277. begin
  278. WriteLn(' FAILED.');
  279. failed := true
  280. end;
  281. op:=dm;
  282. oplist:=oplist+[Dm];
  283. if op in oplist then
  284. WriteLn(' PASSED.')
  285. else
  286. begin
  287. WriteLn(' FAILED.');
  288. failed := true
  289. end;
  290. end;
  291. Procedure SmallSetByte;
  292. { SET_SET_BYTE }
  293. var
  294. op : myenum;
  295. oplist: set of myenum;
  296. Begin
  297. Write('TESTING SET_BYTE(1):');
  298. op:=DA;
  299. oplist:=[];
  300. oplist:=oplist+[op];
  301. if op in oplist then
  302. Begin
  303. WriteLn(' PASSED.');
  304. end
  305. else
  306. Begin
  307. WriteLn(' FAILED.');
  308. failed := true;
  309. end;
  310. end;
  311. Procedure SmallAddSets;
  312. { SET_ADD_SETS }
  313. var
  314. op2list :set of myenum;
  315. oplist: set of myenum;
  316. Begin
  317. op2list:=[];
  318. oplist:=[];
  319. oplist:=[DA]+[DC];
  320. op2list:=[DB];
  321. oplist:=op2list+oplist;
  322. if DA in oplist then
  323. if DC in oplist then
  324. if DB in oplist then
  325. WriteLn('TESTING SET_ADD_SETS: PASSED.')
  326. else
  327. begin
  328. WriteLn('TESTING ADD_SETS: FAILED.');
  329. failed := true
  330. end
  331. else
  332. begin
  333. WriteLn('TESTING ADD_SETS: FAILED.');
  334. failed := true
  335. end
  336. else
  337. begin
  338. WriteLn('TESTING ADD_SETS: FAILED.');
  339. failed := true
  340. end;
  341. end;
  342. Procedure SmallSubsets;
  343. { SET_SUB_SETS }
  344. var
  345. op2list :set of myenum;
  346. oplist: set of myenum;
  347. Begin
  348. op2list:=[];
  349. oplist:=[];
  350. oplist:=[DA]+[DC];
  351. op2list:=[DA]+[DC];
  352. oplist:=op2list-oplist;
  353. if (DA in oplist) or (DB in oplist) or (DC in oplist) then
  354. begin
  355. WriteLn('TESTING SUB_SETS: FAILED.');
  356. failed := true
  357. end
  358. else
  359. WriteLn('TESTING SUB_SETS: PASSED.')
  360. end;
  361. Procedure SmallCompSets;
  362. { SET_COMP_SETS }
  363. var
  364. op2list :set of myenum;
  365. oplist: set of myenum;
  366. Begin
  367. op2list:=[];
  368. oplist:=[];
  369. oplist:=[DA]+[DC];
  370. op2list:=[DA]+[DC];
  371. if oplist=op2list then
  372. WriteLn('TESTING COMP_SETS(1): PASSED.')
  373. else
  374. begin
  375. WriteLn('TESTING COMP_SETS(1): FAILED.');
  376. failed := true
  377. end;
  378. oplist:=[DA];
  379. if oplist=op2list then
  380. begin
  381. WriteLn('TESTING COMP_SETS(2): FAILED.');
  382. failed := true
  383. end
  384. else
  385. WriteLn('TESTING COMP_SETS(2): PASSED.');
  386. end;
  387. Procedure SmallMulSets;
  388. { SET_COMP_SETS }
  389. var
  390. op2list :set of myenum;
  391. oplist: set of myenum;
  392. Begin
  393. op2list:=[];
  394. oplist:=[];
  395. oplist:=[DA]+[DC];
  396. op2list:=[DA];
  397. oplist:=oplist*op2list;
  398. if DC in oplist then
  399. begin
  400. WriteLn('TESTING MUL_SETS(1): FAILED.');
  401. failed := true
  402. end
  403. else
  404. WriteLn('TESTING MUL_SETS(1): PASSED.');
  405. if DA in oplist then
  406. WriteLn('TESTING MUL_SETS(2): PASSED.')
  407. else
  408. begin
  409. WriteLn('TESTING MUL_SETS(2): FAILED.');
  410. failed := true
  411. end;
  412. end;
  413. const
  414. b: myenum = (dA);
  415. var
  416. enum: set of myenum;
  417. oplist: set of tasmop;
  418. l : word;
  419. Begin
  420. { small sets }
  421. enum:=[];
  422. { add }
  423. enum:=enum+[da];
  424. { subtract }
  425. enum:=enum-[da];
  426. if DA in enum then
  427. WriteLn('Found A_LABEL');
  428. { very large sets }
  429. { copy loop test }
  430. WRITELN('LARGE SETS:');
  431. oplist := [A_LABEL];
  432. { secondin test }
  433. if A_LABEL in oplist then
  434. WriteLn('TESTING SIMPLE SECOND_IN: PASSED.')
  435. else
  436. begin
  437. failed := true
  438. end;
  439. { }
  440. oplist:=[];
  441. if A_LABEL in oplist then
  442. begin
  443. WriteLn('SECOND IN FAILED.');
  444. failed := true
  445. end;
  446. SecondinSets;
  447. SetSetByte;
  448. SetAddSets;
  449. SetSubSets;
  450. SetCompSets;
  451. SetMulSets;
  452. WRITELN('SMALL SETS:');
  453. SmallInSets;
  454. SmallAddSets;
  455. SmallSubSets;
  456. SmallCompSets;
  457. SmallMulSets;
  458. l:=word(A_CPRESTORE);
  459. if l = word(A_CPRESTORE) then
  460. Begin
  461. end
  462. else failed := true;
  463. if failed then
  464. begin
  465. WriteLn('One or more test failed');
  466. Halt(1);
  467. end;
  468. end.