aasmtai.pas 51 KB

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