tretopt.pp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. {$mode objfpc}
  2. {$inline on}
  3. type
  4. pshortstring=^shortstring;
  5. tr = record
  6. a,b,c,d,e: shortstring;
  7. end;
  8. ta = array[0..5] of shortstring;
  9. tc = record
  10. p: pointer;
  11. end;
  12. var
  13. p,p2,p3: pointer;
  14. inlined, failed: boolean;
  15. procedure error(err: longint);
  16. begin
  17. writeln('error near ',err, ' (inlined: ',inlined,')');
  18. failed:=true;
  19. end;
  20. function f1(p: pchar): tr;
  21. begin
  22. fillchar(result,sizeof(tr),0);
  23. if (p^<>'x') then
  24. error(1);
  25. f1.a:=p^;
  26. end;
  27. function f2(var s: shortstring): tr;
  28. begin
  29. fillchar(result,sizeof(tr),0);
  30. if (s<>'x') then
  31. error(2);
  32. f2.a:=s;
  33. end;
  34. function f3(const s: shortstring): tr;
  35. begin
  36. fillchar(result,sizeof(tr),0);
  37. if (s<>'x') then
  38. error(3);
  39. f3.a:=s;
  40. end;
  41. function f4(const t: tr): tr;
  42. begin
  43. fillchar(result,sizeof(tr),0);
  44. if (t.a<>'x') then
  45. error(4);
  46. f4:=t;
  47. end;
  48. function f5(p: pchar): ta;
  49. begin
  50. fillchar(result,sizeof(result),0);
  51. if (p^<>'x') then
  52. error(5);
  53. result[3]:=p^;
  54. end;
  55. function f6(var s: shortstring): ta;
  56. begin
  57. fillchar(result,sizeof(result),0);
  58. if (s<>'x') then
  59. error(6);
  60. result[3]:=s;
  61. end;
  62. function f7(const s: shortstring): ta;
  63. begin
  64. fillchar(result,sizeof(result),0);
  65. if (s<>'x') then
  66. error(7);
  67. result[3]:=s;
  68. end;
  69. function f8(const t: ta): ta;
  70. begin
  71. fillchar(result,sizeof(result),0);
  72. if (t[3]<>'x') then
  73. error(8);
  74. result:=t;
  75. end;
  76. procedure temp;
  77. begin
  78. if (pshortstring(p)^<>'x') then
  79. error(9);
  80. end;
  81. function f9: tr;
  82. begin
  83. fillchar(result,sizeof(result),0);
  84. temp;
  85. result.a:='x';
  86. end;
  87. procedure temp2(var a);
  88. begin
  89. p2:=@a;
  90. end;
  91. function f10: tr;
  92. begin
  93. fillchar(result,sizeof(result),0);
  94. if (pshortstring(p2)^<>'x') then
  95. error(10);
  96. result.a:='x';
  97. end;
  98. procedure testrec1;
  99. var
  100. t: tr;
  101. begin
  102. t.a:='x';
  103. t:=f1(@t.a[1]);
  104. end;
  105. procedure testrec2;
  106. var
  107. t: tr;
  108. begin
  109. t.a:='x';
  110. t:=f2(t.a);
  111. end;
  112. procedure testrec3;
  113. var
  114. t: tr;
  115. begin
  116. t.a:='x';
  117. t:=f3(t.a);
  118. end;
  119. procedure testrec4;
  120. var
  121. t: tr;
  122. begin
  123. t.a:='x';
  124. t:=f4(t);
  125. end;
  126. procedure testrec5;
  127. var
  128. t: tr;
  129. begin
  130. t.a:='x';
  131. p:[email protected];
  132. t:=f9;
  133. end;
  134. procedure testrecinl1; inline;
  135. var
  136. t: tr;
  137. begin
  138. inlined:=true;
  139. t.a:='x';
  140. t:=f1(@t.a[1]);
  141. end;
  142. procedure testrecinl2; inline;
  143. var
  144. t: tr;
  145. begin
  146. inlined:=true;
  147. t.a:='x';
  148. t:=f2(t.a);
  149. end;
  150. procedure testrecinl3; inline;
  151. var
  152. t: tr;
  153. begin
  154. inlined:=true;
  155. t.a:='x';
  156. t:=f3(t.a);
  157. end;
  158. procedure testrecinl4; inline;
  159. var
  160. t: tr;
  161. begin
  162. inlined:=true;
  163. t.a:='x';
  164. t:=f4(t);
  165. end;
  166. procedure testrecinl5; inline;
  167. var
  168. t: tr;
  169. begin
  170. inlined:=true;
  171. t.a:='x';
  172. p:[email protected];
  173. t:=f9;
  174. inlined:=false;
  175. end;
  176. procedure testrec2a;
  177. var
  178. t: tr;
  179. begin
  180. t.a:='x';
  181. temp2(t.a);
  182. t:=f10;
  183. end;
  184. procedure testrec2ainl; inline;
  185. var
  186. t: tr;
  187. begin
  188. inlined:=true;
  189. t.a:='x';
  190. temp2(t.a);
  191. t:=f10;
  192. inlined:=false;
  193. end;
  194. {$if defined(cpupowerpc32) or defined(cpupowerpc64) or defined(cpui386)}
  195. function f11: tr;
  196. begin
  197. fillchar(result,sizeof(result),0);
  198. if (pshortstring(p3)^<>'x') then
  199. error(11);
  200. result.a:='x';
  201. end;
  202. procedure testrec3a;
  203. var
  204. t: tr;
  205. begin
  206. asm
  207. {$ifdef cpupowerpc32}
  208. la r3,t
  209. {$ifndef macos}
  210. lis r4,p3@ha
  211. addi r4,r4,p3@l
  212. {$else}
  213. lwz r4,p3(r2)
  214. {$endif}
  215. stw r3,0(r4)
  216. {$endif}
  217. {$ifdef cpupowerpc64}
  218. la r3,t
  219. {$ifndef darwin}
  220. lis r4, p3@highesta
  221. ori r4, r4, p3@highera
  222. sldi r4, r4, 32
  223. oris r4, r4, p3@ha
  224. {$else darwin}
  225. lis r4, p3@ha
  226. {$endif darwin}
  227. std r3,p3@l(r4)
  228. {$endif}
  229. {$ifdef cpui386}
  230. leal t,%eax
  231. {$ifndef FPC_PIC}
  232. movl %eax,p3
  233. {$else FPC_PIC}
  234. call .Lpic
  235. .Lpic:
  236. popl %ecx
  237. {$ifdef darwin}
  238. movl %eax,p3-.Lpic(%ecx)
  239. {$else darwin}
  240. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  241. movl %eax,p3@GOT(%ecx)
  242. {$endif darwin}
  243. {$endif FPC_PIC}
  244. {$endif cpui386}
  245. end;
  246. t.a:='x';
  247. t:=f11;
  248. end;
  249. procedure testrec3ainl; inline;
  250. var
  251. t: tr;
  252. begin
  253. inlined:=true;
  254. asm
  255. {$ifdef cpupowerpc32}
  256. la r3,t
  257. {$ifndef macos}
  258. lis r4,p3@ha
  259. addi r4,r4,p3@l
  260. {$else}
  261. lwz r4,p3(r2)
  262. {$endif}
  263. stw r3,0(r4)
  264. {$endif}
  265. {$ifdef cpupowerpc64}
  266. la r3,t
  267. {$ifndef darwin}
  268. lis r4, p3@highesta
  269. ori r4, r4, p3@highera
  270. sldi r4, r4, 32
  271. oris r4, r4, p3@ha
  272. {$else darwin}
  273. lis r4, p3@ha
  274. {$endif darwin}
  275. std r3,p3@l(r4)
  276. {$endif}
  277. {$ifdef cpui386}
  278. leal t,%eax
  279. {$ifndef FPC_PIC}
  280. movl %eax,p3
  281. {$else FPC_PIC}
  282. call .Lpic
  283. .Lpic:
  284. popl %ecx
  285. {$ifdef darwin}
  286. movl %eax,p3-.Lpic(%ecx)
  287. {$else darwin}
  288. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  289. movl %eax,p3@GOT(%ecx)
  290. {$endif darwin}
  291. {$endif FPC_PIC}
  292. {$endif}
  293. end;
  294. t.a:='x';
  295. t:=f11;
  296. inlined:=false;
  297. end;
  298. {$endif}
  299. procedure testarr1;
  300. var
  301. t: ta;
  302. begin
  303. t[3]:='x';
  304. t:=f5(@t[3][1]);
  305. end;
  306. procedure testarr2;
  307. var
  308. t: ta;
  309. begin
  310. t[3]:='x';
  311. t:=f6(t[3]);
  312. end;
  313. procedure testarr3;
  314. var
  315. t: ta;
  316. begin
  317. t[3]:='x';
  318. t:=f7(t[3]);
  319. end;
  320. procedure testarr4;
  321. var
  322. t: ta;
  323. begin
  324. t[3]:='x';
  325. t:=f8(t);
  326. end;
  327. procedure testarrinl1; inline;
  328. var
  329. t: ta;
  330. begin
  331. inlined:=true;
  332. t[3]:='x';
  333. t:=f5(@t[3][1]);
  334. end;
  335. procedure testarrinl2; inline;
  336. var
  337. t: ta;
  338. begin
  339. inlined:=true;
  340. t[3]:='x';
  341. t:=f6(t[3]);
  342. end;
  343. procedure testarrinl3; inline;
  344. var
  345. t: ta;
  346. begin
  347. inlined:=true;
  348. t[3]:='x';
  349. t:=f7(t[3]);
  350. end;
  351. procedure testarrinl4; inline;
  352. var
  353. t: ta;
  354. begin
  355. inlined:=true;
  356. t[3]:='x';
  357. t:=f8(t);
  358. inlined:=false;
  359. end;
  360. begin
  361. testrec1;
  362. testrec2;
  363. testrec3;
  364. testrec4;
  365. testrec5;
  366. testrecinl1;
  367. testrecinl2;
  368. testrecinl3;
  369. testrecinl4;
  370. testrecinl5;
  371. testrec2a;
  372. testrec2ainl;
  373. {$if defined(cpupowerpc32) or defined(cpui386) or defined(cpupowerpc64)}
  374. testrec3a;
  375. testrec3ainl;
  376. {$endif}
  377. testarr1;
  378. testarr2;
  379. testarr3;
  380. testarr4;
  381. testarrinl1;
  382. testarrinl2;
  383. testarrinl3;
  384. testarrinl4;
  385. if failed then
  386. halt(1);
  387. end.