tsubst.pp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondsubscriptn(), partial secondload() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. {****************************************************************}
  9. { DEFINES: VERBOSE = Write test information to screen }
  10. { FPC = Target is FreePascal compiler }
  11. {****************************************************************}
  12. { REMARKS: }
  13. { }
  14. { }
  15. { }
  16. {****************************************************************}
  17. Program tsubst1;
  18. {$mode objfpc}
  19. {$IFNDEF FPC}
  20. type smallint = integer;
  21. {$ENDIF}
  22. const
  23. { Should be equal to the maximum offset possible in indirect addressing
  24. mode with displacement. (CPU SPECIFIC) }
  25. {$ifdef cpu86}
  26. MAX_DISP = 65535;
  27. {$endif}
  28. {$ifdef cpu68k}
  29. MAX_DISP = 32767;
  30. {$endif}
  31. { These different alignments are described in the PowerPC ABI
  32. supplement, they should represent most possible cases.
  33. }
  34. type
  35. tlevel1rec = record
  36. c: byte;
  37. end;
  38. tlevel2rec = record
  39. c: byte;
  40. d: byte;
  41. s: word;
  42. n: longint;
  43. end;
  44. tlevel3rec = record
  45. c: byte;
  46. s: word;
  47. end;
  48. tlevel4rec = record
  49. c: byte;
  50. i : int64;
  51. s: word;
  52. end;
  53. tlevel5rec = record
  54. c: byte;
  55. s: word;
  56. j: longint;
  57. end;
  58. tlevel1rec_big = record
  59. fill : array[1..MAX_DISP] of byte;
  60. c: byte;
  61. end;
  62. tlevel2rec_big = record
  63. fill : array[1..MAX_DISP] of byte;
  64. c: byte;
  65. d: byte;
  66. s: word;
  67. n: longint;
  68. end;
  69. tlevel3rec_big = record
  70. fill : array[1..MAX_DISP] of byte;
  71. c: byte;
  72. s: word;
  73. end;
  74. tlevel4rec_big = record
  75. fill : array[1..MAX_DISP] of byte;
  76. c: byte;
  77. i : int64;
  78. s: word;
  79. end;
  80. tlevel5rec_big = record
  81. fill : array[1..MAX_DISP] of byte;
  82. c: byte;
  83. s: word;
  84. j: longint;
  85. end;
  86. { packed record, for testing misaligned access }
  87. tlevel1rec_packed = packed record
  88. c: byte;
  89. end;
  90. tlevel2rec_packed = packed record
  91. c: byte;
  92. d: byte;
  93. s: word;
  94. n: longint;
  95. end;
  96. tlevel3rec_packed = packed record
  97. c: byte;
  98. s: word;
  99. end;
  100. tlevel4rec_packed = packed record
  101. c: byte;
  102. i : int64;
  103. s: word;
  104. end;
  105. tlevel5rec_packed = packed record
  106. c: byte;
  107. s: word;
  108. j: longint;
  109. end;
  110. tclass1 = class
  111. fill : array[1..MAX_DISP] of byte;
  112. c: byte;
  113. s: word;
  114. j: longint;
  115. end;
  116. tclass2 = class
  117. c: byte;
  118. s: word;
  119. i: int64;
  120. end;
  121. { test with global variables }
  122. const
  123. RESULT_U8BIT = $55;
  124. RESULT_U16BIT = $500F;
  125. RESULT_S32BIT = $500F0000;
  126. RESULT_S64BIT = $500F0000;
  127. level1rec : tlevel1rec =
  128. (
  129. c: RESULT_U8BIT
  130. );
  131. level2rec : tlevel2rec =
  132. (
  133. c: RESULT_U8BIT;
  134. d: RESULT_U8BIT;
  135. s: RESULT_U16BIT;
  136. n: RESULT_S32BIT;
  137. );
  138. level3rec : tlevel3rec =
  139. (
  140. c: RESULT_U8BIT;
  141. s: RESULT_U16BIT;
  142. );
  143. level4rec : tlevel4rec =
  144. (
  145. c: RESULT_U8BIT;
  146. i : RESULT_S64BIT;
  147. s : RESULT_U16BIT
  148. );
  149. level5rec : tlevel5rec =
  150. (
  151. c: RESULT_U8BIT;
  152. s: RESULT_U16BIT;
  153. j: RESULT_S32BIT;
  154. );
  155. level1rec_packed : tlevel1rec_packed =
  156. (
  157. c: RESULT_U8BIT
  158. );
  159. level2rec_packed : tlevel2rec_packed =
  160. (
  161. c: RESULT_U8BIT;
  162. d: RESULT_U8BIT;
  163. s: RESULT_U16BIT;
  164. n: RESULT_S32BIT;
  165. );
  166. level3rec_packed : tlevel3rec_packed =
  167. (
  168. c: RESULT_U8BIT;
  169. s: RESULT_U16BIT;
  170. );
  171. level4rec_packed : tlevel4rec_packed =
  172. (
  173. c: RESULT_U8BIT;
  174. i : RESULT_S64BIT;
  175. s : RESULT_U16BIT
  176. );
  177. level5rec_packed : tlevel5rec_packed =
  178. (
  179. c: RESULT_U8BIT;
  180. s: RESULT_U16BIT;
  181. j: RESULT_S32BIT;
  182. );
  183. procedure fail;
  184. begin
  185. WriteLn('Failure.');
  186. halt(1);
  187. end;
  188. var
  189. c,d: byte;
  190. s: word;
  191. n,j: longint;
  192. i: int64;
  193. failed : boolean;
  194. class1 : tclass1;
  195. class2 : tclass2;
  196. procedure clear_globals;
  197. begin
  198. c:=0;
  199. d:=0;
  200. s:=0;
  201. n:=0;
  202. j:=0;
  203. i:=0;
  204. class1:=nil;
  205. class2:=nil
  206. end;
  207. function getclass : tclass1;
  208. begin
  209. getclass := class1;
  210. end;
  211. function getclass2: tclass2;
  212. begin
  213. getclass2 := class2;
  214. end;
  215. {$ifndef cpu68k}
  216. procedure testlocal_big_1;
  217. var
  218. local1rec_big : tlevel1rec_big;
  219. begin
  220. clear_globals;
  221. local1rec_big.c := RESULT_U8BIT;
  222. c:= local1rec_big.c;
  223. if c <> RESULT_U8BIT then
  224. failed := true;
  225. end;
  226. procedure testlocal_big_2;
  227. var
  228. local2rec_big : tlevel2rec_big;
  229. begin
  230. clear_globals;
  231. { setup values - assign }
  232. local2rec_big.c := RESULT_U8BIT;
  233. local2rec_big.d := RESULT_U8BIT;
  234. local2rec_big.s := RESULT_U16BIT;
  235. local2rec_big.n := RESULT_S32BIT;
  236. { load values - load }
  237. c:= local2rec_big.c;
  238. if c <> RESULT_U8BIT then
  239. failed := true;
  240. d:= local2rec_big.d;
  241. if d <> RESULT_U8BIT then
  242. failed := true;
  243. s:= local2rec_big.s;
  244. if s <> RESULT_U16BIT then
  245. failed := true;
  246. n:= local2rec_big.n;
  247. if n <> RESULT_S32BIT then
  248. failed := true;
  249. end;
  250. procedure testlocal_big_3;
  251. var
  252. local3rec_big : tlevel3rec_big;
  253. begin
  254. clear_globals;
  255. { setup values - assign }
  256. local3rec_big.c := RESULT_U8BIT;
  257. local3rec_big.s := RESULT_U16BIT;
  258. c:= local3rec_big.c;
  259. if c <> RESULT_U8BIT then
  260. failed := true;
  261. s:= local3rec_big.s;
  262. if s <> RESULT_U16BIT then
  263. failed := true;
  264. end;
  265. procedure testlocal_big_4;
  266. var
  267. local4rec_big : tlevel4rec_big;
  268. begin
  269. clear_globals;
  270. { setup values - assign }
  271. local4rec_big.c := RESULT_U8BIT;
  272. local4rec_big.i := RESULT_S64BIT;
  273. local4rec_big.s := RESULT_U16BIT;
  274. c:= local4rec_big.c;
  275. if c <> RESULT_U8BIT then
  276. failed := true;
  277. i:= local4rec_big.i;
  278. if i <> RESULT_S64BIT then
  279. failed := true;
  280. s:= local4rec_big.s;
  281. if s <> RESULT_U16BIT then
  282. failed := true;
  283. end;
  284. procedure testlocal_big_5;
  285. var
  286. local5rec_big : tlevel5rec_big;
  287. begin
  288. clear_globals;
  289. { setup values - assign }
  290. local5rec_big.c := RESULT_U8BIT;
  291. local5rec_big.s := RESULT_U16BIT;
  292. local5rec_big.j := RESULT_S32BIT;
  293. c:= local5rec_big.c;
  294. if c <> RESULT_U8BIT then
  295. failed := true;
  296. s:= local5rec_big.s;
  297. if s <> RESULT_U16BIT then
  298. failed := true;
  299. j:= local5rec_big.j;
  300. if j <> RESULT_S32BIT then
  301. failed := true;
  302. end;
  303. {$endif}
  304. procedure testlocals;
  305. var
  306. local1rec : tlevel1rec_packed;
  307. local2rec : tlevel2rec_packed;
  308. local3rec : tlevel3rec_packed;
  309. local4rec : tlevel4rec_packed;
  310. local5rec : tlevel5rec_packed;
  311. begin
  312. { normal record access }
  313. Write('Non-Aligned simple local record access (secondvecn())...');
  314. failed := false;
  315. clear_globals;
  316. clear_globals;
  317. local1rec.c := RESULT_U8BIT;
  318. c:= local1rec.c;
  319. if c <> RESULT_U8BIT then
  320. failed := true;
  321. clear_globals;
  322. { setup values - assign }
  323. local2rec.c := RESULT_U8BIT;
  324. local2rec.d := RESULT_U8BIT;
  325. local2rec.s := RESULT_U16BIT;
  326. local2rec.n := RESULT_S32BIT;
  327. { load values - load }
  328. c:= local2rec.c;
  329. if c <> RESULT_U8BIT then
  330. failed := true;
  331. d:= local2rec.d;
  332. if d <> RESULT_U8BIT then
  333. failed := true;
  334. s:= local2rec.s;
  335. if s <> RESULT_U16BIT then
  336. failed := true;
  337. n:= local2rec.n;
  338. if n <> RESULT_S32BIT then
  339. failed := true;
  340. clear_globals;
  341. { setup values - assign }
  342. local3rec.c := RESULT_U8BIT;
  343. local3rec.s := RESULT_U16BIT;
  344. c:= local3rec.c;
  345. if c <> RESULT_U8BIT then
  346. failed := true;
  347. s:= local3rec.s;
  348. if s <> RESULT_U16BIT then
  349. failed := true;
  350. clear_globals;
  351. { setup values - assign }
  352. local4rec.c := RESULT_U8BIT;
  353. local4rec.i := RESULT_S64BIT;
  354. local4rec.s := RESULT_U16BIT;
  355. c:= local4rec.c;
  356. if c <> RESULT_U8BIT then
  357. failed := true;
  358. i:= local4rec.i;
  359. if i <> RESULT_S64BIT then
  360. failed := true;
  361. s:= local4rec.s;
  362. if s <> RESULT_U16BIT then
  363. failed := true;
  364. clear_globals;
  365. { setup values - assign }
  366. local5rec.c := RESULT_U8BIT;
  367. local5rec.s := RESULT_U16BIT;
  368. local5rec.j := RESULT_S32BIT;
  369. c:= local5rec.c;
  370. if c <> RESULT_U8BIT then
  371. failed := true;
  372. s:= local5rec.s;
  373. if s <> RESULT_U16BIT then
  374. failed := true;
  375. j:= local5rec.j;
  376. if j <> RESULT_S32BIT then
  377. failed := true;
  378. if failed then
  379. fail
  380. else
  381. WriteLN('Passed!');
  382. end;
  383. {---------------------------}
  384. var
  385. level1rec_big : tlevel1rec_big;
  386. level2rec_big : tlevel2rec_big;
  387. level3rec_big : tlevel3rec_big;
  388. level4rec_big : tlevel4rec_big;
  389. level5rec_big : tlevel5rec_big;
  390. begin
  391. { normal record access }
  392. Write('Aligned simple global record access (secondvecn())...');
  393. failed := false;
  394. clear_globals;
  395. c:= level1rec.c;
  396. if c <> RESULT_U8BIT then
  397. failed := true;
  398. clear_globals;
  399. c:= level2rec.c;
  400. if c <> RESULT_U8BIT then
  401. failed := true;
  402. d:= level2rec.d;
  403. if d <> RESULT_U8BIT then
  404. failed := true;
  405. s:= level2rec.s;
  406. if s <> RESULT_U16BIT then
  407. failed := true;
  408. n:= level2rec.n;
  409. if n <> RESULT_S32BIT then
  410. failed := true;
  411. clear_globals;
  412. c:= level3rec.c;
  413. if c <> RESULT_U8BIT then
  414. failed := true;
  415. s:= level3rec.s;
  416. if s <> RESULT_U16BIT then
  417. failed := true;
  418. clear_globals;
  419. c:= level4rec.c;
  420. if c <> RESULT_U8BIT then
  421. failed := true;
  422. i:= level4rec.i;
  423. if i <> RESULT_S64BIT then
  424. failed := true;
  425. s:= level4rec.s;
  426. if s <> RESULT_U16BIT then
  427. failed := true;
  428. clear_globals;
  429. c:= level5rec.c;
  430. if c <> RESULT_U8BIT then
  431. failed := true;
  432. s:= level5rec.s;
  433. if s <> RESULT_U16BIT then
  434. failed := true;
  435. j:= level5rec.j;
  436. if j <> RESULT_S32BIT then
  437. failed := true;
  438. if failed then
  439. fail
  440. else
  441. WriteLN('Passed!');
  442. Write('Non-Aligned simple global record access (secondvecn())...');
  443. clear_globals;
  444. c:= level1rec_packed.c;
  445. if c <> RESULT_U8BIT then
  446. failed := true;
  447. clear_globals;
  448. c:= level2rec_packed.c;
  449. if c <> RESULT_U8BIT then
  450. failed := true;
  451. d:= level2rec_packed.d;
  452. if d <> RESULT_U8BIT then
  453. failed := true;
  454. s:= level2rec_packed.s;
  455. if s <> RESULT_U16BIT then
  456. failed := true;
  457. n:= level2rec_packed.n;
  458. if n <> RESULT_S32BIT then
  459. failed := true;
  460. clear_globals;
  461. c:= level3rec_packed.c;
  462. if c <> RESULT_U8BIT then
  463. failed := true;
  464. s:= level3rec_packed.s;
  465. if s <> RESULT_U16BIT then
  466. failed := true;
  467. clear_globals;
  468. c:= level4rec_packed.c;
  469. if c <> RESULT_U8BIT then
  470. failed := true;
  471. i:= level4rec_packed.i;
  472. if i <> RESULT_S64BIT then
  473. failed := true;
  474. s:= level4rec_packed.s;
  475. if s <> RESULT_U16BIT then
  476. failed := true;
  477. clear_globals;
  478. c:= level5rec_packed.c;
  479. if c <> RESULT_U8BIT then
  480. failed := true;
  481. s:= level5rec_packed.s;
  482. if s <> RESULT_U16BIT then
  483. failed := true;
  484. j:= level5rec_packed.j;
  485. if j <> RESULT_S32BIT then
  486. failed := true;
  487. if failed then
  488. fail
  489. else
  490. WriteLN('Passed!');
  491. Write('Non-Aligned big global record access (secondvecn())...');
  492. clear_globals;
  493. level1rec_big.c := RESULT_U8BIT;
  494. c:= level1rec_big.c;
  495. if c <> RESULT_U8BIT then
  496. failed := true;
  497. clear_globals;
  498. { setup values - assign }
  499. level2rec_big.c := RESULT_U8BIT;
  500. level2rec_big.d := RESULT_U8BIT;
  501. level2rec_big.s := RESULT_U16BIT;
  502. level2rec_big.n := RESULT_S32BIT;
  503. { load values - load }
  504. c:= level2rec_big.c;
  505. if c <> RESULT_U8BIT then
  506. failed := true;
  507. d:= level2rec_big.d;
  508. if d <> RESULT_U8BIT then
  509. failed := true;
  510. s:= level2rec_big.s;
  511. if s <> RESULT_U16BIT then
  512. failed := true;
  513. n:= level2rec_big.n;
  514. if n <> RESULT_S32BIT then
  515. failed := true;
  516. clear_globals;
  517. { setup values - assign }
  518. level3rec_big.c := RESULT_U8BIT;
  519. level3rec_big.s := RESULT_U16BIT;
  520. c:= level3rec_big.c;
  521. if c <> RESULT_U8BIT then
  522. failed := true;
  523. s:= level3rec_big.s;
  524. if s <> RESULT_U16BIT then
  525. failed := true;
  526. clear_globals;
  527. { setup values - assign }
  528. level4rec_big.c := RESULT_U8BIT;
  529. level4rec_big.i := RESULT_S64BIT;
  530. level4rec_big.s := RESULT_U16BIT;
  531. c:= level4rec_big.c;
  532. if c <> RESULT_U8BIT then
  533. failed := true;
  534. i:= level4rec_big.i;
  535. if i <> RESULT_S64BIT then
  536. failed := true;
  537. s:= level4rec_big.s;
  538. if s <> RESULT_U16BIT then
  539. failed := true;
  540. clear_globals;
  541. { setup values - assign }
  542. level5rec_big.c := RESULT_U8BIT;
  543. level5rec_big.s := RESULT_U16BIT;
  544. level5rec_big.j := RESULT_S32BIT;
  545. c:= level5rec_big.c;
  546. if c <> RESULT_U8BIT then
  547. failed := true;
  548. s:= level5rec_big.s;
  549. if s <> RESULT_U16BIT then
  550. failed := true;
  551. j:= level5rec_big.j;
  552. if j <> RESULT_S32BIT then
  553. failed := true;
  554. if failed then
  555. fail
  556. else
  557. WriteLN('Passed!');
  558. testlocals;
  559. {$ifndef cpu68k}
  560. Write('Non-Aligned big local record access (secondvecn())...');
  561. failed := false;
  562. testlocal_big_1;
  563. testlocal_big_2;
  564. testlocal_big_3;
  565. testlocal_big_4;
  566. testlocal_big_5;
  567. if failed then
  568. fail
  569. else
  570. WriteLN('Passed!');
  571. {$endif}
  572. Write('Aligned class big field access (secondvecn())...');
  573. clear_globals;
  574. failed := false;
  575. { LOC_REFERENCE }
  576. class1:=tclass1.create;
  577. class1.c:= RESULT_U8BIT;
  578. class1.j:= RESULT_S32BIT;
  579. class1.s:= RESULT_U16BIT;
  580. c:=class1.c;
  581. if c <> RESULT_U8BIT then
  582. failed := true;
  583. j:=class1.j;
  584. if j <> RESULT_S32BIT then
  585. failed := true;
  586. s:=class1.s;
  587. if s <> RESULT_U16BIT then
  588. failed := true;
  589. class1.destroy;
  590. clear_globals;
  591. { LOC_REGISTER }
  592. class1:=tclass1.create;
  593. class1.c:= RESULT_U8BIT;
  594. class1.j:= RESULT_S32BIT;
  595. class1.s:= RESULT_U16BIT;
  596. c:=(getclass).c;
  597. if c <> RESULT_U8BIT then
  598. failed := true;
  599. j:=(getclass).j;
  600. if j <> RESULT_S32BIT then
  601. failed := true;
  602. s:=(getclass).s;
  603. if s <> RESULT_U16BIT then
  604. failed := true;
  605. class1.destroy;
  606. if failed then
  607. fail
  608. else
  609. WriteLN('Passed!');
  610. {----------------------------------------------------------------------------}
  611. Write('Aligned class simple field access (secondvecn())...');
  612. clear_globals;
  613. failed := false;
  614. { LOC_REFERENCE }
  615. class2:=tclass2.create;
  616. class2.c:= RESULT_U8BIT;
  617. class2.i:= RESULT_S64BIT;
  618. class2.s:= RESULT_U16BIT;
  619. c:=class2.c;
  620. if c <> RESULT_U8BIT then
  621. failed := true;
  622. i:=class2.i;
  623. if i <> RESULT_S64BIT then
  624. failed := true;
  625. s:=class2.s;
  626. if s <> RESULT_U16BIT then
  627. failed := true;
  628. class2.destroy;
  629. clear_globals;
  630. { LOC_REGISTER }
  631. class2:=tclass2.create;
  632. class2.c:= RESULT_U8BIT;
  633. class2.i:= RESULT_S64BIT;
  634. class2.s:= RESULT_U16BIT;
  635. c:=(getclass2).c;
  636. if c <> RESULT_U8BIT then
  637. failed := true;
  638. i:=(getclass2).i;
  639. if i <> RESULT_S64BIT then
  640. failed := true;
  641. s:=(getclass2).s;
  642. if s <> RESULT_U16BIT then
  643. failed := true;
  644. class2.destroy;
  645. if failed then
  646. fail
  647. else
  648. WriteLN('Passed!');
  649. end.
  650. {
  651. $Log$
  652. Revision 1.2 2002-09-07 15:40:56 peter
  653. * old logs removed and tabs fixed
  654. Revision 1.1 2002/05/09 20:16:05 carl
  655. * subscriptn() secondpass testing...
  656. }