ncgmem.pas 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate assembler for memory related nodes which are
  4. the same for all (most?) processors
  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. unit ncgmem;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,cgbase,cgutils,cpuinfo,cpubase,
  23. symtype,
  24. node,nmem;
  25. type
  26. tcgloadvmtaddrnode = class(tloadvmtaddrnode)
  27. procedure pass_generate_code;override;
  28. end;
  29. tcgloadparentfpnode = class(tloadparentfpnode)
  30. procedure pass_generate_code;override;
  31. end;
  32. tcgaddrnode = class(taddrnode)
  33. procedure pass_generate_code;override;
  34. end;
  35. tcgderefnode = class(tderefnode)
  36. procedure pass_generate_code;override;
  37. end;
  38. tcgsubscriptnode = class(tsubscriptnode)
  39. protected
  40. function handle_platform_subscript: boolean; virtual;
  41. public
  42. procedure pass_generate_code;override;
  43. end;
  44. tcgwithnode = class(twithnode)
  45. procedure pass_generate_code;override;
  46. end;
  47. tcgvecnode = class(tvecnode)
  48. function get_mul_size : aint;
  49. private
  50. procedure rangecheck_array;
  51. procedure rangecheck_string;
  52. protected
  53. {# This routine is used to calculate the address of the reference.
  54. On entry reg contains the index in the array,
  55. and l contains the size of each element in the array.
  56. This routine should update location.reference correctly,
  57. so it points to the correct address.
  58. }
  59. procedure update_reference_reg_mul(maybe_const_reg: tregister;regsize: tdef; l: aint);virtual;
  60. procedure update_reference_reg_packed(maybe_const_reg: tregister; regsize: tdef; l: aint);virtual;
  61. procedure update_reference_offset(var ref: treference; index, mulsize: aint); virtual;
  62. procedure second_wideansistring;virtual;
  63. procedure second_dynamicarray;virtual;
  64. function valid_index_size(size: tcgsize): boolean;virtual;
  65. public
  66. procedure pass_generate_code;override;
  67. end;
  68. implementation
  69. uses
  70. systems,
  71. cutils,cclasses,verbose,globals,constexp,fmodule,
  72. symconst,symbase,symdef,symsym,symcpu,symtable,defutil,paramgr,
  73. aasmbase,aasmtai,aasmdata,
  74. procinfo,pass_2,parabase,
  75. pass_1,nld,ncon,nadd,ncnv,nutils,
  76. cgobj,hlcgobj,
  77. tgobj,ncgutil,objcgutl,
  78. defcmp
  79. ;
  80. {*****************************************************************************
  81. TCGLOADVMTADDRNODE
  82. *****************************************************************************}
  83. procedure tcgloadvmtaddrnode.pass_generate_code;
  84. var
  85. href : treference;
  86. pool : THashSet;
  87. entry : PHashSetItem;
  88. indirect : boolean;
  89. begin
  90. location_reset(location,LOC_REGISTER,def_cgsize(voidpointertype));
  91. if (left.nodetype=typen) then
  92. begin
  93. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,voidpointertype);
  94. if not is_objcclass(left.resultdef) then
  95. begin
  96. { we are using a direct reference if any of the following is true:
  97. - the target does not support packages
  98. - the target does not use indirect references
  99. - the class is located inside the same unit }
  100. indirect:=(tf_supports_packages in target_info.flags) and
  101. (target_info.system in systems_indirect_var_imports) and
  102. not sym_is_owned_by(left.resultdef.typesym,current_module.globalsymtable) and
  103. (
  104. (current_module.globalsymtable=current_module.localsymtable) or
  105. not sym_is_owned_by(left.resultdef.typesym,current_module.localsymtable)
  106. );
  107. reference_reset_symbol(href,
  108. current_asmdata.RefAsmSymbol(tobjectdef(tclassrefdef(resultdef).pointeddef).vmt_mangledname,AT_DATA,indirect),0,
  109. voidpointertype.size);
  110. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,resultdef,resultdef,href,location.register);
  111. end
  112. else
  113. begin
  114. pool:=current_asmdata.ConstPools[sp_objcclassnamerefs];
  115. entry:=pool.FindOrAdd(@tobjectdef(left.resultdef).objextname^[1],length(tobjectdef(left.resultdef).objextname^));
  116. if (target_info.system in systems_objc_nfabi) then
  117. begin
  118. { find/add necessary classref/classname pool entries }
  119. objcfinishclassrefnfpoolentry(entry,tobjectdef(left.resultdef));
  120. end
  121. else
  122. begin
  123. { find/add necessary classref/classname pool entries }
  124. objcfinishstringrefpoolentry(entry,sp_objcclassnames,sec_objc_cls_refs,sec_objc_class_names);
  125. end;
  126. reference_reset_symbol(href,tasmlabel(entry^.Data),0,voidpointertype.size);
  127. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,objc_idtype,objc_idtype,href,location.register);
  128. end;
  129. end
  130. else
  131. { should be handled in pass 1 }
  132. internalerror(2015052801);
  133. end;
  134. {*****************************************************************************
  135. TCGLOADPARENTFPNODE
  136. *****************************************************************************}
  137. procedure tcgloadparentfpnode.pass_generate_code;
  138. var
  139. currpi : tprocinfo;
  140. hsym : tparavarsym;
  141. href : treference;
  142. begin
  143. if (current_procinfo.procdef.parast.symtablelevel=parentpd.parast.symtablelevel) then
  144. begin
  145. location_reset(location,LOC_REGISTER,def_cgsize(parentfpvoidpointertype));
  146. location.register:=current_procinfo.framepointer;
  147. end
  148. else
  149. begin
  150. currpi:=current_procinfo;
  151. location_reset(location,LOC_REGISTER,def_cgsize(parentfpvoidpointertype));
  152. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,parentfpvoidpointertype);
  153. { load framepointer of current proc }
  154. hsym:=tparavarsym(currpi.procdef.parast.Find('parentfp'));
  155. if not assigned(hsym) then
  156. internalerror(200309281);
  157. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,parentfpvoidpointertype,parentfpvoidpointertype,hsym.localloc,location.register);
  158. { walk parents }
  159. while (currpi.procdef.owner.symtablelevel>parentpd.parast.symtablelevel) do
  160. begin
  161. currpi:=currpi.parent;
  162. if not assigned(currpi) then
  163. internalerror(200311201);
  164. hsym:=tparavarsym(currpi.procdef.parast.Find('parentfp'));
  165. if not assigned(hsym) then
  166. internalerror(200309282);
  167. if hsym.localloc.loc<>LOC_REFERENCE then
  168. internalerror(200309283);
  169. hlcg.reference_reset_base(href,parentfpvoidpointertype,location.register,hsym.localloc.reference.offset,sizeof(pint));
  170. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,parentfpvoidpointertype,parentfpvoidpointertype,href,location.register);
  171. end;
  172. end;
  173. end;
  174. {*****************************************************************************
  175. TCGADDRNODE
  176. *****************************************************************************}
  177. procedure tcgaddrnode.pass_generate_code;
  178. begin
  179. secondpass(left);
  180. location_reset(location,LOC_REGISTER,int_cgsize(resultdef.size));
  181. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,resultdef);
  182. if not(left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  183. { on x86_64-win64, array of chars can be returned in registers, however,
  184. when passing these arrays to other functions, the compiler wants to take
  185. the address of the array so when the addrnode has been created internally,
  186. we have to force the data into memory, see also tw14388.pp
  187. }
  188. if nf_internal in flags then
  189. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef)
  190. else
  191. internalerror(2006111510);
  192. hlcg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.resultdef,resultdef,left.location.reference,location.register);
  193. end;
  194. {*****************************************************************************
  195. TCGDEREFNODE
  196. *****************************************************************************}
  197. procedure tcgderefnode.pass_generate_code;
  198. var
  199. paraloc1 : tcgpara;
  200. pd : tprocdef;
  201. sym : tsym;
  202. st : tsymtable;
  203. hp : pnode;
  204. extraoffset : tcgint;
  205. begin
  206. sym:=nil;
  207. { assume natural alignment, except for packed records }
  208. if not(resultdef.typ in [recorddef,objectdef]) or
  209. (tabstractrecordsymtable(tabstractrecorddef(resultdef).symtable).usefieldalignment<>1) then
  210. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),resultdef.alignment)
  211. else
  212. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),1);
  213. { can we fold an add/sub node into the offset of the deref node? }
  214. extraoffset:=0;
  215. hp:=actualtargetnode(@left);
  216. if (hp^.nodetype=subn) and is_constintnode(taddnode(hp^).right) then
  217. begin
  218. extraoffset:=-tcgint(tordconstnode(taddnode(hp^).right).value);
  219. replacenode(hp^,taddnode(hp^).left);
  220. end
  221. else if (hp^.nodetype=addn) and is_constintnode(taddnode(hp^).right) then
  222. begin
  223. extraoffset:=tcgint(tordconstnode(taddnode(hp^).right).value);
  224. replacenode(hp^,taddnode(hp^).left);
  225. end
  226. else if (hp^.nodetype=addn) and is_constintnode(taddnode(hp^).left) then
  227. begin
  228. extraoffset:=tcgint(tordconstnode(taddnode(hp^).left).value);
  229. replacenode(hp^,taddnode(hp^).right);
  230. end;
  231. secondpass(left);
  232. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE,LOC_CONSTANT]) then
  233. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  234. case left.location.loc of
  235. LOC_CREGISTER,
  236. LOC_REGISTER:
  237. begin
  238. hlcg.maybe_change_load_node_reg(current_asmdata.CurrAsmList,left,true);
  239. {$ifdef cpu_uses_separate_address_registers}
  240. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  241. begin
  242. location.reference.base := cg.getaddressregister(current_asmdata.CurrAsmList);
  243. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,
  244. location.reference.base);
  245. end
  246. else
  247. {$endif}
  248. location.reference.base := left.location.register;
  249. end;
  250. LOC_CREFERENCE,
  251. LOC_REFERENCE:
  252. begin
  253. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  254. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location,location.reference.base);
  255. end;
  256. LOC_CONSTANT:
  257. begin
  258. location.reference.offset:=left.location.value;
  259. end;
  260. else
  261. internalerror(200507031);
  262. end;
  263. location.reference.offset:=location.reference.offset+extraoffset;
  264. if (cs_use_heaptrc in current_settings.globalswitches) and
  265. (cs_checkpointer in current_settings.localswitches) and
  266. not(cs_compilesystem in current_settings.moduleswitches) and
  267. tpointerdef(left.resultdef).compatible_with_pointerdef_size(tpointerdef(voidpointertype)) and
  268. not(nf_no_checkpointer in flags) and
  269. { can be NR_NO in case of LOC_CONSTANT }
  270. (location.reference.base<>NR_NO) then
  271. begin
  272. if not searchsym_in_named_module('HEAPTRC','CHECKPOINTER',sym,st) or
  273. (sym.typ<>procsym) then
  274. internalerror(2012010601);
  275. pd:=tprocdef(tprocsym(sym).ProcdefList[0]);
  276. paraloc1.init;
  277. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,1,paraloc1);
  278. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,left.resultdef,location.reference.base,paraloc1);
  279. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  280. paraloc1.done;
  281. hlcg.allocallcpuregisters(current_asmdata.CurrAsmList);
  282. hlcg.a_call_name(current_asmdata.CurrAsmList,pd,'FPC_CHECKPOINTER',[@paraloc1],nil,false);
  283. hlcg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  284. end;
  285. end;
  286. {*****************************************************************************
  287. TCGSUBSCRIPTNODE
  288. *****************************************************************************}
  289. function tcgsubscriptnode.handle_platform_subscript: boolean;
  290. begin
  291. result:=false;
  292. end;
  293. procedure tcgsubscriptnode.pass_generate_code;
  294. var
  295. asmsym: tasmsymbol;
  296. paraloc1 : tcgpara;
  297. tmpref: treference;
  298. sref: tsubsetreference;
  299. awordoffset,
  300. offsetcorrection : aint;
  301. pd : tprocdef;
  302. sym : tsym;
  303. st : tsymtable;
  304. begin
  305. sym:=nil;
  306. secondpass(left);
  307. if codegenerror then
  308. exit;
  309. paraloc1.init;
  310. { several object types must be dereferenced implicitly }
  311. if is_implicit_pointer_object_type(left.resultdef) then
  312. begin
  313. if (not is_managed_type(left.resultdef)) or
  314. (target_info.system in systems_garbage_collected_managed_types) then
  315. begin
  316. { the contents of a class are aligned to a sizeof(pointer) }
  317. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),voidpointertype.size);
  318. case left.location.loc of
  319. LOC_CREGISTER,
  320. LOC_REGISTER:
  321. begin
  322. {$ifdef cpu_uses_separate_address_registers}
  323. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  324. begin
  325. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  326. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,
  327. left.location.register,location.reference.base);
  328. end
  329. else
  330. {$endif}
  331. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  332. end;
  333. LOC_CREFERENCE,
  334. LOC_REFERENCE,
  335. { tricky type casting of parameters can cause these locations, see tb0592.pp on x86_64-linux }
  336. LOC_SUBSETREG,
  337. LOC_CSUBSETREG,
  338. LOC_SUBSETREF,
  339. LOC_CSUBSETREF:
  340. begin
  341. hlcg.reference_reset_base(location.reference,left.resultdef,
  342. hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  343. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location,location.reference.base);
  344. end;
  345. LOC_CONSTANT:
  346. begin
  347. { can happen with @classtype(pointerconst).field }
  348. location.reference.offset:=left.location.value;
  349. end;
  350. else
  351. internalerror(2009092401);
  352. end;
  353. { implicit deferencing }
  354. if (cs_use_heaptrc in current_settings.globalswitches) and
  355. (cs_checkpointer in current_settings.localswitches) and
  356. not(cs_compilesystem in current_settings.moduleswitches) then
  357. begin
  358. if not searchsym_in_named_module('HEAPTRC','CHECKPOINTER',sym,st) or
  359. (sym.typ<>procsym) then
  360. internalerror(2012010602);
  361. pd:=tprocdef(tprocsym(sym).ProcdefList[0]);
  362. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,1,paraloc1);
  363. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,left.resultdef,location.reference.base,paraloc1);
  364. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  365. hlcg.allocallcpuregisters(current_asmdata.CurrAsmList);
  366. hlcg.a_call_name(current_asmdata.CurrAsmList,pd,'FPC_CHECKPOINTER',[@paraloc1],nil,false);
  367. hlcg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  368. end;
  369. end
  370. else
  371. { reference-counted implicit pointer object types don't have
  372. fields -> cannot be subscripted (calls are handled via call
  373. nodes) }
  374. internalerror(2011011901);
  375. end
  376. else
  377. begin
  378. location_copy(location,left.location);
  379. { some abi's require that functions return (some) records in }
  380. { registers }
  381. case location.loc of
  382. LOC_REFERENCE,
  383. LOC_CREFERENCE:
  384. ;
  385. LOC_CONSTANT,
  386. LOC_REGISTER,
  387. LOC_CREGISTER,
  388. { if a floating point value is casted into a record, it
  389. can happen that we get here an fpu or mm register }
  390. LOC_MMREGISTER,
  391. LOC_FPUREGISTER,
  392. LOC_CMMREGISTER,
  393. LOC_CFPUREGISTER:
  394. begin
  395. { in case the result is not something that can be put
  396. into an integer register (e.g.
  397. function_returning_record().non_regable_field, or
  398. a function returning a value > sizeof(intreg))
  399. -> force to memory
  400. }
  401. if not tstoreddef(left.resultdef).is_intregable or
  402. not tstoreddef(resultdef).is_intregable or
  403. { if the field spans multiple registers, we must force the record into
  404. memory as well }
  405. ((left.location.size in [OS_PAIR,OS_SPAIR]) and
  406. (vs.fieldoffset div sizeof(aword)<>(vs.fieldoffset+vs.getsize-1) div sizeof(aword))) or
  407. (location.loc in [LOC_MMREGISTER,LOC_FPUREGISTER,LOC_CMMREGISTER,LOC_CFPUREGISTER,
  408. { actually, we should be able to "subscript" a constant, but this would require some code
  409. which enables dumping and reading constants from a temporary memory buffer. This
  410. must be done a CPU dependent way, so it is not easy and probably not worth the effort (FK)
  411. }
  412. LOC_CONSTANT]) then
  413. hlcg.location_force_mem(current_asmdata.CurrAsmList,location,left.resultdef)
  414. else
  415. begin
  416. if (left.location.loc = LOC_REGISTER) then
  417. location.loc := LOC_SUBSETREG
  418. else
  419. location.loc := LOC_CSUBSETREG;
  420. location.size:=def_cgsize(resultdef);
  421. offsetcorrection:=0;
  422. if (left.location.size in [OS_PAIR,OS_SPAIR]) then
  423. begin
  424. if not is_packed_record_or_object(left.resultdef) then
  425. awordoffset:=sizeof(aword)
  426. else
  427. awordoffset:=sizeof(aword)*8;
  428. if (vs.fieldoffset>=awordoffset) xor (target_info.endian=endian_big) then
  429. location.sreg.subsetreg := left.location.registerhi
  430. else
  431. location.sreg.subsetreg := left.location.register;
  432. if vs.fieldoffset>=awordoffset then
  433. offsetcorrection := sizeof(aword)*8;
  434. location.sreg.subsetregsize := OS_INT;
  435. end
  436. else
  437. begin
  438. location.sreg.subsetreg := left.location.register;
  439. location.sreg.subsetregsize := left.location.size;
  440. end;
  441. if not is_packed_record_or_object(left.resultdef) then
  442. begin
  443. if (target_info.endian = ENDIAN_BIG) then
  444. location.sreg.startbit := (tcgsize2size[location.sreg.subsetregsize] - tcgsize2size[location.size] - vs.fieldoffset) * 8+offsetcorrection
  445. else
  446. location.sreg.startbit := (vs.fieldoffset * 8)-offsetcorrection;
  447. location.sreg.bitlen := tcgsize2size[location.size] * 8;
  448. end
  449. else
  450. begin
  451. location.sreg.bitlen := resultdef.packedbitsize;
  452. if (target_info.endian = ENDIAN_BIG) then
  453. location.sreg.startbit := (tcgsize2size[location.sreg.subsetregsize]*8 - location.sreg.bitlen) - vs.fieldoffset+offsetcorrection
  454. else
  455. location.sreg.startbit := vs.fieldoffset-offsetcorrection;
  456. end;
  457. end;
  458. end;
  459. LOC_SUBSETREG,
  460. LOC_CSUBSETREG:
  461. begin
  462. location.size:=def_cgsize(resultdef);
  463. if not is_packed_record_or_object(left.resultdef) then
  464. begin
  465. if (target_info.endian = ENDIAN_BIG) then
  466. inc(location.sreg.startbit, (left.resultdef.size - tcgsize2size[location.size] - vs.fieldoffset) * 8)
  467. else
  468. inc(location.sreg.startbit, vs.fieldoffset * 8);
  469. location.sreg.bitlen := tcgsize2size[location.size] * 8;
  470. end
  471. else
  472. begin
  473. location.sreg.bitlen := resultdef.packedbitsize;
  474. if (target_info.endian = ENDIAN_BIG) then
  475. inc(location.sreg.startbit, left.location.sreg.bitlen - location.sreg.bitlen - vs.fieldoffset)
  476. else
  477. inc(location.sreg.startbit, vs.fieldoffset);
  478. end;
  479. end;
  480. else
  481. internalerror(2006031901);
  482. end;
  483. end;
  484. if is_objc_class_or_protocol(left.resultdef) and
  485. (target_info.system in systems_objc_nfabi) then
  486. begin
  487. if (location.loc<>LOC_REFERENCE) or
  488. (location.reference.index<>NR_NO) then
  489. internalerror(2009092402);
  490. { the actual field offset is stored in memory (to solve the
  491. "fragile base class" problem: this way the layout of base
  492. classes can be changed without breaking programs compiled against
  493. earlier versions)
  494. }
  495. asmsym:=current_asmdata.RefAsmSymbol(vs.mangledname);
  496. reference_reset_symbol(tmpref,asmsym,0,sizeof(pint));
  497. hlcg.g_ptrtypecast_ref(current_asmdata.CurrAsmList,left.resultdef,cpointerdef.getreusable(resultdef),location.reference);
  498. location.reference.index:=hlcg.getintregister(current_asmdata.CurrAsmList,ptruinttype);
  499. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,ptruinttype,ptruinttype,tmpref,location.reference.index);
  500. { always packrecords C -> natural alignment }
  501. location.reference.alignment:=vs.vardef.alignment;
  502. end
  503. else if handle_platform_subscript then
  504. begin
  505. { done }
  506. end
  507. else if (location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  508. begin
  509. if not is_packed_record_or_object(left.resultdef) then
  510. begin
  511. inc(location.reference.offset,vs.fieldoffset);
  512. location.reference.alignment:=newalignment(location.reference.alignment,vs.fieldoffset);
  513. end
  514. else if (vs.fieldoffset mod 8 = 0) and
  515. (resultdef.packedbitsize mod 8 = 0) and
  516. { is different in case of e.g. packenum 2 and an enum }
  517. { which fits in 8 bits }
  518. (resultdef.size*8 = resultdef.packedbitsize) then
  519. begin
  520. inc(location.reference.offset,vs.fieldoffset div 8);
  521. location.reference.alignment:=newalignment(location.reference.alignment,vs.fieldoffset div 8);
  522. end
  523. else
  524. begin
  525. sref.ref:=location.reference;
  526. sref.ref.alignment:=1;
  527. sref.bitindexreg:=NR_NO;
  528. inc(sref.ref.offset,vs.fieldoffset div 8);
  529. sref.startbit:=vs.fieldoffset mod 8;
  530. sref.bitlen:=resultdef.packedbitsize;
  531. if (left.location.loc=LOC_REFERENCE) then
  532. location.loc:=LOC_SUBSETREF
  533. else
  534. location.loc:=LOC_CSUBSETREF;
  535. location.sref:=sref;
  536. end;
  537. { also update the size of the location }
  538. location.size:=def_cgsize(resultdef);
  539. end;
  540. paraloc1.done;
  541. end;
  542. {*****************************************************************************
  543. TCGWITHNODE
  544. *****************************************************************************}
  545. procedure tcgwithnode.pass_generate_code;
  546. begin
  547. location_reset(location,LOC_VOID,OS_NO);
  548. if assigned(left) then
  549. secondpass(left);
  550. end;
  551. {*****************************************************************************
  552. TCGVECNODE
  553. *****************************************************************************}
  554. function tcgvecnode.get_mul_size : aint;
  555. begin
  556. if nf_memindex in flags then
  557. get_mul_size:=1
  558. else
  559. begin
  560. if (left.resultdef.typ=arraydef) then
  561. if not is_packed_array(left.resultdef) then
  562. get_mul_size:=tarraydef(left.resultdef).elesize
  563. else
  564. get_mul_size:=tarraydef(left.resultdef).elepackedbitsize
  565. else
  566. get_mul_size:=resultdef.size;
  567. end
  568. end;
  569. { this routine must, like any other routine, not change the contents }
  570. { of base/index registers of references, as these may be regvars. }
  571. { The register allocator can coalesce one LOC_REGISTER being moved }
  572. { into another (as their live ranges won't overlap), but not a }
  573. { LOC_CREGISTER moved into a LOC_(C)REGISTER most of the time (as }
  574. { the live range of the LOC_CREGISTER will most likely overlap the }
  575. { the live range of the target LOC_(C)REGISTER) }
  576. { The passed register may be a LOC_CREGISTER as well. }
  577. procedure tcgvecnode.update_reference_reg_mul(maybe_const_reg: tregister; regsize: tdef; l: aint);
  578. var
  579. hreg: tregister;
  580. begin
  581. if l<>1 then
  582. begin
  583. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  584. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_ADDR,l,maybe_const_reg,hreg);
  585. maybe_const_reg:=hreg;
  586. end;
  587. if location.reference.base=NR_NO then
  588. location.reference.base:=maybe_const_reg
  589. else if location.reference.index=NR_NO then
  590. location.reference.index:=maybe_const_reg
  591. else
  592. begin
  593. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  594. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,location.reference,hreg);
  595. reference_reset_base(location.reference,hreg,0,location.reference.alignment);
  596. { insert new index register }
  597. location.reference.index:=maybe_const_reg;
  598. end;
  599. { update alignment }
  600. if (location.reference.alignment=0) then
  601. internalerror(2009020704);
  602. location.reference.alignment:=newalignment(location.reference.alignment,l);
  603. end;
  604. { see remarks for tcgvecnode.update_reference_reg_mul above }
  605. procedure tcgvecnode.update_reference_reg_packed(maybe_const_reg: tregister; regsize: tdef; l:aint);
  606. var
  607. sref: tsubsetreference;
  608. offsetreg, hreg: tregister;
  609. alignpower: aint;
  610. temp : longint;
  611. begin
  612. { only orddefs are bitpacked. Even then we only need special code in }
  613. { case the bitpacked *byte size* is not a power of two, otherwise }
  614. { everything can be handled using the the regular array code. }
  615. if ((l mod 8) = 0) and
  616. (ispowerof2(l div 8,temp) or
  617. not is_ordinal(resultdef)
  618. {$ifndef cpu64bitalu}
  619. or is_64bitint(resultdef)
  620. {$endif not cpu64bitalu}
  621. ) then
  622. begin
  623. update_reference_reg_mul(maybe_const_reg,regsize,l div 8);
  624. exit;
  625. end;
  626. if (l > 8*sizeof(aint)) then
  627. internalerror(200608051);
  628. sref.ref := location.reference;
  629. hreg := cg.getaddressregister(current_asmdata.CurrAsmList);
  630. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,OS_ADDR,tarraydef(left.resultdef).lowrange,maybe_const_reg,hreg);
  631. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_ADDR,l,hreg);
  632. { keep alignment for index }
  633. sref.ref.alignment := left.resultdef.alignment;
  634. if not ispowerof2(packedbitsloadsize(l),temp) then
  635. internalerror(2006081201);
  636. alignpower:=temp;
  637. offsetreg := cg.getaddressregister(current_asmdata.CurrAsmList);
  638. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_ADDR,3+alignpower,hreg,offsetreg);
  639. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHL,OS_ADDR,alignpower,offsetreg);
  640. if (sref.ref.base = NR_NO) then
  641. sref.ref.base := offsetreg
  642. else if (sref.ref.index = NR_NO) then
  643. sref.ref.index := offsetreg
  644. else
  645. begin
  646. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_ADD,OS_ADDR,sref.ref.base,offsetreg);
  647. sref.ref.base := offsetreg;
  648. end;
  649. { the if expression below is a constant evaluated at compile time, so disable the unreachable code
  650. warning }
  651. {$push}
  652. {$warn 6018 off}
  653. { we can reuse hreg only if OS_INT and OS_ADDR have the same size/type }
  654. if OS_INT<>OS_ADDR then
  655. begin
  656. sref.bitindexreg := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  657. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_INT,hreg,sref.bitindexreg);
  658. end
  659. else
  660. sref.bitindexreg:=hreg;
  661. {$pop}
  662. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_AND,OS_INT,(1 shl (3+alignpower))-1,sref.bitindexreg);
  663. sref.startbit := 0;
  664. sref.bitlen := resultdef.packedbitsize;
  665. if (left.location.loc = LOC_REFERENCE) then
  666. location.loc := LOC_SUBSETREF
  667. else
  668. location.loc := LOC_CSUBSETREF;
  669. location.sref := sref;
  670. end;
  671. procedure tcgvecnode.update_reference_offset(var ref: treference; index, mulsize: aint);
  672. begin
  673. inc(ref.offset,index*mulsize);
  674. end;
  675. procedure tcgvecnode.second_wideansistring;
  676. begin
  677. end;
  678. procedure tcgvecnode.second_dynamicarray;
  679. begin
  680. end;
  681. function tcgvecnode.valid_index_size(size: tcgsize): boolean;
  682. begin
  683. result:=
  684. tcgsize2signed[size]=tcgsize2signed[OS_ADDR];
  685. end;
  686. procedure tcgvecnode.rangecheck_array;
  687. var
  688. hightree : tnode;
  689. poslabel,
  690. neglabel : tasmlabel;
  691. hreg : tregister;
  692. paraloc1,paraloc2 : tcgpara;
  693. pd : tprocdef;
  694. begin
  695. { omit range checking when this is an array access to a pointer which has been
  696. typecasted from an array }
  697. if (ado_isconvertedpointer in tarraydef(left.resultdef).arrayoptions) then
  698. exit;
  699. paraloc1.init;
  700. paraloc2.init;
  701. if is_dynamic_array(left.resultdef) then
  702. begin
  703. pd:=search_system_proc('fpc_dynarray_rangecheck');
  704. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,1,paraloc1);
  705. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,2,paraloc2);
  706. if pd.is_pushleftright then
  707. begin
  708. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,paraloc1);
  709. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.resultdef,right.location,paraloc2);
  710. end
  711. else
  712. begin
  713. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.resultdef,right.location,paraloc2);
  714. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,paraloc1);
  715. end;
  716. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  717. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  718. hlcg.g_call_system_proc(current_asmdata.CurrAsmList,pd,[@paraloc1,@paraloc2],nil).resetiftemp;
  719. end;
  720. { for regular arrays, we don't have to do anything because the index has been
  721. type converted to the index type, which already inserted a range check if
  722. necessary }
  723. paraloc1.done;
  724. paraloc2.done;
  725. end;
  726. procedure tcgvecnode.rangecheck_string;
  727. var
  728. paraloc1,
  729. paraloc2: tcgpara;
  730. helpername: TIDString;
  731. pd: tprocdef;
  732. begin
  733. paraloc1.init;
  734. paraloc2.init;
  735. case tstringdef(left.resultdef).stringtype of
  736. { it's the same for ansi- and wide strings }
  737. st_unicodestring,
  738. st_widestring,
  739. st_ansistring:
  740. begin
  741. helpername:='fpc_'+tstringdef(left.resultdef).stringtypname+'_rangecheck';
  742. pd:=search_system_proc(helpername);
  743. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,1,paraloc1);
  744. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,2,paraloc2);
  745. if pd.is_pushleftright then
  746. begin
  747. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,paraloc1);
  748. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.resultdef,right.location,paraloc2);
  749. end
  750. else
  751. begin
  752. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.resultdef,right.location,paraloc2);
  753. hlcg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.resultdef,left.location,paraloc1);
  754. end;
  755. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  756. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  757. hlcg.g_call_system_proc(current_asmdata.CurrAsmList,pd,[@paraloc1,@paraloc2],nil).resetiftemp;
  758. end;
  759. st_shortstring:
  760. begin
  761. {!!!!!!!!!!!!!!!!!}
  762. { if this one is implemented making use of the high parameter for openshortstrings, update ncgutils.do_get_used_regvars() too (JM) }
  763. end;
  764. st_longstring:
  765. begin
  766. {!!!!!!!!!!!!!!!!!}
  767. end;
  768. end;
  769. paraloc1.done;
  770. paraloc2.done;
  771. end;
  772. procedure tcgvecnode.pass_generate_code;
  773. var
  774. offsetdec,
  775. extraoffset : aint;
  776. rightp : pnode;
  777. newsize : tcgsize;
  778. mulsize,
  779. bytemulsize,
  780. alignpow : aint;
  781. paraloc1,
  782. paraloc2 : tcgpara;
  783. subsetref : tsubsetreference;
  784. temp : longint;
  785. indexdef : tdef;
  786. begin
  787. paraloc1.init;
  788. paraloc2.init;
  789. mulsize:=get_mul_size;
  790. if not is_packed_array(left.resultdef) then
  791. bytemulsize:=mulsize
  792. else
  793. bytemulsize:=mulsize div 8;
  794. newsize:=def_cgsize(resultdef);
  795. secondpass(left);
  796. if left.location.loc=LOC_CREFERENCE then
  797. location_reset_ref(location,LOC_CREFERENCE,newsize,left.location.reference.alignment)
  798. else
  799. location_reset_ref(location,LOC_REFERENCE,newsize,left.location.reference.alignment);
  800. { an ansistring needs to be dereferenced }
  801. if is_ansistring(left.resultdef) or
  802. is_wide_or_unicode_string(left.resultdef) then
  803. begin
  804. if nf_callunique in flags then
  805. internalerror(200304236);
  806. {DM!!!!!}
  807. case left.location.loc of
  808. LOC_REGISTER,
  809. LOC_CREGISTER :
  810. begin
  811. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  812. end;
  813. LOC_CREFERENCE,
  814. LOC_REFERENCE :
  815. begin
  816. hlcg.reference_reset_base(location.reference,left.resultdef,hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  817. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,left.location.reference,location.reference.base);
  818. end;
  819. LOC_CONSTANT:
  820. begin
  821. hlcg.reference_reset_base(location.reference,left.resultdef,NR_NO,left.location.value,location.reference.alignment);
  822. end;
  823. else
  824. internalerror(2002032218);
  825. end;
  826. if is_ansistring(left.resultdef) then
  827. offsetdec:=1
  828. else
  829. offsetdec:=2;
  830. location.reference.alignment:=offsetdec;
  831. { in ansistrings/widestrings S[1] is p<w>char(S)[0] }
  832. if not(cs_zerobasedstrings in current_settings.localswitches) then
  833. update_reference_offset(location.reference,-1,offsetdec);
  834. end
  835. else if is_dynamic_array(left.resultdef) then
  836. begin
  837. case left.location.loc of
  838. LOC_REGISTER,
  839. LOC_CREGISTER :
  840. hlcg.reference_reset_base(location.reference,left.resultdef,left.location.register,0,location.reference.alignment);
  841. LOC_REFERENCE,
  842. LOC_CREFERENCE :
  843. begin
  844. hlcg.reference_reset_base(location.reference,left.resultdef,hlcg.getaddressregister(current_asmdata.CurrAsmList,left.resultdef),0,location.reference.alignment);
  845. hlcg.a_load_ref_reg(current_asmdata.CurrAsmList,left.resultdef,left.resultdef,
  846. left.location.reference,location.reference.base);
  847. end;
  848. else
  849. internalerror(2002032219);
  850. end;
  851. { a dynarray points to the start of a memory block, which
  852. we assume to be always aligned to a multiple of the
  853. pointer size
  854. }
  855. location.reference.alignment:=voidpointertype.size;
  856. end
  857. else
  858. begin
  859. { may happen in case of function results }
  860. case left.location.loc of
  861. LOC_CSUBSETREG,
  862. LOC_CREGISTER,
  863. LOC_CMMREGISTER,
  864. LOC_SUBSETREG,
  865. LOC_REGISTER,
  866. LOC_MMREGISTER:
  867. hlcg.location_force_mem(current_asmdata.CurrAsmList,left.location,left.resultdef);
  868. end;
  869. location_copy(location,left.location);
  870. end;
  871. { location must be memory }
  872. if not(location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  873. internalerror(200411013);
  874. { offset can only differ from 0 if arraydef }
  875. if (left.resultdef.typ=arraydef) and
  876. not(is_dynamic_array(left.resultdef)) and
  877. (not(is_packed_array(left.resultdef)) or
  878. ((mulsize mod 8 = 0) and
  879. ispowerof2(mulsize div 8,temp)) or
  880. { only orddefs are bitpacked }
  881. not is_ordinal(resultdef)
  882. {$ifndef cpu64bitalu}
  883. or is_64bitint(resultdef)
  884. {$endif not cpu64bitalu}
  885. ) then
  886. update_reference_offset(location.reference,-tarraydef(left.resultdef).lowrange,bytemulsize);
  887. if right.nodetype=ordconstn then
  888. begin
  889. { offset can only differ from 0 if arraydef }
  890. if cs_check_range in current_settings.localswitches then
  891. begin
  892. secondpass(right);
  893. case left.resultdef.typ of
  894. arraydef :
  895. rangecheck_array;
  896. stringdef :
  897. rangecheck_string;
  898. end;
  899. end;
  900. if not(is_packed_array(left.resultdef)) or
  901. ((mulsize mod 8 = 0) and
  902. (ispowerof2(mulsize div 8,temp) or
  903. { only orddefs are bitpacked }
  904. not is_ordinal(resultdef))) then
  905. begin
  906. extraoffset:=tordconstnode(right).value.svalue;
  907. update_reference_offset(location.reference,extraoffset,bytemulsize);
  908. { adjust alignment after this change }
  909. location.reference.alignment:=newalignment(location.reference.alignment,extraoffset*bytemulsize);
  910. end
  911. else
  912. begin
  913. subsetref.ref := location.reference;
  914. subsetref.ref.alignment := left.resultdef.alignment;
  915. if not ispowerof2(packedbitsloadsize(resultdef.packedbitsize),temp) then
  916. internalerror(2006081212);
  917. alignpow:=temp;
  918. update_reference_offset(subsetref.ref,(mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) shr (3+alignpow),1 shl alignpow);
  919. subsetref.bitindexreg := NR_NO;
  920. subsetref.startbit := (mulsize * (tordconstnode(right).value.svalue-tarraydef(left.resultdef).lowrange)) and ((1 shl (3+alignpow))-1);
  921. subsetref.bitlen := resultdef.packedbitsize;
  922. if (left.location.loc = LOC_REFERENCE) then
  923. location.loc := LOC_SUBSETREF
  924. else
  925. location.loc := LOC_CSUBSETREF;
  926. location.sref := subsetref;
  927. end;
  928. end
  929. else
  930. { not nodetype=ordconstn }
  931. begin
  932. if (cs_opt_level1 in current_settings.optimizerswitches) and
  933. { if we do range checking, we don't }
  934. { need that fancy code (it would be }
  935. { buggy) }
  936. not(cs_check_range in current_settings.localswitches) and
  937. (left.resultdef.typ=arraydef) and
  938. not is_packed_array(left.resultdef) then
  939. begin
  940. extraoffset:=0;
  941. rightp:=actualtargetnode(@right);
  942. if rightp^.nodetype=addn then
  943. begin
  944. if taddnode(rightp^).right.nodetype=ordconstn then
  945. begin
  946. extraoffset:=tordconstnode(taddnode(rightp^).right).value.svalue;
  947. replacenode(rightp^,taddnode(rightp^).left);
  948. end
  949. else if taddnode(rightp^).left.nodetype=ordconstn then
  950. begin
  951. extraoffset:=tordconstnode(taddnode(rightp^).left).value.svalue;
  952. replacenode(rightp^,taddnode(rightp^).right);
  953. end;
  954. end
  955. else if rightp^.nodetype=subn then
  956. begin
  957. if taddnode(rightp^).right.nodetype=ordconstn then
  958. begin
  959. extraoffset:=-tordconstnode(taddnode(rightp^).right).value.svalue;
  960. replacenode(rightp^,taddnode(rightp^).left);
  961. end;
  962. end;
  963. update_reference_offset(location.reference,extraoffset,mulsize);
  964. end;
  965. { calculate from left to right }
  966. if not(location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  967. internalerror(200304237);
  968. secondpass(right);
  969. if (right.expectloc=LOC_JUMP)<>
  970. (right.location.loc=LOC_JUMP) then
  971. internalerror(2006010801);
  972. { if mulsize = 1, we won't have to modify the index }
  973. if not(right.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  974. not valid_index_size(right.location.size) then
  975. begin
  976. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,ptruinttype,true);
  977. indexdef:=ptruinttype
  978. end
  979. else
  980. indexdef:=right.resultdef;
  981. { produce possible range check code: }
  982. if cs_check_range in current_settings.localswitches then
  983. begin
  984. if left.resultdef.typ=arraydef then
  985. rangecheck_array
  986. else if (left.resultdef.typ=stringdef) then
  987. rangecheck_string;
  988. end;
  989. { insert the register and the multiplication factor in the
  990. reference }
  991. if not is_packed_array(left.resultdef) then
  992. update_reference_reg_mul(right.location.register,indexdef,mulsize)
  993. else
  994. update_reference_reg_packed(right.location.register,indexdef,mulsize);
  995. end;
  996. location.size:=newsize;
  997. paraloc1.done;
  998. paraloc2.done;
  999. end;
  1000. begin
  1001. cloadvmtaddrnode:=tcgloadvmtaddrnode;
  1002. cloadparentfpnode:=tcgloadparentfpnode;
  1003. caddrnode:=tcgaddrnode;
  1004. cderefnode:=tcgderefnode;
  1005. csubscriptnode:=tcgsubscriptnode;
  1006. cwithnode:=tcgwithnode;
  1007. cvecnode:=tcgvecnode;
  1008. end.