tcalcst4.pp 16 KB

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