aasmtai.pas 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  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. destructor destroy;override;
  351. procedure ppuwrite(ppufile:tcompilerppufile);override;
  352. end;
  353. tai_regalloc = class(tai)
  354. allocation : boolean;
  355. reg : tregister;
  356. constructor alloc(r : tregister);
  357. constructor dealloc(r : tregister);
  358. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  359. procedure ppuwrite(ppufile:tcompilerppufile);override;
  360. end;
  361. { Class template for assembler instructions
  362. }
  363. taicpu_abstract = class(tailineinfo)
  364. protected
  365. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  366. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  367. procedure ppuderefoper(var o:toper);virtual;abstract;
  368. public
  369. { Condition flags for instruction }
  370. condition : TAsmCond;
  371. { Number of operands to instruction }
  372. ops : byte;
  373. { Operands of instruction }
  374. oper : array[0..max_operands-1] of toper;
  375. { Actual opcode of instruction }
  376. opcode : tasmop;
  377. {$ifdef x86}
  378. segprefix : tregister;
  379. {$endif x86}
  380. { true if instruction is a jmp }
  381. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  382. Constructor Create(op : tasmop);
  383. Destructor Destroy;override;
  384. function getcopy:TLinkedListItem;override;
  385. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  386. procedure ppuwrite(ppufile:tcompilerppufile);override;
  387. procedure derefimpl;override;
  388. procedure SetCondition(const c:TAsmCond);
  389. procedure loadconst(opidx:longint;l:aword);
  390. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  391. procedure loadref(opidx:longint;const r:treference);
  392. procedure loadreg(opidx:longint;r:tregister);
  393. procedure loadoper(opidx:longint;o:toper);
  394. function is_nop:boolean;virtual;abstract;
  395. end;
  396. { alignment for operator }
  397. tai_align_abstract = class(tai)
  398. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  399. fillsize : byte; { real size to fill }
  400. fillop : byte; { value to fill with - optional }
  401. use_op : boolean;
  402. constructor Create(b:byte);
  403. constructor Create_op(b: byte; _op: byte);
  404. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  405. procedure ppuwrite(ppufile:tcompilerppufile);override;
  406. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  407. end;
  408. Ttranstable=array[Tsuperregister] of Tsuperregister;
  409. taasmoutput = class(tlinkedlist)
  410. function getlasttaifilepos : pfileposinfo;
  411. procedure convert_registers;
  412. procedure translate_registers(const table:Ttranstable);
  413. end;
  414. var
  415. { array with all class types for tais }
  416. aiclass : taiclassarray;
  417. { temporary lists }
  418. exprasmlist,
  419. { default lists }
  420. datasegment,codesegment,bsssegment,
  421. debuglist,withdebuglist,consts,
  422. importssection,exportssection,
  423. resourcesection,rttilist,
  424. resourcestringlist : taasmoutput;
  425. function ppuloadai(ppufile:tcompilerppufile):tai;
  426. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  427. implementation
  428. uses
  429. {$ifdef delphi}
  430. sysutils,
  431. {$else}
  432. strings,
  433. {$endif}
  434. verbose;
  435. const
  436. pputaimarker = 254;
  437. {****************************************************************************
  438. Helpers
  439. ****************************************************************************}
  440. function ppuloadai(ppufile:tcompilerppufile):tai;
  441. var
  442. b : byte;
  443. t : taitype;
  444. begin
  445. { marker }
  446. b:=ppufile.getbyte;
  447. if b<>pputaimarker then
  448. internalerror(200208181);
  449. { load nodetype }
  450. t:=taitype(ppufile.getbyte);
  451. if t<>ait_none then
  452. begin
  453. if t>high(taitype) then
  454. internalerror(200208182);
  455. if not assigned(aiclass[t]) then
  456. internalerror(200208183);
  457. //writeln('taiload: ',taitypestr[t]);
  458. { generate tai of the correct class }
  459. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  460. end
  461. else
  462. ppuloadai:=nil;
  463. end;
  464. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  465. begin
  466. { marker, read by ppuloadnode }
  467. ppufile.putbyte(pputaimarker);
  468. if assigned(n) then
  469. begin
  470. { type, read by ppuloadnode }
  471. ppufile.putbyte(byte(n.typ));
  472. //writeln('taiwrite: ',taitypestr[n.typ]);
  473. n.ppuwrite(ppufile);
  474. end
  475. else
  476. ppufile.putbyte(byte(ait_none));
  477. end;
  478. {****************************************************************************
  479. TAI
  480. ****************************************************************************}
  481. constructor tai.Create;
  482. begin
  483. {$ifndef NOOPT}
  484. optinfo:=nil;
  485. {$endif NOOPT}
  486. end;
  487. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  488. begin
  489. typ:=t;
  490. {$ifndef NOOPT}
  491. optinfo:=nil;
  492. {$endif}
  493. end;
  494. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  495. begin
  496. end;
  497. procedure tai.derefimpl;
  498. begin
  499. end;
  500. procedure tai.checkredefinesym(sym:tasmsymbol);
  501. begin
  502. { if assigned(sym.taiowner) and
  503. (target_asm.id in binassem) then
  504. begin
  505. Message1(asmw_e_redefined_label,sym.name);
  506. end
  507. else
  508. sym.taiowner:=self;}
  509. end;
  510. {****************************************************************************
  511. TAILINEINFO
  512. ****************************************************************************}
  513. constructor tailineinfo.create;
  514. begin
  515. inherited create;
  516. fileinfo:=aktfilepos;
  517. end;
  518. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  519. begin
  520. inherited ppuload(t,ppufile);
  521. ppufile.getposinfo(fileinfo);
  522. end;
  523. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  524. begin
  525. inherited ppuwrite(ppufile);
  526. ppufile.putposinfo(fileinfo);
  527. end;
  528. {****************************************************************************
  529. TAI_SECTION
  530. ****************************************************************************}
  531. constructor tai_section.Create(s : TSection);
  532. begin
  533. inherited Create;
  534. typ:=ait_section;
  535. sec:=s;
  536. end;
  537. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  538. begin
  539. inherited ppuload(t,ppufile);
  540. sec:=tsection(ppufile.getbyte);
  541. end;
  542. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  543. begin
  544. inherited ppuwrite(ppufile);
  545. ppufile.putbyte(byte(sec));
  546. end;
  547. {****************************************************************************
  548. TAI_DATABLOCK
  549. ****************************************************************************}
  550. constructor tai_datablock.Create(const _name : string;_size : longint);
  551. begin
  552. inherited Create;
  553. typ:=ait_datablock;
  554. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  555. { checkredefinesym(sym);}
  556. { keep things aligned }
  557. if _size<=0 then
  558. _size:=4;
  559. size:=_size;
  560. is_global:=false;
  561. end;
  562. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  563. begin
  564. inherited Create;
  565. typ:=ait_datablock;
  566. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  567. { checkredefinesym(sym);}
  568. { keep things aligned }
  569. if _size<=0 then
  570. _size:=4;
  571. size:=_size;
  572. is_global:=true;
  573. end;
  574. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  575. begin
  576. inherited Create;
  577. sym:=ppufile.getasmsymbol;
  578. size:=ppufile.getlongint;
  579. is_global:=boolean(ppufile.getbyte);
  580. end;
  581. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  582. begin
  583. inherited ppuwrite(ppufile);
  584. ppufile.putasmsymbol(sym);
  585. ppufile.putlongint(size);
  586. ppufile.putbyte(byte(is_global));
  587. end;
  588. procedure tai_datablock.derefimpl;
  589. begin
  590. objectlibrary.DerefAsmsymbol(sym);
  591. end;
  592. {****************************************************************************
  593. TAI_SYMBOL
  594. ****************************************************************************}
  595. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  596. begin
  597. inherited Create;
  598. typ:=ait_symbol;
  599. sym:=_sym;
  600. { checkredefinesym(sym);}
  601. size:=siz;
  602. is_global:=(sym.defbind=AB_GLOBAL);
  603. end;
  604. constructor tai_symbol.Createname(const _name : string;siz:longint);
  605. begin
  606. inherited Create;
  607. typ:=ait_symbol;
  608. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_FUNCTION);
  609. { checkredefinesym(sym);}
  610. size:=siz;
  611. is_global:=false;
  612. end;
  613. constructor tai_symbol.Createname_global(const _name : string;siz:longint);
  614. begin
  615. inherited Create;
  616. typ:=ait_symbol;
  617. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_FUNCTION);
  618. { checkredefinesym(sym);}
  619. size:=siz;
  620. is_global:=true;
  621. end;
  622. constructor tai_symbol.Createdataname(const _name : string;siz:longint);
  623. begin
  624. inherited Create;
  625. typ:=ait_symbol;
  626. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  627. { checkredefinesym(sym);}
  628. size:=siz;
  629. is_global:=false;
  630. end;
  631. constructor tai_symbol.Createdataname_global(const _name : string;siz:longint);
  632. begin
  633. inherited Create;
  634. typ:=ait_symbol;
  635. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  636. { checkredefinesym(sym);}
  637. size:=siz;
  638. is_global:=true;
  639. end;
  640. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  641. begin
  642. inherited ppuload(t,ppufile);
  643. sym:=ppufile.getasmsymbol;
  644. size:=ppufile.getlongint;
  645. is_global:=boolean(ppufile.getbyte);
  646. end;
  647. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  648. begin
  649. inherited ppuwrite(ppufile);
  650. ppufile.putasmsymbol(sym);
  651. ppufile.putlongint(size);
  652. ppufile.putbyte(byte(is_global));
  653. end;
  654. procedure tai_symbol.derefimpl;
  655. begin
  656. objectlibrary.DerefAsmsymbol(sym);
  657. end;
  658. {****************************************************************************
  659. TAI_SYMBOL
  660. ****************************************************************************}
  661. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  662. begin
  663. inherited Create;
  664. typ:=ait_symbol_end;
  665. sym:=_sym;
  666. end;
  667. constructor tai_symbol_end.Createname(const _name : string);
  668. begin
  669. inherited Create;
  670. typ:=ait_symbol_end;
  671. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_NONE);
  672. end;
  673. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  674. begin
  675. inherited ppuload(t,ppufile);
  676. sym:=ppufile.getasmsymbol;
  677. end;
  678. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  679. begin
  680. inherited ppuwrite(ppufile);
  681. ppufile.putasmsymbol(sym);
  682. end;
  683. procedure tai_symbol_end.derefimpl;
  684. begin
  685. objectlibrary.DerefAsmsymbol(sym);
  686. end;
  687. {****************************************************************************
  688. TAI_CONST
  689. ****************************************************************************}
  690. constructor tai_const.Create_32bit(_value : longint);
  691. begin
  692. inherited Create;
  693. typ:=ait_const_32bit;
  694. value:=_value;
  695. end;
  696. constructor tai_const.Create_16bit(_value : word);
  697. begin
  698. inherited Create;
  699. typ:=ait_const_16bit;
  700. value:=_value;
  701. end;
  702. constructor tai_const.Create_8bit(_value : byte);
  703. begin
  704. inherited Create;
  705. typ:=ait_const_8bit;
  706. value:=_value;
  707. end;
  708. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  709. begin
  710. inherited ppuload(t,ppufile);
  711. value:=ppufile.getlongint;
  712. end;
  713. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  714. begin
  715. inherited ppuwrite(ppufile);
  716. ppufile.putlongint(value);
  717. end;
  718. {****************************************************************************
  719. TAI_CONST_SYMBOL
  720. ****************************************************************************}
  721. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  722. begin
  723. inherited Create;
  724. typ:=ait_const_symbol;
  725. sym:=_sym;
  726. offset:=0;
  727. { update sym info }
  728. sym.increfs;
  729. end;
  730. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  731. begin
  732. inherited Create;
  733. typ:=ait_const_symbol;
  734. sym:=_sym;
  735. offset:=ofs;
  736. { update sym info }
  737. sym.increfs;
  738. end;
  739. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  740. begin
  741. inherited Create;
  742. typ:=ait_const_rva;
  743. sym:=_sym;
  744. offset:=0;
  745. { update sym info }
  746. sym.increfs;
  747. end;
  748. constructor tai_const_symbol.Createname(const name:string);
  749. begin
  750. inherited Create;
  751. typ:=ait_const_symbol;
  752. sym:=objectlibrary.newasmsymbol(name);
  753. offset:=0;
  754. { update sym info }
  755. sym.increfs;
  756. end;
  757. constructor tai_const_symbol.Createname_offset(const name:string;ofs:longint);
  758. begin
  759. inherited Create;
  760. typ:=ait_const_symbol;
  761. sym:=objectlibrary.newasmsymbol(name);
  762. offset:=ofs;
  763. { update sym info }
  764. sym.increfs;
  765. end;
  766. constructor tai_const_symbol.Createname_rva(const name:string);
  767. begin
  768. inherited Create;
  769. typ:=ait_const_rva;
  770. sym:=objectlibrary.newasmsymbol(name);
  771. offset:=0;
  772. { update sym info }
  773. sym.increfs;
  774. end;
  775. constructor tai_const_symbol.Createdataname(const name:string);
  776. begin
  777. inherited Create;
  778. typ:=ait_const_symbol;
  779. sym:=objectlibrary.newasmsymboltype(name,AB_EXTERNAL,AT_DATA);
  780. offset:=0;
  781. { update sym info }
  782. sym.increfs;
  783. end;
  784. constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  785. begin
  786. inherited ppuload(t,ppufile);
  787. sym:=ppufile.getasmsymbol;
  788. offset:=ppufile.getlongint;
  789. end;
  790. procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
  791. begin
  792. inherited ppuwrite(ppufile);
  793. ppufile.putasmsymbol(sym);
  794. ppufile.putlongint(offset);
  795. end;
  796. procedure tai_const_symbol.derefimpl;
  797. begin
  798. objectlibrary.DerefAsmsymbol(sym);
  799. end;
  800. function tai_const_symbol.getcopy:tlinkedlistitem;
  801. begin
  802. getcopy:=inherited getcopy;
  803. { we need to increase the reference number }
  804. sym.increfs;
  805. end;
  806. {****************************************************************************
  807. TAI_real_32bit
  808. ****************************************************************************}
  809. constructor tai_real_32bit.Create(_value : ts32real);
  810. begin
  811. inherited Create;
  812. typ:=ait_real_32bit;
  813. value:=_value;
  814. end;
  815. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  816. begin
  817. inherited ppuload(t,ppufile);
  818. value:=ppufile.getreal;
  819. end;
  820. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  821. begin
  822. inherited ppuwrite(ppufile);
  823. ppufile.putreal(value);
  824. end;
  825. {****************************************************************************
  826. TAI_real_64bit
  827. ****************************************************************************}
  828. constructor tai_real_64bit.Create(_value : ts64real);
  829. begin
  830. inherited Create;
  831. typ:=ait_real_64bit;
  832. value:=_value;
  833. end;
  834. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  835. begin
  836. inherited ppuload(t,ppufile);
  837. value:=ppufile.getreal;
  838. end;
  839. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  840. begin
  841. inherited ppuwrite(ppufile);
  842. ppufile.putreal(value);
  843. end;
  844. {****************************************************************************
  845. TAI_real_80bit
  846. ****************************************************************************}
  847. constructor tai_real_80bit.Create(_value : ts80real);
  848. begin
  849. inherited Create;
  850. typ:=ait_real_80bit;
  851. value:=_value;
  852. end;
  853. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  854. begin
  855. inherited ppuload(t,ppufile);
  856. value:=ppufile.getreal;
  857. end;
  858. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  859. begin
  860. inherited ppuwrite(ppufile);
  861. ppufile.putreal(value);
  862. end;
  863. {****************************************************************************
  864. Tai_comp_64bit
  865. ****************************************************************************}
  866. constructor tai_comp_64bit.Create(_value : ts64comp);
  867. begin
  868. inherited Create;
  869. typ:=ait_comp_64bit;
  870. value:=_value;
  871. end;
  872. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  873. begin
  874. inherited ppuload(t,ppufile);
  875. ppufile.putdata(value,sizeof(value));
  876. end;
  877. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  878. begin
  879. inherited ppuwrite(ppufile);
  880. ppufile.getdata(value,sizeof(value));
  881. end;
  882. {****************************************************************************
  883. TAI_STRING
  884. ****************************************************************************}
  885. constructor tai_string.Create(const _str : string);
  886. begin
  887. inherited Create;
  888. typ:=ait_string;
  889. len:=length(_str);
  890. getmem(str,len+1);
  891. strpcopy(str,_str);
  892. end;
  893. constructor tai_string.Create_pchar(_str : pchar);
  894. begin
  895. inherited Create;
  896. typ:=ait_string;
  897. str:=_str;
  898. len:=strlen(_str);
  899. end;
  900. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  901. begin
  902. inherited Create;
  903. typ:=ait_string;
  904. str:=_str;
  905. len:=length;
  906. end;
  907. destructor tai_string.destroy;
  908. begin
  909. { you can have #0 inside the strings so }
  910. if str<>nil then
  911. freemem(str,len+1);
  912. inherited Destroy;
  913. end;
  914. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  915. begin
  916. inherited ppuload(t,ppufile);
  917. len:=ppufile.getlongint;
  918. getmem(str,len+1);
  919. ppufile.getdata(str^,len);
  920. str[len]:=#0;
  921. end;
  922. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  923. begin
  924. inherited ppuwrite(ppufile);
  925. ppufile.putlongint(len);
  926. ppufile.putdata(str^,len);
  927. end;
  928. function tai_string.getcopy : tlinkedlistitem;
  929. var
  930. p : tlinkedlistitem;
  931. begin
  932. p:=inherited getcopy;
  933. getmem(tai_string(p).str,len+1);
  934. move(str^,tai_string(p).str^,len+1);
  935. getcopy:=p;
  936. end;
  937. {****************************************************************************
  938. TAI_LABEL
  939. ****************************************************************************}
  940. constructor tai_label.create(_l : tasmlabel);
  941. begin
  942. inherited Create;
  943. typ:=ait_label;
  944. l:=_l;
  945. { checkredefinesym(l);}
  946. l.is_set:=true;
  947. is_global:=(l.defbind=AB_GLOBAL);
  948. end;
  949. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  950. begin
  951. inherited ppuload(t,ppufile);
  952. l:=tasmlabel(ppufile.getasmsymbol);
  953. is_global:=boolean(ppufile.getbyte);
  954. end;
  955. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  956. begin
  957. inherited ppuwrite(ppufile);
  958. ppufile.putasmsymbol(l);
  959. ppufile.putbyte(byte(is_global));
  960. end;
  961. procedure tai_label.derefimpl;
  962. begin
  963. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  964. l.is_set:=true;
  965. end;
  966. {****************************************************************************
  967. TAI_DIRECT
  968. ****************************************************************************}
  969. constructor tai_direct.Create(_str : pchar);
  970. begin
  971. inherited Create;
  972. typ:=ait_direct;
  973. str:=_str;
  974. end;
  975. destructor tai_direct.destroy;
  976. begin
  977. strdispose(str);
  978. inherited Destroy;
  979. end;
  980. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  981. var
  982. len : longint;
  983. begin
  984. inherited ppuload(t,ppufile);
  985. len:=ppufile.getlongint;
  986. getmem(str,len+1);
  987. ppufile.getdata(str^,len);
  988. str[len]:=#0;
  989. end;
  990. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  991. var
  992. len : longint;
  993. begin
  994. inherited ppuwrite(ppufile);
  995. len:=strlen(str);
  996. ppufile.putlongint(len);
  997. ppufile.putdata(str^,len);
  998. end;
  999. function tai_direct.getcopy : tlinkedlistitem;
  1000. var
  1001. p : tlinkedlistitem;
  1002. begin
  1003. p:=inherited getcopy;
  1004. getmem(tai_direct(p).str,strlen(str)+1);
  1005. move(str^,tai_direct(p).str^,strlen(str)+1);
  1006. getcopy:=p;
  1007. end;
  1008. {****************************************************************************
  1009. tai_comment comment to be inserted in the assembler file
  1010. ****************************************************************************}
  1011. constructor tai_comment.Create(_str : pchar);
  1012. begin
  1013. inherited Create;
  1014. typ:=ait_comment;
  1015. str:=_str;
  1016. end;
  1017. destructor tai_comment.destroy;
  1018. begin
  1019. strdispose(str);
  1020. inherited Destroy;
  1021. end;
  1022. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1023. var
  1024. len : longint;
  1025. begin
  1026. inherited ppuload(t,ppufile);
  1027. len:=ppufile.getlongint;
  1028. getmem(str,len+1);
  1029. ppufile.getdata(str^,len);
  1030. str[len]:=#0;
  1031. end;
  1032. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1033. var
  1034. len : longint;
  1035. begin
  1036. inherited ppuwrite(ppufile);
  1037. len:=strlen(str);
  1038. ppufile.putlongint(len);
  1039. ppufile.putdata(str^,len);
  1040. end;
  1041. function tai_comment.getcopy : tlinkedlistitem;
  1042. var
  1043. p : tlinkedlistitem;
  1044. begin
  1045. p:=inherited getcopy;
  1046. getmem(tai_comment(p).str,strlen(str)+1);
  1047. move(str^,tai_comment(p).str^,strlen(str)+1);
  1048. getcopy:=p;
  1049. end;
  1050. {****************************************************************************
  1051. TAI_CUT
  1052. ****************************************************************************}
  1053. constructor tai_cut.Create;
  1054. begin
  1055. inherited Create;
  1056. typ:=ait_cut;
  1057. place:=cut_normal;
  1058. end;
  1059. constructor tai_cut.Create_begin;
  1060. begin
  1061. inherited Create;
  1062. typ:=ait_cut;
  1063. place:=cut_begin;
  1064. end;
  1065. constructor tai_cut.Create_end;
  1066. begin
  1067. inherited Create;
  1068. typ:=ait_cut;
  1069. place:=cut_end;
  1070. end;
  1071. constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
  1072. begin
  1073. inherited ppuload(t,ppufile);
  1074. place:=TCutPlace(ppufile.getbyte);
  1075. end;
  1076. procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
  1077. begin
  1078. inherited ppuwrite(ppufile);
  1079. ppufile.putbyte(byte(place));
  1080. end;
  1081. {****************************************************************************
  1082. Tai_Marker
  1083. ****************************************************************************}
  1084. constructor Tai_Marker.Create(_Kind: TMarker);
  1085. begin
  1086. Inherited Create;
  1087. typ := ait_marker;
  1088. Kind := _Kind;
  1089. end;
  1090. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1091. begin
  1092. inherited ppuload(t,ppufile);
  1093. kind:=TMarker(ppufile.getbyte);
  1094. end;
  1095. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1096. begin
  1097. inherited ppuwrite(ppufile);
  1098. ppufile.putbyte(byte(kind));
  1099. end;
  1100. {*****************************************************************************
  1101. tai_tempalloc
  1102. *****************************************************************************}
  1103. constructor tai_tempalloc.alloc(pos,size:longint);
  1104. begin
  1105. inherited Create;
  1106. typ:=ait_tempalloc;
  1107. allocation:=true;
  1108. temppos:=pos;
  1109. tempsize:=size;
  1110. {$ifdef EXTDEBUG}
  1111. problem:=nil;
  1112. {$endif EXTDEBUG}
  1113. end;
  1114. destructor tai_tempalloc.destroy;
  1115. begin
  1116. {$ifdef EXTDEBUG}
  1117. stringdispose(problem);
  1118. {$endif EXTDEBUG}
  1119. inherited destroy;
  1120. end;
  1121. constructor tai_tempalloc.dealloc(pos,size:longint);
  1122. begin
  1123. inherited Create;
  1124. typ:=ait_tempalloc;
  1125. allocation:=false;
  1126. temppos:=pos;
  1127. tempsize:=size;
  1128. {$ifdef EXTDEBUG}
  1129. problem:=nil;
  1130. {$endif EXTDEBUG}
  1131. end;
  1132. {$ifdef EXTDEBUG}
  1133. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1134. begin
  1135. inherited Create;
  1136. typ:=ait_tempalloc;
  1137. allocation:=false;
  1138. temppos:=pos;
  1139. tempsize:=size;
  1140. problem:=stringdup(st);
  1141. end;
  1142. {$endif EXTDEBUG}
  1143. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1144. begin
  1145. inherited ppuload(t,ppufile);
  1146. temppos:=ppufile.getlongint;
  1147. tempsize:=ppufile.getlongint;
  1148. allocation:=boolean(ppufile.getbyte);
  1149. {$ifdef EXTDEBUG}
  1150. problem:=nil;
  1151. {$endif EXTDEBUG}
  1152. end;
  1153. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1154. begin
  1155. inherited ppuwrite(ppufile);
  1156. ppufile.putlongint(temppos);
  1157. ppufile.putlongint(tempsize);
  1158. ppufile.putbyte(byte(allocation));
  1159. end;
  1160. {*****************************************************************************
  1161. tai_regalloc
  1162. *****************************************************************************}
  1163. constructor tai_regalloc.alloc(r : tregister);
  1164. begin
  1165. inherited create;
  1166. typ:=ait_regalloc;
  1167. allocation:=true;
  1168. reg:=r;
  1169. end;
  1170. constructor tai_regalloc.dealloc(r : tregister);
  1171. begin
  1172. inherited create;
  1173. typ:=ait_regalloc;
  1174. allocation:=false;
  1175. reg:=r;
  1176. end;
  1177. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1178. begin
  1179. inherited ppuload(t,ppufile);
  1180. ppufile.getdata(reg,sizeof(Tregister));
  1181. allocation:=boolean(ppufile.getbyte);
  1182. end;
  1183. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1184. begin
  1185. inherited ppuwrite(ppufile);
  1186. ppufile.putdata(reg,sizeof(Tregister));
  1187. ppufile.putbyte(byte(allocation));
  1188. end;
  1189. {*****************************************************************************
  1190. TaiInstruction
  1191. *****************************************************************************}
  1192. constructor taicpu_abstract.Create(op : tasmop);
  1193. begin
  1194. inherited create;
  1195. typ:=ait_instruction;
  1196. is_jmp:=false;
  1197. opcode:=op;
  1198. ops:=0;
  1199. fillchar(condition,sizeof(condition),0);
  1200. fillchar(oper,sizeof(oper),0);
  1201. end;
  1202. destructor taicpu_abstract.Destroy;
  1203. var
  1204. i : longint;
  1205. begin
  1206. for i:=0 to ops-1 do
  1207. case oper[i].typ of
  1208. top_ref:
  1209. dispose(oper[i].ref);
  1210. end;
  1211. inherited destroy;
  1212. end;
  1213. { ---------------------------------------------------------------------
  1214. Loading of operands.
  1215. ---------------------------------------------------------------------}
  1216. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  1217. begin
  1218. if opidx>=ops then
  1219. ops:=opidx+1;
  1220. with oper[opidx] do
  1221. begin
  1222. if typ=top_ref then
  1223. dispose(ref);
  1224. val:=l;
  1225. typ:=top_const;
  1226. end;
  1227. end;
  1228. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1229. begin
  1230. if not assigned(s) then
  1231. internalerror(200204251);
  1232. if opidx>=ops then
  1233. ops:=opidx+1;
  1234. with oper[opidx] do
  1235. begin
  1236. if typ=top_ref then
  1237. dispose(ref);
  1238. sym:=s;
  1239. symofs:=sofs;
  1240. typ:=top_symbol;
  1241. end;
  1242. s.increfs;
  1243. end;
  1244. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  1245. begin
  1246. if opidx>=ops then
  1247. ops:=opidx+1;
  1248. with oper[opidx] do
  1249. begin
  1250. if typ<>top_ref then
  1251. new(ref);
  1252. ref^:=r;
  1253. {$ifdef i386}
  1254. { We allow this exception for i386, since overloading this would be
  1255. too much of a a speed penalty}
  1256. if ref^.segment.enum=R_INTREGISTER then
  1257. begin
  1258. if (ref^.segment.number <> NR_NO) and (ref^.segment.number <> NR_DS) then
  1259. segprefix:=ref^.segment;
  1260. end
  1261. else
  1262. if not(ref^.segment.enum in [R_DS,R_NO]) then
  1263. segprefix:=ref^.segment;
  1264. {$endif}
  1265. typ:=top_ref;
  1266. { mark symbol as used }
  1267. if assigned(ref^.symbol) then
  1268. ref^.symbol.increfs;
  1269. end;
  1270. end;
  1271. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  1272. begin
  1273. if opidx>=ops then
  1274. ops:=opidx+1;
  1275. with oper[opidx] do
  1276. begin
  1277. if typ=top_ref then
  1278. dispose(ref);
  1279. reg:=r;
  1280. typ:=top_reg;
  1281. end;
  1282. end;
  1283. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  1284. begin
  1285. if opidx>=ops then
  1286. ops:=opidx+1;
  1287. if oper[opidx].typ=top_ref then
  1288. dispose(oper[opidx].ref);
  1289. oper[opidx]:=o;
  1290. { copy also the reference }
  1291. if oper[opidx].typ=top_ref then
  1292. begin
  1293. new(oper[opidx].ref);
  1294. oper[opidx].ref^:=o.ref^;
  1295. end;
  1296. end;
  1297. { ---------------------------------------------------------------------
  1298. Miscellaneous methods.
  1299. ---------------------------------------------------------------------}
  1300. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  1301. begin
  1302. condition:=c;
  1303. end;
  1304. Function taicpu_abstract.getcopy:TLinkedListItem;
  1305. var
  1306. i : longint;
  1307. p : TLinkedListItem;
  1308. begin
  1309. p:=inherited getcopy;
  1310. { make a copy of the references }
  1311. for i:=1 to ops do
  1312. if (taicpu_abstract(p).oper[i-1].typ=top_ref) then
  1313. begin
  1314. new(taicpu_abstract(p).oper[i-1].ref);
  1315. taicpu_abstract(p).oper[i-1].ref^:=oper[i-1].ref^;
  1316. end;
  1317. getcopy:=p;
  1318. end;
  1319. constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1320. var
  1321. i : integer;
  1322. begin
  1323. inherited ppuload(t,ppufile);
  1324. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1325. ppufile.getdata(condition,sizeof(tasmcond));
  1326. ops:=ppufile.getbyte;
  1327. for i:=1 to ops do
  1328. ppuloadoper(ppufile,oper[i-1]);
  1329. opcode:=tasmop(ppufile.getword);
  1330. {$ifdef i386}
  1331. ppufile.getdata(segprefix,sizeof(Tregister));
  1332. {$endif i386}
  1333. is_jmp:=boolean(ppufile.getbyte);
  1334. end;
  1335. procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1336. var
  1337. i : integer;
  1338. begin
  1339. inherited ppuwrite(ppufile);
  1340. ppufile.putdata(condition,sizeof(tasmcond));
  1341. ppufile.putbyte(ops);
  1342. for i:=1 to ops do
  1343. ppuwriteoper(ppufile,oper[i-1]);
  1344. ppufile.putword(word(opcode));
  1345. {$ifdef i386}
  1346. ppufile.putdata(segprefix,sizeof(Tregister));
  1347. {$endif i386}
  1348. ppufile.putbyte(byte(is_jmp));
  1349. end;
  1350. procedure taicpu_abstract.derefimpl;
  1351. var
  1352. i : integer;
  1353. begin
  1354. for i:=1 to ops do
  1355. ppuderefoper(oper[i-1]);
  1356. end;
  1357. {****************************************************************************
  1358. tai_align_abstract
  1359. ****************************************************************************}
  1360. constructor tai_align_abstract.Create(b: byte);
  1361. begin
  1362. inherited Create;
  1363. typ:=ait_align;
  1364. if b in [1,2,4,8,16,32] then
  1365. aligntype := b
  1366. else
  1367. aligntype := 1;
  1368. fillsize:=0;
  1369. fillop:=0;
  1370. use_op:=false;
  1371. end;
  1372. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1373. begin
  1374. inherited Create;
  1375. typ:=ait_align;
  1376. if b in [1,2,4,8,16,32] then
  1377. aligntype := b
  1378. else
  1379. aligntype := 1;
  1380. fillsize:=0;
  1381. fillop:=_op;
  1382. use_op:=true;
  1383. end;
  1384. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1385. begin
  1386. fillchar(buf,high(buf),fillop);
  1387. calculatefillbuf:=pchar(@buf);
  1388. end;
  1389. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1390. begin
  1391. inherited ppuload(t,ppufile);
  1392. aligntype:=ppufile.getbyte;
  1393. fillsize:=0;
  1394. fillop:=ppufile.getbyte;
  1395. use_op:=boolean(ppufile.getbyte);
  1396. end;
  1397. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1398. begin
  1399. inherited ppuwrite(ppufile);
  1400. ppufile.putbyte(aligntype);
  1401. ppufile.putbyte(fillop);
  1402. ppufile.putbyte(byte(use_op));
  1403. end;
  1404. {*****************************************************************************
  1405. TAAsmOutput
  1406. *****************************************************************************}
  1407. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1408. var
  1409. hp : tlinkedlistitem;
  1410. begin
  1411. getlasttaifilepos := nil;
  1412. if assigned(last) then
  1413. begin
  1414. { find the last file information record }
  1415. if not (tai(last).typ in SkipLineInfo) then
  1416. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1417. else
  1418. { go through list backwards to find the first entry
  1419. with line information
  1420. }
  1421. begin
  1422. hp:=tai(last);
  1423. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1424. hp:=hp.Previous;
  1425. { found entry }
  1426. if assigned(hp) then
  1427. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1428. end;
  1429. end;
  1430. end;
  1431. procedure Taasmoutput.convert_registers;
  1432. var p:Tai;
  1433. i:shortint;
  1434. r:Preference;
  1435. begin
  1436. p:=Tai(first);
  1437. while assigned(p) do
  1438. begin
  1439. case p.typ of
  1440. ait_regalloc:
  1441. convert_register_to_enum(Tai_regalloc(p).reg);
  1442. ait_instruction:
  1443. begin
  1444. for i:=0 to Taicpu_abstract(p).ops-1 do
  1445. if Taicpu_abstract(p).oper[i].typ=Top_reg then
  1446. begin
  1447. if Taicpu_abstract(p).oper[i].reg.enum=R_NO then
  1448. internalerror(200302052);
  1449. convert_register_to_enum(Taicpu_abstract(p).oper[i].reg)
  1450. end
  1451. else if Taicpu_abstract(p).oper[i].typ=Top_ref then
  1452. begin
  1453. r:=Taicpu_abstract(p).oper[i].ref;
  1454. {$ifdef i386}
  1455. convert_register_to_enum(r^.segment);
  1456. {$endif i386}
  1457. convert_register_to_enum(r^.base);
  1458. convert_register_to_enum(r^.index);
  1459. end;
  1460. {$ifdef i386}
  1461. convert_register_to_enum(Taicpu_abstract(p).segprefix);
  1462. {$endif}
  1463. end;
  1464. end;
  1465. p:=Tai(p.next);
  1466. end;
  1467. end;
  1468. procedure Taasmoutput.translate_registers(const table:Ttranstable);
  1469. var p,q:Tai;
  1470. i:shortint;
  1471. r:Preference;
  1472. begin
  1473. p:=Tai(first);
  1474. while assigned(p) do
  1475. begin
  1476. case p.typ of
  1477. ait_regalloc:
  1478. Tai_regalloc(p).reg.number:=(Tai_regalloc(p).reg.number and $ff) or
  1479. (table[Tai_regalloc(p).reg.number shr 8] shl 8);
  1480. ait_instruction:
  1481. begin
  1482. for i:=0 to Taicpu_abstract(p).ops-1 do
  1483. if Taicpu_abstract(p).oper[i].typ=Top_reg then
  1484. Taicpu_abstract(p).oper[i].reg.number:=(Taicpu_abstract(p).oper[i].reg.number and $ff) or
  1485. (table[Taicpu_abstract(p).oper[i].reg.number shr 8] shl 8)
  1486. else if Taicpu_abstract(p).oper[i].typ=Top_ref then
  1487. begin
  1488. r:=Taicpu_abstract(p).oper[i].ref;
  1489. if r^.base.number<>NR_NO then
  1490. r^.base.number:=(r^.base.number and $ff) or
  1491. (table[r^.base.number shr 8] shl 8);
  1492. if r^.index.number<>NR_NO then
  1493. r^.index.number:=(r^.index.number and $ff) or
  1494. (table[r^.index.number shr 8] shl 8);
  1495. end;
  1496. if Taicpu_abstract(p).is_nop then
  1497. begin
  1498. q:=p;
  1499. p:=Tai(p.next);
  1500. remove(q);
  1501. continue;
  1502. end;
  1503. end;
  1504. end;
  1505. p:=Tai(p.next);
  1506. end;
  1507. end;
  1508. end.
  1509. {
  1510. $Log$
  1511. Revision 1.27 2003-04-25 20:59:33 peter
  1512. * removed funcretn,funcretsym, function result is now in varsym
  1513. and aliases for result and function name are added using absolutesym
  1514. * vs_hidden parameter for funcret passed in parameter
  1515. * vs_hidden fixes
  1516. * writenode changed to printnode and released from extdebug
  1517. * -vp option added to generate a tree.log with the nodetree
  1518. * nicer printnode for statements, callnode
  1519. Revision 1.26 2002/04/25 16:12:09 florian
  1520. * fixed more problems with cpubase and x86-64
  1521. Revision 1.25 2003/04/25 08:25:26 daniel
  1522. * Ifdefs around a lot of calls to cleartempgen
  1523. * Fixed registers that are allocated but not freed in several nodes
  1524. * Tweak to register allocator to cause less spills
  1525. * 8-bit registers now interfere with esi,edi and ebp
  1526. Compiler can now compile rtl successfully when using new register
  1527. allocator
  1528. Revision 1.24 2003/04/24 13:03:01 florian
  1529. * comp is now written with its bit pattern to the ppu instead as an extended
  1530. Revision 1.23 2003/04/22 14:33:38 peter
  1531. * removed some notes/hints
  1532. Revision 1.22 2003/04/22 10:09:34 daniel
  1533. + Implemented the actual register allocator
  1534. + Scratch registers unavailable when new register allocator used
  1535. + maybe_save/maybe_restore unavailable when new register allocator used
  1536. Revision 1.21 2003/02/19 22:00:14 daniel
  1537. * Code generator converted to new register notation
  1538. - Horribily outdated todo.txt removed
  1539. Revision 1.20 2003/01/30 21:46:20 peter
  1540. * tai_const_symbol.createdataname added
  1541. Revision 1.19 2003/01/21 08:48:08 daniel
  1542. * Another 200301081 fixed
  1543. Revision 1.18 2003/01/09 20:40:59 daniel
  1544. * Converted some code in cgx86.pas to new register numbering
  1545. Revision 1.17 2003/01/09 15:49:56 daniel
  1546. * Added register conversion
  1547. Revision 1.16 2003/01/08 18:43:56 daniel
  1548. * Tregister changed into a record
  1549. Revision 1.15 2003/01/05 13:36:53 florian
  1550. * x86-64 compiles
  1551. + very basic support for float128 type (x86-64 only)
  1552. Revision 1.14 2002/12/06 17:50:21 peter
  1553. * symbol count fix merged
  1554. Revision 1.13 2002/11/17 16:31:55 carl
  1555. * memory optimization (3-4%) : cleanup of tai fields,
  1556. cleanup of tdef and tsym fields.
  1557. * make it work for m68k
  1558. Revision 1.12 2002/11/15 16:29:30 peter
  1559. * made tasmsymbol.refs private (merged)
  1560. Revision 1.11 2002/11/15 01:58:45 peter
  1561. * merged changes from 1.0.7 up to 04-11
  1562. - -V option for generating bug report tracing
  1563. - more tracing for option parsing
  1564. - errors for cdecl and high()
  1565. - win32 import stabs
  1566. - win32 records<=8 are returned in eax:edx (turned off by default)
  1567. - heaptrc update
  1568. - more info for temp management in .s file with EXTDEBUG
  1569. Revision 1.10 2002/11/09 15:38:03 carl
  1570. + NOOPT removed the optinfo field
  1571. Revision 1.9 2002/10/05 12:43:23 carl
  1572. * fixes for Delphi 6 compilation
  1573. (warning : Some features do not work under Delphi)
  1574. Revision 1.8 2002/08/19 19:36:42 peter
  1575. * More fixes for cross unit inlining, all tnodes are now implemented
  1576. * Moved pocall_internconst to po_internconst because it is not a
  1577. calling type at all and it conflicted when inlining of these small
  1578. functions was requested
  1579. Revision 1.7 2002/08/18 20:06:23 peter
  1580. * inlining is now also allowed in interface
  1581. * renamed write/load to ppuwrite/ppuload
  1582. * tnode storing in ppu
  1583. * nld,ncon,nbas are already updated for storing in ppu
  1584. Revision 1.6 2002/08/16 05:21:09 florian
  1585. * powerpc compilation fix
  1586. Revision 1.5 2002/08/15 19:10:35 peter
  1587. * first things tai,tnode storing in ppu
  1588. Revision 1.4 2002/08/11 14:32:25 peter
  1589. * renamed current_library to objectlibrary
  1590. Revision 1.3 2002/08/11 13:24:10 peter
  1591. * saving of asmsymbols in ppu supported
  1592. * asmsymbollist global is removed and moved into a new class
  1593. tasmlibrarydata that will hold the info of a .a file which
  1594. corresponds with a single module. Added librarydata to tmodule
  1595. to keep the library info stored for the module. In the future the
  1596. objectfiles will also be stored to the tasmlibrarydata class
  1597. * all getlabel/newasmsymbol and friends are moved to the new class
  1598. Revision 1.2 2002/08/05 18:27:48 carl
  1599. + more more more documentation
  1600. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1601. Revision 1.1 2002/07/01 18:46:20 peter
  1602. * internal linker
  1603. * reorganized aasm layer
  1604. Revision 1.27 2002/05/18 13:34:04 peter
  1605. * readded missing revisions
  1606. Revision 1.25 2002/05/14 19:34:38 peter
  1607. * removed old logs and updated copyright year
  1608. Revision 1.24 2002/05/14 17:28:08 peter
  1609. * synchronized cpubase between powerpc and i386
  1610. * moved more tables from cpubase to cpuasm
  1611. * tai_align_abstract moved to tainst, cpuasm must define
  1612. the tai_align class now, which may be empty
  1613. Revision 1.23 2002/04/15 18:54:34 carl
  1614. - removed tcpuflags
  1615. Revision 1.22 2002/04/07 13:18:19 carl
  1616. + more documentation
  1617. Revision 1.21 2002/04/07 10:17:40 carl
  1618. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  1619. + changing some comments so its commented automatically
  1620. Revision 1.20 2002/03/24 19:04:31 carl
  1621. + patch for SPARC from Mazen NEIFER
  1622. }