123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373 |
- {
- $Id$
- Copyright (c) 1998-2002 by Florian Klaempfl
- This unit implements an abstract asmoutput class for all processor types
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- { @abstract(This unit implements an abstract asm output class for all processor types)
- This unit implements an abstract assembler output class for all processors, these
- are then overriden for each assembler writer to actually write the data in these
- classes to an assembler file.
- }
- unit aasmtai;
- {$i fpcdefs.inc}
- interface
- uses
- cutils,cclasses,
- globtype,globals,systems,
- cpuinfo,cpubase,
- cgbase,cgutils,
- symtype,
- aasmbase;
- type
- taitype = (
- ait_none,
- ait_align,
- ait_section,
- ait_comment,
- ait_direct,
- ait_string,
- ait_instruction,
- ait_datablock,
- ait_symbol,
- ait_symbol_end, { needed to calc the size of a symbol }
- ait_label,
- ait_const_64bit,
- ait_const_32bit,
- ait_const_16bit,
- ait_const_8bit,
- ait_const_symbol,
- { the following is only used by the win32 version of the compiler }
- { and only the GNU AS Win32 is able to write it }
- ait_const_rva,
- ait_real_32bit,
- ait_real_64bit,
- ait_real_80bit,
- ait_comp_64bit,
- ait_real_128bit,
- {$ifdef GDB}
- ait_stabn,
- ait_stabs,
- ait_force_line,
- ait_stab_function_name,
- {$endif GDB}
- {$ifdef alpha}
- { the follow is for the DEC Alpha }
- ait_frame,
- ait_ent,
- {$endif alpha}
- {$ifdef ia64}
- ait_bundle,
- ait_stop,
- {$endif ia64}
- {$ifdef m68k}
- ait_labeled_instruction,
- {$endif m68k}
- { used to split into tiny assembler files }
- ait_cut,
- ait_regalloc,
- ait_tempalloc,
- { used to mark assembler blocks and inlined functions }
- ait_marker,
- { special symbols for darwin pic code }
- ait_indirect_symbol,
- ait_non_lazy_symbol_pointer
- );
- const
- taitypestr : array[taitype] of string[14] = (
- '<none>',
- 'align',
- 'section',
- 'comment',
- 'direct',
- 'string',
- 'instruction',
- 'datablock',
- 'symbol',
- 'symbol_end',
- 'label',
- 'const_64bit',
- 'const_32bit',
- 'const_16bit',
- 'const_8bit',
- 'const_symbol',
- 'const_rva',
- 'real_32bit',
- 'real_64bit',
- 'real_80bit',
- 'comp_64bit',
- 'real_128bit',
- {$ifdef GDB}
- 'stabn',
- 'stabs',
- 'force_line',
- 'stab_funcname',
- {$endif GDB}
- {$ifdef alpha}
- { the follow is for the DEC Alpha }
- 'frame',
- 'ent',
- {$endif alpha}
- {$ifdef ia64}
- 'bundle',
- 'stop',
- {$endif ia64}
- {$ifdef m68k}
- 'labeled_instr',
- {$endif m68k}
- 'cut',
- 'regalloc',
- 'tempalloc',
- 'marker',
- 'indirect_symbol',
- 'non_lazy_symbol_pointer'
- );
- type
- { Types of operand }
- toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local,
- { ARM only }
- top_regset,
- top_shifterop,
- { m68k only }
- top_reglist);
- { kinds of operations that an instruction can perform on an operand }
- topertype = (operand_read,operand_write,operand_readwrite);
- tlocaloper = record
- localsym : pointer;
- localsymderef : tderef;
- localsymofs : longint;
- localindexreg : tregister;
- localscale : byte;
- localgetoffset : boolean
- end;
- plocaloper = ^tlocaloper;
- { please keep the size of this record <=12 bytes and keep it properly aligned }
- toper = record
- ot : longint;
- case typ : toptype of
- top_none : ();
- top_reg : (reg:tregister);
- top_ref : (ref:preference);
- top_const : (val:aword);
- top_bool : (b:boolean);
- { local varsym that will be inserted in pass_2 }
- top_local : (localoper:plocaloper);
- {$ifdef arm}
- top_regset : (regset:^tcpuregisterset);
- top_shifterop : (shifterop : pshifterop);
- {$endif arm}
- {$ifdef m68k}
- top_regset : (regset:^tcpuregisterset);
- {$endif m68k}
- end;
- poper=^toper;
- { ait_* types which don't result in executable code or which don't influence }
- { the way the program runs/behaves, but which may be encountered by the }
- { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
- { a new ait type! }
- const
- SkipInstr = [ait_comment, ait_symbol,ait_section
- {$ifdef GDB}
- ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
- {$endif GDB}
- ,ait_regalloc, ait_tempalloc, ait_symbol_end];
- { ait_* types which do not have line information (and hence which are of type
- tai, otherwise, they are of type tailineinfo }
- SkipLineInfo =[ait_label,
- ait_regalloc,ait_tempalloc,
- {$ifdef GDB}
- ait_stabn,ait_stabs,ait_stab_function_name,
- {$endif GDB}
- ait_cut,ait_marker,ait_align,ait_section,ait_comment,
- ait_const_8bit,ait_const_16bit,ait_const_32bit,
- ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
- ait_non_lazy_symbol_pointer
- ];
- type
- { cut type, required for alphanumeric ordering of the assembler filenames }
- TCutPlace=(cut_normal,cut_begin,cut_end);
- TMarker = (NoPropInfoStart,NoPropInfoEnd,
- AsmBlockStart,AsmBlockEnd,
- InlineStart,InlineEnd,marker_blockstart,
- marker_position);
- { Buffer type used for alignment }
- tfillbuffer = array[0..63] of char;
- Tspill_temp_list=array[tsuperregister] of Treference;
- { abstract assembler item }
- tai = class(TLinkedListItem)
- {$ifndef NOOPT}
- { pointer to record with optimizer info about this tai object }
- optinfo : pointer;
- {$endif NOOPT}
- typ : taitype;
- constructor Create;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
- procedure ppuwrite(ppufile:tcompilerppufile);virtual;
- procedure buildderefimpl;virtual;
- procedure derefimpl;virtual;
- end;
- { abstract assembler item with line information }
- tailineinfo = class(tai)
- fileinfo : tfileposinfo;
- constructor Create;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- tai_simple = class(tai)
- constructor create(_typ : taitype);
- end;
- taiclass = class of tai;
- taiclassarray = array[taitype] of taiclass;
- { Generates an assembler string }
- tai_string = class(tailineinfo)
- str : pchar;
- { extra len so the string can contain an \0 }
- len : longint;
- constructor Create(const _str : string);
- constructor Create_pchar(_str : pchar);
- constructor Create_length_pchar(_str : pchar;length : longint);
- destructor Destroy;override;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- function getcopy:tlinkedlistitem;override;
- end;
- { Generates a common label }
- tai_symbol = class(tailineinfo)
- is_global : boolean;
- sym : tasmsymbol;
- size : longint;
- constructor Create(_sym:tasmsymbol;siz:longint);
- constructor Create_Global(_sym:tasmsymbol;siz:longint);
- constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
- constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure derefimpl;override;
- end;
- tai_symbol_end = class(tailineinfo)
- sym : tasmsymbol;
- constructor Create(_sym:tasmsymbol);
- constructor Createname(const _name : string);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure derefimpl;override;
- end;
- { Generates an assembler label }
- tai_label = class(tai)
- is_global : boolean;
- l : tasmlabel;
- constructor Create(_l : tasmlabel);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure derefimpl;override;
- end;
- { Directly output data to final assembler file }
- tai_direct = class(tailineinfo)
- str : pchar;
- constructor Create(_str : pchar);
- destructor Destroy; override;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- function getcopy:tlinkedlistitem;override;
- end;
- { Generates an assembler comment }
- tai_comment = class(tai)
- str : pchar;
- constructor Create(_str : pchar);
- destructor Destroy; override;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- function getcopy:tlinkedlistitem;override;
- end;
- { Generates a section / segment directive }
- tai_section = class(tai)
- sec : TSection;
- constructor Create(s : TSection);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Generates an uninitializised data block }
- tai_datablock = class(tailineinfo)
- is_global : boolean;
- sym : tasmsymbol;
- size : longint;
- constructor Create(const _name : string;_size : longint);
- constructor Create_global(const _name : string;_size : longint);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure derefimpl;override;
- end;
- { Generates an integer const }
- tai_const = class(tai)
- value : qword;
- constructor Create_ptr(_value : TConstPtrUInt);
- constructor Create_64bit(_value : qword);
- constructor Create_32bit(_value : cardinal);
- constructor Create_16bit(_value : word);
- constructor Create_8bit(_value : byte);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- tai_const_symbol = class(tailineinfo)
- sym : tasmsymbol;
- offset : aint;
- constructor Create(_sym:tasmsymbol);
- constructor Create_offset(_sym:tasmsymbol;ofs:aint);
- constructor Create_rva(_sym:tasmsymbol);
- constructor Create_indirect(_sym:tasmsymbol);
- constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
- constructor Createname_rva(const name:string);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure derefimpl;override;
- function getcopy:tlinkedlistitem;override;
- end;
- { Generates a single float (32 bit real) }
- tai_real_32bit = class(tai)
- value : ts32real;
- constructor Create(_value : ts32real);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- tformatoptions = (fo_none,fo_hiloswapped);
- { Generates a double float (64 bit real) }
- tai_real_64bit = class(tai)
- value : ts64real;
- {$ifdef ARM}
- formatoptions : tformatoptions;
- constructor Create_hiloswapped(_value : ts64real);
- {$endif ARM}
- constructor Create(_value : ts64real);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Generates an extended float (80 bit real) }
- tai_real_80bit = class(tai)
- value : ts80real;
- constructor Create(_value : ts80real);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Generates an float128 (128 bit real) }
- tai_real_128bit = class(tai)
- value : ts128real;
- constructor Create(_value : ts128real);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Generates a comp int (integer over 64 bits)
- This is Intel 80x86 specific, and is not
- really supported on other processors.
- }
- tai_comp_64bit = class(tai)
- value : ts64comp;
- constructor Create(_value : ts64comp);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Insert a cut to split assembler into several smaller files }
- tai_cut = class(tai)
- place : tcutplace;
- constructor Create;
- constructor Create_begin;
- constructor Create_end;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- { Insert a marker for assembler and inline blocks }
- tai_marker = class(tai)
- Kind: TMarker;
- Constructor Create(_Kind: TMarker);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- tai_tempalloc = class(tai)
- allocation : boolean;
- {$ifdef EXTDEBUG}
- problem : pstring;
- {$endif EXTDEBUG}
- temppos,
- tempsize : longint;
- constructor alloc(pos,size:longint);
- constructor dealloc(pos,size:longint);
- {$ifdef EXTDEBUG}
- constructor allocinfo(pos,size:longint;const st:string);
- {$endif EXTDEBUG}
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- destructor destroy;override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- tai_regalloc = class(tai)
- allocation : boolean;
- reg : tregister;
- constructor alloc(r : tregister);
- constructor dealloc(r : tregister);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- end;
- Taasmoutput=class;
- tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
- Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
- Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
- { Class template for assembler instructions
- }
- taicpu_abstract = class(tailineinfo)
- protected
- procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
- procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
- procedure ppubuildderefimploper(var o:toper);virtual;abstract;
- procedure ppuderefoper(var o:toper);virtual;abstract;
- public
- { Condition flags for instruction }
- condition : TAsmCond;
- { Number of operands to instruction }
- ops : byte;
- { Number of allocate oper structures }
- opercnt : byte;
- { Operands of instruction }
- oper : array[0..max_operands-1] of poper;
- { Actual opcode of instruction }
- opcode : tasmop;
- {$ifdef x86}
- segprefix : tregister;
- {$endif x86}
- { true if instruction is a jmp }
- is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
- Constructor Create(op : tasmop);
- Destructor Destroy;override;
- function getcopy:TLinkedListItem;override;
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- procedure buildderefimpl;override;
- procedure derefimpl;override;
- procedure SetCondition(const c:TAsmCond);
- procedure allocate_oper(opers:longint);
- procedure loadconst(opidx:longint;l:aword);
- procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
- procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
- procedure loadref(opidx:longint;const r:treference);
- procedure loadreg(opidx:longint;r:tregister);
- procedure loadoper(opidx:longint;o:toper);
- procedure clearop(opidx:longint);
- function is_same_reg_move(regtype: Tregistertype):boolean;virtual;abstract;
- { register allocator }
- function spilling_create_load(const ref:treference;r:tregister): tai;virtual;abstract;
- function spilling_create_store(r:tregister; const ref:treference): tai;virtual;abstract;
- function spilling_get_operation_type(opnr: longint): topertype;virtual;abstract;
- end;
- { alignment for operator }
- tai_align_abstract = class(tai)
- aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
- fillsize : byte; { real size to fill }
- fillop : byte; { value to fill with - optional }
- use_op : boolean;
- constructor Create(b:byte);
- constructor Create_op(b: byte; _op: byte);
- constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
- procedure ppuwrite(ppufile:tcompilerppufile);override;
- function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
- end;
- taasmoutput = class(tlinkedlist)
- constructor create;
- function getlasttaifilepos : pfileposinfo;
- procedure InsertAfter(Item,Loc : TLinkedListItem);
- end;
- var
- { array with all class types for tais }
- aiclass : taiclassarray;
- { Current expression list }
- exprasmlist : taasmoutput;
- { labels for BREAK and CONTINUE }
- aktbreaklabel,aktcontinuelabel : tasmlabel;
- { label when the result is true or false }
- truelabel,falselabel : tasmlabel;
- { hook to notify uses of registers }
- add_reg_instruction_hook : tadd_reg_instruction_proc;
- { default lists }
- datasegment,codesegment,bsssegment,
- debuglist,withdebuglist,consts,
- importssection,exportssection,
- resourcesection,rttilist,
- { data used by pic code }
- picdata,
- resourcestringlist : taasmoutput;
- function ppuloadai(ppufile:tcompilerppufile):tai;
- procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
- implementation
- uses
- {$ifdef delphi}
- sysutils,
- {$else}
- strings,
- {$endif}
- verbose;
- const
- pputaimarker = 254;
- {****************************************************************************
- Helpers
- ****************************************************************************}
- function ppuloadai(ppufile:tcompilerppufile):tai;
- var
- b : byte;
- t : taitype;
- begin
- { marker }
- b:=ppufile.getbyte;
- if b<>pputaimarker then
- internalerror(200208181);
- { load nodetype }
- t:=taitype(ppufile.getbyte);
- if t<>ait_none then
- begin
- if t>high(taitype) then
- internalerror(200208182);
- if not assigned(aiclass[t]) then
- internalerror(200208183);
- {writeln('taiload: ',taitypestr[t]);}
- { generate tai of the correct class }
- ppuloadai:=aiclass[t].ppuload(t,ppufile);
- end
- else
- ppuloadai:=nil;
- end;
- procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
- begin
- { marker, read by ppuloadnode }
- ppufile.putbyte(pputaimarker);
- if assigned(n) then
- begin
- { type, read by ppuloadnode }
- ppufile.putbyte(byte(n.typ));
- {writeln('taiwrite: ',taitypestr[n.typ]);}
- n.ppuwrite(ppufile);
- end
- else
- ppufile.putbyte(byte(ait_none));
- end;
- {****************************************************************************
- TAI
- ****************************************************************************}
- constructor tai.Create;
- begin
- {$ifndef NOOPT}
- optinfo:=nil;
- {$endif NOOPT}
- end;
- constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- typ:=t;
- {$ifndef NOOPT}
- optinfo:=nil;
- {$endif}
- end;
- procedure tai.ppuwrite(ppufile:tcompilerppufile);
- begin
- end;
- procedure tai.buildderefimpl;
- begin
- end;
- procedure tai.derefimpl;
- begin
- end;
- {****************************************************************************
- TAILINEINFO
- ****************************************************************************}
- constructor tailineinfo.create;
- begin
- inherited create;
- fileinfo:=aktfilepos;
- end;
- constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- ppufile.getposinfo(fileinfo);
- end;
- procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putposinfo(fileinfo);
- end;
- {****************************************************************************
- TAI_SIMPLE
- ****************************************************************************}
- constructor tai_simple.create(_typ : taitype);
- begin
- inherited create;
- typ:=_typ;
- end;
- {****************************************************************************
- TAI_SECTION
- ****************************************************************************}
- constructor tai_section.Create(s : TSection);
- begin
- inherited Create;
- typ:=ait_section;
- sec:=s;
- end;
- constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- sec:=tsection(ppufile.getbyte);
- end;
- procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putbyte(byte(sec));
- end;
- {****************************************************************************
- TAI_DATABLOCK
- ****************************************************************************}
- constructor tai_datablock.Create(const _name : string;_size : longint);
- begin
- inherited Create;
- typ:=ait_datablock;
- sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
- { keep things aligned }
- if _size<=0 then
- _size:=4;
- size:=_size;
- is_global:=false;
- end;
- constructor tai_datablock.Create_global(const _name : string;_size : longint);
- begin
- inherited Create;
- typ:=ait_datablock;
- sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
- { keep things aligned }
- if _size<=0 then
- _size:=4;
- size:=_size;
- is_global:=true;
- end;
- constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited Create;
- sym:=ppufile.getasmsymbol;
- size:=ppufile.getlongint;
- is_global:=boolean(ppufile.getbyte);
- end;
- procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putasmsymbol(sym);
- ppufile.putlongint(size);
- ppufile.putbyte(byte(is_global));
- end;
- procedure tai_datablock.derefimpl;
- begin
- objectlibrary.DerefAsmsymbol(sym);
- end;
- {****************************************************************************
- TAI_SYMBOL
- ****************************************************************************}
- constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
- begin
- inherited Create;
- typ:=ait_symbol;
- sym:=_sym;
- size:=siz;
- sym.defbind:=AB_LOCAL;
- is_global:=false;
- end;
- constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
- begin
- inherited Create;
- typ:=ait_symbol;
- sym:=_sym;
- size:=siz;
- sym.defbind:=AB_GLOBAL;
- is_global:=true;
- end;
- constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
- begin
- inherited Create;
- typ:=ait_symbol;
- sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
- size:=siz;
- is_global:=false;
- end;
- constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
- begin
- inherited Create;
- typ:=ait_symbol;
- sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
- size:=siz;
- is_global:=true;
- end;
- constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- sym:=ppufile.getasmsymbol;
- size:=ppufile.getlongint;
- is_global:=boolean(ppufile.getbyte);
- end;
- procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putasmsymbol(sym);
- ppufile.putlongint(size);
- ppufile.putbyte(byte(is_global));
- end;
- procedure tai_symbol.derefimpl;
- begin
- objectlibrary.DerefAsmsymbol(sym);
- end;
- {****************************************************************************
- TAI_SYMBOL_END
- ****************************************************************************}
- constructor tai_symbol_end.Create(_sym:tasmsymbol);
- begin
- inherited Create;
- typ:=ait_symbol_end;
- sym:=_sym;
- end;
- constructor tai_symbol_end.Createname(const _name : string);
- begin
- inherited Create;
- typ:=ait_symbol_end;
- sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
- end;
- constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- sym:=ppufile.getasmsymbol;
- end;
- procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putasmsymbol(sym);
- end;
- procedure tai_symbol_end.derefimpl;
- begin
- objectlibrary.DerefAsmsymbol(sym);
- end;
- {****************************************************************************
- TAI_CONST
- ****************************************************************************}
- constructor tai_const.Create_ptr(_value : TConstPtrUInt);
- begin
- {$ifdef cpu64bit}
- self.create_64bit(_value);
- {$else cpu64bit}
- self.create_32bit(_value);
- {$endif cpu64bit}
- end;
- constructor tai_const.Create_64bit(_value : qword);
- begin
- inherited Create;
- typ:=ait_const_64bit;
- value:=_value;
- end;
- constructor tai_const.Create_32bit(_value : cardinal);
- begin
- inherited Create;
- typ:=ait_const_32bit;
- value:=_value;
- end;
- constructor tai_const.Create_16bit(_value : word);
- begin
- inherited Create;
- typ:=ait_const_16bit;
- value:=_value;
- end;
- constructor tai_const.Create_8bit(_value : byte);
- begin
- inherited Create;
- typ:=ait_const_8bit;
- value:=_value;
- end;
- constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- value:=ppufile.getlongint;
- end;
- procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putlongint(value);
- end;
- {****************************************************************************
- TAI_CONST_SYMBOL
- ****************************************************************************}
- constructor tai_const_symbol.Create(_sym:tasmsymbol);
- begin
- inherited Create;
- typ:=ait_const_symbol;
- sym:=_sym;
- offset:=0;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
- begin
- inherited Create;
- typ:=ait_const_symbol;
- sym:=_sym;
- offset:=ofs;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
- begin
- inherited Create;
- typ:=ait_const_rva;
- sym:=_sym;
- offset:=0;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.Create_indirect(_sym:tasmsymbol);
- begin
- inherited Create;
- typ:=ait_indirect_symbol;
- sym:=_sym;
- offset:=0;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.Createname(const name:string;_symtyp:Tasmsymtype;ofs:longint);
- begin
- inherited Create;
- typ:=ait_const_symbol;
- sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
- offset:=ofs;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.Createname_rva(const name:string);
- begin
- inherited Create;
- typ:=ait_const_rva;
- sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
- offset:=0;
- { update sym info }
- sym.increfs;
- end;
- constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- sym:=ppufile.getasmsymbol;
- offset:=ppufile.getlongint;
- end;
- procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putasmsymbol(sym);
- ppufile.putlongint(offset);
- end;
- procedure tai_const_symbol.derefimpl;
- begin
- objectlibrary.DerefAsmsymbol(sym);
- end;
- function tai_const_symbol.getcopy:tlinkedlistitem;
- begin
- getcopy:=inherited getcopy;
- { we need to increase the reference number }
- sym.increfs;
- end;
- {****************************************************************************
- TAI_real_32bit
- ****************************************************************************}
- constructor tai_real_32bit.Create(_value : ts32real);
- begin
- inherited Create;
- typ:=ait_real_32bit;
- value:=_value;
- end;
- constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- value:=ppufile.getreal;
- end;
- procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putreal(value);
- end;
- {****************************************************************************
- TAI_real_64bit
- ****************************************************************************}
- constructor tai_real_64bit.Create(_value : ts64real);
- begin
- inherited Create;
- typ:=ait_real_64bit;
- value:=_value;
- end;
- {$ifdef ARM}
- constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
- begin
- inherited Create;
- typ:=ait_real_64bit;
- value:=_value;
- formatoptions:=fo_hiloswapped;
- end;
- {$endif ARM}
- constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- value:=ppufile.getreal;
- {$ifdef ARM}
- formatoptions:=tformatoptions(ppufile.getbyte);
- {$endif ARM}
- end;
- procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putreal(value);
- {$ifdef ARM}
- ppufile.putbyte(byte(formatoptions));
- {$endif ARM}
- end;
- {****************************************************************************
- TAI_real_80bit
- ****************************************************************************}
- constructor tai_real_80bit.Create(_value : ts80real);
- begin
- inherited Create;
- typ:=ait_real_80bit;
- value:=_value;
- end;
- constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- value:=ppufile.getreal;
- end;
- procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putreal(value);
- end;
- {****************************************************************************
- TAI_real_80bit
- ****************************************************************************}
- constructor tai_real_128bit.Create(_value : ts128real);
- begin
- inherited Create;
- typ:=ait_real_128bit;
- value:=_value;
- end;
- constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- value:=ppufile.getreal;
- end;
- procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putreal(value);
- end;
- {****************************************************************************
- Tai_comp_64bit
- ****************************************************************************}
- constructor tai_comp_64bit.Create(_value : ts64comp);
- begin
- inherited Create;
- typ:=ait_comp_64bit;
- value:=_value;
- end;
- constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- ppufile.putdata(value,sizeof(value));
- end;
- procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.getdata(value,sizeof(value));
- end;
- {****************************************************************************
- TAI_STRING
- ****************************************************************************}
- constructor tai_string.Create(const _str : string);
- begin
- inherited Create;
- typ:=ait_string;
- len:=length(_str);
- getmem(str,len+1);
- strpcopy(str,_str);
- end;
- constructor tai_string.Create_pchar(_str : pchar);
- begin
- inherited Create;
- typ:=ait_string;
- str:=_str;
- len:=strlen(_str);
- end;
- constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
- begin
- inherited Create;
- typ:=ait_string;
- str:=_str;
- len:=length;
- end;
- destructor tai_string.destroy;
- begin
- { you can have #0 inside the strings so }
- if str<>nil then
- freemem(str,len+1);
- inherited Destroy;
- end;
- constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- len:=ppufile.getlongint;
- getmem(str,len+1);
- ppufile.getdata(str^,len);
- str[len]:=#0;
- end;
- procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putlongint(len);
- ppufile.putdata(str^,len);
- end;
- function tai_string.getcopy : tlinkedlistitem;
- var
- p : tlinkedlistitem;
- begin
- p:=inherited getcopy;
- getmem(tai_string(p).str,len+1);
- move(str^,tai_string(p).str^,len+1);
- getcopy:=p;
- end;
- {****************************************************************************
- TAI_LABEL
- ****************************************************************************}
- constructor tai_label.create(_l : tasmlabel);
- begin
- inherited Create;
- typ:=ait_label;
- l:=_l;
- l.is_set:=true;
- is_global:=(l.defbind=AB_GLOBAL);
- end;
- constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- l:=tasmlabel(ppufile.getasmsymbol);
- is_global:=boolean(ppufile.getbyte);
- end;
- procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putasmsymbol(l);
- ppufile.putbyte(byte(is_global));
- end;
- procedure tai_label.derefimpl;
- begin
- objectlibrary.DerefAsmsymbol(tasmsymbol(l));
- l.is_set:=true;
- end;
- {****************************************************************************
- TAI_DIRECT
- ****************************************************************************}
- constructor tai_direct.Create(_str : pchar);
- begin
- inherited Create;
- typ:=ait_direct;
- str:=_str;
- end;
- destructor tai_direct.destroy;
- begin
- strdispose(str);
- inherited Destroy;
- end;
- constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
- var
- len : longint;
- begin
- inherited ppuload(t,ppufile);
- len:=ppufile.getlongint;
- getmem(str,len+1);
- ppufile.getdata(str^,len);
- str[len]:=#0;
- end;
- procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
- var
- len : longint;
- begin
- inherited ppuwrite(ppufile);
- len:=strlen(str);
- ppufile.putlongint(len);
- ppufile.putdata(str^,len);
- end;
- function tai_direct.getcopy : tlinkedlistitem;
- var
- p : tlinkedlistitem;
- begin
- p:=inherited getcopy;
- getmem(tai_direct(p).str,strlen(str)+1);
- move(str^,tai_direct(p).str^,strlen(str)+1);
- getcopy:=p;
- end;
- {****************************************************************************
- tai_comment comment to be inserted in the assembler file
- ****************************************************************************}
- constructor tai_comment.Create(_str : pchar);
- begin
- inherited Create;
- typ:=ait_comment;
- str:=_str;
- end;
- destructor tai_comment.destroy;
- begin
- strdispose(str);
- inherited Destroy;
- end;
- constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
- var
- len : longint;
- begin
- inherited ppuload(t,ppufile);
- len:=ppufile.getlongint;
- getmem(str,len+1);
- ppufile.getdata(str^,len);
- str[len]:=#0;
- end;
- procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
- var
- len : longint;
- begin
- inherited ppuwrite(ppufile);
- len:=strlen(str);
- ppufile.putlongint(len);
- ppufile.putdata(str^,len);
- end;
- function tai_comment.getcopy : tlinkedlistitem;
- var
- p : tlinkedlistitem;
- begin
- p:=inherited getcopy;
- getmem(tai_comment(p).str,strlen(str)+1);
- move(str^,tai_comment(p).str^,strlen(str)+1);
- getcopy:=p;
- end;
- {****************************************************************************
- TAI_CUT
- ****************************************************************************}
- constructor tai_cut.Create;
- begin
- inherited Create;
- typ:=ait_cut;
- place:=cut_normal;
- end;
- constructor tai_cut.Create_begin;
- begin
- inherited Create;
- typ:=ait_cut;
- place:=cut_begin;
- end;
- constructor tai_cut.Create_end;
- begin
- inherited Create;
- typ:=ait_cut;
- place:=cut_end;
- end;
- constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- place:=TCutPlace(ppufile.getbyte);
- end;
- procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putbyte(byte(place));
- end;
- {****************************************************************************
- Tai_Marker
- ****************************************************************************}
- constructor Tai_Marker.Create(_Kind: TMarker);
- begin
- Inherited Create;
- typ := ait_marker;
- Kind := _Kind;
- end;
- constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- kind:=TMarker(ppufile.getbyte);
- end;
- procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putbyte(byte(kind));
- end;
- {*****************************************************************************
- tai_tempalloc
- *****************************************************************************}
- constructor tai_tempalloc.alloc(pos,size:longint);
- begin
- inherited Create;
- typ:=ait_tempalloc;
- allocation:=true;
- temppos:=pos;
- tempsize:=size;
- {$ifdef EXTDEBUG}
- problem:=nil;
- {$endif EXTDEBUG}
- end;
- destructor tai_tempalloc.destroy;
- begin
- {$ifdef EXTDEBUG}
- stringdispose(problem);
- {$endif EXTDEBUG}
- inherited destroy;
- end;
- constructor tai_tempalloc.dealloc(pos,size:longint);
- begin
- inherited Create;
- typ:=ait_tempalloc;
- allocation:=false;
- temppos:=pos;
- tempsize:=size;
- {$ifdef EXTDEBUG}
- problem:=nil;
- {$endif EXTDEBUG}
- end;
- {$ifdef EXTDEBUG}
- constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
- begin
- inherited Create;
- typ:=ait_tempalloc;
- allocation:=false;
- temppos:=pos;
- tempsize:=size;
- problem:=stringdup(st);
- end;
- {$endif EXTDEBUG}
- constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- temppos:=ppufile.getlongint;
- tempsize:=ppufile.getlongint;
- allocation:=boolean(ppufile.getbyte);
- {$ifdef EXTDEBUG}
- problem:=nil;
- {$endif EXTDEBUG}
- end;
- procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putlongint(temppos);
- ppufile.putlongint(tempsize);
- ppufile.putbyte(byte(allocation));
- end;
- {*****************************************************************************
- tai_regalloc
- *****************************************************************************}
- constructor tai_regalloc.alloc(r : tregister);
- begin
- inherited create;
- typ:=ait_regalloc;
- allocation:=true;
- reg:=r;
- end;
- constructor tai_regalloc.dealloc(r : tregister);
- begin
- inherited create;
- typ:=ait_regalloc;
- allocation:=false;
- reg:=r;
- end;
- constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- ppufile.getdata(reg,sizeof(Tregister));
- allocation:=boolean(ppufile.getbyte);
- end;
- procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putdata(reg,sizeof(Tregister));
- ppufile.putbyte(byte(allocation));
- end;
- {*****************************************************************************
- TaiInstruction
- *****************************************************************************}
- constructor taicpu_abstract.Create(op : tasmop);
- begin
- inherited create;
- typ:=ait_instruction;
- is_jmp:=false;
- opcode:=op;
- ops:=0;
- fillchar(condition,sizeof(condition),0);
- fillchar(oper,sizeof(oper),0);
- end;
- destructor taicpu_abstract.Destroy;
- var
- i : integer;
- begin
- for i:=0 to opercnt-1 do
- begin
- with oper[i]^ do
- begin
- case typ of
- top_ref:
- dispose(ref);
- {$ifdef ARM}
- top_shifterop:
- dispose(shifterop);
- {$endif ARM}
- end;
- end;
- dispose(oper[i]);
- end;
- inherited destroy;
- end;
- { ---------------------------------------------------------------------
- Loading of operands.
- ---------------------------------------------------------------------}
- procedure taicpu_abstract.allocate_oper(opers:longint);
- begin
- while (opers>opercnt) do
- begin
- new(oper[opercnt]);
- fillchar(oper[opercnt]^,sizeof(toper),0);
- inc(opercnt);
- end;
- end;
- procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
- begin
- allocate_oper(opidx+1);
- with oper[opidx]^ do
- begin
- if typ<>top_const then
- clearop(opidx);
- val:=l;
- typ:=top_const;
- end;
- end;
- procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
- var
- r : treference;
- begin
- reference_reset_symbol(r,s,sofs);
- r.refaddr:=addr_full;
- loadref(opidx,r);
- end;
- procedure taicpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
- begin
- if not assigned(s) then
- internalerror(200204251);
- allocate_oper(opidx+1);
- with oper[opidx]^ do
- begin
- if typ<>top_local then
- begin
- clearop(opidx);
- new(localoper);
- end;
- with oper[opidx]^.localoper^ do
- begin
- localsym:=s;
- localsymofs:=sofs;
- localindexreg:=indexreg;
- localscale:=scale;
- localgetoffset:=getoffset;
- end;
- typ:=top_local;
- end;
- end;
- procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
- begin
- allocate_oper(opidx+1);
- with oper[opidx]^ do
- begin
- if typ<>top_ref then
- begin
- clearop(opidx);
- new(ref);
- end;
- ref^:=r;
- {$ifdef x86}
- { We allow this exception for x86, since overloading this would be
- too much of a a speed penalty}
- if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
- segprefix:=ref^.segment;
- {$endif}
- typ:=top_ref;
- if assigned(add_reg_instruction_hook) then
- begin
- add_reg_instruction_hook(self,ref^.base);
- add_reg_instruction_hook(self,ref^.index);
- end;
- { mark symbol as used }
- if assigned(ref^.symbol) then
- ref^.symbol.increfs;
- end;
- end;
- procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
- begin
- allocate_oper(opidx+1);
- with oper[opidx]^ do
- begin
- if typ<>top_reg then
- clearop(opidx);
- reg:=r;
- typ:=top_reg;
- end;
- if assigned(add_reg_instruction_hook) then
- add_reg_instruction_hook(self,r);
- {$ifdef ARM}
- { R15 is the PC on the ARM thus moves to R15 are jumps.
- Due to speed considerations we don't use a virtual overridden method here.
- Because the pc/r15 isn't handled by the reg. allocator this should never cause
- problems with iregs getting r15.
- }
- is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
- {$endif ARM}
- end;
- procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
- begin
- allocate_oper(opidx+1);
- clearop(opidx);
- oper[opidx]^:=o;
- { copy also the reference }
- with oper[opidx]^ do
- begin
- case typ of
- top_reg:
- begin
- if assigned(add_reg_instruction_hook) then
- add_reg_instruction_hook(self,reg);
- end;
- top_ref:
- begin
- new(ref);
- ref^:=o.ref^;
- if assigned(add_reg_instruction_hook) then
- begin
- add_reg_instruction_hook(self,ref^.base);
- add_reg_instruction_hook(self,ref^.index);
- end;
- end;
- {$ifdef ARM}
- top_shifterop:
- begin
- new(shifterop);
- shifterop^:=o.shifterop^;
- if assigned(add_reg_instruction_hook) then
- add_reg_instruction_hook(self,shifterop^.rs);
- end;
- {$endif ARM}
- end;
- end;
- end;
- procedure taicpu_abstract.clearop(opidx:longint);
- begin
- with oper[opidx]^ do
- begin
- case typ of
- top_ref:
- dispose(ref);
- top_local:
- dispose(localoper);
- {$ifdef ARM}
- top_shifterop:
- dispose(shifterop);
- top_regset:
- dispose(regset);
- {$endif ARM}
- end;
- typ:=top_none;
- end;
- end;
- { ---------------------------------------------------------------------
- Miscellaneous methods.
- ---------------------------------------------------------------------}
- procedure taicpu_abstract.SetCondition(const c:TAsmCond);
- begin
- condition:=c;
- end;
- Function taicpu_abstract.getcopy:TLinkedListItem;
- var
- i : longint;
- p : taicpu_abstract;
- begin
- p:=taicpu_abstract(inherited getcopy);
- { make a copy of the references }
- p.opercnt:=0;
- p.allocate_oper(ops);
- for i:=0 to ops-1 do
- begin
- p.oper[i]^:=oper[i]^;
- if (oper[i]^.typ=top_ref) then
- begin
- new(p.oper[i]^.ref);
- p.oper[i]^.ref^:=oper[i]^.ref^;
- end;
- end;
- getcopy:=p;
- end;
- constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
- var
- i : integer;
- begin
- inherited ppuload(t,ppufile);
- { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
- ppufile.getdata(condition,sizeof(tasmcond));
- allocate_oper(ppufile.getbyte);
- for i:=0 to ops-1 do
- ppuloadoper(ppufile,oper[i]^);
- opcode:=tasmop(ppufile.getword);
- {$ifdef x86}
- ppufile.getdata(segprefix,sizeof(Tregister));
- {$endif x86}
- is_jmp:=boolean(ppufile.getbyte);
- end;
- procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
- var
- i : integer;
- begin
- inherited ppuwrite(ppufile);
- ppufile.putdata(condition,sizeof(tasmcond));
- ppufile.putbyte(ops);
- for i:=0 to ops-1 do
- ppuwriteoper(ppufile,oper[i]^);
- ppufile.putword(word(opcode));
- {$ifdef x86}
- ppufile.putdata(segprefix,sizeof(Tregister));
- {$endif x86}
- ppufile.putbyte(byte(is_jmp));
- end;
- procedure taicpu_abstract.buildderefimpl;
- var
- i : integer;
- begin
- for i:=0 to ops-1 do
- ppubuildderefimploper(oper[i]^);
- end;
- procedure taicpu_abstract.derefimpl;
- var
- i : integer;
- begin
- for i:=0 to ops-1 do
- ppuderefoper(oper[i]^);
- end;
- {****************************************************************************
- tai_align_abstract
- ****************************************************************************}
- constructor tai_align_abstract.Create(b: byte);
- begin
- inherited Create;
- typ:=ait_align;
- if b in [1,2,4,8,16,32] then
- aligntype := b
- else
- aligntype := 1;
- fillsize:=0;
- fillop:=0;
- use_op:=false;
- end;
- constructor tai_align_abstract.Create_op(b: byte; _op: byte);
- begin
- inherited Create;
- typ:=ait_align;
- if b in [1,2,4,8,16,32] then
- aligntype := b
- else
- aligntype := 1;
- fillsize:=0;
- fillop:=_op;
- use_op:=true;
- end;
- function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
- begin
- fillchar(buf,high(buf),fillop);
- calculatefillbuf:=pchar(@buf);
- end;
- constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
- begin
- inherited ppuload(t,ppufile);
- aligntype:=ppufile.getbyte;
- fillsize:=0;
- fillop:=ppufile.getbyte;
- use_op:=boolean(ppufile.getbyte);
- end;
- procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
- begin
- inherited ppuwrite(ppufile);
- ppufile.putbyte(aligntype);
- ppufile.putbyte(fillop);
- ppufile.putbyte(byte(use_op));
- end;
- {*****************************************************************************
- TAAsmOutput
- *****************************************************************************}
- constructor taasmoutput.create;
- begin
- inherited create;
- { make sure the optimizer won't remove the first tai of this list}
- insert(tai_marker.create(marker_blockstart));
- end;
- function taasmoutput.getlasttaifilepos : pfileposinfo;
- var
- hp : tlinkedlistitem;
- begin
- getlasttaifilepos := nil;
- if assigned(last) then
- begin
- { find the last file information record }
- if not (tai(last).typ in SkipLineInfo) then
- getlasttaifilepos:=@tailineinfo(last).fileinfo
- else
- { go through list backwards to find the first entry
- with line information
- }
- begin
- hp:=tai(last);
- while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
- hp:=hp.Previous;
- { found entry }
- if assigned(hp) then
- getlasttaifilepos:=@tailineinfo(hp).fileinfo
- end;
- end;
- end;
- procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
- begin
- { This is not possible because it is not sure that the
- tai at Loc has taifileinfo as parent }
- {if assigned(Loc) then
- tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
- inherited InsertAfter(Item,Loc);
- end;
- end.
- {
- $Log$
- Revision 1.76 2004-03-02 17:32:12 florian
- * make cycle fixed
- + pic support for darwin
- + support of importing vars from shared libs on darwin implemented
- Revision 1.75 2004/03/02 00:36:32 olle
- * big transformation of Tai_[const_]Symbol.Create[data]name*
- Revision 1.74 2004/02/27 12:13:15 daniel
- - Removed troublesome writeln statement
- Revision 1.73 2004/02/27 10:21:04 florian
- * top_symbol killed
- + refaddr to treference added
- + refsymbol to treference added
- * top_local stuff moved to an extra record to save memory
- + aint introduced
- * tppufile.get/putint64/aint implemented
- Revision 1.72 2004/02/26 16:16:38 peter
- * tai_const.create_ptr added
- Revision 1.71 2004/02/08 23:10:21 jonas
- * taicpu.is_same_reg_move() now gets a regtype parameter so it only
- removes moves of that particular register type. This is necessary so
- we don't remove the live_start instruction of a register before it
- has been processed
- Revision 1.70 2004/02/08 20:15:42 jonas
- - removed taicpu.is_reg_move because it's not used anymore
- + support tracking fpu register moves by rgobj for the ppc
- Revision 1.69 2004/01/31 17:45:16 peter
- * Change several $ifdef i386 to x86
- * Change several OS_32 to OS_INT/OS_ADDR
- Revision 1.68 2004/01/30 13:42:03 florian
- * fixed more alignment issues
- Revision 1.67 2004/01/26 16:12:27 daniel
- * reginfo now also only allocated during register allocation
- * third round of gdb cleanups: kick out most of concatstabto
- Revision 1.66 2004/01/24 18:12:40 florian
- * fixed several arm floating point issues
- Revision 1.65 2004/01/23 15:12:49 florian
- * fixed generic shl/shr operations
- + added register allocation hook calls for arm specific operand types:
- register set and shifter op
- Revision 1.64 2004/01/12 16:37:59 peter
- * moved spilling code from taicpu to rg
- Revision 1.63 2003/12/28 16:20:09 jonas
- - removed unused methods from old generic spilling code
- Revision 1.62 2003/12/26 14:02:30 peter
- * sparc updates
- * use registertype in spill_register
- Revision 1.61 2003/12/15 21:25:48 peter
- * reg allocations for imaginary register are now inserted just
- before reg allocation
- * tregister changed to enum to allow compile time check
- * fixed several tregister-tsuperregister errors
- Revision 1.60 2003/12/14 20:24:28 daniel
- * Register allocator speed optimizations
- - Worklist no longer a ringbuffer
- - No find operations are left
- - Simplify now done in constant time
- - unusedregs is now a Tsuperregisterworklist
- - Microoptimizations
- Revision 1.59 2003/12/08 22:34:24 peter
- * tai_const.create_32bit changed to cardinal
- Revision 1.58 2003/12/06 22:16:12 jonas
- * completely overhauled and fixed generic spilling code. New method:
- spilling_get_operation_type(operand_number): returns the operation
- performed by the instruction on the operand: read/write/read+write.
- See powerpc/aasmcpu.pas for an example
- Revision 1.57 2003/12/03 17:39:04 florian
- * fixed several arm calling conventions issues
- * fixed reference reading in the assembler reader
- * fixed a_loadaddr_ref_reg
- Revision 1.55 2003/11/12 16:05:39 florian
- * assembler readers OOPed
- + typed currency constants
- + typed 128 bit float constants if the CPU supports it
- Revision 1.54 2003/11/07 15:58:32 florian
- * Florian's culmutative nr. 1; contains:
- - invalid calling conventions for a certain cpu are rejected
- - arm softfloat calling conventions
- - -Sp for cpu dependend code generation
- - several arm fixes
- - remaining code for value open array paras on heap
- Revision 1.53 2003/10/30 19:59:00 peter
- * support scalefactor for opr_local
- * support reference with opr_local set, fixes tw2631
- Revision 1.52 2003/10/29 21:06:39 jonas
- * allow more than 3 args in the spilling routine
- Revision 1.51 2003/10/29 15:40:20 peter
- * support indexing and offset retrieval for locals
- Revision 1.50 2003/10/29 14:42:14 mazen
- * code reformatted
- Revision 1.49 2003/10/29 14:05:45 mazen
- * Splling function devided to sub functions to make it easy to understand.
- This commit is just to allow easy diffs to validate the migration (hint use -w)
- Revision 1.48 2003/10/24 17:39:41 peter
- * asmnode.get_position now inserts a marker
- Revision 1.47 2003/10/23 14:44:07 peter
- * splitted buildderef and buildderefimpl to fix interface crc
- calculation
- Revision 1.46 2003/10/22 20:39:59 peter
- * write derefdata in a separate ppu entry
- Revision 1.45 2003/10/21 15:15:35 peter
- * taicpu_abstract.oper[] changed to pointers
- Revision 1.44 2003/10/17 14:38:32 peter
- * 64k registers supported
- * fixed some memory leaks
- Revision 1.43 2003/10/11 16:06:42 florian
- * fixed some MMX<->SSE
- * started to fix ppc, needs an overhaul
- + stabs info improve for spilling, not sure if it works correctly/completly
- - MMX_SUPPORT removed from Makefile.fpc
- Revision 1.42 2003/10/10 17:48:13 peter
- * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
- * tregisteralloctor renamed to trgobj
- * removed rgobj from a lot of units
- * moved location_* and reference_* to cgobj
- * first things for mmx register allocation
- Revision 1.41 2003/10/01 20:34:48 peter
- * procinfo unit contains tprocinfo
- * cginfo renamed to cgbase
- * moved cgmessage to verbose
- * fixed ppc and sparc compiles
- Revision 1.40 2003/09/23 17:56:05 peter
- * locals and paras are allocated in the code generation
- * tvarsym.localloc contains the location of para/local when
- generating code for the current procedure
- Revision 1.39 2003/09/07 22:09:34 peter
- * preparations for different default calling conventions
- * various RA fixes
- Revision 1.38 2003/09/04 00:15:28 florian
- * first bunch of adaptions of arm compiler for new register type
- Revision 1.37 2003/09/03 15:55:00 peter
- * NEWRA branch merged
- Revision 1.36 2003/09/03 11:18:36 florian
- * fixed arm concatcopy
- + arm support in the common compiler sources added
- * moved some generic cg code around
- + tfputype added
- * ...
- Revision 1.35.2.5 2003/08/31 21:08:16 peter
- * first batch of sparc fixes
- Revision 1.35.2.4 2003/08/29 17:28:59 peter
- * next batch of updates
- Revision 1.35.2.3 2003/08/28 18:35:07 peter
- * tregister changed to cardinal
- Revision 1.35.2.2 2003/08/27 20:23:55 peter
- * remove old ra code
- Revision 1.35.2.1 2003/08/27 19:55:54 peter
- * first tregister patch
- Revision 1.35 2003/08/21 14:47:41 peter
- * remove convert_registers
- Revision 1.34 2003/08/20 20:29:06 daniel
- * Some more R_NO changes
- * Preventive code to loadref added
- Revision 1.33 2003/08/17 20:47:47 daniel
- * Notranslation changed into -sr functionality
- Revision 1.32 2003/08/17 16:59:20 jonas
- * fixed regvars so they work with newra (at least for ppc)
- * fixed some volatile register bugs
- + -dnotranslation option for -dnewra, which causes the registers not to
- be translated from virtual to normal registers. Requires support in
- the assembler writer as well, which is only implemented in aggas/
- agppcgas currently
- Revision 1.31 2003/08/11 21:18:20 peter
- * start of sparc support for newra
- Revision 1.30 2003/07/02 16:43:48 jonas
- * always add dummy marker object at the start of an assembler list, so
- the optimizer can't remove the first object
- Revision 1.29 2003/06/03 13:01:59 daniel
- * Register allocator finished
- Revision 1.28 2003/05/12 18:13:57 peter
- * create rtti label using newasmsymboldata and update binding
- only when calling tai_symbol.create
- * tai_symbol.create_global added
- Revision 1.27 2003/04/25 20:59:33 peter
- * removed funcretn,funcretsym, function result is now in varsym
- and aliases for result and function name are added using absolutesym
- * vs_hidden parameter for funcret passed in parameter
- * vs_hidden fixes
- * writenode changed to printnode and released from extdebug
- * -vp option added to generate a tree.log with the nodetree
- * nicer printnode for statements, callnode
- Revision 1.26 2002/04/25 16:12:09 florian
- * fixed more problems with cpubase and x86-64
- Revision 1.25 2003/04/25 08:25:26 daniel
- * Ifdefs around a lot of calls to cleartempgen
- * Fixed registers that are allocated but not freed in several nodes
- * Tweak to register allocator to cause less spills
- * 8-bit registers now interfere with esi,edi and ebp
- Compiler can now compile rtl successfully when using new register
- allocator
- Revision 1.24 2003/04/24 13:03:01 florian
- * comp is now written with its bit pattern to the ppu instead as an extended
- Revision 1.23 2003/04/22 14:33:38 peter
- * removed some notes/hints
- Revision 1.22 2003/04/22 10:09:34 daniel
- + Implemented the actual register allocator
- + Scratch registers unavailable when new register allocator used
- + maybe_save/maybe_restore unavailable when new register allocator used
- Revision 1.21 2003/02/19 22:00:14 daniel
- * Code generator converted to new register notation
- - Horribily outdated todo.txt removed
- Revision 1.20 2003/01/30 21:46:20 peter
- * tai_const_symbol.createdataname added
- Revision 1.19 2003/01/21 08:48:08 daniel
- * Another 200301081 fixed
- Revision 1.18 2003/01/09 20:40:59 daniel
- * Converted some code in cgx86.pas to new register numbering
- Revision 1.17 2003/01/09 15:49:56 daniel
- * Added register conversion
- Revision 1.16 2003/01/08 18:43:56 daniel
- * Tregister changed into a record
- Revision 1.15 2003/01/05 13:36:53 florian
- * x86-64 compiles
- + very basic support for float128 type (x86-64 only)
- Revision 1.14 2002/12/06 17:50:21 peter
- * symbol count fix merged
- Revision 1.13 2002/11/17 16:31:55 carl
- * memory optimization (3-4%) : cleanup of tai fields,
- cleanup of tdef and tsym fields.
- * make it work for m68k
- Revision 1.12 2002/11/15 16:29:30 peter
- * made tasmsymbol.refs private (merged)
- Revision 1.11 2002/11/15 01:58:45 peter
- * merged changes from 1.0.7 up to 04-11
- - -V option for generating bug report tracing
- - more tracing for option parsing
- - errors for cdecl and high()
- - win32 import stabs
- - win32 records<=8 are returned in eax:edx (turned off by default)
- - heaptrc update
- - more info for temp management in .s file with EXTDEBUG
- Revision 1.10 2002/11/09 15:38:03 carl
- + NOOPT removed the optinfo field
- Revision 1.9 2002/10/05 12:43:23 carl
- * fixes for Delphi 6 compilation
- (warning : Some features do not work under Delphi)
- Revision 1.8 2002/08/19 19:36:42 peter
- * More fixes for cross unit inlining, all tnodes are now implemented
- * Moved pocall_internconst to po_internconst because it is not a
- calling type at all and it conflicted when inlining of these small
- functions was requested
- Revision 1.7 2002/08/18 20:06:23 peter
- * inlining is now also allowed in interface
- * renamed write/load to ppuwrite/ppuload
- * tnode storing in ppu
- * nld,ncon,nbas are already updated for storing in ppu
- Revision 1.6 2002/08/16 05:21:09 florian
- * powerpc compilation fix
- Revision 1.5 2002/08/15 19:10:35 peter
- * first things tai,tnode storing in ppu
- Revision 1.4 2002/08/11 14:32:25 peter
- * renamed current_library to objectlibrary
- Revision 1.3 2002/08/11 13:24:10 peter
- * saving of asmsymbols in ppu supported
- * asmsymbollist global is removed and moved into a new class
- tasmlibrarydata that will hold the info of a .a file which
- corresponds with a single module. Added librarydata to tmodule
- to keep the library info stored for the module. In the future the
- objectfiles will also be stored to the tasmlibrarydata class
- * all getlabel/newasmsymbol and friends are moved to the new class
- Revision 1.2 2002/08/05 18:27:48 carl
- + more more more documentation
- + first version include/exclude (can't test though, not enough scratch for i386 :()...
- Revision 1.1 2002/07/01 18:46:20 peter
- * internal linker
- * reorganized aasm layer
- Revision 1.27 2002/05/18 13:34:04 peter
- * readded missing revisions
- Revision 1.25 2002/05/14 19:34:38 peter
- * removed old logs and updated copyright year
- Revision 1.24 2002/05/14 17:28:08 peter
- * synchronized cpubase between powerpc and i386
- * moved more tables from cpubase to cpuasm
- * tai_align_abstract moved to tainst, cpuasm must define
- the tai_align class now, which may be empty
- Revision 1.23 2002/04/15 18:54:34 carl
- - removed tcpuflags
- Revision 1.22 2002/04/07 13:18:19 carl
- + more documentation
- Revision 1.21 2002/04/07 10:17:40 carl
- - remove packenumfixed (requires version 1.0.2 or later to compile now!)
- + changing some comments so its commented automatically
- Revision 1.20 2002/03/24 19:04:31 carl
- + patch for SPARC from Mazen NEIFER
- }
|