aasmtai.pas 48 KB

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