tcalcst4.pp 16 KB

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