cg68kcnv.pas 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Generate m68k assembler for type converting nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$ifdef TP}
  19. {$E+,F+,N+}
  20. {$endif}
  21. unit cg68kcnv;
  22. interface
  23. uses
  24. tree;
  25. procedure secondtypeconv(var p : ptree);
  26. procedure secondas(var p : ptree);
  27. procedure secondis(var p : ptree);
  28. implementation
  29. uses
  30. globtype,systems,symconst,
  31. cobjects,verbose,globals,
  32. symtable,aasm,types,
  33. hcodegen,temp_gen,pass_2,
  34. cpubase,cga68k,tgen68k;
  35. {*****************************************************************************
  36. SecondTypeConv
  37. *****************************************************************************}
  38. procedure maybe_rangechecking(p : ptree;p2,p1 : pdef);
  39. var
  40. hp : preference;
  41. hregister : tregister;
  42. neglabel,poslabel : pasmlabel;
  43. begin
  44. { convert from p2 to p1 }
  45. { range check from enums is not made yet !!}
  46. { and its probably not easy }
  47. if (p1^.deftype<>orddef) or (p2^.deftype<>orddef) then
  48. exit;
  49. { range checking is different for u32bit }
  50. { lets try to generate it allways }
  51. if (cs_check_range in aktlocalswitches) and
  52. { with $R+ explicit type conversations in TP aren't range checked! }
  53. (not(p^.explizit) {or not(cs_tp_compatible in aktmoduleswitches)}) and
  54. ((porddef(p1)^.low>porddef(p2)^.low) or
  55. (porddef(p1)^.high<porddef(p2)^.high) or
  56. (porddef(p1)^.typ=u32bit) or
  57. (porddef(p2)^.typ=u32bit)) then
  58. begin
  59. porddef(p1)^.genrangecheck;
  60. if porddef(p2)^.typ=u8bit then
  61. begin
  62. if (p^.location.loc=LOC_REGISTER) or
  63. (p^.location.loc=LOC_CREGISTER) then
  64. begin
  65. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_B,p^.location.register,R_D6)));
  66. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L,$FF,R_D6)));
  67. end
  68. else
  69. begin
  70. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_B,newreference(p^.location.reference),R_D6)));
  71. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L,$FF,R_D6)));
  72. end;
  73. hregister:=R_D6;
  74. end
  75. else if porddef(p2)^.typ=s8bit then
  76. begin
  77. if (p^.location.loc=LOC_REGISTER) or
  78. (p^.location.loc=LOC_CREGISTER) then
  79. begin
  80. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_B,p^.location.register,R_D6)));
  81. { byte to long }
  82. if aktoptprocessor = MC68020 then
  83. exprasmlist^.concat(new(paicpu,op_reg(A_EXTB,S_L,R_D6)))
  84. else
  85. begin
  86. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_W,R_D6)));
  87. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_L,R_D6)));
  88. end;
  89. end
  90. else
  91. begin
  92. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_B,newreference(p^.location.reference),R_D6)));
  93. { byte to long }
  94. if aktoptprocessor = MC68020 then
  95. exprasmlist^.concat(new(paicpu,op_reg(A_EXTB,S_L,R_D6)))
  96. else
  97. begin
  98. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_W,R_D6)));
  99. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_L,R_D6)));
  100. end;
  101. end; { end outermost else }
  102. hregister:=R_D6;
  103. end
  104. { rangechecking for u32bit ?? !!!!!!}
  105. { lets try }
  106. else if (porddef(p2)^.typ=s32bit) or (porddef(p2)^.typ=u32bit) then
  107. begin
  108. if (p^.location.loc=LOC_REGISTER) or
  109. (p^.location.loc=LOC_CREGISTER) then
  110. hregister:=p^.location.register
  111. else
  112. begin
  113. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(p^.location.reference),R_D6)));
  114. hregister:=R_D6;
  115. end;
  116. end
  117. { rangechecking for u32bit ?? !!!!!!}
  118. else if porddef(p2)^.typ=u16bit then
  119. begin
  120. if (p^.location.loc=LOC_REGISTER) or
  121. (p^.location.loc=LOC_CREGISTER) then
  122. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_W,p^.location.register,R_D6)))
  123. else
  124. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.location.reference),R_D6)));
  125. { unisgned extend }
  126. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L,$FFFF,R_D6)));
  127. hregister:=R_D6;
  128. end
  129. else if porddef(p2)^.typ=s16bit then
  130. begin
  131. if (p^.location.loc=LOC_REGISTER) or
  132. (p^.location.loc=LOC_CREGISTER) then
  133. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_W,p^.location.register,R_D6)))
  134. else
  135. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.location.reference),R_D6)));
  136. { sign extend }
  137. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_L,R_D6)));
  138. hregister:=R_D6;
  139. end
  140. else internalerror(6);
  141. new(hp);
  142. reset_reference(hp^);
  143. hp^.symbol:=stringdup('R_'+tostr(porddef(p1)^.rangenr));
  144. if porddef(p1)^.low>porddef(p1)^.high then
  145. begin
  146. getlabel(neglabel);
  147. getlabel(poslabel);
  148. exprasmlist^.concat(new(paicpu,op_reg(A_TST,S_L,hregister)));
  149. emitl(A_BLT,neglabel);
  150. end;
  151. emit_bounds_check(hp^,hregister);
  152. if porddef(p1)^.low>porddef(p1)^.high then
  153. begin
  154. new(hp);
  155. reset_reference(hp^);
  156. hp^.symbol:=stringdup('R_'+tostr(porddef(p1)^.rangenr+1));
  157. emitl(A_JMP,poslabel);
  158. emitl(A_LABEL,neglabel);
  159. emit_bounds_check(hp^,hregister);
  160. emitl(A_LABEL,poslabel);
  161. end;
  162. end;
  163. end;
  164. type
  165. tsecondconvproc = procedure(p,hp : ptree;convtyp : tconverttype);
  166. procedure second_only_rangecheck(p,hp : ptree;convtyp : tconverttype);
  167. begin
  168. maybe_rangechecking(p,hp^.resulttype,p^.resulttype);
  169. end;
  170. procedure second_smaller(p,hp : ptree;convtyp : tconverttype);
  171. var
  172. hregister,destregister : tregister;
  173. {opsize : topsize;}
  174. ref : boolean;
  175. hpp : preference;
  176. begin
  177. { !!!!!!!! Rangechecking }
  178. ref:=false;
  179. { problems with enums !! }
  180. { with $R+ explicit type conversations in TP aren't range checked! }
  181. if (p^.resulttype^.deftype=orddef) and
  182. (hp^.resulttype^.deftype=orddef) and
  183. ((porddef(p^.resulttype)^.low>porddef(hp^.resulttype)^.low) or
  184. (porddef(p^.resulttype)^.high<porddef(hp^.resulttype)^.high)) then
  185. begin
  186. if (cs_check_range in aktlocalswitches) and
  187. (not(p^.explizit) {or not(cs_tp_compatible in aktmoduleswitches)}) then
  188. porddef(p^.resulttype)^.genrangecheck;
  189. if porddef(hp^.resulttype)^.typ=s32bit then
  190. begin
  191. if (p^.location.loc=LOC_REGISTER) or
  192. (p^.location.loc=LOC_CREGISTER) then
  193. hregister:=p^.location.register
  194. else
  195. begin
  196. hregister:=getregister32;
  197. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(p^.location.reference),hregister)));
  198. end;
  199. end
  200. { rangechecking for u32bit ?? !!!!!!}
  201. else if porddef(hp^.resulttype)^.typ=u16bit then
  202. begin
  203. hregister:=getregister32;
  204. if (p^.location.loc=LOC_REGISTER) or
  205. (p^.location.loc=LOC_CREGISTER) then
  206. begin
  207. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_W,p^.location.register,hregister)));
  208. end
  209. else
  210. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.location.reference),hregister)));
  211. { clear unused bits i.e unsigned extend}
  212. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L, $FFFF, hregister)));
  213. end
  214. else if porddef(hp^.resulttype)^.typ=s16bit then
  215. begin
  216. hregister:=getregister32;
  217. if (p^.location.loc=LOC_REGISTER) or
  218. (p^.location.loc=LOC_CREGISTER) then
  219. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_W,p^.location.register,hregister)))
  220. else
  221. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.location.reference),hregister)));
  222. { sign extend }
  223. exprasmlist^.concat(new(paicpu,op_reg(A_EXT, S_L, hregister)));
  224. end
  225. else internalerror(6);
  226. if (cs_check_range in aktlocalswitches) and
  227. (not(p^.explizit) {or not(cs_tp_compatible in aktmoduleswitches)}) then
  228. Begin
  229. new(hpp);
  230. reset_reference(hpp^);
  231. hpp^.symbol:=stringdup('R_'+tostr(porddef(p^.resulttype)^.rangenr));
  232. emit_bounds_check(hpp^, hregister);
  233. end;
  234. clear_location(p^.location);
  235. p^.location.loc:=LOC_REGISTER;
  236. p^.location.register:=hregister;
  237. exit;
  238. end
  239. { -------------- endian problems once again --------------------}
  240. { If RIGHT enumdef (32-bit) and we do a typecase to a smaller }
  241. { type we must absolutely load it into a register first. }
  242. { --------------------------------------------------------------}
  243. { ------------ supposing enumdef is always 32-bit --------------}
  244. { --------------------------------------------------------------}
  245. else
  246. if (hp^.resulttype^.deftype = enumdef) and (p^.resulttype^.deftype = orddef) then
  247. begin
  248. if (hp^.location.loc=LOC_REGISTER) or (hp^.location.loc=LOC_CREGISTER) then
  249. hregister:=hp^.location.register
  250. else
  251. begin
  252. hregister:=getregister32;
  253. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(hp^.location.reference),hregister)));
  254. end;
  255. clear_location(p^.location);
  256. p^.location.loc:=LOC_REGISTER;
  257. p^.location.register:=hregister;
  258. exit;
  259. end;
  260. if (p^.left^.location.loc=LOC_REGISTER) or
  261. (p^.left^.location.loc=LOC_CREGISTER) then
  262. begin
  263. { handled by secondpas by called routine ??? }
  264. p^.location.register:=p^.left^.location.register;
  265. end;
  266. end;
  267. procedure second_bigger(p,hp : ptree;convtyp : tconverttype);
  268. var
  269. hregister : tregister;
  270. opsize : topsize;
  271. op : tasmop;
  272. is_register : boolean;
  273. begin
  274. {$ifdef dummy}
  275. is_register:=p^.left^.location.loc=LOC_REGISTER;
  276. if not(is_register) and (p^.left^.location.loc<>LOC_CREGISTER) then
  277. begin
  278. del_reference(p^.left^.location.reference);
  279. { we can do this here as we need no temp inside second_bigger }
  280. ungetiftemp(p^.left^.location.reference);
  281. end;
  282. { this is wrong !!!
  283. gives me movl (%eax),%eax
  284. for the length(string !!!
  285. use only for constant values }
  286. {Constanst cannot be loaded into registers using MOVZX!}
  287. if (p^.left^.location.loc<>LOC_MEM) or (not p^.left^.location.reference.isintvalue) then
  288. case convtyp of
  289. tc_int_2_int:
  290. begin
  291. if is_register then
  292. hregister := p^.left^.location.register
  293. else
  294. hregister := getregister32;
  295. if is_register then
  296. emit_reg_reg(A_MOVE,S_B,p^.left^.location.register, hregister)
  297. else
  298. begin
  299. if p^.left^.location.loc = LOC_CREGISTER then
  300. emit_reg_reg(A_MOVE,S_B,p^.left^.location.register,hregister)
  301. else
  302. exprasmlist^.concat(new(paicpu, op_ref_reg(A_MOVE,S_B,
  303. newreference(P^.left^.location.reference), hregister)));
  304. end;
  305. case convtyp of
  306. tc_u8bit_2_s32bit,
  307. tc_u8bit_2_u32bit:
  308. exprasmlist^.concat(new(paicpu, op_const_reg(
  309. A_AND,S_L,$FF,hregister)));
  310. tc_s8bit_2_u32bit,
  311. tc_s8bit_2_s32bit:
  312. begin
  313. if aktoptprocessor = MC68020 then
  314. exprasmlist^.concat(new(paicpu,op_reg
  315. (A_EXTB,S_L,hregister)))
  316. else { else if aktoptprocessor }
  317. begin
  318. { byte to word }
  319. exprasmlist^.concat(new(paicpu,op_reg
  320. (A_EXT,S_W,hregister)));
  321. { word to long }
  322. exprasmlist^.concat(new(paicpu,op_reg
  323. (A_EXT,S_L,hregister)));
  324. end;
  325. end;
  326. tc_s8bit_2_u16bit,
  327. tc_u8bit_2_s16bit,
  328. tc_u8bit_2_u16bit:
  329. exprasmlist^.concat(new(paicpu, op_const_reg(
  330. A_AND,S_W,$FF,hregister)));
  331. tc_s8bit_2_s16bit:
  332. exprasmlist^.concat(new(paicpu, op_reg(
  333. A_EXT, S_W, hregister)));
  334. end; { inner case }
  335. end;
  336. tc_u16bit_2_u32bit,
  337. tc_u16bit_2_s32bit,
  338. tc_s16bit_2_u32bit,
  339. tc_s16bit_2_s32bit: begin
  340. if is_register then
  341. hregister := p^.left^.location.register
  342. else
  343. hregister := getregister32;
  344. if is_register then
  345. emit_reg_reg(A_MOVE,S_W,p^.left^.location.register, hregister)
  346. else
  347. begin
  348. if p^.left^.location.loc = LOC_CREGISTER then
  349. emit_reg_reg(A_MOVE,S_W,p^.left^.location.register,hregister)
  350. else
  351. exprasmlist^.concat(new(paicpu, op_ref_reg(A_MOVE,S_W,
  352. newreference(P^.left^.location.reference), hregister)));
  353. end;
  354. if (convtyp = tc_u16bit_2_s32bit) or
  355. (convtyp = tc_u16bit_2_u32bit) then
  356. exprasmlist^.concat(new(paicpu, op_const_reg(
  357. A_AND, S_L, $ffff, hregister)))
  358. else { tc_s16bit_2_s32bit }
  359. { tc_s16bit_2_u32bit }
  360. exprasmlist^.concat(new(paicpu, op_reg(A_EXT,S_L,
  361. hregister)));
  362. end;
  363. end { end case }
  364. else
  365. begin
  366. case convtyp of
  367. tc_u8bit_2_s32bit,
  368. tc_s8bit_2_s32bit,
  369. tc_u16bit_2_s32bit,
  370. tc_s16bit_2_s32bit,
  371. tc_u8bit_2_u32bit,
  372. tc_s8bit_2_u32bit,
  373. tc_u16bit_2_u32bit,
  374. tc_s16bit_2_u32bit:
  375. begin
  376. hregister:=getregister32;
  377. op:=A_MOVE;
  378. opsize:=S_L;
  379. end;
  380. tc_s8bit_2_u16bit,
  381. tc_s8bit_2_s16bit,
  382. tc_u8bit_2_s16bit,
  383. tc_u8bit_2_u16bit:
  384. begin
  385. hregister:=getregister32;
  386. op:=A_MOVE;
  387. opsize:=S_W;
  388. end;
  389. end;
  390. if is_register then
  391. begin
  392. emit_reg_reg(op,opsize,p^.left^.location.register,hregister);
  393. end
  394. else
  395. begin
  396. if p^.left^.location.loc=LOC_CREGISTER then
  397. emit_reg_reg(op,opsize,p^.left^.location.register,hregister)
  398. else exprasmlist^.concat(new(paicpu,op_ref_reg(op,opsize,
  399. newreference(p^.left^.location.reference),hregister)));
  400. end;
  401. end; { end elseif }
  402. clear_location(p^.location);
  403. p^.location.loc:=LOC_REGISTER;
  404. p^.location.register:=hregister;
  405. maybe_rangechecking(p,p^.left^.resulttype,p^.resulttype);
  406. {$endif dummy}
  407. end;
  408. procedure second_string_string(p,hp : ptree;convtyp : tconverttype);
  409. var
  410. pushed : tpushed;
  411. begin
  412. { does anybody know a better solution than this big case statement ? }
  413. { ok, a proc table would do the job }
  414. case pstringdef(p)^.string_typ of
  415. st_shortstring:
  416. case pstringdef(p^.left)^.string_typ of
  417. st_shortstring:
  418. begin
  419. stringdispose(p^.location.reference.symbol);
  420. gettempofsizereference(p^.resulttype^.size,p^.location.reference);
  421. del_reference(p^.left^.location.reference);
  422. copystring(p^.location.reference,p^.left^.location.reference,pstringdef(p^.resulttype)^.len);
  423. ungetiftemp(p^.left^.location.reference);
  424. end;
  425. st_longstring:
  426. begin
  427. {!!!!!!!}
  428. internalerror(8888);
  429. end;
  430. st_ansistring:
  431. begin
  432. {!!!!!!!}
  433. internalerror(8888);
  434. end;
  435. st_widestring:
  436. begin
  437. {!!!!!!!}
  438. internalerror(8888);
  439. end;
  440. end;
  441. st_longstring:
  442. case pstringdef(p^.left)^.string_typ of
  443. st_shortstring:
  444. begin
  445. {!!!!!!!}
  446. internalerror(8888);
  447. end;
  448. st_ansistring:
  449. begin
  450. {!!!!!!!}
  451. internalerror(8888);
  452. end;
  453. st_widestring:
  454. begin
  455. {!!!!!!!}
  456. internalerror(8888);
  457. end;
  458. end;
  459. st_ansistring:
  460. case pstringdef(p^.left)^.string_typ of
  461. st_shortstring:
  462. begin
  463. pushusedregisters(pushed,$ff);
  464. push_int(p^.resulttype^.size-1);
  465. gettempofsizereference(p^.resulttype^.size,p^.location.reference);
  466. emitpushreferenceaddr(exprasmlist,p^.location.reference);
  467. case p^.right^.location.loc of
  468. LOC_REGISTER,LOC_CREGISTER:
  469. begin
  470. { !!!!! exprasmlist^.concat(new(paicpu,op_reg(A_PUSH,S_L,p^.right^.location.register))); }
  471. ungetregister32(p^.left^.location.register);
  472. end;
  473. LOC_REFERENCE,LOC_MEM:
  474. begin
  475. emit_push_mem(p^.left^.location.reference);
  476. del_reference(p^.left^.location.reference);
  477. end;
  478. end;
  479. emitcall('FPC_ANSI_TO_SHORTSTRING',true);
  480. maybe_loada5;
  481. popusedregisters(pushed);
  482. end;
  483. st_longstring:
  484. begin
  485. {!!!!!!!}
  486. internalerror(8888);
  487. end;
  488. st_widestring:
  489. begin
  490. {!!!!!!!}
  491. internalerror(8888);
  492. end;
  493. end;
  494. st_widestring:
  495. case pstringdef(p^.left)^.string_typ of
  496. st_shortstring:
  497. begin
  498. {!!!!!!!}
  499. internalerror(8888);
  500. end;
  501. st_longstring:
  502. begin
  503. {!!!!!!!}
  504. internalerror(8888);
  505. end;
  506. st_ansistring:
  507. begin
  508. {!!!!!!!}
  509. internalerror(8888);
  510. end;
  511. st_widestring:
  512. begin
  513. {!!!!!!!}
  514. internalerror(8888);
  515. end;
  516. end;
  517. end;
  518. end;
  519. procedure second_cstring_charpointer(p,hp : ptree;convtyp : tconverttype);
  520. begin
  521. clear_location(p^.location);
  522. p^.location.loc:=LOC_REGISTER;
  523. p^.location.register:=getregister32;
  524. inc(p^.left^.location.reference.offset);
  525. exprasmlist^.concat(new(paicpu,op_ref_reg(A_LEA,S_L,newreference(p^.left^.location.reference),
  526. R_A0)));
  527. emit_reg_reg(A_MOVE, S_L, R_A0, p^.location.register);
  528. end;
  529. procedure second_string_chararray(p,hp : ptree;convtyp : tconverttype);
  530. begin
  531. inc(p^.location.reference.offset);
  532. end;
  533. procedure second_array_to_pointer(p,hp : ptree;convtyp : tconverttype);
  534. begin
  535. del_reference(p^.left^.location.reference);
  536. clear_location(p^.location);
  537. p^.location.loc:=LOC_REGISTER;
  538. p^.location.register:=getregister32;
  539. exprasmlist^.concat(new(paicpu,op_ref_reg(A_LEA,S_L,newreference(p^.left^.location.reference),
  540. R_A0)));
  541. emit_reg_reg(A_MOVE,S_L,R_A0, P^.location.register);
  542. end;
  543. procedure second_pointer_to_array(p,hp : ptree;convtyp : tconverttype);
  544. var
  545. reg: tregister;
  546. begin
  547. clear_location(p^.location);
  548. p^.location.loc:=LOC_REFERENCE;
  549. clear_reference(p^.location.reference);
  550. { here, after doing some arithmetic on the pointer }
  551. { we put it back in an address register }
  552. if p^.left^.location.loc=LOC_REGISTER then
  553. begin
  554. reg := getaddressreg;
  555. { move the pointer in a data register back into }
  556. { an address register. }
  557. emit_reg_reg(A_MOVE, S_L, p^.left^.location.register,reg);
  558. p^.location.reference.base:=reg;
  559. ungetregister32(p^.left^.location.register);
  560. end
  561. else
  562. begin
  563. if p^.left^.location.loc=LOC_CREGISTER then
  564. begin
  565. p^.location.reference.base:=getaddressreg;
  566. emit_reg_reg(A_MOVE,S_L,p^.left^.location.register,
  567. p^.location.reference.base);
  568. end
  569. else
  570. begin
  571. del_reference(p^.left^.location.reference);
  572. p^.location.reference.base:=getaddressreg;
  573. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(p^.left^.location.reference),
  574. p^.location.reference.base)));
  575. end;
  576. end;
  577. end;
  578. { generates the code for the type conversion from an array of char }
  579. { to a string }
  580. procedure second_chararray_to_string(p,hp : ptree;convtyp : tconverttype);
  581. var
  582. l : longint;
  583. begin
  584. { this is a type conversion which copies the data, so we can't }
  585. { return a reference }
  586. clear_location(p^.location);
  587. p^.location.loc:=LOC_MEM;
  588. { first get the memory for the string }
  589. stringdispose(p^.location.reference.symbol);
  590. gettempofsizereference(256,p^.location.reference);
  591. { calc the length of the array }
  592. l:=parraydef(p^.left^.resulttype)^.highrange-
  593. parraydef(p^.left^.resulttype)^.lowrange+1;
  594. if l>255 then
  595. CGMessage(type_e_mismatch);
  596. { write the length }
  597. exprasmlist^.concat(new(paicpu,op_const_ref(A_MOVE,S_B,l,
  598. newreference(p^.location.reference))));
  599. { copy to first char of string }
  600. inc(p^.location.reference.offset);
  601. { generates the copy code }
  602. { and we need the source never }
  603. concatcopy(p^.left^.location.reference,p^.location.reference,l,true);
  604. { correct the string location }
  605. dec(p^.location.reference.offset);
  606. end;
  607. procedure second_char_to_string(p,hp : ptree;convtyp : tconverttype);
  608. begin
  609. stringdispose(p^.location.reference.symbol);
  610. gettempofsizereference(256,p^.location.reference);
  611. { call loadstring with correct left and right }
  612. p^.right:=p^.left;
  613. p^.left:=p;
  614. loadstring(p);
  615. p^.left:=nil; { reset left tree, which is empty }
  616. { p^.right is not disposed for typeconv !! PM }
  617. disposetree(p^.right);
  618. p^.right:=nil;
  619. end;
  620. procedure second_int_real(p,hp : ptree;convtyp : tconverttype);
  621. var
  622. r : preference;
  623. begin
  624. emitloadord2reg(p^.left^.location, porddef(p^.left^.resulttype), R_D6, true);
  625. ungetiftemp(p^.left^.location.reference);
  626. if porddef(p^.left^.resulttype)^.typ=u32bit then
  627. push_int(0);
  628. emit_reg_reg(A_MOVE, S_L, R_D6, R_SPPUSH);
  629. new(r);
  630. reset_reference(r^);
  631. r^.base := R_SP;
  632. { no emulation }
  633. { for u32bit a solution would be to push $0 and to load a
  634. + comp
  635. + if porddef(p^.left^.resulttype)^.typ=u32bit then
  636. + exprasmlist^.concat(new(paicpu,op_ref(A_FILD,S_IQ,r)))
  637. + else}
  638. clear_location(p^.location);
  639. p^.location.loc := LOC_FPU;
  640. { get floating point register. }
  641. if (cs_fp_emulation in aktmoduleswitches) then
  642. begin
  643. p^.location.fpureg := getregister32;
  644. exprasmlist^.concat(new(paicpu, op_ref_reg(A_MOVE, S_L, r, R_D0)));
  645. emitcall('FPC_LONG2SINGLE',true);
  646. emit_reg_reg(A_MOVE,S_L,R_D0,p^.location.fpureg);
  647. end
  648. else
  649. begin
  650. p^.location.fpureg := getfloatreg;
  651. exprasmlist^.concat(new(paicpu, op_ref_reg(A_FMOVE, S_L, r, p^.location.fpureg)))
  652. end;
  653. if porddef(p^.left^.resulttype)^.typ=u32bit then
  654. exprasmlist^.concat(new(paicpu,op_const_reg(A_ADD,S_L,8,R_SP)))
  655. else
  656. { restore the stack to the previous address }
  657. exprasmlist^.concat(new(paicpu, op_const_reg(A_ADDQ, S_L, 4, R_SP)));
  658. end;
  659. procedure second_real_fix(p,hp : ptree;convtyp : tconverttype);
  660. var
  661. rreg : tregister;
  662. ref : treference;
  663. begin
  664. rreg:=getregister32;
  665. { Are we in a LOC_FPU, if not then use scratch registers }
  666. { instead of allocating reserved registers. }
  667. if (p^.left^.location.loc<>LOC_FPU) then
  668. begin
  669. if (cs_fp_emulation in aktmoduleswitches) then
  670. begin
  671. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(p^.left^.location.reference),R_D0)));
  672. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_L,65536,R_D1)));
  673. emitcall('FPC_LONGMUL',true);
  674. emit_reg_reg(A_MOVE,S_L,R_D0,rreg);
  675. end
  676. else
  677. begin
  678. exprasmlist^.concat(new(paicpu,op_ref_reg(A_FMOVE,S_L,newreference(p^.left^.location.reference),R_FP0)));
  679. exprasmlist^.concat(new(paicpu,op_const_reg(A_FMUL,S_L,65536,R_FP0)));
  680. exprasmlist^.concat(new(paicpu,op_reg_reg(A_FMOVE,S_L,R_FP0,rreg)));
  681. end;
  682. end
  683. else
  684. begin
  685. if (cs_fp_emulation in aktmoduleswitches) then
  686. begin
  687. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D0)));
  688. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_L,65536,R_D1)));
  689. emitcall('FPC_LONGMUL',true);
  690. emit_reg_reg(A_MOVE,S_L,R_D0,rreg);
  691. end
  692. else
  693. begin
  694. exprasmlist^.concat(new(paicpu,op_const_reg(A_FMUL,S_L,65536,p^.left^.location.fpureg)));
  695. exprasmlist^.concat(new(paicpu,op_reg_reg(A_FMOVE,S_L,p^.left^.location.fpureg,rreg)));
  696. end;
  697. end;
  698. clear_location(p^.location);
  699. p^.location.loc:=LOC_REGISTER;
  700. p^.location.register:=rreg;
  701. end;
  702. procedure second_float_float(p,hp : ptree;convtyp : tconverttype);
  703. begin
  704. case p^.left^.location.loc of
  705. LOC_FPU : begin
  706. { reload }
  707. clear_location(p^.location);
  708. p^.location.loc := LOC_FPU;
  709. p^.location.fpureg := p^.left^.location.fpureg;
  710. end;
  711. LOC_MEM,
  712. LOC_REFERENCE : floatload(pfloatdef(p^.left^.resulttype)^.typ,
  713. p^.left^.location.reference,p^.location);
  714. end;
  715. { ALREADY HANDLED BY FLOATLOAD }
  716. { p^.location.loc:=LOC_FPU; }
  717. end;
  718. procedure second_fix_real(p,hp : ptree;convtyp : tconverttype);
  719. var
  720. startreg : tregister;
  721. hl : pasmlabel;
  722. r : treference;
  723. reg1: tregister;
  724. hl1,hl2,hl3,hl4,hl5,hl6,hl7,hl8,hl9: pasmlabel;
  725. begin
  726. if (p^.left^.location.loc=LOC_REGISTER) or
  727. (p^.left^.location.loc=LOC_CREGISTER) then
  728. begin
  729. startreg:=p^.left^.location.register;
  730. ungetregister(startreg);
  731. { move d0,d0 is removed by emit_reg_reg }
  732. emit_reg_reg(A_MOVE,S_L,startreg,R_D0);
  733. end
  734. else
  735. begin
  736. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(
  737. p^.left^.location.reference),R_D0)));
  738. del_reference(p^.left^.location.reference);
  739. startreg:=R_NO;
  740. end;
  741. reg1 := getregister32;
  742. { Motorola 68000 equivalent of CDQ }
  743. { we choose d1:d0 pair for quad word }
  744. exprasmlist^.concat(new(paicpu,op_reg(A_TST,S_L,R_D0)));
  745. getlabel(hl1);
  746. emitl(A_BPL,hl1);
  747. { we copy all bits (-ve number) }
  748. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_L,$ffffffff,R_D1)));
  749. getlabel(hl2);
  750. emitl(A_BRA,hl2);
  751. emitl(A_LABEL,hl1);
  752. exprasmlist^.concat(new(paicpu,op_reg(A_CLR,S_L,R_D0)));
  753. emitl(A_LABEL,hl2);
  754. { end CDQ }
  755. exprasmlist^.concat(new(paicpu,op_reg_reg(A_EOR,S_L,R_D1,R_D0)));
  756. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,reg1)));
  757. getlabel(hl3);
  758. emitl(A_BEQ,hl3);
  759. { Motorola 68000 equivalent of RCL }
  760. getlabel(hl4);
  761. emitl(A_BCC,hl4);
  762. exprasmlist^.concat(new(paicpu,op_const_reg(A_LSL,S_L,1,reg1)));
  763. exprasmlist^.concat(new(paicpu,op_const_reg(A_OR,S_L,1,reg1)));
  764. getlabel(hl5);
  765. emitl(A_BRA,hl5);
  766. emitl(A_LABEL,hl4);
  767. exprasmlist^.concat(new(paicpu,op_const_reg(A_LSL,S_L,1,reg1)));
  768. emitl(A_LABEL,hl5);
  769. { end RCL }
  770. { Motorola 68000 equivalent of BSR }
  771. { save register }
  772. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,R_D6)));
  773. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_B,31,R_D0)));
  774. getlabel(hl6);
  775. emitl(A_LABEL,hl6);
  776. exprasmlist^.concat(new(paicpu,op_reg_reg(A_BTST,S_L,R_D0,R_D1)));
  777. getlabel(hl7);
  778. emitl(A_BNE,hl7);
  779. exprasmlist^.concat(new(paicpu,op_const_reg(A_SUBQ,S_B,1,R_D0)));
  780. emitl(A_BPL,hl6);
  781. { restore register }
  782. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D6,R_D0)));
  783. emitl(A_LABEL,hl7);
  784. { end BSR }
  785. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_B,32,R_D6)));
  786. exprasmlist^.concat(new(paicpu,op_reg_reg(A_SUB,S_B,R_D1,R_D6)));
  787. exprasmlist^.concat(new(paicpu,op_reg_reg(A_LSL,S_L,R_D6,R_D0)));
  788. exprasmlist^.concat(new(paicpu,op_const_reg(A_ADD,S_W,1007,R_D1)));
  789. exprasmlist^.concat(new(paicpu,op_const_reg(A_LSL,S_L,5,R_D1)));
  790. { Motorola 68000 equivalent of SHLD }
  791. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_W,11,R_D6)));
  792. { save register }
  793. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D1,R_A0)));
  794. getlabel(hl8);
  795. emitl(A_LABEL,hl8);
  796. exprasmlist^.concat(new(paicpu,op_const_reg(A_ROXL,S_W,1,R_D1)));
  797. exprasmlist^.concat(new(paicpu,op_const_reg(A_ROXL,S_W,1,reg1)));
  798. exprasmlist^.concat(new(paicpu,op_const_reg(A_SUBQ,S_B,1,R_D6)));
  799. emitl(A_BNE,hl8);
  800. { restore register }
  801. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_A0,R_D1)));
  802. { end Motorola equivalent of SHLD }
  803. { Motorola 68000 equivalent of SHLD }
  804. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_W,20,R_D6)));
  805. { save register }
  806. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,R_A0)));
  807. getlabel(hl9);
  808. emitl(A_LABEL,hl9);
  809. exprasmlist^.concat(new(paicpu,op_const_reg(A_ROXL,S_W,1,R_D0)));
  810. exprasmlist^.concat(new(paicpu,op_const_reg(A_ROXL,S_W,1,reg1)));
  811. exprasmlist^.concat(new(paicpu,op_const_reg(A_SUBQ,S_B,1,R_D6)));
  812. emitl(A_BNE,hl9);
  813. { restore register }
  814. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_A0,R_D0)));
  815. { end Motorola equivalent of SHLD }
  816. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_B,20,R_D6)));
  817. exprasmlist^.concat(new(paicpu,op_reg_reg(A_SUB,S_L,R_D6,R_D0)));
  818. emitl(A_LABEL, hl3);
  819. { create temp values and put on stack }
  820. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,reg1,R_SPPUSH)));
  821. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,R_SPPUSH)));
  822. reset_reference(r);
  823. r.base:=R_SP;
  824. if (cs_fp_emulation in aktmoduleswitches) then
  825. begin
  826. clear_location(p^.location);
  827. p^.location.loc:=LOC_FPU;
  828. p^.location.fpureg := getregister32;
  829. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(r),
  830. p^.left^.location.fpureg)))
  831. end
  832. else
  833. begin
  834. clear_location(p^.location);
  835. p^.location.loc:=LOC_FPU;
  836. p^.location.fpureg := getfloatreg;
  837. exprasmlist^.concat(new(paicpu,op_ref_reg(A_FMOVE,S_L,newreference(r),
  838. p^.left^.location.fpureg)))
  839. end;
  840. { clear temporary space }
  841. exprasmlist^.concat(new(paicpu,op_const_reg(A_ADDQ,S_L,8,R_SP)));
  842. ungetregister32(reg1);
  843. { Alreadu handled above... }
  844. { p^.location.loc:=LOC_FPU; }
  845. end;
  846. procedure second_int_fix(p,hp : ptree;convtyp : tconverttype);
  847. var
  848. {hs : string;}
  849. hregister : tregister;
  850. begin
  851. if (p^.left^.location.loc=LOC_REGISTER) then
  852. hregister:=p^.left^.location.register
  853. else if (p^.left^.location.loc=LOC_CREGISTER) then
  854. hregister:=getregister32
  855. else
  856. begin
  857. del_reference(p^.left^.location.reference);
  858. hregister:=getregister32;
  859. case porddef(p^.left^.resulttype)^.typ of
  860. s8bit : begin
  861. exprasmlist^.concat(new(paicpu, op_ref_reg(A_MOVE,S_B,
  862. newreference(p^.left^.location.reference),hregister)));
  863. if aktoptprocessor = MC68020 then
  864. exprasmlist^.concat(new(paicpu, op_reg(A_EXTB,S_L,hregister)))
  865. else
  866. begin
  867. exprasmlist^.concat(new(paicpu, op_reg(A_EXT,S_W,hregister)));
  868. exprasmlist^.concat(new(paicpu, op_reg(A_EXT,S_L,hregister)));
  869. end;
  870. end;
  871. u8bit : begin
  872. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_B,newreference(p^.left^.location.reference),
  873. hregister)));
  874. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L,$ff,hregister)));
  875. end;
  876. s16bit :begin
  877. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.left^.location.reference),
  878. hregister)));
  879. exprasmlist^.concat(new(paicpu,op_reg(A_EXT,S_L,hregister)));
  880. end;
  881. u16bit : begin
  882. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,newreference(p^.left^.location.reference),
  883. hregister)));
  884. exprasmlist^.concat(new(paicpu,op_const_reg(A_AND,S_L,$ffff,hregister)));
  885. end;
  886. s32bit,u32bit : exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(p^.left^.location.reference),
  887. hregister)));
  888. {!!!! u32bit }
  889. end;
  890. end;
  891. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVEQ,S_L,16,R_D1)));
  892. exprasmlist^.concat(new(paicpu,op_reg_reg(A_LSL,S_L,R_D1,hregister)));
  893. clear_location(p^.location);
  894. p^.location.loc:=LOC_REGISTER;
  895. p^.location.register:=hregister;
  896. end;
  897. procedure second_proc_to_procvar(p,hp : ptree;convtyp : tconverttype);
  898. begin
  899. { secondpass(hp); already done in secondtypeconv PM }
  900. clear_location(p^.location);
  901. p^.location.loc:=LOC_REGISTER;
  902. del_reference(hp^.location.reference);
  903. p^.location.register:=getregister32;
  904. exprasmlist^.concat(new(paicpu,op_ref_reg(A_LEA,S_L,
  905. newreference(hp^.location.reference),R_A0)));
  906. emit_reg_reg(A_MOVE, S_L, R_A0, P^.location.register);
  907. end;
  908. procedure second_bool_to_int(p,hp : ptree;convtyp : tconverttype);
  909. var
  910. oldtruelabel,oldfalselabel,hlabel : pasmlabel;
  911. hregister : tregister;
  912. newsize,
  913. opsize : topsize;
  914. op : tasmop;
  915. begin
  916. oldtruelabel:=truelabel;
  917. oldfalselabel:=falselabel;
  918. getlabel(truelabel);
  919. getlabel(falselabel);
  920. secondpass(hp);
  921. clear_location(p^.location);
  922. p^.location.loc:=LOC_REGISTER;
  923. del_reference(hp^.location.reference);
  924. hregister:=getregister32;
  925. case porddef(hp^.resulttype)^.typ of
  926. bool8bit : begin
  927. case porddef(p^.resulttype)^.typ of
  928. u8bit,s8bit,
  929. bool8bit : opsize:=S_B;
  930. u16bit,s16bit,
  931. bool16bit : opsize:=S_BW;
  932. u32bit,s32bit,
  933. bool32bit : opsize:=S_BL;
  934. end;
  935. end;
  936. bool16bit : begin
  937. case porddef(p^.resulttype)^.typ of
  938. u8bit,s8bit,
  939. bool8bit : opsize:=S_B;
  940. u16bit,s16bit,
  941. bool16bit : opsize:=S_W;
  942. u32bit,s32bit,
  943. bool32bit : opsize:=S_WL;
  944. end;
  945. end;
  946. bool32bit : begin
  947. case porddef(p^.resulttype)^.typ of
  948. u8bit,s8bit,
  949. bool8bit : opsize:=S_B;
  950. u16bit,s16bit,
  951. bool16bit : opsize:=S_W;
  952. u32bit,s32bit,
  953. bool32bit : opsize:=S_L;
  954. end;
  955. end;
  956. end;
  957. op:=A_MOVE;
  958. { if opsize in [S_B,S_W,S_L] then
  959. op:=A_MOVE
  960. else
  961. if (porddef(p^.resulttype)^.typ in [s8bit,s16bit,s32bit]) then
  962. op:=A_MOVSX
  963. else
  964. op:=A_MOVZX; }
  965. case porddef(p^.resulttype)^.typ of
  966. bool8bit,u8bit,s8bit : begin
  967. p^.location.register:=hregister;
  968. newsize:=S_B;
  969. end;
  970. bool16bit,u16bit,s16bit : begin
  971. p^.location.register:=hregister;
  972. newsize:=S_W;
  973. end;
  974. bool32bit,u32bit,s32bit : begin
  975. p^.location.register:=hregister;
  976. newsize:=S_L;
  977. end;
  978. else
  979. internalerror(10060);
  980. end;
  981. case hp^.location.loc of
  982. LOC_MEM,
  983. LOC_REFERENCE : exprasmlist^.concat(new(paicpu,op_ref_reg(op,opsize,
  984. newreference(hp^.location.reference),p^.location.register)));
  985. LOC_REGISTER,
  986. LOC_CREGISTER : exprasmlist^.concat(new(paicpu,op_reg_reg(op,opsize,
  987. hp^.location.register,p^.location.register)));
  988. LOC_FLAGS : begin
  989. { hregister:=reg32toreg8(hregister); }
  990. exprasmlist^.concat(new(paicpu,op_reg(flag_2_set[hp^.location.resflags],S_B,hregister)));
  991. { !!!!!!!!
  992. case porddef(p^.resulttype)^.typ of
  993. bool16bit,
  994. u16bit,s16bit : exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVZX,S_BW,hregister,p^.location.register)));
  995. bool32bit,
  996. u32bit,s32bit : exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVZX,S_BL,hregister,p^.location.register)));
  997. end; }
  998. end;
  999. LOC_JUMP : begin
  1000. getlabel(hlabel);
  1001. emitl(A_LABEL,truelabel);
  1002. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,newsize,1,hregister)));
  1003. emitl(A_JMP,hlabel);
  1004. emitl(A_LABEL,falselabel);
  1005. exprasmlist^.concat(new(paicpu,op_reg(A_CLR,newsize,hregister)));
  1006. emitl(A_LABEL,hlabel);
  1007. end;
  1008. else
  1009. internalerror(10061);
  1010. end;
  1011. freelabel(truelabel);
  1012. freelabel(falselabel);
  1013. truelabel:=oldtruelabel;
  1014. falselabel:=oldfalselabel;
  1015. end;
  1016. procedure second_int_to_bool(p,hp : ptree;convtyp : tconverttype);
  1017. var
  1018. hregister : tregister;
  1019. begin
  1020. clear_location(p^.location);
  1021. p^.location.loc:=LOC_REGISTER;
  1022. del_reference(hp^.location.reference);
  1023. case hp^.location.loc of
  1024. LOC_MEM,LOC_REFERENCE :
  1025. begin
  1026. hregister:=getregister32;
  1027. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  1028. newreference(hp^.location.reference),hregister)));
  1029. end;
  1030. LOC_REGISTER,LOC_CREGISTER :
  1031. begin
  1032. hregister:=hp^.location.register;
  1033. end;
  1034. else
  1035. internalerror(10062);
  1036. end;
  1037. exprasmlist^.concat(new(paicpu,op_reg_reg(A_OR,S_L,hregister,hregister)));
  1038. { hregister:=reg32toreg8(hregister); }
  1039. exprasmlist^.concat(new(paicpu,op_reg(flag_2_set[hp^.location.resflags],S_B,hregister)));
  1040. case porddef(p^.resulttype)^.typ of
  1041. bool8bit : p^.location.register:=hregister;
  1042. { !!!!!!!!!!!
  1043. bool16bit : begin
  1044. p^.location.register:=reg8toreg16(hregister);
  1045. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVZX,S_BW,hregister,p^.location.register)));
  1046. end;
  1047. bool32bit : begin
  1048. p^.location.register:=reg16toreg32(hregister);
  1049. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVZX,S_BL,hregister,p^.location.register)));
  1050. end; }
  1051. else
  1052. internalerror(10064);
  1053. end;
  1054. end;
  1055. procedure second_load_smallset(p,hp : ptree;convtyp : tconverttype);
  1056. var
  1057. href : treference;
  1058. pushedregs : tpushed;
  1059. begin
  1060. href.symbol:=nil;
  1061. pushusedregisters(pushedregs,$ff);
  1062. gettempofsizereference(32,href);
  1063. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  1064. emitpushreferenceaddr(exprasmlist,href);
  1065. emitcall('FPC_SET_LOAD_SMALL',true);
  1066. maybe_loada5;
  1067. popusedregisters(pushedregs);
  1068. clear_location(p^.location);
  1069. p^.location.loc:=LOC_MEM;
  1070. stringdispose(p^.location.reference.symbol);
  1071. p^.location.reference:=href;
  1072. end;
  1073. procedure second_ansistring_to_pchar(p,hp : ptree;convtyp : tconverttype);
  1074. var
  1075. l1,l2 : pasmlabel;
  1076. hr : preference;
  1077. begin
  1078. InternalError(342132);
  1079. {!!!!!!!!!!!
  1080. clear_location(p^.location);
  1081. p^.location.loc:=LOC_REGISTER;
  1082. getlabel(l1);
  1083. getlabel(l2);
  1084. case hp^.location.loc of
  1085. LOC_CREGISTER,LOC_REGISTER:
  1086. exprasmlist^.concat(new(paicpu,op_const_reg(A_CMP,S_L,0,
  1087. hp^.location.register)));
  1088. LOC_MEM,LOC_REFERENCE:
  1089. begin
  1090. exprasmlist^.concat(new(paicpu,op_const_ref(A_CMP,S_L,0,
  1091. newreference(hp^.location.reference))));
  1092. del_reference(hp^.location.reference);
  1093. p^.location.register:=getregister32;
  1094. end;
  1095. end;
  1096. emitl(A_JZ,l1);
  1097. if hp^.location.loc in [LOC_MEM,LOC_REFERENCE] then
  1098. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOV,S_L,newreference(
  1099. hp^.location.reference),
  1100. p^.location.register)));
  1101. emitl(A_JMP,l2);
  1102. emitl(A_LABEL,l1);
  1103. new(hr);
  1104. reset_reference(hr^);
  1105. hr^.symbol:=stringdup('FPC_EMPTYCHAR');
  1106. exprasmlist^.concat(new(paicpu,op_ref_reg(A_LEA,S_L,hr,
  1107. p^.location.register)));
  1108. emitl(A_LABEL,l2); }
  1109. end;
  1110. procedure second_pchar_to_string(p,hp : ptree;convtyp : tconverttype);
  1111. begin
  1112. internalerror(12121);
  1113. end;
  1114. procedure second_nothing(p,hp : ptree;convtyp : tconverttype);
  1115. begin
  1116. end;
  1117. {****************************************************************************
  1118. SecondTypeConv
  1119. ****************************************************************************}
  1120. procedure secondtypeconv(var p : ptree);
  1121. const
  1122. secondconvert : array[tconverttype] of
  1123. tsecondconvproc = (second_nothing,second_nothing,
  1124. second_bigger,second_only_rangecheck,
  1125. second_bigger,second_bigger,second_bigger,
  1126. second_smaller,second_smaller,
  1127. second_smaller,second_string_string,
  1128. second_cstring_charpointer,second_string_chararray,
  1129. second_array_to_pointer,second_pointer_to_array,
  1130. second_char_to_string,second_bigger,
  1131. second_bigger,second_bigger,
  1132. second_smaller,second_smaller,
  1133. second_smaller,second_smaller,
  1134. second_bigger);
  1135. {$ifdef dummy}
  1136. ,second_smaller,
  1137. second_only_rangecheck,second_bigger,
  1138. second_bigger,second_bigger,
  1139. second_bigger,second_only_rangecheck,
  1140. second_smaller,second_smaller,
  1141. second_smaller,second_smaller,
  1142. second_bool_to_int,second_int_to_bool,
  1143. second_int_real,second_real_fix,
  1144. second_fix_real,second_int_fix,second_float_float,
  1145. second_chararray_to_string,
  1146. second_proc_to_procvar,
  1147. { is constant char to pchar, is done by firstpass }
  1148. second_nothing,
  1149. second_load_smallset,
  1150. second_ansistring_to_pchar,
  1151. second_pchar_to_string,
  1152. second_nothing);
  1153. {$endif dummy}
  1154. begin
  1155. { this isn't good coding, I think tc_bool_2_int, shouldn't be }
  1156. { type conversion (FK) }
  1157. { this is necessary, because second_bool_byte, have to change }
  1158. { true- and false label before calling secondpass }
  1159. if p^.convtyp<>tc_bool_2_int then
  1160. begin
  1161. secondpass(p^.left);
  1162. set_location(p^.location,p^.left^.location);
  1163. if codegenerror then
  1164. exit;
  1165. end;
  1166. if not(p^.convtyp in [tc_equal,tc_not_possible]) then
  1167. {the second argument only is for maybe_range_checking !}
  1168. secondconvert[p^.convtyp](p,p^.left,p^.convtyp)
  1169. end;
  1170. {*****************************************************************************
  1171. SecondIs
  1172. *****************************************************************************}
  1173. procedure secondis(var p : ptree);
  1174. var
  1175. pushed : tpushed;
  1176. begin
  1177. { save all used registers }
  1178. pushusedregisters(pushed,$ffff);
  1179. secondpass(p^.left);
  1180. clear_location(p^.location);
  1181. p^.location.loc:=LOC_FLAGS;
  1182. p^.location.resflags:=F_NE;
  1183. { push instance to check: }
  1184. case p^.left^.location.loc of
  1185. LOC_REGISTER,LOC_CREGISTER:
  1186. begin
  1187. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,
  1188. S_L,p^.left^.location.register,R_SPPUSH)));
  1189. ungetregister32(p^.left^.location.register);
  1190. end;
  1191. LOC_MEM,LOC_REFERENCE:
  1192. begin
  1193. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,
  1194. S_L,newreference(p^.left^.location.reference),R_SPPUSH)));
  1195. del_reference(p^.left^.location.reference);
  1196. end;
  1197. else internalerror(100);
  1198. end;
  1199. { generate type checking }
  1200. secondpass(p^.right);
  1201. case p^.right^.location.loc of
  1202. LOC_REGISTER,LOC_CREGISTER:
  1203. begin
  1204. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,
  1205. S_L,p^.right^.location.register,R_SPPUSH)));
  1206. ungetregister32(p^.right^.location.register);
  1207. end;
  1208. LOC_MEM,LOC_REFERENCE:
  1209. begin
  1210. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,
  1211. S_L,newreference(p^.right^.location.reference),R_SPPUSH)));
  1212. del_reference(p^.right^.location.reference);
  1213. end;
  1214. else internalerror(100);
  1215. end;
  1216. emitcall('FPC_DO_IS',true);
  1217. exprasmlist^.concat(new(paicpu,op_reg(A_TST,S_B,R_D0)));
  1218. popusedregisters(pushed);
  1219. end;
  1220. {*****************************************************************************
  1221. SecondAs
  1222. *****************************************************************************}
  1223. procedure secondas(var p : ptree);
  1224. var
  1225. pushed : tpushed;
  1226. begin
  1227. set_location(p^.location,p^.left^.location);
  1228. { save all used registers }
  1229. pushusedregisters(pushed,$ffff);
  1230. { push the vmt of the class }
  1231. exprasmlist^.concat(new(paicpu,op_csymbol_reg(A_MOVE,
  1232. S_L,newcsymbol(pobjectdef(p^.right^.resulttype)^.vmt_mangledname,0),R_SPPUSH)));
  1233. emitpushreferenceaddr(exprasmlist,p^.location.reference);
  1234. emitcall('FPC_DO_AS',true);
  1235. popusedregisters(pushed);
  1236. end;
  1237. end.
  1238. {
  1239. $Log$
  1240. Revision 1.14 1999-09-16 23:05:51 florian
  1241. * m68k compiler is again compilable (only gas writer, no assembler reader)
  1242. Revision 1.13 1999/08/25 11:59:48 jonas
  1243. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1244. Revision 1.12 1998/12/11 00:02:59 peter
  1245. + globtype,tokens,version unit splitted from globals
  1246. Revision 1.11 1998/11/05 12:02:36 peter
  1247. * released useansistring
  1248. * removed -Sv, its now available in fpc modes
  1249. Revision 1.10 1998/10/15 12:41:17 pierre
  1250. * last memory leaks found when compiler
  1251. a native atari compiler fixed
  1252. Revision 1.9 1998/10/14 11:28:17 florian
  1253. * emitpushreferenceaddress gets now the asmlist as parameter
  1254. * m68k version compiles with -duseansistrings
  1255. Revision 1.8 1998/10/14 10:45:05 pierre
  1256. * ppu problems for m68k fixed (at least in cross compiling)
  1257. * one last memory leak for sysamiga fixed
  1258. * the amiga RTL compiles now completely !!
  1259. Revision 1.7 1998/10/13 16:50:06 pierre
  1260. * undid some changes of Peter that made the compiler wrong
  1261. for m68k (I had to reinsert some ifdefs)
  1262. * removed several memory leaks under m68k
  1263. * removed the meory leaks for assembler readers
  1264. * cross compiling shoud work again better
  1265. ( crosscompiling sysamiga works
  1266. but as68k still complain about some code !)
  1267. Revision 1.6 1998/10/06 20:48:56 peter
  1268. * m68k compiler compiles again
  1269. Revision 1.5 1998/09/17 09:42:23 peter
  1270. + pass_2 for cg386
  1271. * Message() -> CGMessage() for pass_1/pass_2
  1272. Revision 1.4 1998/09/14 10:43:56 peter
  1273. * all internal RTL functions start with FPC_
  1274. Revision 1.3 1998/09/11 12:29:43 pierre
  1275. * removed explicit range_checking as it is buggy
  1276. Revision 1.2.2.1 1998/09/11 12:08:57 pierre
  1277. * removed explicit range_check was buggy
  1278. Revision 1.2 1998/09/04 08:41:45 peter
  1279. * updated some error messages
  1280. Revision 1.1 1998/09/01 09:07:09 peter
  1281. * m68k fixes, splitted cg68k like cgi386
  1282. }