ncgmem.pas 48 KB

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