aasmtai.pas 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements an abstract asmoutput class for all processor types
  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. { @abstract(This unit implements an abstract asm output class for all processor types)
  19. This unit implements an abstract assembler output class for all processors, these
  20. are then overriden for each assembler writer to actually write the data in these
  21. classes to an assembler file.
  22. }
  23. unit aasmtai;
  24. {$i fpcdefs.inc}
  25. interface
  26. uses
  27. cutils,cclasses,
  28. globtype,globals,systems,
  29. cpuinfo,cpubase,
  30. symppu,
  31. aasmbase;
  32. type
  33. taitype = (
  34. ait_none,
  35. ait_align,
  36. ait_section,
  37. ait_comment,
  38. ait_direct,
  39. ait_string,
  40. ait_instruction,
  41. ait_datablock,
  42. ait_symbol,
  43. ait_symbol_end, { needed to calc the size of a symbol }
  44. ait_label,
  45. ait_const_32bit,
  46. ait_const_16bit,
  47. ait_const_8bit,
  48. ait_const_symbol,
  49. { the following is only used by the win32 version of the compiler }
  50. { and only the GNU AS Win32 is able to write it }
  51. ait_const_rva,
  52. ait_real_32bit,
  53. ait_real_64bit,
  54. ait_real_80bit,
  55. ait_comp_64bit,
  56. ait_real_128bit,
  57. {$ifdef GDB}
  58. ait_stabn,
  59. ait_stabs,
  60. ait_force_line,
  61. ait_stab_function_name,
  62. {$endif GDB}
  63. {$ifdef alpha}
  64. { the follow is for the DEC Alpha }
  65. ait_frame,
  66. ait_ent,
  67. {$endif alpha}
  68. {$ifdef ia64}
  69. ait_bundle,
  70. ait_stop,
  71. {$endif ia64}
  72. {$ifdef m68k}
  73. ait_labeled_instruction,
  74. {$endif m68k}
  75. {$ifdef SPARC}
  76. ait_labeled_instruction,
  77. {$endif SPARC}
  78. ait_cut, { used to split into tiny assembler files }
  79. ait_regalloc,
  80. ait_tempalloc,
  81. ait_marker { used to mark assembler blocks and inlined functions }
  82. );
  83. const
  84. taitypestr : array[taitype] of string[14] = (
  85. '<none>',
  86. 'align',
  87. 'section',
  88. 'comment',
  89. 'direct',
  90. 'string',
  91. 'instruction',
  92. 'datablock',
  93. 'symbol',
  94. 'symbol_end',
  95. 'label',
  96. 'const_32bit',
  97. 'const_16bit',
  98. 'const_8bit',
  99. 'const_symbol',
  100. 'const_rva',
  101. 'real_32bit',
  102. 'real_64bit',
  103. 'real_80bit',
  104. 'comp_64bit',
  105. 'real_128bit',
  106. {$ifdef GDB}
  107. 'stabn',
  108. 'stabs',
  109. 'force_line',
  110. 'stab_funcname',
  111. {$endif GDB}
  112. {$ifdef alpha}
  113. { the follow is for the DEC Alpha }
  114. 'frame',
  115. 'ent',
  116. {$endif alpha}
  117. {$ifdef ia64}
  118. 'bundle',
  119. 'stop',
  120. {$endif ia64}
  121. {$ifdef m68k}
  122. 'labeled_instr',
  123. {$endif m68k}
  124. {$ifdef SPARC}
  125. 'labeled_instr',
  126. {$endif SPARC}
  127. 'cut',
  128. 'regalloc',
  129. 'tempalloc',
  130. 'marker'
  131. );
  132. { ait_* types which don't result in executable code or which don't influence }
  133. { the way the program runs/behaves, but which may be encountered by the }
  134. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  135. { a new ait type! }
  136. const
  137. SkipInstr = [ait_comment, ait_symbol,ait_section
  138. {$ifdef GDB}
  139. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  140. {$endif GDB}
  141. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  142. { ait_* types which do not have line information (and hence which are of type
  143. tai, otherwise, they are of type tailineinfo }
  144. { ait_* types which do not have line information (and hence which are of type
  145. tai, otherwise, they are of type tailineinfo }
  146. SkipLineInfo =[ait_label,
  147. ait_regalloc,ait_tempalloc,
  148. {$ifdef GDB}
  149. ait_stabn,ait_stabs,ait_stab_function_name,
  150. {$endif GDB}
  151. ait_cut,ait_marker,ait_align,ait_section,ait_comment,
  152. ait_const_8bit,ait_const_16bit,ait_const_32bit,
  153. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit
  154. ];
  155. type
  156. { cut type, required for alphanumeric ordering of the assembler filenames }
  157. TCutPlace=(cut_normal,cut_begin,cut_end);
  158. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  159. AsmBlockStart,AsmBlockEnd,
  160. InlineStart,InlineEnd);
  161. { Buffer type used for alignment }
  162. tfillbuffer = array[0..63] of char;
  163. { abstract assembler item }
  164. tai = class(TLinkedListItem)
  165. {$ifndef NOOPT}
  166. { pointer to record with optimizer info about this tai object }
  167. optinfo : pointer;
  168. {$endif NOOPT}
  169. typ : taitype;
  170. constructor Create;
  171. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  172. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  173. procedure derefimpl;virtual;
  174. { helper for checking symbol redefines }
  175. procedure checkredefinesym(sym:tasmsymbol);
  176. end;
  177. { abstract assembler item with line information }
  178. tailineinfo = class(tai)
  179. fileinfo : tfileposinfo;
  180. constructor Create;
  181. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  182. procedure ppuwrite(ppufile:tcompilerppufile);override;
  183. end;
  184. taiclass = class of tai;
  185. taiclassarray = array[taitype] of taiclass;
  186. { Generates an assembler string }
  187. tai_string = class(tailineinfo)
  188. str : pchar;
  189. { extra len so the string can contain an \0 }
  190. len : longint;
  191. constructor Create(const _str : string);
  192. constructor Create_pchar(_str : pchar);
  193. constructor Create_length_pchar(_str : pchar;length : longint);
  194. destructor Destroy;override;
  195. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  196. procedure ppuwrite(ppufile:tcompilerppufile);override;
  197. function getcopy:tlinkedlistitem;override;
  198. end;
  199. { Generates a common label }
  200. tai_symbol = class(tailineinfo)
  201. is_global : boolean;
  202. sym : tasmsymbol;
  203. size : longint;
  204. constructor Create(_sym:tasmsymbol;siz:longint);
  205. constructor Createname(const _name : string;siz:longint);
  206. constructor Createname_global(const _name : string;siz:longint);
  207. constructor Createdataname(const _name : string;siz:longint);
  208. constructor Createdataname_global(const _name : string;siz:longint);
  209. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  210. procedure ppuwrite(ppufile:tcompilerppufile);override;
  211. procedure derefimpl;override;
  212. end;
  213. tai_symbol_end = class(tailineinfo)
  214. sym : tasmsymbol;
  215. constructor Create(_sym:tasmsymbol);
  216. constructor Createname(const _name : string);
  217. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  218. procedure ppuwrite(ppufile:tcompilerppufile);override;
  219. procedure derefimpl;override;
  220. end;
  221. { Generates an assembler label }
  222. tai_label = class(tai)
  223. is_global : boolean;
  224. l : tasmlabel;
  225. constructor Create(_l : tasmlabel);
  226. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  227. procedure ppuwrite(ppufile:tcompilerppufile);override;
  228. procedure derefimpl;override;
  229. end;
  230. { Directly output data to final assembler file }
  231. tai_direct = class(tailineinfo)
  232. str : pchar;
  233. constructor Create(_str : pchar);
  234. destructor Destroy; override;
  235. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  236. procedure ppuwrite(ppufile:tcompilerppufile);override;
  237. function getcopy:tlinkedlistitem;override;
  238. end;
  239. { Generates an assembler comment }
  240. tai_comment = class(tai)
  241. str : pchar;
  242. constructor Create(_str : pchar);
  243. destructor Destroy; override;
  244. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. function getcopy:tlinkedlistitem;override;
  247. end;
  248. { Generates a section / segment directive }
  249. tai_section = class(tai)
  250. sec : TSection;
  251. constructor Create(s : TSection);
  252. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  253. procedure ppuwrite(ppufile:tcompilerppufile);override;
  254. end;
  255. { Generates an uninitializised data block }
  256. tai_datablock = class(tailineinfo)
  257. is_global : boolean;
  258. sym : tasmsymbol;
  259. size : longint;
  260. constructor Create(const _name : string;_size : longint);
  261. constructor Create_global(const _name : string;_size : longint);
  262. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. procedure derefimpl;override;
  265. end;
  266. { Generates a long integer (32 bit) }
  267. tai_const = class(tai)
  268. value : longint;
  269. constructor Create_32bit(_value : longint);
  270. constructor Create_16bit(_value : word);
  271. constructor Create_8bit(_value : byte);
  272. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  273. procedure ppuwrite(ppufile:tcompilerppufile);override;
  274. end;
  275. tai_const_symbol = class(tailineinfo)
  276. sym : tasmsymbol;
  277. offset : longint;
  278. constructor Create(_sym:tasmsymbol);
  279. constructor Create_offset(_sym:tasmsymbol;ofs:longint);
  280. constructor Create_rva(_sym:tasmsymbol);
  281. constructor Createname(const name:string);
  282. constructor Createname_offset(const name:string;ofs:longint);
  283. constructor Createname_rva(const name:string);
  284. constructor Createdataname(const name:string);
  285. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure derefimpl;override;
  288. function getcopy:tlinkedlistitem;override;
  289. end;
  290. { Generates a single float (32 bit real) }
  291. tai_real_32bit = class(tai)
  292. value : ts32real;
  293. constructor Create(_value : ts32real);
  294. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. end;
  297. { Generates a double float (64 bit real) }
  298. tai_real_64bit = class(tai)
  299. value : ts64real;
  300. constructor Create(_value : ts64real);
  301. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  302. procedure ppuwrite(ppufile:tcompilerppufile);override;
  303. end;
  304. { Generates an extended float (80 bit real) }
  305. tai_real_80bit = class(tai)
  306. value : ts80real;
  307. constructor Create(_value : ts80real);
  308. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  309. procedure ppuwrite(ppufile:tcompilerppufile);override;
  310. end;
  311. { Generates a comp int (integer over 64 bits)
  312. This is Intel 80x86 specific, and is not
  313. really supported on other processors.
  314. }
  315. tai_comp_64bit = class(tai)
  316. value : ts64comp;
  317. constructor Create(_value : ts64comp);
  318. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  319. procedure ppuwrite(ppufile:tcompilerppufile);override;
  320. end;
  321. { Insert a cut to split assembler into several smaller files }
  322. tai_cut = class(tai)
  323. place : tcutplace;
  324. constructor Create;
  325. constructor Create_begin;
  326. constructor Create_end;
  327. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  328. procedure ppuwrite(ppufile:tcompilerppufile);override;
  329. end;
  330. { Insert a marker for assembler and inline blocks }
  331. tai_marker = class(tai)
  332. Kind: TMarker;
  333. Constructor Create(_Kind: TMarker);
  334. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  335. procedure ppuwrite(ppufile:tcompilerppufile);override;
  336. end;
  337. tai_tempalloc = class(tai)
  338. allocation : boolean;
  339. {$ifdef EXTDEBUG}
  340. problem : pstring;
  341. {$endif EXTDEBUG}
  342. temppos,
  343. tempsize : longint;
  344. constructor alloc(pos,size:longint);
  345. constructor dealloc(pos,size:longint);
  346. {$ifdef EXTDEBUG}
  347. constructor allocinfo(pos,size:longint;const st:string);
  348. {$endif EXTDEBUG}
  349. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  350. procedure ppuwrite(ppufile:tcompilerppufile);override;
  351. end;
  352. tai_regalloc = class(tai)
  353. allocation : boolean;
  354. reg : tregister;
  355. constructor alloc(r : tregister);
  356. constructor dealloc(r : tregister);
  357. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  358. procedure ppuwrite(ppufile:tcompilerppufile);override;
  359. end;
  360. { Class template for assembler instructions
  361. }
  362. taicpu_abstract = class(tailineinfo)
  363. protected
  364. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  365. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  366. procedure ppuderefoper(var o:toper);virtual;abstract;
  367. public
  368. { Condition flags for instruction }
  369. condition : TAsmCond;
  370. { Number of operands to instruction }
  371. ops : byte;
  372. { Operands of instruction }
  373. oper : array[0..max_operands-1] of toper;
  374. { Actual opcode of instruction }
  375. opcode : tasmop;
  376. {$ifdef i386}
  377. segprefix : tregister;
  378. {$endif i386}
  379. { true if instruction is a jmp }
  380. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  381. Constructor Create(op : tasmop);
  382. Destructor Destroy;override;
  383. function getcopy:TLinkedListItem;override;
  384. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  385. procedure ppuwrite(ppufile:tcompilerppufile);override;
  386. procedure derefimpl;override;
  387. procedure SetCondition(const c:TAsmCond);
  388. procedure loadconst(opidx:longint;l:aword);
  389. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  390. procedure loadref(opidx:longint;const r:treference);
  391. procedure loadreg(opidx:longint;r:tregister);
  392. procedure loadoper(opidx:longint;o:toper);
  393. function is_nop:boolean;virtual;abstract;
  394. end;
  395. { alignment for operator }
  396. tai_align_abstract = class(tai)
  397. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  398. fillsize : byte; { real size to fill }
  399. fillop : byte; { value to fill with - optional }
  400. use_op : boolean;
  401. constructor Create(b:byte);
  402. constructor Create_op(b: byte; _op: byte);
  403. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  404. procedure ppuwrite(ppufile:tcompilerppufile);override;
  405. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  406. end;
  407. Ttranstable=array[Tsuperregister] of Tsuperregister;
  408. taasmoutput = class(tlinkedlist)
  409. function getlasttaifilepos : pfileposinfo;
  410. procedure convert_registers;
  411. procedure translate_registers(const table:Ttranstable);
  412. end;
  413. var
  414. { array with all class types for tais }
  415. aiclass : taiclassarray;
  416. { temporary lists }
  417. exprasmlist,
  418. { default lists }
  419. datasegment,codesegment,bsssegment,
  420. debuglist,withdebuglist,consts,
  421. importssection,exportssection,
  422. resourcesection,rttilist,
  423. resourcestringlist : taasmoutput;
  424. function ppuloadai(ppufile:tcompilerppufile):tai;
  425. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  426. implementation
  427. uses
  428. {$ifdef delphi}
  429. sysutils,
  430. {$else}
  431. strings,
  432. {$endif}
  433. verbose;
  434. const
  435. pputaimarker = 254;
  436. {****************************************************************************
  437. Helpers
  438. ****************************************************************************}
  439. function ppuloadai(ppufile:tcompilerppufile):tai;
  440. var
  441. b : byte;
  442. t : taitype;
  443. begin
  444. { marker }
  445. b:=ppufile.getbyte;
  446. if b<>pputaimarker then
  447. internalerror(200208181);
  448. { load nodetype }
  449. t:=taitype(ppufile.getbyte);
  450. if t<>ait_none then
  451. begin
  452. if t>high(taitype) then
  453. internalerror(200208182);
  454. if not assigned(aiclass[t]) then
  455. internalerror(200208183);
  456. //writeln('taiload: ',taitypestr[t]);
  457. { generate tai of the correct class }
  458. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  459. end
  460. else
  461. ppuloadai:=nil;
  462. end;
  463. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  464. begin
  465. { marker, read by ppuloadnode }
  466. ppufile.putbyte(pputaimarker);
  467. if assigned(n) then
  468. begin
  469. { type, read by ppuloadnode }
  470. ppufile.putbyte(byte(n.typ));
  471. //writeln('taiwrite: ',taitypestr[n.typ]);
  472. n.ppuwrite(ppufile);
  473. end
  474. else
  475. ppufile.putbyte(byte(ait_none));
  476. end;
  477. {****************************************************************************
  478. TAI
  479. ****************************************************************************}
  480. constructor tai.Create;
  481. begin
  482. {$ifndef NOOPT}
  483. optinfo:=nil;
  484. {$endif NOOPT}
  485. end;
  486. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  487. begin
  488. typ:=t;
  489. {$ifndef NOOPT}
  490. optinfo:=nil;
  491. {$endif}
  492. end;
  493. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  494. begin
  495. end;
  496. procedure tai.derefimpl;
  497. begin
  498. end;
  499. procedure tai.checkredefinesym(sym:tasmsymbol);
  500. begin
  501. { if assigned(sym.taiowner) and
  502. (target_asm.id in binassem) then
  503. begin
  504. Message1(asmw_e_redefined_label,sym.name);
  505. end
  506. else
  507. sym.taiowner:=self;}
  508. end;
  509. {****************************************************************************
  510. TAILINEINFO
  511. ****************************************************************************}
  512. constructor tailineinfo.create;
  513. begin
  514. inherited create;
  515. fileinfo:=aktfilepos;
  516. end;
  517. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  518. begin
  519. inherited ppuload(t,ppufile);
  520. ppufile.getposinfo(fileinfo);
  521. end;
  522. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  523. begin
  524. inherited ppuwrite(ppufile);
  525. ppufile.putposinfo(fileinfo);
  526. end;
  527. {****************************************************************************
  528. TAI_SECTION
  529. ****************************************************************************}
  530. constructor tai_section.Create(s : TSection);
  531. begin
  532. inherited Create;
  533. typ:=ait_section;
  534. sec:=s;
  535. end;
  536. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  537. begin
  538. inherited ppuload(t,ppufile);
  539. sec:=tsection(ppufile.getbyte);
  540. end;
  541. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  542. begin
  543. inherited ppuwrite(ppufile);
  544. ppufile.putbyte(byte(sec));
  545. end;
  546. {****************************************************************************
  547. TAI_DATABLOCK
  548. ****************************************************************************}
  549. constructor tai_datablock.Create(const _name : string;_size : longint);
  550. begin
  551. inherited Create;
  552. typ:=ait_datablock;
  553. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  554. { checkredefinesym(sym);}
  555. { keep things aligned }
  556. if _size<=0 then
  557. _size:=4;
  558. size:=_size;
  559. is_global:=false;
  560. end;
  561. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  562. begin
  563. inherited Create;
  564. typ:=ait_datablock;
  565. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  566. { checkredefinesym(sym);}
  567. { keep things aligned }
  568. if _size<=0 then
  569. _size:=4;
  570. size:=_size;
  571. is_global:=true;
  572. end;
  573. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  574. begin
  575. inherited Create;
  576. sym:=ppufile.getasmsymbol;
  577. size:=ppufile.getlongint;
  578. is_global:=boolean(ppufile.getbyte);
  579. end;
  580. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  581. begin
  582. inherited ppuwrite(ppufile);
  583. ppufile.putasmsymbol(sym);
  584. ppufile.putlongint(size);
  585. ppufile.putbyte(byte(is_global));
  586. end;
  587. procedure tai_datablock.derefimpl;
  588. begin
  589. objectlibrary.DerefAsmsymbol(sym);
  590. end;
  591. {****************************************************************************
  592. TAI_SYMBOL
  593. ****************************************************************************}
  594. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  595. begin
  596. inherited Create;
  597. typ:=ait_symbol;
  598. sym:=_sym;
  599. { checkredefinesym(sym);}
  600. size:=siz;
  601. is_global:=(sym.defbind=AB_GLOBAL);
  602. end;
  603. constructor tai_symbol.Createname(const _name : string;siz:longint);
  604. begin
  605. inherited Create;
  606. typ:=ait_symbol;
  607. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_FUNCTION);
  608. { checkredefinesym(sym);}
  609. size:=siz;
  610. is_global:=false;
  611. end;
  612. constructor tai_symbol.Createname_global(const _name : string;siz:longint);
  613. begin
  614. inherited Create;
  615. typ:=ait_symbol;
  616. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_FUNCTION);
  617. { checkredefinesym(sym);}
  618. size:=siz;
  619. is_global:=true;
  620. end;
  621. constructor tai_symbol.Createdataname(const _name : string;siz:longint);
  622. begin
  623. inherited Create;
  624. typ:=ait_symbol;
  625. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  626. { checkredefinesym(sym);}
  627. size:=siz;
  628. is_global:=false;
  629. end;
  630. constructor tai_symbol.Createdataname_global(const _name : string;siz:longint);
  631. begin
  632. inherited Create;
  633. typ:=ait_symbol;
  634. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  635. { checkredefinesym(sym);}
  636. size:=siz;
  637. is_global:=true;
  638. end;
  639. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  640. begin
  641. inherited ppuload(t,ppufile);
  642. sym:=ppufile.getasmsymbol;
  643. size:=ppufile.getlongint;
  644. is_global:=boolean(ppufile.getbyte);
  645. end;
  646. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  647. begin
  648. inherited ppuwrite(ppufile);
  649. ppufile.putasmsymbol(sym);
  650. ppufile.putlongint(size);
  651. ppufile.putbyte(byte(is_global));
  652. end;
  653. procedure tai_symbol.derefimpl;
  654. begin
  655. objectlibrary.DerefAsmsymbol(sym);
  656. end;
  657. {****************************************************************************
  658. TAI_SYMBOL
  659. ****************************************************************************}
  660. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  661. begin
  662. inherited Create;
  663. typ:=ait_symbol_end;
  664. sym:=_sym;
  665. end;
  666. constructor tai_symbol_end.Createname(const _name : string);
  667. begin
  668. inherited Create;
  669. typ:=ait_symbol_end;
  670. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_NONE);
  671. end;
  672. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  673. begin
  674. inherited ppuload(t,ppufile);
  675. sym:=ppufile.getasmsymbol;
  676. end;
  677. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  678. begin
  679. inherited ppuwrite(ppufile);
  680. ppufile.putasmsymbol(sym);
  681. end;
  682. procedure tai_symbol_end.derefimpl;
  683. begin
  684. objectlibrary.DerefAsmsymbol(sym);
  685. end;
  686. {****************************************************************************
  687. TAI_CONST
  688. ****************************************************************************}
  689. constructor tai_const.Create_32bit(_value : longint);
  690. begin
  691. inherited Create;
  692. typ:=ait_const_32bit;
  693. value:=_value;
  694. end;
  695. constructor tai_const.Create_16bit(_value : word);
  696. begin
  697. inherited Create;
  698. typ:=ait_const_16bit;
  699. value:=_value;
  700. end;
  701. constructor tai_const.Create_8bit(_value : byte);
  702. begin
  703. inherited Create;
  704. typ:=ait_const_8bit;
  705. value:=_value;
  706. end;
  707. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  708. begin
  709. inherited ppuload(t,ppufile);
  710. value:=ppufile.getlongint;
  711. end;
  712. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  713. begin
  714. inherited ppuwrite(ppufile);
  715. ppufile.putlongint(value);
  716. end;
  717. {****************************************************************************
  718. TAI_CONST_SYMBOL
  719. ****************************************************************************}
  720. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  721. begin
  722. inherited Create;
  723. typ:=ait_const_symbol;
  724. sym:=_sym;
  725. offset:=0;
  726. { update sym info }
  727. sym.increfs;
  728. end;
  729. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  730. begin
  731. inherited Create;
  732. typ:=ait_const_symbol;
  733. sym:=_sym;
  734. offset:=ofs;
  735. { update sym info }
  736. sym.increfs;
  737. end;
  738. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  739. begin
  740. inherited Create;
  741. typ:=ait_const_rva;
  742. sym:=_sym;
  743. offset:=0;
  744. { update sym info }
  745. sym.increfs;
  746. end;
  747. constructor tai_const_symbol.Createname(const name:string);
  748. begin
  749. inherited Create;
  750. typ:=ait_const_symbol;
  751. sym:=objectlibrary.newasmsymbol(name);
  752. offset:=0;
  753. { update sym info }
  754. sym.increfs;
  755. end;
  756. constructor tai_const_symbol.Createname_offset(const name:string;ofs:longint);
  757. begin
  758. inherited Create;
  759. typ:=ait_const_symbol;
  760. sym:=objectlibrary.newasmsymbol(name);
  761. offset:=ofs;
  762. { update sym info }
  763. sym.increfs;
  764. end;
  765. constructor tai_const_symbol.Createname_rva(const name:string);
  766. begin
  767. inherited Create;
  768. typ:=ait_const_rva;
  769. sym:=objectlibrary.newasmsymbol(name);
  770. offset:=0;
  771. { update sym info }
  772. sym.increfs;
  773. end;
  774. constructor tai_const_symbol.Createdataname(const name:string);
  775. begin
  776. inherited Create;
  777. typ:=ait_const_symbol;
  778. sym:=objectlibrary.newasmsymboltype(name,AB_EXTERNAL,AT_DATA);
  779. offset:=0;
  780. { update sym info }
  781. sym.increfs;
  782. end;
  783. constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  784. begin
  785. inherited ppuload(t,ppufile);
  786. sym:=ppufile.getasmsymbol;
  787. offset:=ppufile.getlongint;
  788. end;
  789. procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
  790. begin
  791. inherited ppuwrite(ppufile);
  792. ppufile.putasmsymbol(sym);
  793. ppufile.putlongint(offset);
  794. end;
  795. procedure tai_const_symbol.derefimpl;
  796. begin
  797. objectlibrary.DerefAsmsymbol(sym);
  798. end;
  799. function tai_const_symbol.getcopy:tlinkedlistitem;
  800. begin
  801. getcopy:=inherited getcopy;
  802. { we need to increase the reference number }
  803. sym.increfs;
  804. end;
  805. {****************************************************************************
  806. TAI_real_32bit
  807. ****************************************************************************}
  808. constructor tai_real_32bit.Create(_value : ts32real);
  809. begin
  810. inherited Create;
  811. typ:=ait_real_32bit;
  812. value:=_value;
  813. end;
  814. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  815. begin
  816. inherited ppuload(t,ppufile);
  817. value:=ppufile.getreal;
  818. end;
  819. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  820. begin
  821. inherited ppuwrite(ppufile);
  822. ppufile.putreal(value);
  823. end;
  824. {****************************************************************************
  825. TAI_real_64bit
  826. ****************************************************************************}
  827. constructor tai_real_64bit.Create(_value : ts64real);
  828. begin
  829. inherited Create;
  830. typ:=ait_real_64bit;
  831. value:=_value;
  832. end;
  833. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  834. begin
  835. inherited ppuload(t,ppufile);
  836. value:=ppufile.getreal;
  837. end;
  838. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  839. begin
  840. inherited ppuwrite(ppufile);
  841. ppufile.putreal(value);
  842. end;
  843. {****************************************************************************
  844. TAI_real_80bit
  845. ****************************************************************************}
  846. constructor tai_real_80bit.Create(_value : ts80real);
  847. begin
  848. inherited Create;
  849. typ:=ait_real_80bit;
  850. value:=_value;
  851. end;
  852. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  853. begin
  854. inherited ppuload(t,ppufile);
  855. value:=ppufile.getreal;
  856. end;
  857. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  858. begin
  859. inherited ppuwrite(ppufile);
  860. ppufile.putreal(value);
  861. end;
  862. {****************************************************************************
  863. Tai_comp_64bit
  864. ****************************************************************************}
  865. constructor tai_comp_64bit.Create(_value : ts64comp);
  866. begin
  867. inherited Create;
  868. typ:=ait_comp_64bit;
  869. value:=_value;
  870. end;
  871. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  872. begin
  873. inherited ppuload(t,ppufile);
  874. ppufile.putdata(value,sizeof(value));
  875. end;
  876. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  877. begin
  878. inherited ppuwrite(ppufile);
  879. ppufile.getdata(value,sizeof(value));
  880. end;
  881. {****************************************************************************
  882. TAI_STRING
  883. ****************************************************************************}
  884. constructor tai_string.Create(const _str : string);
  885. begin
  886. inherited Create;
  887. typ:=ait_string;
  888. len:=length(_str);
  889. getmem(str,len+1);
  890. strpcopy(str,_str);
  891. end;
  892. constructor tai_string.Create_pchar(_str : pchar);
  893. begin
  894. inherited Create;
  895. typ:=ait_string;
  896. str:=_str;
  897. len:=strlen(_str);
  898. end;
  899. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  900. begin
  901. inherited Create;
  902. typ:=ait_string;
  903. str:=_str;
  904. len:=length;
  905. end;
  906. destructor tai_string.destroy;
  907. begin
  908. { you can have #0 inside the strings so }
  909. if str<>nil then
  910. freemem(str,len+1);
  911. inherited Destroy;
  912. end;
  913. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  914. begin
  915. inherited ppuload(t,ppufile);
  916. len:=ppufile.getlongint;
  917. getmem(str,len+1);
  918. ppufile.getdata(str^,len);
  919. str[len]:=#0;
  920. end;
  921. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  922. begin
  923. inherited ppuwrite(ppufile);
  924. ppufile.putlongint(len);
  925. ppufile.putdata(str^,len);
  926. end;
  927. function tai_string.getcopy : tlinkedlistitem;
  928. var
  929. p : tlinkedlistitem;
  930. begin
  931. p:=inherited getcopy;
  932. getmem(tai_string(p).str,len+1);
  933. move(str^,tai_string(p).str^,len+1);
  934. getcopy:=p;
  935. end;
  936. {****************************************************************************
  937. TAI_LABEL
  938. ****************************************************************************}
  939. constructor tai_label.create(_l : tasmlabel);
  940. begin
  941. inherited Create;
  942. typ:=ait_label;
  943. l:=_l;
  944. { checkredefinesym(l);}
  945. l.is_set:=true;
  946. is_global:=(l.defbind=AB_GLOBAL);
  947. end;
  948. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  949. begin
  950. inherited ppuload(t,ppufile);
  951. l:=tasmlabel(ppufile.getasmsymbol);
  952. is_global:=boolean(ppufile.getbyte);
  953. end;
  954. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  955. begin
  956. inherited ppuwrite(ppufile);
  957. ppufile.putasmsymbol(l);
  958. ppufile.putbyte(byte(is_global));
  959. end;
  960. procedure tai_label.derefimpl;
  961. begin
  962. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  963. l.is_set:=true;
  964. end;
  965. {****************************************************************************
  966. TAI_DIRECT
  967. ****************************************************************************}
  968. constructor tai_direct.Create(_str : pchar);
  969. begin
  970. inherited Create;
  971. typ:=ait_direct;
  972. str:=_str;
  973. end;
  974. destructor tai_direct.destroy;
  975. begin
  976. strdispose(str);
  977. inherited Destroy;
  978. end;
  979. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  980. var
  981. len : longint;
  982. begin
  983. inherited ppuload(t,ppufile);
  984. len:=ppufile.getlongint;
  985. getmem(str,len+1);
  986. ppufile.getdata(str^,len);
  987. str[len]:=#0;
  988. end;
  989. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  990. var
  991. len : longint;
  992. begin
  993. inherited ppuwrite(ppufile);
  994. len:=strlen(str);
  995. ppufile.putlongint(len);
  996. ppufile.putdata(str^,len);
  997. end;
  998. function tai_direct.getcopy : tlinkedlistitem;
  999. var
  1000. p : tlinkedlistitem;
  1001. begin
  1002. p:=inherited getcopy;
  1003. getmem(tai_direct(p).str,strlen(str)+1);
  1004. move(str^,tai_direct(p).str^,strlen(str)+1);
  1005. getcopy:=p;
  1006. end;
  1007. {****************************************************************************
  1008. tai_comment comment to be inserted in the assembler file
  1009. ****************************************************************************}
  1010. constructor tai_comment.Create(_str : pchar);
  1011. begin
  1012. inherited Create;
  1013. typ:=ait_comment;
  1014. str:=_str;
  1015. end;
  1016. destructor tai_comment.destroy;
  1017. begin
  1018. strdispose(str);
  1019. inherited Destroy;
  1020. end;
  1021. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1022. var
  1023. len : longint;
  1024. begin
  1025. inherited ppuload(t,ppufile);
  1026. len:=ppufile.getlongint;
  1027. getmem(str,len+1);
  1028. ppufile.getdata(str^,len);
  1029. str[len]:=#0;
  1030. end;
  1031. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1032. var
  1033. len : longint;
  1034. begin
  1035. inherited ppuwrite(ppufile);
  1036. len:=strlen(str);
  1037. ppufile.putlongint(len);
  1038. ppufile.putdata(str^,len);
  1039. end;
  1040. function tai_comment.getcopy : tlinkedlistitem;
  1041. var
  1042. p : tlinkedlistitem;
  1043. begin
  1044. p:=inherited getcopy;
  1045. getmem(tai_comment(p).str,strlen(str)+1);
  1046. move(str^,tai_comment(p).str^,strlen(str)+1);
  1047. getcopy:=p;
  1048. end;
  1049. {****************************************************************************
  1050. TAI_CUT
  1051. ****************************************************************************}
  1052. constructor tai_cut.Create;
  1053. begin
  1054. inherited Create;
  1055. typ:=ait_cut;
  1056. place:=cut_normal;
  1057. end;
  1058. constructor tai_cut.Create_begin;
  1059. begin
  1060. inherited Create;
  1061. typ:=ait_cut;
  1062. place:=cut_begin;
  1063. end;
  1064. constructor tai_cut.Create_end;
  1065. begin
  1066. inherited Create;
  1067. typ:=ait_cut;
  1068. place:=cut_end;
  1069. end;
  1070. constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
  1071. begin
  1072. inherited ppuload(t,ppufile);
  1073. place:=TCutPlace(ppufile.getbyte);
  1074. end;
  1075. procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
  1076. begin
  1077. inherited ppuwrite(ppufile);
  1078. ppufile.putbyte(byte(place));
  1079. end;
  1080. {****************************************************************************
  1081. Tai_Marker
  1082. ****************************************************************************}
  1083. constructor Tai_Marker.Create(_Kind: TMarker);
  1084. begin
  1085. Inherited Create;
  1086. typ := ait_marker;
  1087. Kind := _Kind;
  1088. end;
  1089. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1090. begin
  1091. inherited ppuload(t,ppufile);
  1092. kind:=TMarker(ppufile.getbyte);
  1093. end;
  1094. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1095. begin
  1096. inherited ppuwrite(ppufile);
  1097. ppufile.putbyte(byte(kind));
  1098. end;
  1099. {*****************************************************************************
  1100. tai_tempalloc
  1101. *****************************************************************************}
  1102. constructor tai_tempalloc.alloc(pos,size:longint);
  1103. begin
  1104. inherited Create;
  1105. typ:=ait_tempalloc;
  1106. allocation:=true;
  1107. temppos:=pos;
  1108. tempsize:=size;
  1109. {$ifdef EXTDEBUG}
  1110. problem:=nil;
  1111. {$endif EXTDEBUG}
  1112. end;
  1113. constructor tai_tempalloc.dealloc(pos,size:longint);
  1114. begin
  1115. inherited Create;
  1116. typ:=ait_tempalloc;
  1117. allocation:=false;
  1118. temppos:=pos;
  1119. tempsize:=size;
  1120. {$ifdef EXTDEBUG}
  1121. problem:=nil;
  1122. {$endif EXTDEBUG}
  1123. end;
  1124. {$ifdef EXTDEBUG}
  1125. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1126. begin
  1127. inherited Create;
  1128. typ:=ait_tempalloc;
  1129. allocation:=false;
  1130. temppos:=pos;
  1131. tempsize:=size;
  1132. problem:=stringdup(st);
  1133. end;
  1134. {$endif EXTDEBUG}
  1135. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1136. begin
  1137. inherited ppuload(t,ppufile);
  1138. temppos:=ppufile.getlongint;
  1139. tempsize:=ppufile.getlongint;
  1140. allocation:=boolean(ppufile.getbyte);
  1141. {$ifdef EXTDEBUG}
  1142. problem:=nil;
  1143. {$endif EXTDEBUG}
  1144. end;
  1145. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1146. begin
  1147. inherited ppuwrite(ppufile);
  1148. ppufile.putlongint(temppos);
  1149. ppufile.putlongint(tempsize);
  1150. ppufile.putbyte(byte(allocation));
  1151. end;
  1152. {*****************************************************************************
  1153. tai_regalloc
  1154. *****************************************************************************}
  1155. constructor tai_regalloc.alloc(r : tregister);
  1156. begin
  1157. inherited create;
  1158. typ:=ait_regalloc;
  1159. allocation:=true;
  1160. reg:=r;
  1161. end;
  1162. constructor tai_regalloc.dealloc(r : tregister);
  1163. begin
  1164. inherited create;
  1165. typ:=ait_regalloc;
  1166. allocation:=false;
  1167. reg:=r;
  1168. end;
  1169. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1170. begin
  1171. inherited ppuload(t,ppufile);
  1172. ppufile.getdata(reg,sizeof(Tregister));
  1173. allocation:=boolean(ppufile.getbyte);
  1174. end;
  1175. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1176. begin
  1177. inherited ppuwrite(ppufile);
  1178. ppufile.putdata(reg,sizeof(Tregister));
  1179. ppufile.putbyte(byte(allocation));
  1180. end;
  1181. {*****************************************************************************
  1182. TaiInstruction
  1183. *****************************************************************************}
  1184. constructor taicpu_abstract.Create(op : tasmop);
  1185. begin
  1186. inherited create;
  1187. typ:=ait_instruction;
  1188. is_jmp:=false;
  1189. opcode:=op;
  1190. ops:=0;
  1191. fillchar(condition,sizeof(condition),0);
  1192. fillchar(oper,sizeof(oper),0);
  1193. end;
  1194. destructor taicpu_abstract.Destroy;
  1195. var
  1196. i : longint;
  1197. begin
  1198. for i:=0 to ops-1 do
  1199. case oper[i].typ of
  1200. top_ref:
  1201. dispose(oper[i].ref);
  1202. end;
  1203. inherited destroy;
  1204. end;
  1205. { ---------------------------------------------------------------------
  1206. Loading of operands.
  1207. ---------------------------------------------------------------------}
  1208. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  1209. begin
  1210. if opidx>=ops then
  1211. ops:=opidx+1;
  1212. with oper[opidx] do
  1213. begin
  1214. if typ=top_ref then
  1215. dispose(ref);
  1216. val:=l;
  1217. typ:=top_const;
  1218. end;
  1219. end;
  1220. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1221. begin
  1222. if not assigned(s) then
  1223. internalerror(200204251);
  1224. if opidx>=ops then
  1225. ops:=opidx+1;
  1226. with oper[opidx] do
  1227. begin
  1228. if typ=top_ref then
  1229. dispose(ref);
  1230. sym:=s;
  1231. symofs:=sofs;
  1232. typ:=top_symbol;
  1233. end;
  1234. s.increfs;
  1235. end;
  1236. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  1237. begin
  1238. if opidx>=ops then
  1239. ops:=opidx+1;
  1240. with oper[opidx] do
  1241. begin
  1242. if typ<>top_ref then
  1243. new(ref);
  1244. ref^:=r;
  1245. {$ifdef i386}
  1246. { We allow this exception for i386, since overloading this would be
  1247. too much of a a speed penalty}
  1248. if ref^.segment.enum=R_INTREGISTER then
  1249. begin
  1250. if (ref^.segment.number <> NR_NO) and (ref^.segment.number <> NR_DS) then
  1251. segprefix:=ref^.segment;
  1252. end
  1253. else
  1254. if not(ref^.segment.enum in [R_DS,R_NO]) then
  1255. segprefix:=ref^.segment;
  1256. {$endif}
  1257. typ:=top_ref;
  1258. { mark symbol as used }
  1259. if assigned(ref^.symbol) then
  1260. ref^.symbol.increfs;
  1261. end;
  1262. end;
  1263. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  1264. begin
  1265. if opidx>=ops then
  1266. ops:=opidx+1;
  1267. with oper[opidx] do
  1268. begin
  1269. if typ=top_ref then
  1270. dispose(ref);
  1271. reg:=r;
  1272. typ:=top_reg;
  1273. end;
  1274. end;
  1275. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  1276. begin
  1277. if opidx>=ops then
  1278. ops:=opidx+1;
  1279. if oper[opidx].typ=top_ref then
  1280. dispose(oper[opidx].ref);
  1281. oper[opidx]:=o;
  1282. { copy also the reference }
  1283. if oper[opidx].typ=top_ref then
  1284. begin
  1285. new(oper[opidx].ref);
  1286. oper[opidx].ref^:=o.ref^;
  1287. end;
  1288. end;
  1289. { ---------------------------------------------------------------------
  1290. Miscellaneous methods.
  1291. ---------------------------------------------------------------------}
  1292. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  1293. begin
  1294. condition:=c;
  1295. end;
  1296. Function taicpu_abstract.getcopy:TLinkedListItem;
  1297. var
  1298. i : longint;
  1299. p : TLinkedListItem;
  1300. begin
  1301. p:=inherited getcopy;
  1302. { make a copy of the references }
  1303. for i:=1 to ops do
  1304. if (taicpu_abstract(p).oper[i-1].typ=top_ref) then
  1305. begin
  1306. new(taicpu_abstract(p).oper[i-1].ref);
  1307. taicpu_abstract(p).oper[i-1].ref^:=oper[i-1].ref^;
  1308. end;
  1309. getcopy:=p;
  1310. end;
  1311. constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1312. var
  1313. i : integer;
  1314. begin
  1315. inherited ppuload(t,ppufile);
  1316. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1317. ppufile.getdata(condition,sizeof(tasmcond));
  1318. ops:=ppufile.getbyte;
  1319. for i:=1 to ops do
  1320. ppuloadoper(ppufile,oper[i-1]);
  1321. opcode:=tasmop(ppufile.getword);
  1322. {$ifdef i386}
  1323. ppufile.getdata(segprefix,sizeof(Tregister));
  1324. {$endif i386}
  1325. is_jmp:=boolean(ppufile.getbyte);
  1326. end;
  1327. procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1328. var
  1329. i : integer;
  1330. begin
  1331. inherited ppuwrite(ppufile);
  1332. ppufile.putdata(condition,sizeof(tasmcond));
  1333. ppufile.putbyte(ops);
  1334. for i:=1 to ops do
  1335. ppuwriteoper(ppufile,oper[i-1]);
  1336. ppufile.putword(word(opcode));
  1337. {$ifdef i386}
  1338. ppufile.putdata(segprefix,sizeof(Tregister));
  1339. {$endif i386}
  1340. ppufile.putbyte(byte(is_jmp));
  1341. end;
  1342. procedure taicpu_abstract.derefimpl;
  1343. var
  1344. i : integer;
  1345. begin
  1346. for i:=1 to ops do
  1347. ppuderefoper(oper[i-1]);
  1348. end;
  1349. {****************************************************************************
  1350. tai_align_abstract
  1351. ****************************************************************************}
  1352. constructor tai_align_abstract.Create(b: byte);
  1353. begin
  1354. inherited Create;
  1355. typ:=ait_align;
  1356. if b in [1,2,4,8,16,32] then
  1357. aligntype := b
  1358. else
  1359. aligntype := 1;
  1360. fillsize:=0;
  1361. fillop:=0;
  1362. use_op:=false;
  1363. end;
  1364. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1365. begin
  1366. inherited Create;
  1367. typ:=ait_align;
  1368. if b in [1,2,4,8,16,32] then
  1369. aligntype := b
  1370. else
  1371. aligntype := 1;
  1372. fillsize:=0;
  1373. fillop:=_op;
  1374. use_op:=true;
  1375. end;
  1376. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1377. begin
  1378. fillchar(buf,high(buf),fillop);
  1379. calculatefillbuf:=pchar(@buf);
  1380. end;
  1381. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1382. begin
  1383. inherited ppuload(t,ppufile);
  1384. aligntype:=ppufile.getbyte;
  1385. fillsize:=0;
  1386. fillop:=ppufile.getbyte;
  1387. use_op:=boolean(ppufile.getbyte);
  1388. end;
  1389. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1390. begin
  1391. inherited ppuwrite(ppufile);
  1392. ppufile.putbyte(aligntype);
  1393. ppufile.putbyte(fillop);
  1394. ppufile.putbyte(byte(use_op));
  1395. end;
  1396. {*****************************************************************************
  1397. TAAsmOutput
  1398. *****************************************************************************}
  1399. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1400. var
  1401. hp : tlinkedlistitem;
  1402. begin
  1403. getlasttaifilepos := nil;
  1404. if assigned(last) then
  1405. begin
  1406. { find the last file information record }
  1407. if not (tai(last).typ in SkipLineInfo) then
  1408. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1409. else
  1410. { go through list backwards to find the first entry
  1411. with line information
  1412. }
  1413. begin
  1414. hp:=tai(last);
  1415. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1416. hp:=hp.Previous;
  1417. { found entry }
  1418. if assigned(hp) then
  1419. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1420. end;
  1421. end;
  1422. end;
  1423. procedure Taasmoutput.convert_registers;
  1424. var p:Tai;
  1425. i:shortint;
  1426. r:Preference;
  1427. begin
  1428. p:=Tai(first);
  1429. while assigned(p) do
  1430. begin
  1431. case p.typ of
  1432. ait_regalloc:
  1433. convert_register_to_enum(Tai_regalloc(p).reg);
  1434. ait_instruction:
  1435. begin
  1436. for i:=0 to Taicpu_abstract(p).ops-1 do
  1437. if Taicpu_abstract(p).oper[i].typ=Top_reg then
  1438. begin
  1439. if Taicpu_abstract(p).oper[i].reg.enum=R_NO then
  1440. internalerror(200302052);
  1441. convert_register_to_enum(Taicpu_abstract(p).oper[i].reg)
  1442. end
  1443. else if Taicpu_abstract(p).oper[i].typ=Top_ref then
  1444. begin
  1445. r:=Taicpu_abstract(p).oper[i].ref;
  1446. {$ifdef i386}
  1447. convert_register_to_enum(r^.segment);
  1448. {$endif i386}
  1449. convert_register_to_enum(r^.base);
  1450. convert_register_to_enum(r^.index);
  1451. end;
  1452. {$ifdef i386}
  1453. convert_register_to_enum(Taicpu_abstract(p).segprefix);
  1454. {$endif}
  1455. end;
  1456. end;
  1457. p:=Tai(p.next);
  1458. end;
  1459. end;
  1460. procedure Taasmoutput.translate_registers(const table:Ttranstable);
  1461. var p,q:Tai;
  1462. i:shortint;
  1463. r:Preference;
  1464. begin
  1465. p:=Tai(first);
  1466. while assigned(p) do
  1467. begin
  1468. case p.typ of
  1469. ait_regalloc:
  1470. Tai_regalloc(p).reg.number:=(Tai_regalloc(p).reg.number and $ff) or
  1471. (table[Tai_regalloc(p).reg.number shr 8] shl 8);
  1472. ait_instruction:
  1473. begin
  1474. for i:=0 to Taicpu_abstract(p).ops-1 do
  1475. if Taicpu_abstract(p).oper[i].typ=Top_reg then
  1476. Taicpu_abstract(p).oper[i].reg.number:=(Taicpu_abstract(p).oper[i].reg.number and $ff) or
  1477. (table[Taicpu_abstract(p).oper[i].reg.number shr 8] shl 8)
  1478. else if Taicpu_abstract(p).oper[i].typ=Top_ref then
  1479. begin
  1480. r:=Taicpu_abstract(p).oper[i].ref;
  1481. r^.base.number:=(r^.base.number and $ff) or
  1482. (table[r^.base.number shr 8] shl 8);
  1483. r^.index.number:=(r^.index.number and $ff) or
  1484. (table[r^.index.number shr 8] shl 8);
  1485. end;
  1486. if Taicpu_abstract(p).is_nop then
  1487. begin
  1488. q:=p;
  1489. p:=Tai(p.next);
  1490. remove(q);
  1491. continue;
  1492. end;
  1493. end;
  1494. end;
  1495. p:=Tai(p.next);
  1496. end;
  1497. end;
  1498. end.
  1499. {
  1500. $Log$
  1501. Revision 1.24 2003-04-24 13:03:01 florian
  1502. * comp is now written with its bit pattern to the ppu instead as an extended
  1503. Revision 1.23 2003/04/22 14:33:38 peter
  1504. * removed some notes/hints
  1505. Revision 1.22 2003/04/22 10:09:34 daniel
  1506. + Implemented the actual register allocator
  1507. + Scratch registers unavailable when new register allocator used
  1508. + maybe_save/maybe_restore unavailable when new register allocator used
  1509. Revision 1.21 2003/02/19 22:00:14 daniel
  1510. * Code generator converted to new register notation
  1511. - Horribily outdated todo.txt removed
  1512. Revision 1.20 2003/01/30 21:46:20 peter
  1513. * tai_const_symbol.createdataname added
  1514. Revision 1.19 2003/01/21 08:48:08 daniel
  1515. * Another 200301081 fixed
  1516. Revision 1.18 2003/01/09 20:40:59 daniel
  1517. * Converted some code in cgx86.pas to new register numbering
  1518. Revision 1.17 2003/01/09 15:49:56 daniel
  1519. * Added register conversion
  1520. Revision 1.16 2003/01/08 18:43:56 daniel
  1521. * Tregister changed into a record
  1522. Revision 1.15 2003/01/05 13:36:53 florian
  1523. * x86-64 compiles
  1524. + very basic support for float128 type (x86-64 only)
  1525. Revision 1.14 2002/12/06 17:50:21 peter
  1526. * symbol count fix merged
  1527. Revision 1.13 2002/11/17 16:31:55 carl
  1528. * memory optimization (3-4%) : cleanup of tai fields,
  1529. cleanup of tdef and tsym fields.
  1530. * make it work for m68k
  1531. Revision 1.12 2002/11/15 16:29:30 peter
  1532. * made tasmsymbol.refs private (merged)
  1533. Revision 1.11 2002/11/15 01:58:45 peter
  1534. * merged changes from 1.0.7 up to 04-11
  1535. - -V option for generating bug report tracing
  1536. - more tracing for option parsing
  1537. - errors for cdecl and high()
  1538. - win32 import stabs
  1539. - win32 records<=8 are returned in eax:edx (turned off by default)
  1540. - heaptrc update
  1541. - more info for temp management in .s file with EXTDEBUG
  1542. Revision 1.10 2002/11/09 15:38:03 carl
  1543. + NOOPT removed the optinfo field
  1544. Revision 1.9 2002/10/05 12:43:23 carl
  1545. * fixes for Delphi 6 compilation
  1546. (warning : Some features do not work under Delphi)
  1547. Revision 1.8 2002/08/19 19:36:42 peter
  1548. * More fixes for cross unit inlining, all tnodes are now implemented
  1549. * Moved pocall_internconst to po_internconst because it is not a
  1550. calling type at all and it conflicted when inlining of these small
  1551. functions was requested
  1552. Revision 1.7 2002/08/18 20:06:23 peter
  1553. * inlining is now also allowed in interface
  1554. * renamed write/load to ppuwrite/ppuload
  1555. * tnode storing in ppu
  1556. * nld,ncon,nbas are already updated for storing in ppu
  1557. Revision 1.6 2002/08/16 05:21:09 florian
  1558. * powerpc compilation fix
  1559. Revision 1.5 2002/08/15 19:10:35 peter
  1560. * first things tai,tnode storing in ppu
  1561. Revision 1.4 2002/08/11 14:32:25 peter
  1562. * renamed current_library to objectlibrary
  1563. Revision 1.3 2002/08/11 13:24:10 peter
  1564. * saving of asmsymbols in ppu supported
  1565. * asmsymbollist global is removed and moved into a new class
  1566. tasmlibrarydata that will hold the info of a .a file which
  1567. corresponds with a single module. Added librarydata to tmodule
  1568. to keep the library info stored for the module. In the future the
  1569. objectfiles will also be stored to the tasmlibrarydata class
  1570. * all getlabel/newasmsymbol and friends are moved to the new class
  1571. Revision 1.2 2002/08/05 18:27:48 carl
  1572. + more more more documentation
  1573. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1574. Revision 1.1 2002/07/01 18:46:20 peter
  1575. * internal linker
  1576. * reorganized aasm layer
  1577. Revision 1.27 2002/05/18 13:34:04 peter
  1578. * readded missing revisions
  1579. Revision 1.25 2002/05/14 19:34:38 peter
  1580. * removed old logs and updated copyright year
  1581. Revision 1.24 2002/05/14 17:28:08 peter
  1582. * synchronized cpubase between powerpc and i386
  1583. * moved more tables from cpubase to cpuasm
  1584. * tai_align_abstract moved to tainst, cpuasm must define
  1585. the tai_align class now, which may be empty
  1586. Revision 1.23 2002/04/15 18:54:34 carl
  1587. - removed tcpuflags
  1588. Revision 1.22 2002/04/07 13:18:19 carl
  1589. + more documentation
  1590. Revision 1.21 2002/04/07 10:17:40 carl
  1591. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  1592. + changing some comments so its commented automatically
  1593. Revision 1.20 2002/03/24 19:04:31 carl
  1594. + patch for SPARC from Mazen NEIFER
  1595. }