tsubst.pp 15 KB

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