tset2c.pp 11 KB

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