tcalcst4.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondcallparan() }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. { secondtryexcept() }
  11. { secondcalln() }
  12. { secondadd() }
  13. {****************************************************************}
  14. { DEFINES: }
  15. { FPC = Target is FreePascal compiler }
  16. {****************************************************************}
  17. { REMARKS: This tests a subset of the secondcalln() node }
  18. { (const parameters with cdecl calling convention) }
  19. {****************************************************************}
  20. program tcalcst4;
  21. {$ifdef fpc}
  22. {$mode objfpc}
  23. {$INLINE ON}
  24. {$endif}
  25. {$R+}
  26. {$ifdef VER70}
  27. {$define tp}
  28. {$endif}
  29. { REAL should map to single or double }
  30. { so it is not checked, since single }
  31. { double nodes are checked. }
  32. { assumes that enumdef is the same as orddef (same storage format) }
  33. const
  34. { should be defined depending on CPU target }
  35. {$ifdef fpc}
  36. {$ifdef cpu68k}
  37. BIG_INDEX = 8000;
  38. SMALL_INDEX = 13;
  39. {$else}
  40. BIG_INDEX = 33000;
  41. SMALL_INDEX = 13; { value should not be aligned! }
  42. {$endif}
  43. {$else}
  44. BIG_INDEX = 33000;
  45. SMALL_INDEX = 13; { value should not be aligned! }
  46. {$endif}
  47. RESULT_U8BIT = $55;
  48. RESULT_U16BIT = $500F;
  49. RESULT_S32BIT = $500F0000;
  50. RESULT_S64BIT = $500F0000;
  51. RESULT_S32REAL = 1777.12;
  52. RESULT_S64REAL = 3444.24;
  53. RESULT_BOOL8BIT = 1;
  54. RESULT_BOOL16BIT = 1;
  55. RESULT_BOOL32BIT = 1;
  56. RESULT_PCHAR = 'Hello world';
  57. RESULT_BIGSTRING = 'Hello world';
  58. RESULT_SMALLSTRING = 'H';
  59. RESULT_CHAR = 'I';
  60. RESULT_BOOLEAN = TRUE;
  61. type
  62. {$ifndef tp}
  63. tclass1 = class
  64. end;
  65. {$else}
  66. shortstring = string;
  67. {$endif}
  68. tprocedure = procedure;
  69. tsmallrecord = packed record
  70. b: byte;
  71. w: word;
  72. end;
  73. tlargerecord = packed record
  74. b: array[1..BIG_INDEX] of byte;
  75. end;
  76. tsmallarray = packed array[1..SMALL_INDEX] of byte;
  77. tsmallsetenum =
  78. (A_A,A_B,A_C,A_D);
  79. tsmallset = set of tsmallsetenum;
  80. tlargeset = set of char;
  81. tsmallstring = string[2];
  82. var
  83. global_u8bit : byte;
  84. global_u16bit : word;
  85. global_s32bit : longint;
  86. global_s32real : single;
  87. global_s64real : double;
  88. global_ptr : pchar;
  89. global_proc : tprocedure;
  90. global_bigstring : shortstring;
  91. global_boolean : boolean;
  92. global_char : char;
  93. value_u8bit : byte;
  94. value_u16bit : word;
  95. value_s32bit : longint;
  96. {$ifndef tp}
  97. global_class : tclass1;
  98. global_s64bit : int64;
  99. value_s64bit : int64;
  100. value_class : tclass1;
  101. {$endif}
  102. value_s32real : single;
  103. value_s64real : double;
  104. value_proc : tprocedure;
  105. value_ptr : pchar;
  106. value_smallrec : tsmallrecord;
  107. value_largerec : tlargerecord;
  108. value_smallset : tsmallset;
  109. value_smallstring : tsmallstring;
  110. value_bigstring : shortstring;
  111. value_largeset : tlargeset;
  112. value_smallarray : tsmallarray;
  113. value_boolean : boolean;
  114. value_char : char;
  115. procedure fail;
  116. begin
  117. WriteLn('Failure.');
  118. halt(1);
  119. end;
  120. procedure clear_globals;
  121. begin
  122. global_u8bit := 0;
  123. global_u16bit := 0;
  124. global_s32bit := 0;
  125. global_s32real := 0.0;
  126. global_s64real := 0.0;
  127. global_ptr := nil;
  128. global_proc := nil;
  129. global_bigstring := '';
  130. global_boolean := false;
  131. global_char := #0;
  132. {$ifndef tp}
  133. global_s64bit := 0;
  134. global_class := nil;
  135. {$endif}
  136. end;
  137. procedure clear_values;
  138. begin
  139. value_u8bit := 0;
  140. value_u16bit := 0;
  141. value_s32bit := 0;
  142. value_s32real := 0.0;
  143. value_s64real := 0.0;
  144. value_proc := nil;
  145. value_ptr := nil;
  146. {$ifndef tp}
  147. value_s64bit := 0;
  148. value_class := nil;
  149. {$endif}
  150. fillchar(value_smallrec, sizeof(value_smallrec), #0);
  151. fillchar(value_largerec, sizeof(value_largerec), #0);
  152. value_smallset := [];
  153. value_smallstring := '';
  154. value_bigstring := '';
  155. value_largeset := [];
  156. fillchar(value_smallarray, sizeof(value_smallarray), #0);
  157. value_boolean := false;
  158. value_char:=#0;
  159. end;
  160. procedure testprocedure;
  161. begin
  162. end;
  163. function getu8bit : byte;
  164. begin
  165. getu8bit:=RESULT_U8BIT;
  166. end;
  167. function getu16bit: word;
  168. begin
  169. getu16bit:=RESULT_U16BIT;
  170. end;
  171. function gets32bit: longint;
  172. begin
  173. gets32bit:=RESULT_S32BIT;
  174. end;
  175. function gets64bit: int64;
  176. begin
  177. gets64bit:=RESULT_S64BIT;
  178. end;
  179. function gets32real: single;
  180. begin
  181. gets32real:=RESULT_S32REAL;
  182. end;
  183. function gets64real: double;
  184. begin
  185. gets64real:=RESULT_S64REAL;
  186. end;
  187. {************************************************************************}
  188. { CONST PARAMETERS }
  189. {************************************************************************}
  190. procedure proc_const_s32bit(const v : longint);cdecl;
  191. begin
  192. global_s32bit := v;
  193. end;
  194. {$ifndef tp}
  195. procedure proc_const_s64bit(const v: int64);cdecl;
  196. begin
  197. global_s64bit:= v;
  198. end;
  199. {$endif}
  200. procedure proc_const_smallrecord(const smallrec : tsmallrecord);cdecl;
  201. begin
  202. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  203. global_u8bit := RESULT_U8BIT;
  204. end;
  205. procedure proc_const_largerecord(const largerec : tlargerecord);cdecl;
  206. begin
  207. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  208. global_u8bit := RESULT_U8BIT;
  209. end;
  210. procedure proc_const_smallset(const smallset : tsmallset);cdecl;
  211. begin
  212. if A_D in smallset then
  213. global_u8bit := RESULT_U8BIT;
  214. end;
  215. procedure proc_const_largeset(const largeset : tlargeset);cdecl;
  216. begin
  217. if 'I' in largeset then
  218. global_u8bit := RESULT_U8BIT;
  219. end;
  220. procedure proc_const_smallstring(const s:tsmallstring);cdecl;
  221. begin
  222. if s = RESULT_SMALLSTRING then
  223. global_u8bit := RESULT_u8BIT;
  224. end;
  225. procedure proc_const_bigstring(const s:shortstring);cdecl;
  226. begin
  227. if s = RESULT_BIGSTRING then
  228. global_u8bit := RESULT_u8BIT;
  229. end;
  230. procedure proc_const_smallarray(const arr : tsmallarray);cdecl;
  231. begin
  232. if arr[SMALL_INDEX] = RESULT_U8BIT then
  233. global_u8bit := RESULT_U8BIT;
  234. end;
  235. procedure proc_const_smallarray_open(const arr : array of byte);cdecl;
  236. begin
  237. { form 0 to N-1 indexes in open arrays }
  238. if arr[SMALL_INDEX-1] = RESULT_U8BIT then
  239. global_u8bit := RESULT_U8BIT;
  240. end;
  241. procedure proc_const_formaldef_array(const buf);cdecl;
  242. var
  243. p: pchar;
  244. begin
  245. { array is indexed from 1 }
  246. p := @buf;
  247. global_u8bit := byte(p[SMALL_INDEX-1]);
  248. end;
  249. {************************************************************************}
  250. { MIXED CONST PARAMETERS }
  251. {************************************************************************}
  252. procedure proc_const_s32bit_mixed(b1: byte; const v : longint; b2: byte);cdecl;
  253. begin
  254. global_s32bit := v;
  255. value_u8bit := b2;
  256. end;
  257. {$ifndef tp}
  258. procedure proc_const_s64bit_mixed(b1 : byte; const v: int64; b2: byte);cdecl;
  259. begin
  260. global_s64bit:= v;
  261. value_u8bit := b2;
  262. end;
  263. {$endif}
  264. procedure proc_const_smallrecord_mixed(b1 : byte; const smallrec : tsmallrecord; b2: byte);cdecl;
  265. begin
  266. if (smallrec.b = RESULT_U8BIT) and (smallrec.w = RESULT_U16BIT) then
  267. global_u8bit := RESULT_U8BIT;
  268. value_u8bit := b2;
  269. end;
  270. procedure proc_const_largerecord_mixed(b1: byte; const largerec : tlargerecord; b2: byte);cdecl;
  271. begin
  272. if (largerec.b[1] = RESULT_U8BIT) and (largerec.b[2] = RESULT_U8BIT) then
  273. global_u8bit := RESULT_U8BIT;
  274. value_u8bit := b2;
  275. end;
  276. procedure proc_const_smallset_mixed(b1: byte; const smallset : tsmallset; b2: byte);cdecl;
  277. begin
  278. if A_D in smallset then
  279. global_u8bit := RESULT_U8BIT;
  280. value_u8bit := b2;
  281. end;
  282. procedure proc_const_largeset_mixed(b1: byte; const largeset : tlargeset; b2: byte);cdecl;
  283. begin
  284. if 'I' in largeset then
  285. global_u8bit := RESULT_U8BIT;
  286. value_u8bit := b2;
  287. end;
  288. procedure proc_const_smallstring_mixed(b1: byte; const s:tsmallstring; b2: byte);cdecl;
  289. begin
  290. if s = RESULT_SMALLSTRING then
  291. global_u8bit := RESULT_u8BIT;
  292. value_u8bit := b2;
  293. end;
  294. procedure proc_const_bigstring_mixed(b1: byte; const s:shortstring; b2: byte);cdecl;
  295. begin
  296. if s = RESULT_BIGSTRING then
  297. global_u8bit := RESULT_u8BIT;
  298. value_u8bit := b2;
  299. end;
  300. procedure proc_const_smallarray_mixed(b1: byte; const arr : tsmallarray; b2: byte);cdecl;
  301. begin
  302. if arr[SMALL_INDEX] = RESULT_U8BIT then
  303. global_u8bit := RESULT_U8BIT;
  304. value_u8bit := b2;
  305. end;
  306. procedure proc_const_formaldef_array_mixed(b1: byte; const buf; b2: byte);cdecl;
  307. var
  308. p: pchar;
  309. begin
  310. { array is indexed from 1 }
  311. p := @buf;
  312. global_u8bit := byte(p[SMALL_INDEX-1]);
  313. value_u8bit := b2;
  314. end;
  315. var
  316. failed: boolean;
  317. pp : ^pchar;
  318. begin
  319. {***************************** NORMAL TESTS *******************************}
  320. write('Const parameter test (src : LOC_REGISTER (orddef)))...');
  321. clear_globals;
  322. clear_values;
  323. failed:=false;
  324. proc_const_s32bit(gets32bit);
  325. if global_s32bit <> RESULT_S32BIT then
  326. failed:=true;
  327. {$ifndef tp}
  328. proc_const_s64bit(gets64bit);
  329. if global_s64bit <> RESULT_S64BIT then
  330. failed:=true;
  331. {$endif}
  332. if failed then
  333. fail
  334. else
  335. WriteLn('Passed!');
  336. write('Const parameter test (src : LOC_REFERENCE (recorddef)))...');
  337. clear_globals;
  338. clear_values;
  339. failed := false;
  340. value_smallrec.b := RESULT_U8BIT;
  341. value_smallrec.w := RESULT_U16BIT;
  342. proc_const_smallrecord(value_smallrec);
  343. if global_u8bit <> RESULT_U8BIT then
  344. failed := true;
  345. clear_globals;
  346. clear_values;
  347. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  348. proc_const_largerecord(value_largerec);
  349. if global_u8bit <> RESULT_U8BIT then
  350. failed := true;
  351. if failed then
  352. fail
  353. else
  354. WriteLn('Passed!');
  355. write('const parameter test (src : LOC_REFERENCE (setdef)))...');
  356. clear_globals;
  357. clear_values;
  358. failed := false;
  359. value_smallset := [A_A,A_D];
  360. proc_const_smallset(value_smallset);
  361. if global_u8bit <> RESULT_U8BIT then
  362. failed := true;
  363. clear_globals;
  364. clear_values;
  365. value_largeset := ['I'];
  366. proc_const_largeset(value_largeset);
  367. if global_u8bit <> RESULT_U8BIT then
  368. failed := true;
  369. if failed then
  370. fail
  371. else
  372. WriteLn('Passed!');
  373. write('const parameter test (src : LOC_REFERENCE (stringdef)))...');
  374. clear_globals;
  375. clear_values;
  376. failed := false;
  377. value_smallstring := RESULT_SMALLSTRING;
  378. proc_const_smallstring(value_smallstring);
  379. if global_u8bit <> RESULT_U8BIT then
  380. failed := true;
  381. clear_globals;
  382. clear_values;
  383. value_bigstring := RESULT_BIGSTRING;
  384. proc_const_bigstring(value_bigstring);
  385. if global_u8bit <> RESULT_U8BIT then
  386. failed := true;
  387. if failed then
  388. fail
  389. else
  390. WriteLn('Passed!');
  391. write('Const parameter test (src : LOC_REFERENCE (formaldef)))...');
  392. clear_globals;
  393. clear_values;
  394. failed:=false;
  395. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  396. proc_const_formaldef_array(value_smallarray);
  397. if global_u8bit <> RESULT_U8BIT then
  398. failed := true;
  399. if failed then
  400. fail
  401. else
  402. WriteLn('Passed!');
  403. write('Const parameter test (src : LOC_REFERENCE (arraydef)))...');
  404. clear_globals;
  405. clear_values;
  406. failed:=false;
  407. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  408. proc_const_smallarray(value_smallarray);
  409. if global_u8bit <> RESULT_U8BIT then
  410. failed := true;
  411. clear_globals;
  412. clear_values;
  413. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  414. proc_const_smallarray_open(value_smallarray);
  415. if global_u8bit <> RESULT_U8BIT then
  416. failed := true;
  417. if failed then
  418. fail
  419. else
  420. WriteLn('Passed!');
  421. {***************************** MIXED TESTS *******************************}
  422. write('Mixed const parameter test (src : LOC_REGISTER (orddef)))...');
  423. clear_globals;
  424. clear_values;
  425. failed:=false;
  426. proc_const_s32bit_mixed(RESULT_U8BIT,gets32bit,RESULT_U8BIT);
  427. if global_s32bit <> RESULT_S32BIT then
  428. failed:=true;
  429. if value_u8bit <> RESULT_U8BIT then
  430. failed := true;
  431. {$ifndef tp}
  432. proc_const_s64bit_mixed(RESULT_U8BIT,gets64bit,RESULT_U8BIT);
  433. if global_s64bit <> RESULT_S64BIT then
  434. failed:=true;
  435. if value_u8bit <> RESULT_U8BIT then
  436. failed := true;
  437. {$endif}
  438. if failed then
  439. fail
  440. else
  441. WriteLn('Passed!');
  442. write('Mixed const parameter test (src : LOC_REFERENCE (recorddef)))...');
  443. clear_globals;
  444. clear_values;
  445. failed := false;
  446. value_smallrec.b := RESULT_U8BIT;
  447. value_smallrec.w := RESULT_U16BIT;
  448. proc_const_smallrecord_mixed(RESULT_U8BIT,value_smallrec,RESULT_U8BIT);
  449. if global_u8bit <> RESULT_U8BIT then
  450. failed := true;
  451. if value_u8bit <> RESULT_U8BIT then
  452. failed := true;
  453. clear_globals;
  454. clear_values;
  455. fillchar(value_largerec,sizeof(value_largerec),RESULT_U8BIT);
  456. proc_const_largerecord_mixed(RESULT_U8BIT,value_largerec,RESULT_U8BIT);
  457. if global_u8bit <> RESULT_U8BIT then
  458. failed := true;
  459. if value_u8bit <> RESULT_U8BIT then
  460. failed := true;
  461. if failed then
  462. fail
  463. else
  464. WriteLn('Passed!');
  465. write('Mixed const parameter test (src : LOC_REFERENCE (setdef)))...');
  466. clear_globals;
  467. clear_values;
  468. failed := false;
  469. value_smallset := [A_A,A_D];
  470. proc_const_smallset_mixed(RESULT_U8BIT,value_smallset,RESULT_U8BIT);
  471. if global_u8bit <> RESULT_U8BIT then
  472. failed := true;
  473. if value_u8bit <> RESULT_U8BIT then
  474. failed := true;
  475. clear_globals;
  476. clear_values;
  477. value_largeset := ['I'];
  478. proc_const_largeset_mixed(RESULT_U8BIT,value_largeset,RESULT_U8BIT);
  479. if global_u8bit <> RESULT_U8BIT then
  480. failed := true;
  481. if value_u8bit <> RESULT_U8BIT then
  482. failed := true;
  483. if failed then
  484. fail
  485. else
  486. WriteLn('Passed!');
  487. write('Mixed const parameter test (src : LOC_REFERENCE (stringdef)))...');
  488. clear_globals;
  489. clear_values;
  490. failed := false;
  491. value_smallstring := RESULT_SMALLSTRING;
  492. proc_const_smallstring_mixed(RESULT_U8BIT,value_smallstring,RESULT_U8BIT);
  493. if global_u8bit <> RESULT_U8BIT then
  494. failed := true;
  495. if value_u8bit <> RESULT_U8BIT then
  496. failed := true;
  497. clear_globals;
  498. clear_values;
  499. value_bigstring := RESULT_BIGSTRING;
  500. proc_const_bigstring_mixed(RESULT_U8BIT,value_bigstring,RESULT_U8BIT);
  501. if global_u8bit <> RESULT_U8BIT then
  502. failed := true;
  503. if value_u8bit <> RESULT_U8BIT then
  504. failed := true;
  505. if failed then
  506. fail
  507. else
  508. WriteLn('Passed!');
  509. write('Mixed const parameter test (src : LOC_REFERENCE (formaldef)))...');
  510. clear_globals;
  511. clear_values;
  512. failed:=false;
  513. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  514. proc_const_formaldef_array_mixed(RESULT_U8BIT,value_smallarray,RESULT_U8BIT);
  515. if global_u8bit <> RESULT_U8BIT then
  516. failed := true;
  517. if value_u8bit <> RESULT_U8BIT then
  518. failed := true;
  519. if failed then
  520. fail
  521. else
  522. WriteLn('Passed!');
  523. write('Mixed const parameter test (src : LOC_REFERENCE (arraydef)))...');
  524. clear_globals;
  525. clear_values;
  526. failed:=false;
  527. value_smallarray[SMALL_INDEX] := RESULT_U8BIT;
  528. proc_const_smallarray_mixed(RESULT_U8BIt,value_smallarray,RESULT_U8BIT);
  529. if global_u8bit <> RESULT_U8BIT then
  530. failed := true;
  531. if value_u8bit <> RESULT_U8BIT then
  532. failed := true;
  533. if failed then
  534. fail
  535. else
  536. WriteLn('Passed!');
  537. end.
  538. {
  539. $Log$
  540. Revision 1.8 2003-04-22 10:24:29 florian
  541. * fixed defines for powerpc
  542. Revision 1.7 2002/11/20 19:39:21 carl
  543. - high() cannot be used in cdecle'd routines
  544. Revision 1.6 2002/11/09 21:47:36 carl
  545. + updated tests for correct parsing (array of const now allowed with high!)
  546. Revision 1.5 2002/09/22 14:16:12 carl
  547. * fix small typo
  548. Revision 1.4 2002/09/22 09:08:40 carl
  549. * gets64bit was not returning an int64!
  550. Revision 1.3 2002/09/07 15:40:50 peter
  551. * old logs removed and tabs fixed
  552. Revision 1.2 2002/05/13 13:45:36 peter
  553. * updated to compile tests with kylix
  554. Revision 1.1 2002/04/13 17:47:06 carl
  555. + constant parameter passing for different calling conventions
  556. }