tsubst.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  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. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  383. end;
  384. {---------------------------}
  385. var
  386. level1rec_big : tlevel1rec_big;
  387. level2rec_big : tlevel2rec_big;
  388. level3rec_big : tlevel3rec_big;
  389. level4rec_big : tlevel4rec_big;
  390. level5rec_big : tlevel5rec_big;
  391. begin
  392. { normal record access }
  393. Write('Aligned simple global record access (secondvecn())...');
  394. failed := false;
  395. clear_globals;
  396. c:= level1rec.c;
  397. if c <> RESULT_U8BIT then
  398. failed := true;
  399. clear_globals;
  400. c:= level2rec.c;
  401. if c <> RESULT_U8BIT then
  402. failed := true;
  403. d:= level2rec.d;
  404. if d <> RESULT_U8BIT then
  405. failed := true;
  406. s:= level2rec.s;
  407. if s <> RESULT_U16BIT then
  408. failed := true;
  409. n:= level2rec.n;
  410. if n <> RESULT_S32BIT then
  411. failed := true;
  412. clear_globals;
  413. c:= level3rec.c;
  414. if c <> RESULT_U8BIT then
  415. failed := true;
  416. s:= level3rec.s;
  417. if s <> RESULT_U16BIT then
  418. failed := true;
  419. clear_globals;
  420. c:= level4rec.c;
  421. if c <> RESULT_U8BIT then
  422. failed := true;
  423. i:= level4rec.i;
  424. if i <> RESULT_S64BIT then
  425. failed := true;
  426. s:= level4rec.s;
  427. if s <> RESULT_U16BIT then
  428. failed := true;
  429. clear_globals;
  430. c:= level5rec.c;
  431. if c <> RESULT_U8BIT then
  432. failed := true;
  433. s:= level5rec.s;
  434. if s <> RESULT_U16BIT then
  435. failed := true;
  436. j:= level5rec.j;
  437. if j <> RESULT_S32BIT then
  438. failed := true;
  439. if failed then
  440. fail
  441. else
  442. WriteLN('Passed!');
  443. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  444. Write('Non-Aligned simple global record access (secondvecn())...');
  445. clear_globals;
  446. c:= level1rec_packed.c;
  447. if c <> RESULT_U8BIT then
  448. failed := true;
  449. clear_globals;
  450. c:= level2rec_packed.c;
  451. if c <> RESULT_U8BIT then
  452. failed := true;
  453. d:= level2rec_packed.d;
  454. if d <> RESULT_U8BIT then
  455. failed := true;
  456. s:= level2rec_packed.s;
  457. if s <> RESULT_U16BIT then
  458. failed := true;
  459. n:= level2rec_packed.n;
  460. if n <> RESULT_S32BIT then
  461. failed := true;
  462. clear_globals;
  463. c:= level3rec_packed.c;
  464. if c <> RESULT_U8BIT then
  465. failed := true;
  466. s:= level3rec_packed.s;
  467. if s <> RESULT_U16BIT then
  468. failed := true;
  469. clear_globals;
  470. c:= level4rec_packed.c;
  471. if c <> RESULT_U8BIT then
  472. failed := true;
  473. i:= level4rec_packed.i;
  474. if i <> RESULT_S64BIT then
  475. failed := true;
  476. s:= level4rec_packed.s;
  477. if s <> RESULT_U16BIT then
  478. failed := true;
  479. clear_globals;
  480. c:= level5rec_packed.c;
  481. if c <> RESULT_U8BIT then
  482. failed := true;
  483. s:= level5rec_packed.s;
  484. if s <> RESULT_U16BIT then
  485. failed := true;
  486. j:= level5rec_packed.j;
  487. if j <> RESULT_S32BIT then
  488. failed := true;
  489. if failed then
  490. fail
  491. else
  492. WriteLN('Passed!');
  493. Write('Non-Aligned big global record access (secondvecn())...');
  494. clear_globals;
  495. level1rec_big.c := RESULT_U8BIT;
  496. c:= level1rec_big.c;
  497. if c <> RESULT_U8BIT then
  498. failed := true;
  499. clear_globals;
  500. { setup values - assign }
  501. level2rec_big.c := RESULT_U8BIT;
  502. level2rec_big.d := RESULT_U8BIT;
  503. level2rec_big.s := RESULT_U16BIT;
  504. level2rec_big.n := RESULT_S32BIT;
  505. { load values - load }
  506. c:= level2rec_big.c;
  507. if c <> RESULT_U8BIT then
  508. failed := true;
  509. d:= level2rec_big.d;
  510. if d <> RESULT_U8BIT then
  511. failed := true;
  512. s:= level2rec_big.s;
  513. if s <> RESULT_U16BIT then
  514. failed := true;
  515. n:= level2rec_big.n;
  516. if n <> RESULT_S32BIT then
  517. failed := true;
  518. clear_globals;
  519. { setup values - assign }
  520. level3rec_big.c := RESULT_U8BIT;
  521. level3rec_big.s := RESULT_U16BIT;
  522. c:= level3rec_big.c;
  523. if c <> RESULT_U8BIT then
  524. failed := true;
  525. s:= level3rec_big.s;
  526. if s <> RESULT_U16BIT then
  527. failed := true;
  528. clear_globals;
  529. { setup values - assign }
  530. level4rec_big.c := RESULT_U8BIT;
  531. level4rec_big.i := RESULT_S64BIT;
  532. level4rec_big.s := RESULT_U16BIT;
  533. c:= level4rec_big.c;
  534. if c <> RESULT_U8BIT then
  535. failed := true;
  536. i:= level4rec_big.i;
  537. if i <> RESULT_S64BIT then
  538. failed := true;
  539. s:= level4rec_big.s;
  540. if s <> RESULT_U16BIT then
  541. failed := true;
  542. clear_globals;
  543. { setup values - assign }
  544. level5rec_big.c := RESULT_U8BIT;
  545. level5rec_big.s := RESULT_U16BIT;
  546. level5rec_big.j := RESULT_S32BIT;
  547. c:= level5rec_big.c;
  548. if c <> RESULT_U8BIT then
  549. failed := true;
  550. s:= level5rec_big.s;
  551. if s <> RESULT_U16BIT then
  552. failed := true;
  553. j:= level5rec_big.j;
  554. if j <> RESULT_S32BIT then
  555. failed := true;
  556. if failed then
  557. fail
  558. else
  559. WriteLN('Passed!');
  560. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  561. testlocals;
  562. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  563. {$ifndef cpu68k}
  564. Write('Non-Aligned big local record access (secondvecn())...');
  565. failed := false;
  566. testlocal_big_1;
  567. testlocal_big_2;
  568. testlocal_big_3;
  569. testlocal_big_4;
  570. testlocal_big_5;
  571. if failed then
  572. fail
  573. else
  574. WriteLN('Passed!');
  575. {$endif}
  576. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  577. Write('Aligned class big field access (secondvecn())...');
  578. clear_globals;
  579. failed := false;
  580. { LOC_REFERENCE }
  581. class1:=tclass1.create;
  582. class1.c:= RESULT_U8BIT;
  583. class1.j:= RESULT_S32BIT;
  584. class1.s:= RESULT_U16BIT;
  585. c:=class1.c;
  586. if c <> RESULT_U8BIT then
  587. failed := true;
  588. j:=class1.j;
  589. if j <> RESULT_S32BIT then
  590. failed := true;
  591. s:=class1.s;
  592. if s <> RESULT_U16BIT then
  593. failed := true;
  594. class1.destroy;
  595. clear_globals;
  596. { LOC_REGISTER }
  597. class1:=tclass1.create;
  598. class1.c:= RESULT_U8BIT;
  599. class1.j:= RESULT_S32BIT;
  600. class1.s:= RESULT_U16BIT;
  601. c:=(getclass).c;
  602. if c <> RESULT_U8BIT then
  603. failed := true;
  604. j:=(getclass).j;
  605. if j <> RESULT_S32BIT then
  606. failed := true;
  607. s:=(getclass).s;
  608. if s <> RESULT_U16BIT then
  609. failed := true;
  610. class1.destroy;
  611. if failed then
  612. fail
  613. else
  614. WriteLN('Passed!');
  615. {----------------------------------------------------------------------------}
  616. Write('Aligned class simple field access (secondvecn())...');
  617. clear_globals;
  618. failed := false;
  619. { LOC_REFERENCE }
  620. class2:=tclass2.create;
  621. class2.c:= RESULT_U8BIT;
  622. class2.i:= RESULT_S64BIT;
  623. class2.s:= RESULT_U16BIT;
  624. c:=class2.c;
  625. if c <> RESULT_U8BIT then
  626. failed := true;
  627. i:=class2.i;
  628. if i <> RESULT_S64BIT then
  629. failed := true;
  630. s:=class2.s;
  631. if s <> RESULT_U16BIT then
  632. failed := true;
  633. class2.destroy;
  634. clear_globals;
  635. { LOC_REGISTER }
  636. class2:=tclass2.create;
  637. class2.c:= RESULT_U8BIT;
  638. class2.i:= RESULT_S64BIT;
  639. class2.s:= RESULT_U16BIT;
  640. c:=(getclass2).c;
  641. if c <> RESULT_U8BIT then
  642. failed := true;
  643. i:=(getclass2).i;
  644. if i <> RESULT_S64BIT then
  645. failed := true;
  646. s:=(getclass2).s;
  647. if s <> RESULT_U16BIT then
  648. failed := true;
  649. class2.destroy;
  650. if failed then
  651. fail
  652. else
  653. WriteLN('Passed!');
  654. end.