ppudump.pp 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058
  1. {
  2. Copyright (c) 1998-2013 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. program ppudump;
  17. {$i fpcdefs.inc}
  18. {$H+}
  19. {$packenum 1}
  20. {$define IN_PPUDUMP}
  21. uses
  22. { do NOT add symconst or globtype to make merging easier }
  23. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  24. cutils,
  25. SysUtils,
  26. constexp,
  27. symconst,
  28. ppu,
  29. entfile,
  30. systems,
  31. cpuinfo,
  32. globals,
  33. globtype,
  34. widestr,
  35. tokens,
  36. version,
  37. ppuout,
  38. ppujson,
  39. ppuxml;
  40. const
  41. Title = 'PPU-Analyser';
  42. Copyright = 'Copyright (c) 1998-2013 by the Free Pascal Development Team';
  43. { verbosity }
  44. v_none = $0;
  45. v_header = $1;
  46. v_defs = $2;
  47. v_syms = $4;
  48. v_interface = $8;
  49. v_implementation = $10;
  50. // v_browser = $20;
  51. v_all = $ff;
  52. { not needed anymore $i systems.inc }
  53. { List of all supported cpus }
  54. const
  55. CpuTxt : array[tsystemcpu] of string[16]=
  56. (
  57. { 0 } 'none',
  58. { 1 } 'i386',
  59. { 2 } 'm68k',
  60. { 3 } 'alpha (obsolete)',
  61. { 4 } 'powerpc',
  62. { 5 } 'sparc',
  63. { 6 } 'vis (obsolete)',
  64. { 7 } 'ia64 (obsolete)',
  65. { 8 } 'x86_64',
  66. { 9 } 'mipseb',
  67. { 10 } 'arm',
  68. { 11 } 'powerpc64',
  69. { 12 } 'avr',
  70. { 13 } 'mipsel',
  71. { 14 } 'jvm',
  72. { 15 } 'i8086',
  73. { 16 } 'aarch64',
  74. { 17 } 'wasm',
  75. { 18 } 'sparc64'
  76. );
  77. CpuHasController : array[tsystemcpu] of boolean =
  78. (
  79. { 0 } false {'none'},
  80. { 1 } false {'i386'},
  81. { 2 } false {'m68k'},
  82. { 3 } false {'alpha (obsolete)'},
  83. { 4 } false {'powerpc'},
  84. { 5 } false {'sparc'},
  85. { 6 } false {'vis (obsolete)'},
  86. { 7 } false {'ia64 (obsolete)'},
  87. { 8 } false {'x86_64'},
  88. { 9 } false {'mipseb'},
  89. { 10 } true {'arm'},
  90. { 11 } false {'powerpc64'},
  91. { 12 } true {'avr'},
  92. { 13 } true {'mipsel'},
  93. { 14 } false {'jvm'},
  94. { 15 } false {'i8086'},
  95. { 16 } false {'aarch64'},
  96. { 17 } false {'wasm'},
  97. { 18 } false {'sparc64'}
  98. );
  99. { List of all supported system-cpu couples }
  100. const
  101. Targets : array[tsystem] of string[26]=(
  102. { 0 } 'none',
  103. { 1 } 'GO32V1 (obsolete)',
  104. { 2 } 'GO32V2',
  105. { 3 } 'Linux-i386',
  106. { 4 } 'OS/2',
  107. { 5 } 'Win32',
  108. { 6 } 'FreeBSD-i386',
  109. { 7 } 'Amiga',
  110. { 8 } 'Atari',
  111. { 9 } 'MacOSClassic-m68k',
  112. { 10 } 'Linux-m68k',
  113. { 11 } 'PalmOS-m68k',
  114. { 12 } 'Linux-alpha (obsolete)',
  115. { 13 } 'Linux-ppc',
  116. { 14 } 'MacOSClassic-ppc',
  117. { 15 } 'Solaris-i386',
  118. { 16 } 'BeOS-i386',
  119. { 17 } 'NetBSD-i386',
  120. { 18 } 'NetBSD-m68k',
  121. { 19 } 'Netware-i386-clib',
  122. { 20 } 'Qnx-i386',
  123. { 21 } 'WDOSX-i386',
  124. { 22 } 'Solaris-sparc',
  125. { 23 } 'Linux-sparc',
  126. { 24 } 'OpenBSD-i386',
  127. { 25 } 'OpenBSD-m68k (obsolete)',
  128. { 26 } 'Linux-x86-64',
  129. { 27 } 'Darwin-ppc',
  130. { 28 } 'OS/2 via EMX',
  131. { 29 } 'NetBSD-powerpc',
  132. { 30 } 'OpenBSD-powerpc',
  133. { 31 } 'Linux-arm',
  134. { 32 } 'Watcom-i386',
  135. { 33 } 'MorphOS-powerpc',
  136. { 34 } 'FreeBSD-x86-64',
  137. { 35 } 'Netware-i386-libc',
  138. { 36 } 'Amiga-PowerPC',
  139. { 37 } 'Win64-x64',
  140. { 38 } 'WinCE-ARM',
  141. { 39 } 'Win64-iA64 (obsolete)',
  142. { 40 } 'WinCE-i386',
  143. { 41 } 'Linux-x64',
  144. { 42 } 'GBA-arm',
  145. { 43 } 'Linux-powerpc64',
  146. { 44 } 'Darwin-i386',
  147. { 45 } 'PalmOS-arm',
  148. { 46 } 'Darwin-powerpc64',
  149. { 47 } 'NDS-arm',
  150. { 48 } 'Embedded-i386',
  151. { 49 } 'Embedded-m68k',
  152. { 50 } 'Embedded-alpha (obsolete)',
  153. { 51 } 'Embedded-powerpc',
  154. { 52 } 'Embedded-sparc',
  155. { 53 } 'Embedded-vm (obsolete)',
  156. { 54 } 'Embedded-iA64 (obsolete)',
  157. { 55 } 'Embedded-x64',
  158. { 56 } 'Embedded-mips',
  159. { 57 } 'Embedded-arm',
  160. { 58 } 'Embedded-powerpc64',
  161. { 59 } 'Symbian-i386',
  162. { 60 } 'Symbian-arm',
  163. { 61 } 'Darwin-x64',
  164. { 62 } 'Embedded-avr',
  165. { 63 } 'Haiku-i386',
  166. { 64 } 'iOS-ARM',
  167. { 65 } 'Solaris-x86-64',
  168. { 66 } 'Linux-MIPS',
  169. { 67 } 'Linux-MIPSel',
  170. { 68 } 'NativeNT-i386',
  171. { 69 } 'iPhoneSim-i386',
  172. { 70 } 'Wii-powerpc',
  173. { 71 } 'OpenBSD-x86-64',
  174. { 72 } 'NetBSD-x86-64',
  175. { 73 } 'AIX-powerpc',
  176. { 74 } 'AIX-powerpc64',
  177. { 75 } 'Java-JVM',
  178. { 76 } 'Android-JVM',
  179. { 77 } 'Android-arm',
  180. { 78 } 'Android-i386',
  181. { 79 } 'MSDOS-i8086',
  182. { 80 } 'Android-MIPSel',
  183. { 81 } 'Embedded-mipseb',
  184. { 82 } 'Embedded-mipsel',
  185. { 83 } 'AROS-i386',
  186. { 84 } 'AROS-x86-64',
  187. { 85 } 'DragonFly-x86-64',
  188. { 86 } 'iOS-AArch64',
  189. { 87 } 'iPhoneSim-x86-64',
  190. { 88 } 'Linux-AArch64',
  191. { 89 } 'Win16',
  192. { 90 } 'Embedded-i8086',
  193. { 91 } 'AROS-arm',
  194. { 92 } 'WebAssembly-wasm',
  195. { 93 } 'Linux-sparc64',
  196. { 94 } 'Solaris-sparc64',
  197. { 95 } 'NetBSD-arm',
  198. { 96 } 'Linux-RiscV32',
  199. { 97 } 'Linux-RiscV64',
  200. { 98 } 'Embedded-RiscV32',
  201. { 99 } 'Embedded-RiscV64',
  202. { 100 } 'Android-AArch64',
  203. { 101 } 'Android-x86-64',
  204. { 102 } 'Haiku-x86-64',
  205. { 111 } 'Darwin-AArch64'
  206. );
  207. const
  208. { in widestr, we have the following definition
  209. type
  210. tcompilerwidechar = word;
  211. thus widecharsize seems to always be 2 bytes }
  212. widecharsize : longint = 2;
  213. cpu : tsystemcpu = cpu_no;
  214. { This type is defined in scanner.pas unit }
  215. type
  216. tspecialgenerictoken = (
  217. ST_LOADSETTINGS,
  218. ST_LINE,
  219. ST_COLUMN,
  220. ST_FILEINDEX,
  221. ST_LOADMESSAGES,
  222. ST_INVALID);
  223. type
  224. tcpu_i386 = (
  225. cpu_variant_i386_none,
  226. cpu_variant_386,
  227. cpu_variant_486,
  228. cpu_variant_Pentium,
  229. cpu_variant_Pentium2,
  230. cpu_variant_Pentium3,
  231. cpu_variant_Pentium4,
  232. cpu_variant_PentiumM,
  233. cpu_variant_core_i,
  234. cpu_variant_core_avx,
  235. cpu_variant_core_avx2);
  236. tcpu_m68k = (
  237. cpu_variant_m68k_none,
  238. cpu_variant_MC68000,
  239. cpu_variant_MC68020,
  240. cpu_variant_MC68040,
  241. cpu_variant_MC68060,
  242. cpu_variant_isa_a,
  243. cpu_variant_isa_a_p,
  244. cpu_variant_isa_b,
  245. cpu_variant_isa_c,
  246. cpu_variant_cfv4e
  247. );
  248. tcpu_powerpc = (
  249. cpu_variant_powerpc_none,
  250. cpu_variant_ppc604,
  251. cpu_variant_ppc750,
  252. cpu_variant_ppc7400,
  253. cpu_variant_ppc970
  254. );
  255. tcpu_sparc = (
  256. cpu_variant_sparc_none,
  257. cpu_variant_SPARC_V7,
  258. cpu_variant_SPARC_V8,
  259. cpu_variant_SPARC_V9
  260. );
  261. tcpu_x86_64 = (
  262. cpu_variant_x86_64_none,
  263. cpu_variant_athlon64,
  264. cpu_variant_x86_64_core_i,
  265. cpu_variant_x86_64_core_avx,
  266. cpu_variant_x86_64_core_avx2
  267. );
  268. tcpu_mipseb = (
  269. cpu_variant_mipseb_none,
  270. cpu_variant_mips1,
  271. cpu_variant_mips2,
  272. cpu_variant_mips3,
  273. cpu_variant_mips4,
  274. cpu_variant_mips5,
  275. cpu_variant_mips32,
  276. cpu_variant_mips32r2,
  277. cpu_variant_pic32mx
  278. );
  279. tcpu_arm = (
  280. cpu_variant_arm_none,
  281. cpu_variant_armv3,
  282. cpu_variant_armv4,
  283. cpu_variant_armv4t,
  284. cpu_variant_armv5,
  285. cpu_variant_armv5t,
  286. cpu_variant_armv5te,
  287. cpu_variant_armv5tej,
  288. cpu_variant_armv6,
  289. cpu_variant_armv6k,
  290. cpu_variant_armv6t2,
  291. cpu_variant_armv6z,
  292. cpu_variant_armv6m,
  293. cpu_variant_armv7,
  294. cpu_variant_armv7a,
  295. cpu_variant_armv7r,
  296. cpu_variant_armv7m,
  297. cpu_variant_armv7em
  298. );
  299. tcpu_powerpc64 = (
  300. cpu_variant_powerpc64_none,
  301. cpu_variant_powerpc64_ppc970
  302. );
  303. tcpu_avr = (
  304. cpu_variant_avr_none,
  305. cpu_variant_avr1,
  306. cpu_variant_avr2,
  307. cpu_variant_avr25,
  308. cpu_variant_avr3,
  309. cpu_variant_avr31,
  310. cpu_variant_avr35,
  311. cpu_variant_avr4,
  312. cpu_variant_avr5,
  313. cpu_variant_avr51,
  314. cpu_variant_avr6
  315. );
  316. tcpu_mipsel = tcpu_mipseb;
  317. tcpu_jvm = (
  318. cpu_variant_jvm_none,
  319. { jvm, same as cpu_none }
  320. cpu_variant_jvm,
  321. { jvm byte code to be translated into Dalvik bytecode: more type-
  322. sensitive }
  323. cpu_variant_dalvik
  324. );
  325. tcpu_i8086 = (
  326. cpu_variant_i8086_none,
  327. cpu_variant_8086,
  328. cpu_variant_186,
  329. cpu_variant_286,
  330. cpu_variant_i8086_386,
  331. cpu_variant_i8086_486,
  332. cpu_variant_i8086_Pentium,
  333. cpu_variant_i8086_Pentium2,
  334. cpu_variant_i8086_Pentium3,
  335. cpu_variant_i8086_Pentium4,
  336. cpu_variant_i8086_PentiumM
  337. );
  338. tcpu_aarch64 = (
  339. cpu_variant_aarch64_none,
  340. cpu_variant_armv8
  341. );
  342. tcpu_wasm = (
  343. cpu_variant_wasm_none);
  344. tcpu_sparc64 = (
  345. cpu_variant_sparc64_none,
  346. cpu_variant_SPARC64_V9
  347. );
  348. tcpu_type = record
  349. case tsystemcpu of
  350. cpu_no: { 0 }
  351. ();
  352. cpu_i386: { 1 }
  353. (cpu_i386 : tcpu_i386;);
  354. cpu_m68k: { 2 }
  355. (cpu_m68k : tcpu_m68k;);
  356. obsolete_cpu_alpha: { 3 }
  357. ();
  358. cpu_powerpc: { 4 }
  359. (cpu_powerpc : tcpu_powerpc;);
  360. cpu_sparc: { 5 }
  361. (cpu_sparc : tcpu_sparc;);
  362. obsolete_cpu_vm: { 6 }
  363. ();
  364. obsolete_cpu_ia64: { 7 }
  365. ();
  366. cpu_x86_64: { 8 }
  367. (cpu_x86_64 : tcpu_x86_64;);
  368. cpu_mipseb: { 9 }
  369. (cpu_mipseb : tcpu_mipseb;);
  370. cpu_arm: { 10 }
  371. (cpu_arm : tcpu_arm;);
  372. cpu_powerpc64: { 11 }
  373. (cpu_powerpc64 : tcpu_powerpc64;);
  374. cpu_avr: { 12 }
  375. (cpu_avr : tcpu_avr;);
  376. cpu_mipsel: { 13 }
  377. (cpu_mipsel : tcpu_mipsel;);
  378. cpu_jvm: { 14 }
  379. (cpu_jvm : tcpu_jvm;);
  380. cpu_i8086: { 15 }
  381. (cpu_i8086 : tcpu_i8086;);
  382. cpu_aarch64: { 16 }
  383. (cpu_aarch64 : tcpu_aarch64;);
  384. cpu_wasm: { 17 }
  385. (cpu_wasm : tcpu_wasm;);
  386. cpu_sparc64: { 18 }
  387. (cpu_sparc64 : tcpu_sparc64;);
  388. end;
  389. TPpuModuleDef = class(TPpuUnitDef)
  390. // ModuleFlags: tmoduleflags; { not yet merged }
  391. end;
  392. type
  393. tppudumpfile = class(tppufile)
  394. protected
  395. procedure RaiseAssertion(Code: Longint); override;
  396. end;
  397. var
  398. ppufile : tppudumpfile;
  399. ppuversion : dword;
  400. space : string;
  401. verbose : longint;
  402. derefdata : pbyte;
  403. derefdatalen : longint;
  404. pout: TPpuOutput;
  405. nostdout: boolean;
  406. UnitList: TPpuContainerDef;
  407. CurUnit: TPpuUnitDef;
  408. SkipVersionCheck: boolean;
  409. var
  410. { needed during tobjectdef parsing... }
  411. current_defoptions : tdefoptions;
  412. current_objectoptions : tobjectoptions;
  413. current_symtable_options : tsymtableoptions;
  414. {****************************************************************************
  415. Helper Routines
  416. ****************************************************************************}
  417. {****************************************************************************
  418. Routine to read 80-bit reals
  419. ****************************************************************************
  420. }
  421. {$PUSH}
  422. {$WARN 6018 OFF} { Turn off unreachable code warning }
  423. { On platforms with sizeof(ext) <> 10 the code below will cause an unreachable
  424. code warning, which will cause compilation failures with -Sew (KB) }
  425. type
  426. TSplit80bitReal = packed record
  427. case byte of
  428. 0: (bytes: Array[0..9] of byte);
  429. 1: (words: Array[0..4] of word);
  430. {$ifdef FPC_LITTLE_ENDIAN}
  431. 2: (cards: Array[0..1] of cardinal; w: word);
  432. {$else not FPC_LITTLE_ENDIAN}
  433. 2: (w:word; cards: Array[0..1] of cardinal);
  434. {$endif not FPC_LITTLE_ENDIAN}
  435. end;
  436. const
  437. maxDigits = 17;
  438. function Real80bitToStr(var e : TSplit80bitReal;var ext : extended) : string;
  439. var
  440. Temp : string;
  441. new : TSplit80bitReal;
  442. fraczero, expmaximal, sign, outside_double : boolean;
  443. exp : smallint;
  444. d : double;
  445. i : longint;
  446. mantval : qword;
  447. begin
  448. if ppufile.change_endian then
  449. begin
  450. for i:=0 to 9 do
  451. new.bytes[i]:=e.bytes[9-i];
  452. e:=new;
  453. end;
  454. if sizeof(ext)=10 then
  455. begin
  456. ext:=pextended(@e)^;
  457. str(ext,result);
  458. exit;
  459. end;
  460. { extended, format (MSB): 1 Sign bit, 15 bit exponent, 64 bit mantissa }
  461. sign := (e.w and $8000) <> 0;
  462. expMaximal := (e.w and $7fff) = 32767;
  463. exp:=(e.w and $7fff) - 16383 - 63;
  464. fraczero := (e.cards[0] = 0) and
  465. ((e.cards[1] and $7fffffff) = 0);
  466. {$ifdef FPC_LITTLE_ENDIAN}
  467. mantval := qword(e.cards[0]) or (qword(e.cards[1]) shl 32);
  468. {$else not FPC_LITTLE_ENDIAN}
  469. mantval := (qword(e.cards[0]) shl 32) or qword(e.cards[1]);
  470. {$endif not FPC_LITTLE_ENDIAN}
  471. if expMaximal then
  472. if fraczero then
  473. if sign then
  474. temp := '-Inf'
  475. else temp := '+Inf'
  476. else temp := 'Nan'
  477. else
  478. begin
  479. d:=double(mantval);
  480. if sign then
  481. d:=-d;
  482. outside_double:=false;
  483. Try
  484. if exp > 0 then
  485. begin
  486. for i:=1 to exp do
  487. d:=d *2.0;
  488. end
  489. else if exp < 0 then
  490. begin
  491. for i:=1 to -exp do
  492. d:=d /2.0;
  493. end;
  494. Except
  495. outside_double:=true;
  496. end;
  497. if (mantval<>0) and (d=0.0) then
  498. outside_double:=true;
  499. if outside_double then
  500. begin
  501. Temp:='Extended value outside double bound';
  502. ext:=0.0;
  503. end
  504. else
  505. begin
  506. ext:=d;
  507. system.str(d,temp);
  508. end;
  509. end;
  510. result:=temp;
  511. end;
  512. {$POP}
  513. const has_errors : boolean = false;
  514. has_warnings : boolean = false;
  515. has_more_infos : boolean = false;
  516. procedure SetHasErrors;
  517. begin
  518. has_errors:=true;
  519. end;
  520. Procedure WriteError(const S : string);
  521. Begin
  522. system.Writeln(StdErr, S);
  523. SetHasErrors;
  524. End;
  525. procedure StrAppend(var st : string; const st2 : string);
  526. begin
  527. st:=st+st2;
  528. end;
  529. procedure tppudumpfile.RaiseAssertion(Code: Longint);
  530. begin
  531. WriteError('Internal Error ' + ToStr(Code));
  532. inherited RaiseAssertion(Code);
  533. end;
  534. Procedure WriteWarning(const S : string);
  535. var
  536. ss: string;
  537. Begin
  538. ss:='!! Warning: ' + S;
  539. if nostdout then
  540. system.Writeln(StdErr, ss)
  541. else
  542. system.Writeln(ss);
  543. has_warnings:=true;
  544. End;
  545. procedure Write(const s: string);
  546. begin
  547. if nostdout then exit;
  548. system.write(s);
  549. end;
  550. procedure Write(const params: array of const);
  551. var
  552. i: integer;
  553. { Last vtType define in rtl/inc/objpash.inc }
  554. const
  555. max_vttype = vtUnicodeString;
  556. begin
  557. if nostdout then exit;
  558. for i:=Low(params) to High(params) do
  559. { All vtType in
  560. vtInteger = 0;
  561. vtBoolean = 1;
  562. vtChar = 2;
  563. vtExtended = 3;
  564. vtString = 4;
  565. vtPointer = 5;
  566. vtPChar = 6;
  567. vtObject = 7;
  568. vtClass = 8;
  569. vtWideChar = 9;
  570. vtPWideChar = 10;
  571. vtAnsiString32 = 11; called vtAnsiString in objpas unit
  572. vtCurrency = 12;
  573. vtVariant = 13;
  574. vtInterface = 14;
  575. vtWideString = 15;
  576. vtInt64 = 16;
  577. vtQWord = 17;
  578. vtUnicodeString = 18;
  579. // vtAnsiString16 = 19; not yet used
  580. // vtAnsiString64 = 20; not yet used
  581. }
  582. with TVarRec(params[i]) do
  583. case VType of
  584. vtInteger: system.write(VInteger);
  585. vtBoolean: system.write(VBoolean);
  586. vtChar: system.write(VChar);
  587. vtExtended: system.write(VExtended^);
  588. vtString: system.write(VString^);
  589. vtPointer:
  590. begin
  591. { Not sure the display will be correct
  592. if sizeof pointer is not native }
  593. WriteWarning('Pointer constant');
  594. end;
  595. vtPChar: system.write(VPChar);
  596. vtObject:
  597. begin
  598. { Not sure the display will be correct
  599. if sizeof pointer is not native }
  600. WriteWarning('Object constant');
  601. end;
  602. vtClass:
  603. begin
  604. { Not sure the display will be correct
  605. if sizeof pointer is not native }
  606. WriteWarning('Class constant');
  607. end;
  608. vtWideChar: system.write(VWideChar);
  609. vtPWideChar:
  610. begin
  611. WriteWarning('PWideChar constant');
  612. end;
  613. vtAnsiString: system.write(ansistring(VAnsiString));
  614. vtCurrency : system.write(VCurrency^);
  615. vtVariant :
  616. begin
  617. { Not sure the display will be correct
  618. if sizeof pointer is not native }
  619. WriteWarning('Variant constant');
  620. end;
  621. vtInterface :
  622. begin
  623. { Not sure the display will be correct
  624. if sizeof pointer is not native }
  625. WriteWarning('Interface constant');
  626. end;
  627. vtWideString : system.write(widestring(VWideString));
  628. vtInt64: system.write(VInt64^);
  629. vtQWord: system.write(VQWord^);
  630. vtUnicodeString : system.write(unicodestring(VUnicodeString));
  631. else
  632. begin
  633. system.writeln;
  634. system.writeln('Unsupported var type: ', VType);
  635. Halt(10);
  636. end;
  637. end;
  638. end;
  639. procedure Writeln(const s: string = '');
  640. begin
  641. if nostdout then exit;
  642. system.writeln(s);
  643. end;
  644. procedure Writeln(const params: array of const);
  645. begin
  646. if nostdout then exit;
  647. Write(params);
  648. system.writeln;
  649. end;
  650. Procedure HasMoreInfos;
  651. begin
  652. Writeln('!! Entry has more information stored');
  653. has_more_infos:=true;
  654. end;
  655. function Unknown(const st : string; val :longint) : string;
  656. Begin
  657. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  658. SetHasErrors;
  659. end;
  660. function ToStr(w:longint):String;
  661. begin
  662. Str(w,ToStr);
  663. end;
  664. Function Target2Str(w:longint):string;
  665. begin
  666. if w<=ord(high(tsystem)) then
  667. Target2Str:=Targets[tsystem(w)]
  668. else
  669. Target2Str:=Unknown('target',w);
  670. end;
  671. Function Cpu2Str(w:longint):string;
  672. begin
  673. if w<=ord(high(tsystemcpu)) then
  674. begin
  675. cpu:=tsystemcpu(w);
  676. Cpu2Str:=CpuTxt[cpu];
  677. end
  678. else
  679. Cpu2Str:=Unknown('cpu',w);
  680. end;
  681. Function Varspez2Str(w:longint):string;
  682. const
  683. { in symconst unit
  684. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  685. varspezstr : array[tvarspez] of string[8]=('Value','Const','Var','Out','ConstRef','Final');
  686. begin
  687. if w<=ord(high(varspezstr)) then
  688. Varspez2Str:=varspezstr[tvarspez(w)]
  689. else
  690. Varspez2Str:=Unknown('varspez',w);
  691. end;
  692. Function VarRegable2Str(w:longint):string;
  693. { tvarregable type is defined in symconst unit }
  694. const
  695. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  696. begin
  697. if w<=ord(high(varregablestr)) then
  698. Varregable2Str:=varregablestr[tvarregable(w)]
  699. else
  700. Varregable2Str:=Unknown('regable',w);
  701. end;
  702. Function Visibility2Str(w:longint):string;
  703. const
  704. { tvisibility type is defined in symconst unit }
  705. visibilityName : array[tvisibility] of string[16] = (
  706. 'hidden','strict private','private','strict protected','protected',
  707. 'public','published','<none>'
  708. );
  709. begin
  710. if w<=ord(high(visibilityName)) then
  711. result:=visibilityName[tvisibility(w)]
  712. else
  713. result:=Unknown('visibility',w);
  714. end;
  715. Function IntfEntryType2Str(w:longint):string;
  716. const
  717. { tinterfaceentrytype type is defined in symconst unit }
  718. Name : array[tinterfaceentrytype] of string = (
  719. 'standard','virtual method result','static method result','field value','virtual method class',
  720. 'static method class','field value class'
  721. );
  722. begin
  723. if w<=ord(high(Name)) then
  724. result:=Name[tinterfaceentrytype(w)]
  725. else
  726. result:=Unknown('entry type',w);
  727. end;
  728. function PPUFlags2Str(flags:dword):string;
  729. type
  730. tflagopt=record
  731. mask : dword;
  732. str : string[30];
  733. end;
  734. const
  735. flagopts=32;
  736. flagopt : array[1..flagopts] of tflagopt=(
  737. (mask: $1 ;str:'init'),
  738. (mask: $2 ;str:'final'),
  739. (mask: $4 ;str:'big_endian'),
  740. (mask: $8 ;str:'dbx'),
  741. // (mask: $10 ;str:'browser'),
  742. (mask: $20 ;str:'in_library'),
  743. (mask: $40 ;str:'smart_linked'),
  744. (mask: $80 ;str:'static_linked'),
  745. (mask: $100 ;str:'shared_linked'),
  746. (mask: $200 ;str:'uses_checkpointer'),
  747. (mask: $400 ;str:'no_link'),
  748. (mask: $800 ;str:'has_resources'),
  749. (mask: $1000 ;str:'little_endian'),
  750. (mask: $2000 ;str:'release'),
  751. (mask: $4000 ;str:'local_threadvars'),
  752. (mask: $8000 ;str:'fpu_emulation_on'),
  753. (mask: $210000 ;str:'has_debug_info'),
  754. (mask: $10000 ;str:'stabs_debug_info'),
  755. (mask: $200000 ;str:'dwarf_debug_info'),
  756. (mask: $20000 ;str:'local_symtable'),
  757. (mask: $40000 ;str:'uses_variants'),
  758. (mask: $80000 ;str:'has_resourcefiles'),
  759. (mask: $100000 ;str:'has_exports'),
  760. (mask: $400000 ;str:'has_wideinits'),
  761. (mask: $800000 ;str:'has_classinits'),
  762. (mask: $1000000 ;str:'has_resstrinits'),
  763. (mask: $2000000 ;str:'i8086_far_code'),
  764. (mask: $4000000 ;str:'i8086_far_data'),
  765. (mask: $8000000 ;str:'i8086_huge_data'),
  766. (mask: $10000000;str:'i8086_cs_equals_ds'),
  767. (mask: $20000000;str:'package_deny'),
  768. (mask: $40000000;str:'package_weak'),
  769. (mask: dword($80000000);str:'i8086_ss_equals_ds')
  770. );
  771. var
  772. i : longint;
  773. ntflags : dword;
  774. first : boolean;
  775. s : string;
  776. begin
  777. s:='';
  778. ntflags:=flags;
  779. if flags<>0 then
  780. begin
  781. first:=true;
  782. for i:=1to flagopts do
  783. if (flags and flagopt[i].mask)<>0 then
  784. begin
  785. if first then
  786. first:=false
  787. else
  788. s:=s+', ';
  789. s:=s+flagopt[i].str;
  790. ntflags:=ntflags and (not flagopt[i].mask);
  791. end;
  792. end
  793. else
  794. s:='none';
  795. if ntflags<>0 then
  796. begin
  797. s:=s+' unknown '+hexstr(ntflags,8);
  798. SetHasErrors;
  799. end;
  800. PPUFlags2Str:=s;
  801. end;
  802. Function L0(l:longint):string;
  803. {
  804. return the string of value l, if l<10 then insert a zero, so
  805. the string is always at least 2 chars '01','02',etc
  806. }
  807. var
  808. s : string;
  809. begin
  810. Str(l,s);
  811. if l<10 then
  812. s:='0'+s;
  813. L0:=s;
  814. end;
  815. function filetimestring( t : longint) : string;
  816. {
  817. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  818. }
  819. var
  820. DT : TDateTime;
  821. hsec : word;
  822. Year,Month,Day: Word;
  823. hour,min,sec : word;
  824. begin
  825. if t=-1 then
  826. begin
  827. Result := 'Not Found';
  828. SetHasErrors;
  829. exit;
  830. end;
  831. DT := FileDateToDateTime(t);
  832. DecodeTime(DT,hour,min,sec,hsec);
  833. DecodeDate(DT,year,month,day);
  834. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  835. end;
  836. {****************************************************************************
  837. Read Routines
  838. ****************************************************************************}
  839. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;forward;
  840. procedure readrecsymtableoptions;
  841. var
  842. usefieldalignment : shortint;
  843. begin
  844. if ppufile.readentry<>ibrecsymtableoptions then
  845. begin
  846. SetHasErrors;
  847. exit;
  848. end;
  849. writeln([space,' recordalignment: ',shortint(ppufile.getbyte)]);
  850. usefieldalignment:=shortint(ppufile.getbyte);
  851. writeln([space,' usefieldalignment: ',usefieldalignment]);
  852. writeln([space,' recordalignmin: ',shortint(ppufile.getbyte)]);
  853. if (usefieldalignment=C_alignment) then
  854. writeln([space,' fieldalignment: ',shortint(ppufile.getbyte)]);
  855. readmanagementoperatoroptions(space,'Fields have MOPs');
  856. end;
  857. function readsymtableoptions(const s: string) : tsymtableoptions;
  858. type
  859. tsymtblopt=record
  860. mask : tsymtableoption;
  861. str : string[30];
  862. end;
  863. const
  864. symtblopts=ord(high(tsymtableoption)) + 1;
  865. symtblopt : array[1..symtblopts] of tsymtblopt=(
  866. (mask:sto_has_helper; str:'Has helper'),
  867. (mask:sto_has_generic; str:'Has generic'),
  868. (mask:sto_has_operator; str:'Has operator'),
  869. (mask:sto_needs_init_final;str:'Needs init final table'),
  870. (mask:sto_has_non_trivial_init;str:'Has non trivial init')
  871. );
  872. var
  873. options : tsymtableoptions;
  874. first : boolean;
  875. i : integer;
  876. begin
  877. if ppufile.readentry<>ibsymtableoptions then
  878. begin
  879. SetHasErrors;
  880. exit;
  881. end;
  882. ppufile.getsmallset(options);
  883. if space<>'' then
  884. writeln([space,'------ ',s,' ------']);
  885. write([space,'Symtable options: ']);
  886. if options<>[] then
  887. begin
  888. first:=true;
  889. for i:=1 to symtblopts do
  890. if (symtblopt[i].mask in options) then
  891. begin
  892. if first then
  893. first:=false
  894. else
  895. write(', ');
  896. write(symtblopt[i].str);
  897. end;
  898. end
  899. else
  900. write('none');
  901. writeln;
  902. readsymtableoptions:=options;
  903. end;
  904. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef); forward;
  905. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil); forward;
  906. procedure readsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  907. var
  908. stored_symtable_options : tsymtableoptions;
  909. begin
  910. stored_symtable_options:=current_symtable_options;
  911. current_symtable_options:=readsymtableoptions(s);
  912. readdefinitions(s, ParentDef);
  913. readsymbols(s, ParentDef);
  914. current_symtable_options:=stored_symtable_options;
  915. end;
  916. procedure readrecordsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  917. begin
  918. readrecsymtableoptions;
  919. readsymtable(s, ParentDef);
  920. end;
  921. Procedure ReadLinkContainer(const prefix:string);
  922. {
  923. Read a serie of strings and write to the screen starting every line
  924. with prefix
  925. }
  926. function maskstr(m:longint):string;
  927. { link options are in globtype unit
  928. const
  929. link_none = $0;
  930. link_always = $1;
  931. link_static = $2;
  932. link_smart = $4;
  933. link_shared = $8; }
  934. var
  935. s : string;
  936. begin
  937. s:='';
  938. if (m and link_always)<>0 then
  939. s:=s+'always ';
  940. if (m and link_static)<>0 then
  941. s:=s+'static ';
  942. if (m and link_smart)<>0 then
  943. s:=s+'smart ';
  944. if (m and link_shared)<>0 then
  945. s:=s+'shared ';
  946. maskstr:=s;
  947. end;
  948. var
  949. s : string;
  950. m : longint;
  951. begin
  952. while not ppufile.endofentry do
  953. begin
  954. s:=ppufile.getstring;
  955. m:=ppufile.getlongint;
  956. WriteLn([prefix,s,' (',maskstr(m),')']);
  957. end;
  958. end;
  959. Procedure ReadContainer(const prefix:string);
  960. {
  961. Read a series of strings and write to the screen starting every line
  962. with prefix
  963. }
  964. begin
  965. while not ppufile.endofentry do
  966. WriteLn([prefix,ppufile.getstring]);
  967. end;
  968. procedure ReadLoadUnit;
  969. var
  970. ucrc,uintfcrc, indcrc : cardinal;
  971. un: TPpuUnitDef;
  972. begin
  973. while not ppufile.EndOfEntry do
  974. begin
  975. un:=TPpuUnitDef.Create(CurUnit.UsedUnits);
  976. un.Name:=ppufile.getstring;
  977. write(['Uses unit: ',un.Name]);
  978. ucrc:=cardinal(ppufile.getlongint);
  979. uintfcrc:=cardinal(ppufile.getlongint);
  980. indcrc:=cardinal(ppufile.getlongint);
  981. writeln([' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')']);
  982. un.Crc:=ucrc;
  983. un.IntfCrc:=uintfcrc;
  984. end;
  985. end;
  986. Procedure ReadDerefmap;
  987. var
  988. i,mapsize : longint;
  989. s: string;
  990. begin
  991. mapsize:=ppufile.getlongint;
  992. writeln(['DerefMapsize: ',mapsize]);
  993. SetLength(CurUnit.RefUnits, mapsize);
  994. for i:=0 to mapsize-1 do
  995. begin
  996. s:=ppufile.getstring;
  997. writeln(['DerefMap[',i,'] = ',s]);
  998. CurUnit.RefUnits[i]:=LowerCase(s);
  999. end;
  1000. end;
  1001. Procedure ReadImportSymbols;
  1002. var
  1003. extlibname : string;
  1004. j,
  1005. extsymcnt : longint;
  1006. extsymname : string;
  1007. extsymmangledname : string;
  1008. extsymordnr : longint;
  1009. extsymisvar : boolean;
  1010. begin
  1011. while not ppufile.endofentry do
  1012. begin
  1013. extlibname:=ppufile.getstring;
  1014. extsymcnt:=ppufile.getlongint;
  1015. writeln(['External Library: ',extlibname,' (',extsymcnt,' imports)']);
  1016. for j:=0 to extsymcnt-1 do
  1017. begin
  1018. extsymname:=ppufile.getstring;
  1019. if ppuversion>130 then
  1020. extsymmangledname:=ppufile.getstring
  1021. else
  1022. extsymmangledname:=extsymname;
  1023. extsymordnr:=ppufile.getlongint;
  1024. extsymisvar:=ppufile.getbyte<>0;
  1025. writeln([' ',extsymname,' as ',extsymmangledname,
  1026. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')']);
  1027. end;
  1028. end;
  1029. end;
  1030. Procedure ReadDerefdata;
  1031. begin
  1032. derefdatalen:=ppufile.entrysize;
  1033. if derefdatalen=0 then
  1034. begin
  1035. Writeln(['No Derefdata length=0']);
  1036. derefdata:=nil;
  1037. exit;
  1038. end;
  1039. Writeln(['Derefdata length: ',derefdatalen]);
  1040. derefdata:=allocmem(derefdatalen);
  1041. ppufile.getdata(derefdata^,derefdatalen);
  1042. end;
  1043. Procedure FreeDerefdata;
  1044. begin
  1045. if assigned(derefdata) then
  1046. begin
  1047. FreeMem(derefdata);
  1048. derefdata:=nil;
  1049. derefdatalen:=0;
  1050. end;
  1051. end;
  1052. Procedure ReadWpoFileInfo;
  1053. begin
  1054. Writeln(['Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint)]);
  1055. end;
  1056. Procedure ReadAsmSymbols;
  1057. const
  1058. unitasmlisttype: array[tunitasmlisttype] of string[6]=(
  1059. 'PUBLIC',
  1060. 'EXTERN'
  1061. );
  1062. type
  1063. { Copied from aasmbase.pas }
  1064. TAsmsymbind=(
  1065. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  1066. { global in the current program/library, but not visible outside it }
  1067. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
  1068. { a symbol that's internal to the compiler and used as a temp }
  1069. AB_TEMP,
  1070. { a global symbol that points to another global symbol and is only used
  1071. to allow indirect loading in case of packages and indirect imports }
  1072. AB_INDIRECT,AB_EXTERNAL_INDIRECT);
  1073. TAsmsymtype=(
  1074. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  1075. {
  1076. the address of this code label is taken somewhere in the code
  1077. so it must be taken care of it when creating pic
  1078. }
  1079. AT_ADDR,
  1080. { Label for debug or other non-program information }
  1081. AT_METADATA,
  1082. { label for data that must always be accessed indirectly, because it
  1083. is handled explcitely in the system unit or (e.g. RTTI and threadvar
  1084. tables) -- never seen in an assembler/assembler writer, always
  1085. changed to AT_DATA }
  1086. AT_DATA_FORCEINDIRECT,
  1087. { don't generate an implicit indirect symbol as that might be provided
  1088. by other means (e.g. the typed const builder) to ensure a correct
  1089. section name }
  1090. AT_DATA_NOINDIRECT,
  1091. { Thread-local symbol (ELF targets) }
  1092. AT_TLS,
  1093. { GNU indirect function (ELF targets) }
  1094. AT_GNU_IFUNC
  1095. );
  1096. var
  1097. s,
  1098. bindstr,
  1099. typestr : string;
  1100. i : longint;
  1101. t: tunitasmlisttype;
  1102. begin
  1103. writeln([space,'Assembler Symbols']);
  1104. writeln([space,'-----------------']);
  1105. t:=tunitasmlisttype(ppufile.getbyte);
  1106. if (t>=Low(tunitasmlisttype)) and (t<=High(tunitasmlisttype)) then
  1107. typestr:=unitasmlisttype[t]
  1108. else
  1109. typestr:='UNKNOWN';
  1110. writeln([space,'Type: ',typestr]);
  1111. writeln([space,'Count: ',ppufile.getlongint]);
  1112. i:=0;
  1113. while (not ppufile.endofentry) and (not ppufile.error) do
  1114. begin
  1115. s:=ppufile.getstring;
  1116. case tasmsymbind(ppufile.getbyte) of
  1117. AB_EXTERNAL :
  1118. bindstr:='External';
  1119. AB_COMMON :
  1120. bindstr:='Common';
  1121. AB_LOCAL :
  1122. bindstr:='Local';
  1123. AB_GLOBAL :
  1124. bindstr:='Global';
  1125. AB_WEAK_EXTERNAL :
  1126. bindstr:='Weak external';
  1127. AB_PRIVATE_EXTERN :
  1128. bindstr:='Private extern';
  1129. AB_LAZY :
  1130. bindstr:='Lazy';
  1131. AB_IMPORT :
  1132. bindstr:='Import';
  1133. AB_TEMP :
  1134. bindstr:='Temp';
  1135. AB_INDIRECT :
  1136. bindstr:='Indirect';
  1137. AB_EXTERNAL_INDIRECT :
  1138. bindstr:='Indirect external';
  1139. else
  1140. begin
  1141. bindstr:='<Error !!>';
  1142. SetHasErrors;
  1143. end;
  1144. end;
  1145. case tasmsymtype(ppufile.getbyte) of
  1146. AT_FUNCTION :
  1147. typestr:='Function';
  1148. AT_DATA :
  1149. typestr:='Data';
  1150. AT_SECTION :
  1151. typestr:='Section';
  1152. AT_LABEL :
  1153. typestr:='Label';
  1154. AT_ADDR :
  1155. typestr:='Label (with address taken)';
  1156. AT_METADATA :
  1157. typestr:='Metadata';
  1158. { this shouldn't appear in a PPU }
  1159. AT_DATA_FORCEINDIRECT :
  1160. typestr:='Data (ForceIndirect)';
  1161. { this shouldn't appear in a PPU }
  1162. AT_DATA_NOINDIRECT:
  1163. typestr:='Data (NoIndirect)';
  1164. AT_TLS :
  1165. typestr:='TLS';
  1166. AT_GNU_IFUNC :
  1167. typestr:='GNU IFUNC';
  1168. else
  1169. begin
  1170. typestr:='<Error !!>';
  1171. SetHasErrors;
  1172. end;
  1173. end;
  1174. Writeln([space,' ',i,' : ',s,' [',bindstr,',',typestr,']']);
  1175. inc(i);
  1176. end;
  1177. writeln([space]);
  1178. end;
  1179. function getexprint:Tconstexprint;
  1180. begin
  1181. getexprint.overflow:=false;
  1182. getexprint.signed:=ppufile.getboolean;
  1183. getexprint.svalue:=ppufile.getint64;
  1184. end;
  1185. Procedure ReadPosInfo(Def: TPpuDef = nil);
  1186. var
  1187. info : byte;
  1188. fileindex,line,column : longint;
  1189. begin
  1190. with ppufile do
  1191. begin
  1192. fileindex:=0;
  1193. line:=0;
  1194. column:=0;
  1195. {
  1196. info byte layout in bits:
  1197. 0-1 - amount of bytes for fileindex
  1198. 2-3 - amount of bytes for line
  1199. 4-5 - amount of bytes for column
  1200. }
  1201. info:=getbyte;
  1202. case (info and $03) of
  1203. 0 : fileindex:=getbyte;
  1204. 1 : fileindex:=getword;
  1205. 2 : fileindex:=(getbyte shl 16) or getword;
  1206. 3 : fileindex:=getlongint;
  1207. end;
  1208. case ((info shr 2) and $03) of
  1209. 0 : line:=getbyte;
  1210. 1 : line:=getword;
  1211. 2 : line:=(getbyte shl 16) or getword;
  1212. 3 : line:=getlongint;
  1213. end;
  1214. case ((info shr 4) and $03) of
  1215. 0 : column:=getbyte;
  1216. 1 : column:=getword;
  1217. 2 : column:=(getbyte shl 16) or getword;
  1218. 3 : column:=getlongint;
  1219. end;
  1220. Writeln([fileindex,' (',line,',',column,')']);
  1221. if Def <> nil then
  1222. begin
  1223. Def.FilePos.FileIndex:=fileindex;
  1224. Def.FilePos.Line:=line;
  1225. Def.FilePos.Col:=column;
  1226. end;
  1227. end;
  1228. end;
  1229. procedure readderef(const derefspace: string; Ref: TPpuRef = nil);
  1230. var
  1231. b : tdereftype;
  1232. first : boolean;
  1233. idx : longint;
  1234. i,n : byte;
  1235. pdata : pbyte;
  1236. begin
  1237. if not assigned(derefdata) then
  1238. exit;
  1239. first:=true;
  1240. idx:=ppufile.getlongint;
  1241. if idx = -1 then
  1242. begin
  1243. writeln('Nil');
  1244. exit;
  1245. end;
  1246. if (idx>derefdatalen) then
  1247. begin
  1248. WriteError('!! Error: Deref idx '+IntToStr(idx)+' > '+IntToStr(derefdatalen));
  1249. exit;
  1250. end;
  1251. write([derefspace,'(',idx,') ']);
  1252. pdata:=@derefdata[idx];
  1253. i:=0;
  1254. n:=pdata[i];
  1255. inc(i);
  1256. if n<1 then
  1257. begin
  1258. WriteError('!! Error: Deref len < 1');
  1259. exit;
  1260. end;
  1261. while (i<=n) do
  1262. begin
  1263. if not first then
  1264. write(', ')
  1265. else
  1266. first:=false;
  1267. b:=tdereftype(pdata[i]);
  1268. inc(i);
  1269. case b of
  1270. deref_nil :
  1271. write('Nil');
  1272. deref_symid :
  1273. begin
  1274. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1275. inc(i,4);
  1276. write(['SymId ',idx]);
  1277. if Ref <> nil then
  1278. Ref.Id:=idx;
  1279. end;
  1280. deref_defid :
  1281. begin
  1282. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1283. inc(i,4);
  1284. write(['DefId ',idx]);
  1285. if Ref <> nil then
  1286. Ref.Id:=idx;
  1287. end;
  1288. deref_unit :
  1289. begin
  1290. idx:=pdata[i] shl 8 or pdata[i+1];
  1291. inc(i,2);
  1292. write(['Unit ',idx]);
  1293. if Ref <> nil then
  1294. Ref.UnitIndex:=idx;
  1295. end;
  1296. else
  1297. begin
  1298. WriteError('!! unsupported dereftyp: '+IntToStr(ord(b)));
  1299. break;
  1300. end;
  1301. end;
  1302. end;
  1303. writeln;
  1304. end;
  1305. Procedure ReadUnitImportSyms;
  1306. var
  1307. c,i : longint;
  1308. begin
  1309. writeln([space,'Imported Symbols']);
  1310. writeln([space,'----------------']);
  1311. c:=ppufile.getlongint;
  1312. for i:=0 to c-1 do
  1313. readderef(space);
  1314. writeln([space]);
  1315. end;
  1316. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1317. { type tsltype is in symconst unit }
  1318. const
  1319. slstr : array[tsltype] of string[12] = (
  1320. '',
  1321. 'load',
  1322. 'call',
  1323. 'subscript',
  1324. 'vec',
  1325. 'typeconv',
  1326. 'absolutetype'
  1327. );
  1328. var
  1329. sl : tsltype;
  1330. begin
  1331. readderef('',Ref);
  1332. repeat
  1333. sl:=tsltype(ppufile.getbyte);
  1334. if sl=sl_none then
  1335. break;
  1336. write([s,'(',slstr[sl],') ']);
  1337. case sl of
  1338. sl_call,
  1339. sl_load,
  1340. sl_subscript :
  1341. if (Ref <> nil) and (Ref.IsNull) then
  1342. begin
  1343. readderef('',Ref);
  1344. Ref.IsSymId:=True;
  1345. end
  1346. else
  1347. readderef('');
  1348. sl_absolutetype,
  1349. sl_typeconv :
  1350. readderef('');
  1351. sl_vec :
  1352. begin
  1353. writeln([ppufile.getlongint]);
  1354. readderef('');
  1355. end;
  1356. end;
  1357. until false;
  1358. end;
  1359. (*
  1360. talignmentinfo = packed record
  1361. procalign,
  1362. loopalign,
  1363. jumpalign,
  1364. constalignmin,
  1365. constalignmax,
  1366. varalignmin,
  1367. varalignmax,
  1368. localalignmin,
  1369. localalignmax,
  1370. recordalignmin,
  1371. recordalignmax,
  1372. maxCrecordalign : longint;
  1373. end;
  1374. tsettings = packed record
  1375. alignment : talignmentinfo;
  1376. globalswitches : tglobalswitches;
  1377. moduleswitches : tmoduleswitches;
  1378. localswitches : tlocalswitches;
  1379. modeswitches : tmodeswitches;
  1380. optimizerswitches : toptimizerswitches;
  1381. { generate information necessary to perform these wpo's during a subsequent compilation }
  1382. genwpoptimizerswitches: twpoptimizerswitches;
  1383. { perform these wpo's using information generated during a previous compilation }
  1384. dowpoptimizerswitches: twpoptimizerswitches;
  1385. debugswitches : tdebugswitches;
  1386. { 0: old behaviour for sets <=256 elements
  1387. >0: round to this size }
  1388. setalloc,
  1389. packenum : shortint;
  1390. packrecords : shortint;
  1391. maxfpuregisters : shortint;
  1392. cputype,
  1393. optimizecputype : tcputype;
  1394. fputype : tfputype;
  1395. asmmode : tasmmode;
  1396. interfacetype : tinterfacetypes;
  1397. defproccall : tproccalloption;
  1398. sourcecodepage : tcodepagestring;
  1399. minfpconstprec : tfloattype;
  1400. disabledircache : boolean;
  1401. { CPU targets with microcontroller support can add a controller specific unit }
  1402. controllertype : tcontrollertype;
  1403. { WARNING: this pointer cannot be written as such in record token }
  1404. pmessage : pmessagestaterecord;
  1405. end;
  1406. *)
  1407. procedure readprocinfooptions(space : string);
  1408. (*
  1409. tprocinfoflag=(
  1410. { procedure has at least one assembler block }
  1411. pi_has_assembler_block,
  1412. { procedure does a call }
  1413. pi_do_call,
  1414. { procedure has a try statement = no register optimization }
  1415. pi_uses_exceptions,
  1416. { procedure is declared as @var(assembler), don't optimize}
  1417. pi_is_assembler,
  1418. { procedure contains data which needs to be finalized }
  1419. pi_needs_implicit_finally,
  1420. { procedure has the implicit try..finally generated }
  1421. pi_has_implicit_finally,
  1422. { procedure uses fpu}
  1423. pi_uses_fpu,
  1424. { procedure uses GOT for PIC code }
  1425. pi_needs_got,
  1426. { references var/proc/type/const in static symtable,
  1427. i.e. not allowed for inlining from other units }
  1428. pi_uses_static_symtable,
  1429. { set if the procedure has to push parameters onto the stack }
  1430. pi_has_stackparameter,
  1431. { set if the procedure has at least one label }
  1432. pi_has_label,
  1433. { calls itself recursive }
  1434. pi_is_recursive,
  1435. { stack frame optimization not possible (only on x86 probably) }
  1436. pi_needs_stackframe,
  1437. { set if the procedure has at least one register saved on the stack }
  1438. pi_has_saved_regs,
  1439. { dfa was generated for this proc }
  1440. pi_dfaavailable,
  1441. { subroutine contains interprocedural used labels }
  1442. pi_has_interproclabel,
  1443. { subroutine contains interprocedural gotos }
  1444. pi_has_global_goto
  1445. ); *)
  1446. type
  1447. tprocinfoopt=record
  1448. mask : tprocinfoflag;
  1449. str : string[81];
  1450. end;
  1451. const
  1452. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1453. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1454. (mask:pi_has_assembler_block;
  1455. str:' has at least one assembler block'),
  1456. (mask:pi_do_call;
  1457. str:' does a call'),
  1458. (mask:pi_uses_exceptions;
  1459. str:' has a try statement = no register optimization '),
  1460. (mask:pi_is_assembler;
  1461. str:' is declared as @var(assembler), don''t optimize'),
  1462. (mask:pi_needs_implicit_finally;
  1463. str:' contains data which needs to be finalized '),
  1464. (mask:pi_has_implicit_finally;
  1465. str:' has the implicit try..finally generated '),
  1466. (mask:pi_uses_fpu;
  1467. str:' uses fpu'),
  1468. (mask:pi_needs_got;
  1469. str:' uses GOT for PIC code '),
  1470. (mask:pi_uses_static_symtable;
  1471. str:' references var/proc/type/const in static symtable'),
  1472. (mask:pi_has_stackparameter;
  1473. str:' set if the procedure has to push parameters onto the stack '),
  1474. (mask:pi_has_label;
  1475. str:' set if the procedure has at least one label '),
  1476. (mask:pi_is_recursive;
  1477. str:' calls itself recursive '),
  1478. (mask:pi_needs_stackframe;
  1479. str:' stack frame optimization not possible (only on x86 probably) '),
  1480. (mask:pi_has_saved_regs;
  1481. str:' set if the procedure has at least one register saved on the stack '),
  1482. (mask:pi_dfaavailable;
  1483. str:' dfa was generated for this proc '),
  1484. (mask:pi_has_interproclabel;
  1485. str:' subroutine contains interprocedural used labels '),
  1486. (mask:pi_has_unwind_info;
  1487. str:' unwinding info was generated for this proc '),
  1488. (mask:pi_has_global_goto;
  1489. str:' subroutine contains interprocedural goto '),
  1490. (mask:pi_has_inherited;
  1491. str:' subroutine contains inherited call '),
  1492. (mask:pi_has_nested_exit;
  1493. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1494. (mask:pi_has_stack_allocs;
  1495. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1496. (mask:pi_estimatestacksize;
  1497. str:' stack size is estimated before subroutine is compiled '),
  1498. (mask:pi_calls_c_varargs;
  1499. str:' calls function with C-style varargs '),
  1500. (mask:pi_has_open_array_parameter;
  1501. str:' has open array parameter ')
  1502. );
  1503. var
  1504. procinfooptions : tprocinfoflags;
  1505. i : longint;
  1506. first : boolean;
  1507. begin
  1508. ppufile.getsmallset(procinfooptions);
  1509. if procinfooptions<>[] then
  1510. begin
  1511. first:=true;
  1512. for i:=0 to procinfoopts do
  1513. if (procinfoopt[i].mask in procinfooptions) then
  1514. begin
  1515. if first then
  1516. first:=false
  1517. else
  1518. write(', ');
  1519. write(procinfoopt[i].str);
  1520. end;
  1521. end;
  1522. writeln;
  1523. end;
  1524. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1525. type
  1526. tsymopt=record
  1527. mask : tsymoption;
  1528. str : string[30];
  1529. end;
  1530. const
  1531. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1532. { sp_none = 0 corresponds to nothing }
  1533. symopt : array[1..symopts] of tsymopt=(
  1534. (mask:sp_static; str:'Static'),
  1535. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1536. (mask:sp_hint_platform; str:'Hint Platform'),
  1537. (mask:sp_hint_library; str:'Hint Library'),
  1538. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1539. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1540. (mask:sp_has_overloaded; str:'Has overloaded'),
  1541. (mask:sp_internal; str:'Internal'),
  1542. (mask:sp_implicitrename; str:'Implicit Rename'),
  1543. (mask:sp_generic_para; str:'Generic Parameter'),
  1544. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1545. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1546. (mask:sp_explicitrename; str:'Explicit Rename')
  1547. );
  1548. var
  1549. symoptions : tsymoptions;
  1550. i : longint;
  1551. first : boolean;
  1552. begin
  1553. ppufile.getsmallset(symoptions);
  1554. if symoptions<>[] then
  1555. begin
  1556. if Def <> nil then
  1557. if sp_internal in symoptions then
  1558. Def.Visibility:=dvHidden;
  1559. first:=true;
  1560. for i:=1to symopts do
  1561. if (symopt[i].mask in symoptions) then
  1562. begin
  1563. if first then
  1564. first:=false
  1565. else
  1566. write(', ');
  1567. write(symopt[i].str);
  1568. end;
  1569. end;
  1570. writeln;
  1571. if sp_has_deprecated_msg in symoptions then
  1572. writeln([space,'Deprecated : ', ppufile.getstring]);
  1573. end;
  1574. procedure readvisibility(Def: TPpuDef = nil);
  1575. var
  1576. i: byte;
  1577. begin
  1578. i:=ppufile.getbyte;
  1579. if Def <> nil then
  1580. case tvisibility(i) of
  1581. vis_public: Def.Visibility:=dvPublic;
  1582. vis_published: Def.Visibility:=dvPublished;
  1583. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1584. else Def.Visibility:=dvPrivate;
  1585. end;
  1586. writeln(Visibility2Str(i));
  1587. end;
  1588. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1589. var
  1590. i: integer;
  1591. n: string;
  1592. begin
  1593. n:=ppufile.getstring;
  1594. if Def <> nil then
  1595. Def.Name:=n;
  1596. i:=ppufile.getlongint;
  1597. if Def <> nil then
  1598. Def.SetSymId(i);
  1599. writeln([space,'** Symbol Id ',i,' **']);
  1600. writeln([space,s,n]);
  1601. write ([space,' File Pos : ']);
  1602. readposinfo(Def);
  1603. write ([space,' Visibility : ']);
  1604. readvisibility(Def);
  1605. write ([space,' SymOptions : ']);
  1606. readsymoptions(space+' ',Def);
  1607. end;
  1608. procedure readcgpara(const space:string);
  1609. { this is originally in cgbase.pas }
  1610. type
  1611. TCGLoc=(LOC_INVALID, LOC_VOID, LOC_CONSTANT, LOC_JUMP, LOC_FLAGS,
  1612. LOC_REGISTER, LOC_CREGISTER, LOC_FPUREGISTER, LOC_CFPUREGISTER,
  1613. LOC_MMXREGISTER, LOC_CMMXREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  1614. LOC_SUBSETREG, LOC_CSUBSETREG, LOC_SUBSETREF, LOC_CSUBSETREF,
  1615. LOC_CREFERENCE, LOC_REFERENCE);
  1616. const
  1617. tcgloc2str : array[TCGLoc] of string[12] = (
  1618. 'LOC_INVALID', 'LOC_VOID', 'LOC_CONST', 'LOC_JUMP', 'LOC_FLAGS',
  1619. 'LOC_REG', 'LOC_CREG', 'LOC_FPUREG', 'LOC_CFPUREG',
  1620. 'LOC_MMXREG', 'LOC_CMMXREG', 'LOC_MMREG', 'LOC_CMMREG',
  1621. 'LOC_SSETREG', 'LOC_CSSETREG', 'LOC_SSETREF', 'LOC_CSSETREF',
  1622. 'LOC_CREF', 'LOC_REF');
  1623. var
  1624. i: byte;
  1625. ii: longint;
  1626. np: byte;
  1627. loc: tcgloc;
  1628. begin
  1629. i:=ppufile.getbyte;
  1630. writeln([space,' Alignment : ',i]);
  1631. i:=ppufile.getbyte;
  1632. writeln([space,' Size : ',i]);
  1633. ii:=ppufile.getaint;
  1634. writeln([space,' IntSize : ',ii]);
  1635. readderef(space+' ');
  1636. np:=ppufile.getbyte;
  1637. writeln([space,' NumParaloc : ',np]);
  1638. while np > 0 do
  1639. begin
  1640. i:=ppufile.getbyte;
  1641. writeln([space,' Paraloc Size : ',i]);
  1642. loc:=tcgloc(ppufile.getbyte);
  1643. if loc > high(tcgloc) then
  1644. begin
  1645. WriteError('!! Location is out of range! '+IntToStr(ord(loc)));
  1646. loc:=LOC_INVALID;
  1647. end;
  1648. writeln([space,' Paraloc Loc : (',ord(loc),') ',tcgloc2str[loc]]);
  1649. case loc of
  1650. LOC_REFERENCE:
  1651. begin
  1652. writeln([space,' RegIndex : $',hexstr(ppufile.getdword,8)]);
  1653. writeln([space,' Offset : ',ppufile.getaint]);
  1654. end;
  1655. LOC_FPUREGISTER,
  1656. LOC_CFPUREGISTER,
  1657. LOC_MMREGISTER,
  1658. LOC_CMMREGISTER,
  1659. LOC_REGISTER,
  1660. LOC_CREGISTER :
  1661. begin
  1662. writeln([space,' ShiftVal : ',ppufile.getbyte]);
  1663. writeln([space,' Register : $',hexstr(ppufile.getdword,8)]);
  1664. end;
  1665. LOC_VOID:
  1666. begin end
  1667. else
  1668. WriteError('!! Invalid location error')
  1669. end;
  1670. dec(np);
  1671. end;
  1672. end;
  1673. procedure displaytokenbuffer(tokenbuf : pbyte;tokenbufsize : longint);
  1674. type
  1675. ptoken=^ttoken;
  1676. pmsgstate =^tmsgstate;
  1677. var
  1678. tbi : longint;
  1679. state : tmsgstate;
  1680. prev_settings, new_settings : Tsettings;
  1681. nb, msgvalue, mesgnb : longint;
  1682. function readtoken: ttoken;
  1683. var
  1684. b,b2 : byte;
  1685. begin
  1686. b:=tokenbuf[tbi];
  1687. inc(tbi);
  1688. if (b and $80)<>0 then
  1689. begin
  1690. b2:=tokenbuf[tbi];
  1691. inc(tbi);
  1692. result:=ttoken(((b and $7f) shl 8) or b2);
  1693. end
  1694. else
  1695. result:=ttoken(b);
  1696. end;
  1697. function gettokenbufdword : dword;
  1698. var
  1699. var32 : dword;
  1700. begin
  1701. var32:=unaligned(pdword(@tokenbuf[tbi])^);
  1702. inc(tbi,sizeof(dword));
  1703. if ppufile.change_endian then
  1704. var32:=swapendian(var32);
  1705. result:=var32;
  1706. end;
  1707. function gettokenbufword : word;
  1708. var
  1709. var16 : word;
  1710. begin
  1711. var16:=unaligned(pword(@tokenbuf[tbi])^);
  1712. inc(tbi,sizeof(word));
  1713. if ppufile.change_endian then
  1714. var16:=swapendian(var16);
  1715. result:=var16;
  1716. end;
  1717. function gettokenbuflongint : longint;
  1718. var
  1719. var32 : longint;
  1720. begin
  1721. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1722. inc(tbi,sizeof(longint));
  1723. if ppufile.change_endian then
  1724. var32:=swapendian(var32);
  1725. result:=var32;
  1726. end;
  1727. function gettokenbufshortint : shortint;
  1728. var
  1729. var8 : shortint;
  1730. begin
  1731. var8:=pshortint(@tokenbuf[tbi])^;
  1732. inc(tbi,sizeof(shortint));
  1733. result:=var8;
  1734. end;
  1735. procedure tokenreadset(var b;size : longint);
  1736. var
  1737. i : longint;
  1738. begin
  1739. move(tokenbuf[tbi],b,size);
  1740. inc(tbi,size);
  1741. if ppufile.change_endian then
  1742. for i:=0 to size-1 do
  1743. Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
  1744. end;
  1745. function gettokenbufbyte : byte;
  1746. begin
  1747. result:=pbyte(@tokenbuf[tbi])^;
  1748. inc(tbi);
  1749. end;
  1750. function tokenreadenum(size : longint) : longword;
  1751. begin
  1752. if size=1 then
  1753. result:=gettokenbufbyte
  1754. else if size=2 then
  1755. result:=gettokenbufword
  1756. else if size=4 then
  1757. result:=gettokenbufdword;
  1758. end;
  1759. function gettokenbufsizeint : int64;
  1760. var
  1761. var64 : int64;
  1762. var32 : longint;
  1763. var16 : smallint;
  1764. begin
  1765. if CpuAddrBitSize[cpu]=64 then
  1766. begin
  1767. var64:=unaligned(pint64(@tokenbuf[tbi])^);
  1768. inc(tbi,sizeof(int64));
  1769. if ppufile.change_endian then
  1770. var64:=swapendian(var64);
  1771. result:=var64;
  1772. end
  1773. else if CpuAddrBitSize[cpu]=32 then
  1774. begin
  1775. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1776. inc(tbi,sizeof(longint));
  1777. if ppufile.change_endian then
  1778. var32:=swapendian(var32);
  1779. result:=var32;
  1780. end
  1781. else if CpuAddrBitSize[cpu]=16 then
  1782. begin
  1783. { ASizeInt is still a longint, see globtype.pas unit }
  1784. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1785. inc(tbi,sizeof(longint));
  1786. if ppufile.change_endian then
  1787. var32:=swapendian(var32);
  1788. result:=var32;
  1789. end
  1790. else
  1791. begin
  1792. WriteError('Wrong CpuAddrBitSize');
  1793. result:=0;
  1794. end;
  1795. end;
  1796. procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
  1797. { This procedure
  1798. needs to be changed whenever
  1799. globals.tsettings type is changed,
  1800. the problem is that no error will appear
  1801. before tests with generics are tested. PM }
  1802. var
  1803. startpos, endpos : longword;
  1804. begin
  1805. { WARNING all those fields need to be in the correct
  1806. order otherwise cross_endian PPU reading will fail }
  1807. startpos:=tbi;
  1808. with asettings do
  1809. begin
  1810. alignment.procalign:=gettokenbuflongint;
  1811. alignment.loopalign:=gettokenbuflongint;
  1812. alignment.jumpalign:=gettokenbuflongint;
  1813. alignment.constalignmin:=gettokenbuflongint;
  1814. alignment.constalignmax:=gettokenbuflongint;
  1815. alignment.varalignmin:=gettokenbuflongint;
  1816. alignment.varalignmax:=gettokenbuflongint;
  1817. alignment.localalignmin:=gettokenbuflongint;
  1818. alignment.localalignmax:=gettokenbuflongint;
  1819. alignment.recordalignmin:=gettokenbuflongint;
  1820. alignment.recordalignmax:=gettokenbuflongint;
  1821. alignment.maxCrecordalign:=gettokenbuflongint;
  1822. tokenreadset(globalswitches,sizeof(globalswitches));
  1823. tokenreadset(targetswitches,sizeof(targetswitches));
  1824. tokenreadset(moduleswitches,sizeof(moduleswitches));
  1825. tokenreadset(localswitches,sizeof(localswitches));
  1826. tokenreadset(modeswitches,sizeof(modeswitches));
  1827. tokenreadset(optimizerswitches,sizeof(optimizerswitches));
  1828. tokenreadset(genwpoptimizerswitches,sizeof(genwpoptimizerswitches));
  1829. tokenreadset(dowpoptimizerswitches,sizeof(dowpoptimizerswitches));
  1830. tokenreadset(debugswitches,sizeof(debugswitches));
  1831. { 0: old behaviour for sets <=256 elements
  1832. >0: round to this size }
  1833. setalloc:=gettokenbufshortint;
  1834. packenum:=gettokenbufshortint;
  1835. packrecords:=gettokenbufshortint;
  1836. maxfpuregisters:=gettokenbufshortint;
  1837. cputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1838. optimizecputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1839. fputype:=tfputype(tokenreadenum(sizeof(tfputype)));
  1840. asmmode:=tasmmode(tokenreadenum(sizeof(tasmmode)));
  1841. interfacetype:=tinterfacetypes(tokenreadenum(sizeof(tinterfacetypes)));
  1842. defproccall:=tproccalloption(tokenreadenum(sizeof(tproccalloption)));
  1843. { tstringencoding is word type,
  1844. thus this should be OK here }
  1845. sourcecodepage:=tstringEncoding(gettokenbufword);
  1846. minfpconstprec:=tfloattype(tokenreadenum(sizeof(tfloattype)));
  1847. disabledircache:=boolean(gettokenbufbyte);
  1848. { TH: Since the field was conditional originally, it was not stored in PPUs. }
  1849. { While adding ControllerSupport constant, I decided not to store ct_none }
  1850. { on targets not supporting controllers, but this might be changed here and }
  1851. { in tokenwritesettings in the future to unify the PPU structure and handling }
  1852. { of this field in the compiler. }
  1853. {$PUSH}
  1854. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1855. if CpuHasController[cpu] then
  1856. controllertype:=tcontrollertype(tokenreadenum(sizeof(tcontrollertype)))
  1857. else
  1858. ControllerType:=ct_none;
  1859. {$POP}
  1860. endpos:=tbi;
  1861. if endpos-startpos<>expected_size then
  1862. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  1863. end;
  1864. end;
  1865. procedure dump_new_settings;
  1866. (* tsettings = record
  1867. alignment : talignmentinfo;
  1868. globalswitches : tglobalswitches;
  1869. targetswitches : ttargetswitches;
  1870. moduleswitches : tmoduleswitches;
  1871. localswitches : tlocalswitches;
  1872. modeswitches : tmodeswitches;
  1873. optimizerswitches : toptimizerswitches;
  1874. { generate information necessary to perform these wpo's during a subsequent compilation }
  1875. genwpoptimizerswitches: twpoptimizerswitches;
  1876. { perform these wpo's using information generated during a previous compilation }
  1877. dowpoptimizerswitches: twpoptimizerswitches;
  1878. debugswitches : tdebugswitches;
  1879. { 0: old behaviour for sets <=256 elements
  1880. >0: round to this size }
  1881. setalloc,
  1882. packenum : shortint;
  1883. packrecords : shortint;
  1884. maxfpuregisters : shortint;
  1885. cputype,
  1886. optimizecputype,
  1887. asmcputype : tcputype;
  1888. fputype : tfputype;
  1889. asmmode : tasmmode;
  1890. interfacetype : tinterfacetypes;
  1891. defproccall : tproccalloption;
  1892. sourcecodepage : tstringencoding;
  1893. minfpconstprec : tfloattype;
  1894. disabledircache : boolean;
  1895. tlsmodel : ttlsmodel;
  1896. {$if defined(i8086)}
  1897. x86memorymodel : tx86memorymodel;
  1898. {$endif defined(i8086)}
  1899. {$if defined(ARM)}
  1900. instructionset : tinstructionset;
  1901. {$endif defined(ARM)}
  1902. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  1903. llvmversion: tllvmversion;
  1904. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  1905. { CPU targets with microcontroller support can add a controller specific unit }
  1906. controllertype : tcontrollertype;
  1907. { WARNING: this pointer cannot be written as such in record token }
  1908. pmessage : pmessagestaterecord;
  1909. end; *)
  1910. const
  1911. targetswitchname : array[ttargetswitch] of string[30] =
  1912. { global target-specific switches }
  1913. ('Target None', {ts_none}
  1914. { generate code that results in smaller TOCs than normal (AIX) }
  1915. 'Small TOC', {ts_small_toc}
  1916. { for the JVM target: generate integer array initializations via string
  1917. constants in order to reduce the generated code size (Java routines
  1918. are limited to 64kb of bytecode) }
  1919. 'JVM compact int array init', {ts_compact_int_array_init}
  1920. { for the JVM target: intialize enum fields in constructors with the
  1921. enum class instance corresponding to ordinal value 0 (not done by
  1922. default because this initialization can only be performed after the
  1923. inherited constructors have run, and if they call a virtual method
  1924. of the current class, then this virtual method may already have
  1925. initialized that field with another value and the constructor
  1926. initialization will result in data loss }
  1927. 'JVM enum field init', {ts_jvm_enum_field_init}
  1928. { when automatically generating getters/setters for properties, use
  1929. these strings as prefixes for the generated getters/setter names }
  1930. 'Auto getter prefix', {ts_auto_getter_prefix}
  1931. 'Auto setter prefix', {ts_auto_setter_predix}
  1932. 'Thumb interworking', {ts_thumb_interworking,}
  1933. { lowercase the first character of routine names, used to generate
  1934. names that are compliant with Java coding standards from code
  1935. written according to Delphi coding standards }
  1936. 'LowerCase proc start', {ts_lowercase_proc_start,}
  1937. { initialise local variables on the JVM target so you won't get
  1938. accidental uses of uninitialised values }
  1939. 'Init locals', {ts_init_locals}
  1940. { emit a CLD instruction before using the x86 string instructions }
  1941. 'Emit CLD instruction', {ts_cld}
  1942. { increment BP before pushing it in the function prologue and decrement
  1943. it after popping it in the function epilogue, iff the function is
  1944. going to terminate with a far ret. Thus, the BP value pushed on the
  1945. stack becomes odd if the function is far and even if the function is
  1946. near. This allows walking the BP chain on the stack and e.g.
  1947. obtaining a stack trace even if the program uses a mixture of near
  1948. and far calls. This is also required for Win16 real mode, because it
  1949. allows Windows to move code segments around (in order to defragment
  1950. memory) and then walk through the stacks of all running programs and
  1951. update the segment values of the segment that has moved. }
  1952. 'Use odd BP for far procs' {ts_x86_far_procs_push_odd_bp}
  1953. );
  1954. moduleswitchname : array[tmoduleswitch] of string[40] =
  1955. ('Module None', {cs_modulenone,}
  1956. { parser }
  1957. 'Floating Point Emulation',{ cs_fp_emulation}
  1958. 'Extended syntax', {cs_extsyntax}
  1959. 'Open string', {cs_openstring}
  1960. { support }
  1961. 'Goto allowed', {cs_support_goto}
  1962. 'Macro support', {cs_support_macro}
  1963. 'C operator support', {cs_support_c_operators}
  1964. { generation }
  1965. 'Profile', {cs_profile}
  1966. 'Debug information', {cs_debuginfo}
  1967. 'Compilation of System unit', {cs_compilesystem}
  1968. 'Line information', {cs_lineinfo}
  1969. 'Implicit exceptions', {cs_implicit_exceptions}
  1970. 'Explicit CodePage', {cs_explicit_codepage}
  1971. 'System CodePage', {cs_system_codepage}
  1972. { linking }
  1973. 'Create smart units', {cs_create_smart}
  1974. 'Create dynamic', {cs_create_dynamic}
  1975. 'Create PIC code', {cs_create_pic}
  1976. { browser switches are back }
  1977. 'Browser', {cs_browser}
  1978. 'Local Browser', {cs_local_browser}
  1979. { target specific }
  1980. 'Executable Stack', {cs_executable_stack}
  1981. { i8086 specific }
  1982. 'Hude code', {cs_huge_code}
  1983. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  1984. { Record usage of checkpointer experimental feature }
  1985. 'CheckPointer used' {cs_checkpointer_called}
  1986. );
  1987. globalswitchname : array[tglobalswitch] of string[50] =
  1988. ('Global None',{cs_globalnone}
  1989. { parameter switches }
  1990. 'Check unit name', {cs_check_unit_name}
  1991. 'Constructor name', {cs_constructor_name}
  1992. 'Support exceptions',{cs_support_exceptions}
  1993. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  1994. 'Transparent file names', {cs_transparent_file_names}
  1995. { units }
  1996. 'Load Objpas Unit', {cs_load_objpas_unit}
  1997. 'Load GPC unit', {cs_load_gpc_unit}
  1998. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  1999. 'Support Vectors', {cs_support_vectors}
  2000. { debuginfo }
  2001. 'Use HeapTRc unit', {cs_use_heaptrc}
  2002. 'Use line information', {cs_use_lineinfo}
  2003. 'Use GDB Valgrind', {cs_gdb_valgrind}
  2004. 'No regalloc', {cs_no_regalloc}
  2005. 'Stabs preserve cases', {cs_stabs_preservecase}
  2006. { assembling }
  2007. 'Leave assembler file', {cs_asm_leave}
  2008. 'Use external assembler', {cs_asm_extern}
  2009. 'Use pipes to call assembler', {cs_asm_pipe}
  2010. 'Add source infos into assembler files', {cs_asm_source}
  2011. 'Add register allocation into assembler files', {cs_asm_regalloc}
  2012. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  2013. 'Add node information into assembler files', {cs_asm_nodes}
  2014. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  2015. { linking }
  2016. 'Skip linking stage', {cs_link_nolink}
  2017. 'Link static', {cs_link_static}
  2018. 'Link smart', {cs_link_smart}
  2019. 'Link shared', {cs_link_shared}
  2020. 'Link deffile', {cs_link_deffile}
  2021. 'Strip after linking', {cs_link_strip}
  2022. 'Use linker static flag',{cs_link_staticflag}
  2023. 'Link on target OS',{cs_link_on_target}
  2024. 'Use external linker', {cs_link_extern}
  2025. 'Link opt vtable', {cs_link_opt_vtable}
  2026. 'Link opt used sections', {cs_link_opt_used_sections}
  2027. 'Link debug to separate file',{cs_link_separate_dbg_file}
  2028. 'Create linker map', {cs_link_map}
  2029. 'Link to pthread', {cs_link_pthread}
  2030. 'Link no default lib order', {cs_link_no_default_lib_order}
  2031. 'Link using native linker', {cs_link_native}
  2032. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  2033. 'Link using vlink', {cs_link_vlink}
  2034. 'Link using ld.lld GNU compatible LLVM linker' {cs_link_lld}
  2035. );
  2036. localswitchname : array[tlocalswitch] of string[50] =
  2037. { Switches which can be changed locally }
  2038. ('Local None', {cs_localnone}
  2039. { codegen }
  2040. 'Check overflow', {cs_check_overflow}
  2041. 'Check range', {cs_check_range}
  2042. 'Check object error', {cs_check_object}
  2043. 'Check I/O error', {cs_check_io}
  2044. 'Check stack', {cs_check_stack}
  2045. 'Check pointer', {cs_checkpointer}
  2046. 'Check ordinal size', {cs_check_ordinal_size}
  2047. 'Generate stackframes', {cs_generate_stackframes}
  2048. 'Do assertions', {cs_do_assertion}
  2049. 'Generate RTTI', {cs_generate_rtti}
  2050. 'Full boolean evaluaion', {cs_full_boolean_eval}
  2051. 'Typed constant are writable', {cs_typed_const_writable}
  2052. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  2053. 'Do inline', {cs_do_inline}
  2054. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  2055. 'IEEE errors', {cs_ieee_errors}
  2056. 'Check low address loading', {cs_check_low_addr_load}
  2057. 'Imported data', {cs_imported_data}
  2058. 'Excess precision', {cs_excessprecision}
  2059. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  2060. // 'Check all case coverage', {cs_check_all_case_coverage} {not yet merged}
  2061. { mmx }
  2062. 'Allow MMX instructions', {cs_mmx}
  2063. 'Use MMX saturation', {cs_mmx_saturation}
  2064. { parser }
  2065. 'Use typed addresses', {cs_typed_addresses}
  2066. 'Use strict var strings', {cs_strict_var_strings}
  2067. 'Use reference counted strings', {cs_refcountedstrings}
  2068. 'Use bit-packing', {cs_bitpacking}
  2069. 'Use var property setter', {cs_varpropsetter}
  2070. 'Use scoped enums',{cs_scopedenums}
  2071. 'Use pointer math', {cs_pointermath}
  2072. { macpas specific}
  2073. 'MACPAS exteranl variable', {cs_external_var}
  2074. 'MACPAS externally visible', {cs_externally_visible}
  2075. { jvm specific }
  2076. 'JVM check var copyout', {cs_check_var_copyout}
  2077. 'Zero based strings', {cs_zerobasedstrings}
  2078. { i8086 specific }
  2079. 'i8086 force FAR calls', {cs_force_far_calls}
  2080. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2081. 'i8086 huge pointer comparison' {cs_hugeptr_comparison_normalization}
  2082. );
  2083. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  2084. modeswitchname : array[tmodeswitch] of string[50] =
  2085. ('m_none',
  2086. { generic }
  2087. 'm_fpc','m_objfpc','m_delphi','m_tp7','m_mac','m_iso','m_extpas',
  2088. {$ifdef gpc_mode}'m_gpc',{$endif}
  2089. { more specific }
  2090. 'm_class', { delphi class model }
  2091. 'm_objpas', { load objpas unit }
  2092. 'm_result', { result in functions }
  2093. 'm_string_pchar', { pchar 2 string conversion }
  2094. 'm_cvar_support', { cvar variable directive }
  2095. 'm_nested_comment', { nested comments }
  2096. 'm_tp_procvar', { tp style procvars (no @ needed) }
  2097. 'm_mac_procvar', { macpas style procvars }
  2098. 'm_repeat_forward', { repeating forward declarations is needed }
  2099. 'm_pointer_2_procedure', { allows the assignement of pointers to
  2100. procedure variables }
  2101. 'm_autoderef', { does auto dereferencing of struct. vars }
  2102. 'm_initfinal', { initialization/finalization for units }
  2103. 'm_default_ansistring', { ansistring turned on by default }
  2104. 'm_out', { support the calling convention OUT }
  2105. 'm_default_para', { support default parameters }
  2106. 'm_hintdirective', { support hint directives }
  2107. 'm_duplicate_names', { allow locals/paras to have duplicate names of globals }
  2108. 'm_property', { allow properties }
  2109. 'm_default_inline', { allow inline proc directive }
  2110. 'm_except', { allow exception-related keywords }
  2111. 'm_objectivec1', { support interfacing with Objective-C (1.0) }
  2112. 'm_objectivec2', { support interfacing with Objective-C (2.0) }
  2113. 'm_nested_procvars', { support nested procedural variables }
  2114. 'm_non_local_goto', { support non local gotos (like iso pascal) }
  2115. 'm_advanced_records', { advanced record syntax with visibility sections, methods and properties }
  2116. 'm_isolike_unary_minus', { unary minus like in iso pascal: same precedence level as binary minus/plus }
  2117. 'm_systemcodepage', { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  2118. 'm_final_fields', { allows declaring fields as "final", which means they must be initialised
  2119. in the (class) constructor and are constant from then on (same as final
  2120. fields in Java) }
  2121. 'm_default_unicodestring', { makes the default string type in $h+ mode unicodestring rather than
  2122. ansistring; similarly, char becomes unicodechar rather than ansichar }
  2123. 'm_type_helpers', { allows the declaration of "type helper" for all supported types
  2124. (primitive types, records, classes, interfaces) }
  2125. 'm_blocks', { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  2126. 'm_isolike_io', { I/O as it required by an ISO compatible compiler }
  2127. 'm_isolike_program_para',{ program parameters as it required by an ISO compatible compiler }
  2128. 'm_isolike_mod', { mod operation as it is required by an iso compatible compiler }
  2129. 'm_array_operators' { use Delphi compatible array operators instead of custom ones ("+") }
  2130. // 'm_multi_helpers', { helpers can appear in multiple scopes simultaneously } {not yet merged}
  2131. // 'm_array2dynarray', { regular arrays can be implicitly converted to dynamic arrays } {not yet merged}
  2132. // 'm_prefixed_attributes' { enable attributes that are defined before the type they belong to } {not yet merged}
  2133. );
  2134. { optimizer }
  2135. optimizerswitchname : array[toptimizerswitch] of string[50] =
  2136. ('cs_opt_none',
  2137. 'cs_opt_level1',
  2138. 'cs_opt_level2',
  2139. 'cs_opt_level3',
  2140. 'cs_opt_level4',
  2141. 'cs_opt_regvar',
  2142. 'cs_opt_uncertain',
  2143. 'cs_opt_size',
  2144. 'cs_opt_stackframe',
  2145. 'cs_opt_peephole',
  2146. 'cs_opt_loopunroll',
  2147. 'cs_opt_tailrecursion',
  2148. 'cs_opt_nodecse',
  2149. 'cs_opt_nodedfa',
  2150. 'cs_opt_loopstrength',
  2151. 'cs_opt_scheduler',
  2152. 'cs_opt_autoinline',
  2153. 'cs_useebp',
  2154. 'cs_userbp',
  2155. 'cs_opt_reorder_fields',
  2156. 'cs_opt_fastmath',
  2157. { Allow removing expressions whose result is not used, even when this
  2158. can change program behaviour (range check errors disappear',
  2159. access violations due to invalid pointer derefences disappear, ...).
  2160. Note: it does not (and must not) remove expressions that have
  2161. explicit side-effects, only implicit side-effects (like the ones
  2162. mentioned before) can disappear.
  2163. }
  2164. 'cs_opt_dead_values',
  2165. { compiler checks for empty procedures/methods and removes calls to them if possible }
  2166. 'cs_opt_remove_emtpy_proc',
  2167. 'cs_opt_constant_propagate',
  2168. 'cs_opt_dead_store_eliminate',
  2169. 'cs_opt_forcenostackframe',
  2170. 'cs_opt_use_load_modify_store'
  2171. );
  2172. var
  2173. globalswitch : tglobalswitch;
  2174. targetswitch : ttargetswitch;
  2175. moduleswitch : tmoduleswitch;
  2176. localswitch : tlocalswitch;
  2177. modeswitch : tmodeswitch;
  2178. optimizerswitch : toptimizerswitch;
  2179. globalswitches : tglobalswitches;
  2180. targetswitches : ttargetswitches;
  2181. moduleswitches : tmoduleswitches;
  2182. localswitches : tlocalswitches;
  2183. modeswitches : tmodeswitches;
  2184. optimizerswitches : toptimizerswitches;
  2185. begin
  2186. {alignment : talignmentinfo;}
  2187. {talignmentinfo = packed record}
  2188. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2189. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2190. { alignment for labels after unconditional jumps, this must be a power of two }
  2191. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2192. { max. alignment for labels after unconditional jumps:
  2193. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2194. the next smaller power of two of jumpalign }
  2195. // writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax)); {not yet merged}
  2196. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2197. // writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign)); {not yet merged}
  2198. { max. alignment for labels where two flows of the program flow coalesce
  2199. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2200. the next smaller power of two of coalescealign }
  2201. // writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax)); {not yet merged}
  2202. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2203. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2204. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2205. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2206. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2207. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2208. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2209. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2210. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2211. globalswitches:=new_settings.globalswitches;
  2212. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2213. if globalswitch in globalswitches then
  2214. begin
  2215. writeln('global switch: '+globalswitchname[globalswitch]);
  2216. exclude(globalswitches,globalswitch);
  2217. end;
  2218. if (globalswitches <> []) then
  2219. writeln('Unknown global switch');
  2220. targetswitches:=new_settings.targetswitches;
  2221. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2222. if targetswitch in targetswitches then
  2223. begin
  2224. writeln('target switch: '+targetswitchname[targetswitch]);
  2225. exclude(targetswitches,targetswitch);
  2226. end;
  2227. if (targetswitches <> []) then
  2228. writeln('Unknown target switch');
  2229. moduleswitches:=new_settings.moduleswitches;
  2230. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2231. if moduleswitch in moduleswitches then
  2232. begin
  2233. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2234. exclude(moduleswitches,moduleswitch);
  2235. end;
  2236. if (moduleswitches <> []) then
  2237. writeln('Unknown module switch');
  2238. localswitches:=new_settings.localswitches;
  2239. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2240. if localswitch in localswitches then
  2241. begin
  2242. writeln('local switch: '+localswitchname[localswitch]);
  2243. exclude(localswitches,localswitch);
  2244. end;
  2245. if (localswitches <> []) then
  2246. writeln('Unknown local switch');
  2247. modeswitches:=new_settings.modeswitches;
  2248. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2249. if modeswitch in modeswitches then
  2250. begin
  2251. writeln(['mode switch: ',modeswitchname[modeswitch]]);
  2252. exclude(modeswitches,modeswitch);
  2253. end;
  2254. if (modeswitches <> []) then
  2255. writeln('Unknown mode switch');
  2256. optimizerswitches:=new_settings.optimizerswitches;
  2257. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2258. if optimizerswitch in optimizerswitches then
  2259. begin
  2260. writeln(['optimizer switch: ',optimizerswitchname[optimizerswitch]]);
  2261. exclude(optimizerswitches,optimizerswitch);
  2262. end;
  2263. if (optimizerswitches <> []) then
  2264. writeln('Unknown optimizer switch');
  2265. writeln(['Set allocation size ',new_settings.setalloc]);
  2266. writeln(['Pack enums ',new_settings.packenum]);
  2267. writeln(['Pack records ',new_settings.packrecords]);
  2268. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2269. writeln(['CPU type ',new_settings.cputype]);
  2270. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2271. writeln(['FPU type ',new_settings.fputype]);
  2272. writeln(['ASM mode ',new_settings.asmmode]);
  2273. end;
  2274. var
  2275. linestr,genstr : string;
  2276. token : ttoken;
  2277. copy_size, stbi, last_col, new_col : longint;
  2278. last_line,new_line : dword;
  2279. len : sizeint;
  2280. wstring : widestring;
  2281. astring : ansistring;
  2282. begin
  2283. tbi:=0;
  2284. last_line:=0;
  2285. last_col:=0;
  2286. linestr:='';
  2287. genstr:='';
  2288. fillchar(new_settings,sizeof(new_settings),#0);
  2289. fillchar(prev_settings,sizeof(prev_settings),#0);
  2290. write([space,' Tokens: ']);
  2291. while tbi<tokenbufsize do
  2292. begin
  2293. token:=readtoken;
  2294. if token<>_GENERICSPECIALTOKEN then
  2295. begin
  2296. if token <= high(ttoken) then
  2297. begin
  2298. write(arraytokeninfo[token].str);
  2299. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2300. _INTCONST,_REALNUMBER, _ID]) then
  2301. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2302. end
  2303. else
  2304. begin
  2305. HasMoreInfos;
  2306. write('Error in Token List');
  2307. break;
  2308. end;
  2309. {idtoken:=}readtoken;
  2310. end;
  2311. case token of
  2312. _CWCHAR,
  2313. _CWSTRING :
  2314. begin
  2315. len:=gettokenbufsizeint;
  2316. setlength(wstring,len);
  2317. move(tokenbuf[tbi],wstring[1],len*2);
  2318. write([' ''',wstring,'''']);
  2319. StrAppend(linestr,' ''');
  2320. StrAppend(linestr,wstring);
  2321. StrAppend(linestr,'''');
  2322. inc(tbi,len*2);
  2323. end;
  2324. _CSTRING:
  2325. begin
  2326. len:=gettokenbufsizeint;
  2327. setlength(astring,len);
  2328. if len>0 then
  2329. move(tokenbuf[tbi],astring[1],len);
  2330. write([' ''',astring,'''']);
  2331. StrAppend(linestr,' ''');
  2332. StrAppend(linestr,astring);
  2333. StrAppend(linestr,'''');
  2334. inc(tbi,len);
  2335. end;
  2336. _CCHAR:
  2337. begin
  2338. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2339. StrAppend(linestr,' ''');
  2340. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2341. StrAppend(linestr,'''');
  2342. inc(tbi,tokenbuf[tbi]+1);
  2343. end;
  2344. _INTCONST,
  2345. _REALNUMBER :
  2346. begin
  2347. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2348. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2349. inc(tbi,tokenbuf[tbi]+1);
  2350. end;
  2351. _ID :
  2352. begin
  2353. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2354. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2355. inc(tbi,tokenbuf[tbi]+1);
  2356. end;
  2357. _GENERICSPECIALTOKEN:
  2358. begin
  2359. { Short version of column change,
  2360. byte or $80 used }
  2361. if (tokenbuf[tbi] and $80)<>0 then
  2362. begin
  2363. new_col:=tokenbuf[tbi] and $7f;
  2364. write(['Col: ',new_col]);
  2365. if length(linestr)<new_col-1 then
  2366. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2367. inc(tbi);
  2368. last_col:=new_col;
  2369. end
  2370. else
  2371. case tspecialgenerictoken(tokenbuf[tbi]) of
  2372. ST_LOADSETTINGS:
  2373. begin
  2374. inc(tbi);
  2375. write([space,'Settings: ']);
  2376. fillchar(new_settings,sizeof(new_settings),#0);
  2377. { This does not load pmessage pointer }
  2378. new_settings.pmessage:=nil;
  2379. { TSettings size depends in target...
  2380. We first read the size of the copied part }
  2381. { Still not cross endian ready :( }
  2382. copy_size:=gettokenbufsizeint;
  2383. stbi:=tbi;
  2384. tokenreadsettings(new_settings, copy_size);
  2385. tbi:=stbi+copy_size;
  2386. if CompareByte(new_settings,prev_settings,sizeof(new_settings))<>0 then
  2387. begin
  2388. dump_new_settings;
  2389. writeln;
  2390. end
  2391. else
  2392. begin
  2393. writeln('Unchanged');
  2394. end;
  2395. prev_settings:=new_settings;
  2396. end;
  2397. ST_LOADMESSAGES:
  2398. begin
  2399. inc(tbi);
  2400. mesgnb:=tokenbuf[tbi];
  2401. writeln([space,mesgnb,' messages: ']);
  2402. inc(tbi);
  2403. for nb:=1 to mesgnb do
  2404. begin
  2405. msgvalue:=gettokenbufsizeint;
  2406. //inc(tbi,sizeof(sizeint));
  2407. state:=tmsgstate(gettokenbufsizeint);
  2408. writeln(['#',msgvalue,' ',state]);
  2409. end;
  2410. end;
  2411. ST_LINE:
  2412. begin
  2413. inc(tbi);
  2414. new_line:=gettokenbufdword;
  2415. if (new_line<>last_line) then
  2416. begin
  2417. StrAppend(genstr,linestr+LineEnding);
  2418. linestr:='';
  2419. end;
  2420. writeln(['Line: ',new_line]);
  2421. last_line:=new_line;
  2422. end;
  2423. ST_COLUMN:
  2424. begin
  2425. inc(tbi);
  2426. new_col:=gettokenbufword;
  2427. write(['Col: ',new_col]);
  2428. if length(linestr)<new_col - 1 then
  2429. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2430. last_col:=new_col;
  2431. end;
  2432. ST_FILEINDEX:
  2433. begin
  2434. inc(tbi);
  2435. StrAppend(genstr,linestr+LineEnding);
  2436. linestr:='';
  2437. write(['File: ',gettokenbufword]);
  2438. end;
  2439. else
  2440. begin
  2441. HasMoreInfos;
  2442. write('Error in Token List');
  2443. break;
  2444. end;
  2445. end;
  2446. end;
  2447. else ; { empty else to avoid warning }
  2448. end;
  2449. if tbi<tokenbufsize then
  2450. write(',');
  2451. end;
  2452. writeln;
  2453. StrAppend(genstr,linestr);
  2454. writeln(['##',genstr,'##']);
  2455. end;
  2456. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  2457. type
  2458. tdefopt=record
  2459. mask : tdefoption;
  2460. str : string[30];
  2461. end;
  2462. tdefstateinfo=record
  2463. mask : tdefstate;
  2464. str : string[30];
  2465. end;
  2466. tgenconstrflag=record
  2467. mask : tgenericconstraintflag;
  2468. str : string[30];
  2469. end;
  2470. const
  2471. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  2472. (mask:df_unique; str:'Unique Type'),
  2473. (mask:df_generic; str:'Generic'),
  2474. (mask:df_specialization; str:'Specialization'),
  2475. (mask:df_copied_def; str:'Copied Typedef'),
  2476. (mask:df_genconstraint; str:'Generic Constraint'),
  2477. { this should never happen for defs stored to a ppu file }
  2478. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  2479. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  2480. (mask:df_internal; str:'Internal')
  2481. );
  2482. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  2483. (mask:ds_vmt_written; str:'VMT Written'),
  2484. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  2485. (mask:ds_init_table_used; str:'InitTable Used'),
  2486. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  2487. (mask:ds_init_table_written; str:'InitTable Written'),
  2488. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  2489. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  2490. );
  2491. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  2492. (mask:gcf_constructor; str:'Constructor'),
  2493. (mask:gcf_class; str:'Class'),
  2494. (mask:gcf_record; str:'Record')
  2495. );
  2496. var
  2497. defstates : tdefstates;
  2498. i, nb, len : longint;
  2499. first : boolean;
  2500. min_size, tokenbufsize : longint;
  2501. tokenbuf : pbyte;
  2502. genconstr : tgenericconstraintflags;
  2503. begin
  2504. i:=ppufile.getlongint;
  2505. if Def <> nil then
  2506. Def.Id:=i;
  2507. writeln([space,'** Definition Id ',i,' **']);
  2508. writeln([space,s]);
  2509. write ([space,' Type symbol : ']);
  2510. if Def <> nil then
  2511. readderef('', Def.Ref)
  2512. else
  2513. readderef('');
  2514. write ([space,' DefOptions : ']);
  2515. ppufile.getsmallset(defoptions);
  2516. if defoptions<>[] then
  2517. begin
  2518. first:=true;
  2519. for i:=1to high(defopt) do
  2520. if (defopt[i].mask in defoptions) then
  2521. begin
  2522. if first then
  2523. first:=false
  2524. else
  2525. write(', ');
  2526. write(defopt[i].str);
  2527. end;
  2528. end;
  2529. writeln;
  2530. write ([space,' DefStates : ']);
  2531. ppufile.getsmallset(defstates);
  2532. if defstates<>[] then
  2533. begin
  2534. first:=true;
  2535. for i:=1 to high(defstate) do
  2536. if (defstate[i].mask in defstates) then
  2537. begin
  2538. if first then
  2539. first:=false
  2540. else
  2541. write(', ');
  2542. write(defstate[i].str);
  2543. end;
  2544. end;
  2545. writeln;
  2546. if df_genconstraint in defoptions then
  2547. begin
  2548. ppufile.getsmallset(genconstr);
  2549. write ([space,' GenConstraints : ']);
  2550. if genconstr<>[] then
  2551. begin
  2552. first:=true;
  2553. for i:=1 to high(genconstrflag) do
  2554. if (genconstrflag[i].mask in genconstr) then
  2555. begin
  2556. if first then
  2557. first:=false
  2558. else
  2559. write(', ');
  2560. write(genconstrflag[i].str);
  2561. end;
  2562. end;
  2563. writeln;
  2564. len:=ppufile.getlongint;
  2565. if len>0 then
  2566. begin
  2567. space:=' '+space;
  2568. writeln([space,'------ constraint defs begin ------']);
  2569. for i:=0 to len-1 do
  2570. begin
  2571. writeln([space,'------ constraint def ',i,' ------']);
  2572. readderef(space);
  2573. end;
  2574. writeln([space,'------ constraint defs end ------']);
  2575. delete(space,1,4);
  2576. end;
  2577. end;
  2578. if [df_generic,df_specialization]*defoptions<>[] then
  2579. begin
  2580. nb:=ppufile.getlongint;
  2581. writeln([space,'has ',nb,' parameters']);
  2582. if nb>0 then
  2583. begin
  2584. for i:=0 to nb-1 do
  2585. begin
  2586. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2587. readderef(space);
  2588. end;
  2589. end;
  2590. end;
  2591. if df_generic in defoptions then
  2592. begin
  2593. tokenbufsize:=ppufile.getlongint;
  2594. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2595. tokenbuf:=allocmem(tokenbufsize);
  2596. ppufile.getdata(tokenbuf^,tokenbufsize);
  2597. displaytokenbuffer(tokenbuf,tokenbufsize);
  2598. freemem(tokenbuf);
  2599. end;
  2600. if df_specialization in defoptions then
  2601. begin
  2602. write ([space,' Orig. GenericDef : ']);
  2603. readderef('');
  2604. end;
  2605. current_defoptions:=defoptions;
  2606. end;
  2607. { Read abstract procdef and return if inline procdef }
  2608. { type tproccalloption is in globtype unit }
  2609. { type tproctypeoption is in globtype unit }
  2610. { type tprocoption is in globtype unit }
  2611. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2612. type
  2613. tproccallopt=record
  2614. mask : tproccalloption;
  2615. str : string[30];
  2616. end;
  2617. tproctypeopt=record
  2618. mask : tproctypeoption;
  2619. str : string[30];
  2620. end;
  2621. tprocopt=record
  2622. mask : tprocoption;
  2623. str : string[31];
  2624. end;
  2625. const
  2626. {proccalloptionStr is also in globtype unit }
  2627. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2628. (mask:potype_proginit; str:'ProgInit'),
  2629. (mask:potype_unitinit; str:'UnitInit'),
  2630. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2631. (mask:potype_constructor; str:'Constructor'),
  2632. (mask:potype_destructor; str:'Destructor'),
  2633. (mask:potype_operator; str:'Operator'),
  2634. (mask:potype_procedure; str:'Procedure'),
  2635. (mask:potype_function; str:'Function'),
  2636. (mask:potype_class_constructor; str:'Class Constructor'),
  2637. (mask:potype_class_destructor; str:'Class Destructor'),
  2638. { Dispinterface property accessors }
  2639. (mask:potype_propgetter; str:'Property Getter'),
  2640. (mask:potype_propsetter; str:'Property Setter'),
  2641. (mask:potype_exceptfilter; str:'SEH filter'),
  2642. (mask:potype_mainstub; str:'main stub'),
  2643. (mask:potype_pkgstub; str:'package stub')
  2644. );
  2645. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2646. (mask:po_classmethod; str:'ClassMethod'),
  2647. (mask:po_virtualmethod; str:'VirtualMethod'),
  2648. (mask:po_abstractmethod; str:'AbstractMethod'),
  2649. (mask:po_finalmethod; str:'FinalMethod'),
  2650. (mask:po_staticmethod; str:'StaticMethod'),
  2651. (mask:po_overridingmethod;str:'OverridingMethod'),
  2652. (mask:po_methodpointer; str:'MethodPointer'),
  2653. (mask:po_interrupt; str:'Interrupt'),
  2654. (mask:po_iocheck; str:'IOCheck'),
  2655. (mask:po_assembler; str:'Assembler'),
  2656. (mask:po_msgstr; str:'MsgStr'),
  2657. (mask:po_msgint; str:'MsgInt'),
  2658. (mask:po_exports; str:'Exports'),
  2659. (mask:po_external; str:'External'),
  2660. (mask:po_overload; str:'Overload'),
  2661. (mask:po_varargs; str:'VarArgs'),
  2662. (mask:po_internconst; str:'InternConst'),
  2663. (mask:po_addressonly; str:'AddressOnly'),
  2664. (mask:po_public; str:'Public'),
  2665. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2666. (mask:po_reintroduce; str:'ReIntroduce'),
  2667. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2668. (mask:po_nostackframe; str:'NoStackFrame'),
  2669. (mask:po_has_mangledname; str:'HasMangledName'),
  2670. (mask:po_has_public_name; str:'HasPublicName'),
  2671. (mask:po_forward; str:'Forward'),
  2672. (mask:po_global; str:'Global'),
  2673. (mask:po_syscall; str:'Syscall'),
  2674. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2675. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2676. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2677. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2678. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2679. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2680. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2681. (mask:po_inline; str:'Inline'),
  2682. (mask:po_compilerproc; str:'CompilerProc'),
  2683. (mask:po_has_importdll; str:'HasImportDLL'),
  2684. (mask:po_has_importname; str:'HasImportName'),
  2685. (mask:po_kylixlocal; str:'KylixLocal'),
  2686. (mask:po_dispid; str:'DispId'),
  2687. (mask:po_weakexternal; str:'WeakExternal'),
  2688. (mask:po_objc; str:'ObjC'),
  2689. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2690. (mask:po_optional; str: 'Optional'),
  2691. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2692. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2693. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2694. (mask:po_rtlproc; str: 'RTL procedure'),
  2695. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2696. (mask:po_far; str: 'Far'),
  2697. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2698. (mask:po_noreturn; str: 'No return'),
  2699. (mask:po_is_function_ref; str: 'Function reference'),
  2700. (mask:po_is_block; str: 'C "Block"'),
  2701. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2702. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2703. (mask:po_objc_related_result_type; str: 'Objective-C related result type')
  2704. );
  2705. var
  2706. proctypeoption : tproctypeoption;
  2707. i : longint;
  2708. first : boolean;
  2709. begin
  2710. write([space,' Return type : ']);
  2711. readderef('', ProcDef.ReturnType);
  2712. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2713. case proctypeoption of
  2714. potype_function: Include(ProcDef.Options, poFunction);
  2715. potype_procedure: Include(ProcDef.Options, poProcedure);
  2716. potype_constructor: Include(ProcDef.Options, poConstructor);
  2717. potype_destructor: Include(ProcDef.Options, poDestructor);
  2718. potype_operator: Include(ProcDef.Options, poOperator);
  2719. end;
  2720. write([space,' TypeOption : ']);
  2721. first:=true;
  2722. for i:=1 to high(proctypeopt) do
  2723. if (proctypeopt[i].mask=proctypeoption) then
  2724. begin
  2725. if first then
  2726. first:=false
  2727. else
  2728. write(', ');
  2729. write(proctypeopt[i].str);
  2730. end;
  2731. writeln;
  2732. proccalloption:=tproccalloption(ppufile.getbyte);
  2733. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2734. ppufile.getnormalset(procoptions);
  2735. if procoptions<>[] then
  2736. begin
  2737. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2738. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2739. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2740. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2741. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2742. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2743. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2744. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2745. write([space,' Options : ']);
  2746. first:=true;
  2747. for i:=1 to high(procopt) do
  2748. if (procopt[i].mask in procoptions) then
  2749. begin
  2750. if first then
  2751. first:=false
  2752. else
  2753. write(', ');
  2754. write(procopt[i].str);
  2755. end;
  2756. writeln;
  2757. end;
  2758. if (po_explicitparaloc in procoptions) then
  2759. begin
  2760. readcgpara(space);
  2761. end;
  2762. end;
  2763. { type tvaroption is in unit symconst }
  2764. { register variable }
  2765. { type tvarregable is in unit symconst }
  2766. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2767. type
  2768. tvaropt=record
  2769. mask : tvaroption;
  2770. str : string[30];
  2771. end;
  2772. const
  2773. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  2774. (mask:vo_is_external; str:'External'),
  2775. (mask:vo_is_dll_var; str:'DLLVar'),
  2776. (mask:vo_is_thread_var; str:'ThreadVar'),
  2777. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  2778. (mask:vo_is_const; str:'Constant'),
  2779. (mask:vo_is_public; str:'Public'),
  2780. (mask:vo_is_high_para; str:'HighValue'),
  2781. (mask:vo_is_funcret; str:'Funcret'),
  2782. (mask:vo_is_self; str:'Self'),
  2783. (mask:vo_is_vmt; str:'VMT'),
  2784. (mask:vo_is_result; str:'Result'),
  2785. (mask:vo_is_parentfp; str:'ParentFP'),
  2786. (mask:vo_is_loop_counter; str:'LoopCounter'),
  2787. (mask:vo_is_hidden_para; str:'Hidden'),
  2788. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  2789. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  2790. (mask:vo_has_mangledname; str:'HasMangledName'),
  2791. (mask:vo_is_typed_const; str:'TypedConst'),
  2792. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  2793. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  2794. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  2795. (mask:vo_is_msgsel;str:'MsgSel'),
  2796. (mask:vo_is_weak_external;str:'WeakExternal'),
  2797. (mask:vo_is_first_field;str:'IsFirstField'),
  2798. (mask:vo_volatile; str:'Volatile'),
  2799. (mask:vo_has_section; str:'HasSection'),
  2800. (mask:vo_force_finalize; str:'ForceFinalize'),
  2801. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  2802. (mask:vo_is_far; str:'IsFar')
  2803. );
  2804. var
  2805. i : longint;
  2806. first : boolean;
  2807. begin
  2808. readcommonsym(s, VarDef);
  2809. i:=ppufile.getbyte;
  2810. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  2811. with TPpuParamDef(VarDef) do
  2812. case tvarspez(i) of
  2813. vs_value: Spez:=psValue;
  2814. vs_var: Spez:=psVar;
  2815. vs_out: Spez:=psOut;
  2816. vs_const: Spez:=psConst;
  2817. vs_constref: Spez:=psConstRef;
  2818. end;
  2819. writeln([space,' Spez : ',Varspez2Str(i)]);
  2820. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  2821. writeln([space,' Addr Taken : ',(ppufile.getbyte<>0)]);
  2822. writeln([space,'Escaped Scope : ',(ppufile.getbyte<>0)]);
  2823. write ([space,' Var Type : ']);
  2824. if VarDef <> nil then
  2825. readderef('',VarDef.VarType)
  2826. else
  2827. readderef('');
  2828. ppufile.getsmallset(varoptions);
  2829. if varoptions<>[] then
  2830. begin
  2831. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  2832. TPpuParamDef(VarDef).Spez:=psHidden;
  2833. write([space,' Options : ']);
  2834. first:=true;
  2835. for i:=1 to high(varopt) do
  2836. if (varopt[i].mask in varoptions) then
  2837. begin
  2838. if first then
  2839. first:=false
  2840. else
  2841. write(', ');
  2842. write(varopt[i].str);
  2843. end;
  2844. writeln;
  2845. end;
  2846. end;
  2847. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  2848. type
  2849. tsymopt=record
  2850. mask : tobjectoption;
  2851. str : string[30];
  2852. end;
  2853. const
  2854. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  2855. (mask:oo_is_forward; str:'IsForward'),
  2856. (mask:oo_is_abstract; str:'IsAbstract'),
  2857. (mask:oo_is_sealed; str:'IsSealed'),
  2858. (mask:oo_has_virtual; str:'HasVirtual'),
  2859. (mask:oo_has_private; str:'HasPrivate'),
  2860. (mask:oo_has_protected; str:'HasProtected'),
  2861. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  2862. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  2863. (mask:oo_has_constructor; str:'HasConstructor'),
  2864. (mask:oo_has_destructor; str:'HasDestructor'),
  2865. (mask:oo_has_vmt; str:'HasVMT'),
  2866. (mask:oo_has_msgstr; str:'HasMsgStr'),
  2867. (mask:oo_has_msgint; str:'HasMsgInt'),
  2868. (mask:oo_can_have_published; str:'CanHavePublished'),
  2869. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  2870. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  2871. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  2872. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  2873. (mask:oo_is_external; str:'External'),
  2874. (mask:oo_is_formal; str:'Formal'),
  2875. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  2876. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  2877. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  2878. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  2879. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  2880. );
  2881. var
  2882. i : longint;
  2883. first : boolean;
  2884. begin
  2885. ppufile.getsmallset(current_objectoptions);
  2886. if current_objectoptions<>[] then
  2887. begin
  2888. if ObjDef <> nil then
  2889. begin
  2890. if oo_is_abstract in current_objectoptions then
  2891. Include(ObjDef.Options, ooIsAbstract);
  2892. end;
  2893. first:=true;
  2894. for i:=1 to high(symopt) do
  2895. if (symopt[i].mask in current_objectoptions) then
  2896. begin
  2897. if first then
  2898. first:=false
  2899. else
  2900. write(', ');
  2901. write(symopt[i].str);
  2902. end;
  2903. end;
  2904. writeln;
  2905. end;
  2906. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  2907. type
  2908. tpiopt=record
  2909. mask : timplprocoption;
  2910. str : string[30];
  2911. end;
  2912. const
  2913. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  2914. (mask:pio_empty; str:'IsEmpty'),
  2915. (mask:pio_has_inlininginfo; str:'HasInliningInfo')
  2916. );
  2917. var
  2918. i: timplprocoption;
  2919. first: boolean;
  2920. begin
  2921. ppufile.getsmallset(implprocoptions);
  2922. if implprocoptions<>[] then
  2923. begin
  2924. first:=true;
  2925. write([space,' Options : ']);
  2926. for i:=low(piopt) to high(piopt) do
  2927. begin
  2928. if i in implprocoptions then
  2929. begin
  2930. if first then
  2931. first:=false
  2932. else
  2933. write(', ');
  2934. write(piopt[i].str);
  2935. end;
  2936. end;
  2937. writeln;
  2938. end;
  2939. end;
  2940. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  2941. { type tarraydefoption is in unit symconst }
  2942. const
  2943. symopt : array[tarraydefoption] of string = (
  2944. { ado_IsConvertedPointer } 'ConvertedPointer',
  2945. { ado_IsDynamicArray } 'IsDynamicArray',
  2946. { ado_IsVariant } 'IsVariant',
  2947. { ado_IsConstructor } 'IsConstructor',
  2948. { ado_IsArrayOfConst } 'ArrayOfConst',
  2949. { ado_IsConstString } 'ConstString',
  2950. { ado_IsBitPacked } 'BitPacked'
  2951. );
  2952. var
  2953. symoptions: tarraydefoptions;
  2954. i: tarraydefoption;
  2955. first: boolean;
  2956. begin
  2957. ppufile.getsmallset(symoptions);
  2958. if symoptions<>[] then
  2959. begin
  2960. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  2961. first:=true;
  2962. for i:=Low(symopt) to high(symopt) do
  2963. if (i in symoptions) then
  2964. begin
  2965. if first then
  2966. first:=false
  2967. else
  2968. write(', ');
  2969. write(symopt[i]);
  2970. end;
  2971. end;
  2972. writeln;
  2973. end;
  2974. (* options for properties
  2975. tpropertyoption=(ppo_none,
  2976. ppo_indexed,
  2977. ppo_defaultproperty,
  2978. ppo_stored,
  2979. ppo_hasparameters,
  2980. ppo_implements,
  2981. ppo_enumerator_current,
  2982. ppo_overrides,
  2983. ppo_dispid_write { no longer used }
  2984. );
  2985. tpropertyoptions=set of tpropertyoption;
  2986. *)
  2987. function readpropertyoptions:tpropertyoptions;
  2988. { type tarraydefoption is in unit symconst }
  2989. type
  2990. tpropopt=record
  2991. mask : tpropertyoption;
  2992. str : string[30];
  2993. end;
  2994. const
  2995. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  2996. (mask:ppo_indexed;str:'indexed'),
  2997. (mask:ppo_defaultproperty;str:'default'),
  2998. (mask:ppo_stored;str:'stored'),
  2999. (mask:ppo_hasparameters;str:'has parameters'),
  3000. (mask:ppo_implements;str:'implements'),
  3001. (mask:ppo_enumerator_current;str:'enumerator current'),
  3002. (mask:ppo_overrides;str:'overrides'),
  3003. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  3004. );
  3005. var
  3006. i : longint;
  3007. first : boolean;
  3008. begin
  3009. ppufile.getsmallset(result);
  3010. if result<>[] then
  3011. begin
  3012. first:=true;
  3013. for i:=1 to high(symopt) do
  3014. if (symopt[i].mask in result) then
  3015. begin
  3016. if first then
  3017. first:=false
  3018. else
  3019. write(', ');
  3020. write(symopt[i].str);
  3021. end;
  3022. end;
  3023. writeln;
  3024. end;
  3025. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  3026. { type is in unit symconst }
  3027. { Management operator options
  3028. tmanagementoperator=(
  3029. mop_none,
  3030. mop_initialize,
  3031. mop_finalize,
  3032. mop_addref,
  3033. mop_copy);
  3034. }
  3035. type
  3036. tmopopt=record
  3037. mask : tmanagementoperator;
  3038. str : string[10];
  3039. end;
  3040. const
  3041. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  3042. (mask:mop_initialize;str:'initialize'),
  3043. (mask:mop_finalize;str:'finalize'),
  3044. (mask:mop_addref;str:'addref'),
  3045. (mask:mop_copy;str:'copy')
  3046. );
  3047. var
  3048. i : longint;
  3049. first : boolean;
  3050. begin
  3051. ppufile.getsmallset(result);
  3052. if result<>[] then
  3053. begin
  3054. first:=true;
  3055. for i:=1 to high(managementoperatoropt) do
  3056. if (managementoperatoropt[i].mask in result) then
  3057. begin
  3058. if first then
  3059. begin
  3060. write(space);
  3061. write(name);
  3062. write(': ');
  3063. first:=false;
  3064. end
  3065. else
  3066. write(', ');
  3067. write(managementoperatoropt[i].str);
  3068. end;
  3069. if not first then
  3070. writeln;
  3071. end;
  3072. end;
  3073. procedure readnodetree;
  3074. var
  3075. l : longint;
  3076. p : pointer;
  3077. begin
  3078. with ppufile do
  3079. begin
  3080. if space<>'' then
  3081. Writeln([space,'------ nodetree ------']);
  3082. if readentry=ibnodetree then
  3083. begin
  3084. l:=entrysize;
  3085. Writeln([space,'Tree size : ',l]);
  3086. { Read data to prevent error that entry is not completly read }
  3087. getmem(p,l);
  3088. getdata(p^,l);
  3089. freemem(p);
  3090. end
  3091. else
  3092. begin
  3093. WriteError('!! ibnodetree not found');
  3094. end;
  3095. end;
  3096. end;
  3097. procedure ReadCreatedObjTypes;
  3098. var
  3099. i,j,
  3100. len,
  3101. bssize: longint;
  3102. bs: pbyte;
  3103. begin
  3104. if ppufile.readentry<>ibcreatedobjtypes then
  3105. begin
  3106. WriteError('!! ibcreatedobjtypes entry not found');
  3107. ppufile.skipdata(ppufile.entrysize);
  3108. exit
  3109. end;
  3110. writeln;
  3111. writeln([space,'WPO info']);
  3112. writeln([space,'--------']);
  3113. len:=ppufile.getlongint;
  3114. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  3115. space:=space+' ';
  3116. for i:=0 to len-1 do
  3117. readderef(space);
  3118. setlength(space,length(space)-2);
  3119. len:=ppufile.getlongint;
  3120. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  3121. space:=space+' ';
  3122. for i:=0 to len-1 do
  3123. readderef(space);
  3124. setlength(space,length(space)-2);
  3125. len:=ppufile.getlongint;
  3126. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  3127. space:=space+' ';
  3128. for i:=0 to len-1 do
  3129. readderef(space);
  3130. setlength(space,length(space)-2);
  3131. len:=ppufile.getlongint;
  3132. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3133. space:=space+' ';
  3134. for i:=0 to len-1 do
  3135. begin
  3136. write([space,'Class def : ']);
  3137. readderef('');
  3138. write([space+' ','Called vmtentries : ']);
  3139. bssize:=ppufile.getlongint;
  3140. getmem(bs,bssize);
  3141. ppufile.readdata(bs^,bssize);
  3142. for j:=0 to bssize*8-1 do
  3143. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3144. write([j,', ']);
  3145. writeln;
  3146. freemem(bs);
  3147. end;
  3148. setlength(space,length(space)-2);
  3149. end;
  3150. {****************************************************************************
  3151. Read Symbols Part
  3152. ****************************************************************************}
  3153. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3154. function _finddef(symdef: TPpuDef): TPpuDef;
  3155. begin
  3156. Result:=nil;
  3157. if symdef.Ref.IsCurUnit then
  3158. begin;
  3159. Result:=CurUnit.FindById(symdef.Ref.Id);
  3160. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3161. begin
  3162. Result.Name:=symdef.Name;
  3163. Result.FilePos:=symdef.FilePos;
  3164. end
  3165. else
  3166. Result:=nil;
  3167. end;
  3168. end;
  3169. type
  3170. pguid = ^tguid;
  3171. tguid = packed record
  3172. D1: LongWord;
  3173. D2: Word;
  3174. D3: Word;
  3175. D4: array[0..7] of Byte;
  3176. end;
  3177. var
  3178. b : byte;
  3179. pc : pchar;
  3180. ch : dword;
  3181. startnewline : boolean;
  3182. i,j,len : longint;
  3183. prettyname, ss : ansistring;
  3184. ws: widestring;
  3185. guid : tguid;
  3186. realvalue : ppureal;
  3187. doublevalue : double;
  3188. singlevalue : single;
  3189. realstr : shortstring;
  3190. extended : TSplit80bitReal;
  3191. pw : pcompilerwidestring;
  3192. varoptions : tvaroptions;
  3193. propoptions : tpropertyoptions;
  3194. iexp: Tconstexprint;
  3195. def: TPpuDef;
  3196. constdef: TPpuConstDef absolute def;
  3197. begin
  3198. with ppufile do
  3199. begin
  3200. if space<>'' then
  3201. Writeln([space,'------ ',s,' ------']);
  3202. if readentry=ibstartsyms then
  3203. begin
  3204. Writeln([space,'Symtable count: ',getlongint]);
  3205. end
  3206. else
  3207. Writeln('!! ibstartsym not found');
  3208. repeat
  3209. def:=nil;
  3210. b:=readentry;
  3211. case b of
  3212. ibunitsym :
  3213. readcommonsym('Unit symbol ');
  3214. ibnamespacesym :
  3215. begin
  3216. readcommonsym('NameSpace symbol ');
  3217. write([space,' Hidden Unit : ']);
  3218. readderef('');
  3219. end;
  3220. iblabelsym :
  3221. readcommonsym('Label symbol ');
  3222. ibtypesym :
  3223. begin
  3224. def:=TPpuTypeRef.Create(nil);
  3225. readcommonsym('Type symbol ',def);
  3226. write([space,' Result Type : ']);
  3227. readderef('', def.Ref);
  3228. if _finddef(def) = nil then
  3229. def.Parent:=ParentDef;
  3230. prettyname:=getansistring;
  3231. if prettyname<>'' then
  3232. begin
  3233. write([space,' Pretty Name : ']);
  3234. Writeln(prettyname);
  3235. end;
  3236. end;
  3237. ibprocsym :
  3238. begin
  3239. def:=TPpuDef.Create(nil);
  3240. readcommonsym('Procedure symbol ', def);
  3241. len:=ppufile.getword;
  3242. for i:=1 to len do
  3243. begin
  3244. write([space,' Definition : ']);
  3245. readderef('', def.Ref);
  3246. _finddef(def);
  3247. end;
  3248. end;
  3249. ibconstsym :
  3250. begin
  3251. constdef:=TPpuConstDef.Create(ParentDef);
  3252. readcommonsym('Constant symbol ',constdef);
  3253. b:=getbyte;
  3254. case tconsttyp(b) of
  3255. constord :
  3256. begin
  3257. write ([space,' OrdinalType : ']);
  3258. readderef('',constdef.TypeRef);
  3259. iexp:=getexprint;
  3260. constdef.ConstType:=ctInt;
  3261. constdef.VInt:=iexp.svalue;
  3262. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3263. end;
  3264. constpointer :
  3265. begin
  3266. write ([space,' PointerType : ']);
  3267. readderef('',constdef.TypeRef);
  3268. constdef.ConstType:=ctInt;
  3269. constdef.VInt:=int64(getptruint);
  3270. writeln([space,' Value : ',constdef.VInt])
  3271. end;
  3272. conststring,
  3273. constresourcestring :
  3274. begin
  3275. write ([space,' StringType : ']);
  3276. readderef('',constdef.TypeRef);
  3277. len:=getlongint;
  3278. getmem(pc,len+1);
  3279. getdata(pc^,len);
  3280. (pc+len)^:= #0;
  3281. writeln([space,' Length : ',len]);
  3282. writeln([space,' Value : "',pc,'"']);
  3283. constdef.ConstType:=ctStr;
  3284. SetString(constdef.VStr, pc, len);
  3285. constdef.VStr:=UTF8Encode(constdef.VStr);
  3286. freemem(pc,len+1);
  3287. end;
  3288. constreal :
  3289. begin
  3290. constdef.ConstType:=ctFloat;
  3291. write ([space,' RealType : ']);
  3292. readderef('',constdef.TypeRef);
  3293. write([space,' Value : ']);
  3294. if entryleft=sizeof(ppureal) then
  3295. begin
  3296. realvalue:=getrealsize(sizeof(ppureal));
  3297. constdef.VFloat:=realvalue;
  3298. system.str(realvalue,realstr);
  3299. writeln([realstr]);
  3300. end
  3301. else if entryleft=sizeof(double) then
  3302. begin
  3303. doublevalue:=getrealsize(sizeof(double));
  3304. constdef.VFloat:=doublevalue;
  3305. system.str(doublevalue,realstr);
  3306. writeln([realstr]);
  3307. end
  3308. else if entryleft=sizeof(single) then
  3309. begin
  3310. singlevalue:=getrealsize(sizeof(single));
  3311. constdef.VFloat:=singlevalue;
  3312. system.str(singlevalue,realstr);
  3313. writeln([realstr]);
  3314. end
  3315. else if entryleft=10 then
  3316. begin
  3317. getdata(extended,entryleft);
  3318. ss:=Real80bitToStr(extended,constdef.VFloat);
  3319. writeln(ss);
  3320. end
  3321. else
  3322. begin
  3323. realvalue:=0.0;
  3324. WriteError('Error reading real value');
  3325. end;
  3326. end;
  3327. constset :
  3328. begin
  3329. constdef.ConstType:=ctSet;
  3330. write ([space,' Set Type : ']);
  3331. readderef('',constdef.TypeRef);
  3332. for i:=1to 4 do
  3333. begin
  3334. write ([space,' Value : ']);
  3335. for j:=1to 8 do
  3336. begin
  3337. if j>1 then
  3338. write(',');
  3339. b:=getbyte;
  3340. write(hexstr(b,2));
  3341. constdef.VSet[i*j-1]:=b;
  3342. end;
  3343. writeln;
  3344. end;
  3345. end;
  3346. constnil:
  3347. begin
  3348. write([space,' NIL pointer :']);
  3349. readderef('',constdef.TypeRef);
  3350. constdef.ConstType:=ctPtr;
  3351. constdef.VInt:=0;
  3352. end;
  3353. constwstring :
  3354. begin
  3355. initwidestring(pw);
  3356. setlengthwidestring(pw,getlongint);
  3357. if widecharsize=2 then
  3358. { don't use getdata, because the compilerwidechars may have to
  3359. be byteswapped
  3360. }
  3361. begin
  3362. for i:=0 to pw^.len-1 do
  3363. pw^.data[i]:=ppufile.getword;
  3364. SetString(ws, PWideChar(pw^.data), pw^.len);
  3365. constdef.VStr:=UTF8Encode(ws);
  3366. constdef.ConstType:=ctStr;
  3367. end
  3368. else if widecharsize=4 then
  3369. begin
  3370. for i:=0 to pw^.len-1 do
  3371. pw^.data[i]:=cardinal(ppufile.getlongint);
  3372. end
  3373. else
  3374. begin
  3375. WriteError('Unsupported tcompilerwidechar size');
  3376. end;
  3377. Write([space,'Wide string type']);
  3378. startnewline:=true;
  3379. for i:=0 to pw^.len-1 do
  3380. begin
  3381. if startnewline then
  3382. begin
  3383. writeln;
  3384. write(space);
  3385. startnewline:=false;
  3386. end;
  3387. ch:=pw^.data[i];
  3388. if widecharsize=2 then
  3389. write(hexstr(ch,4))
  3390. else
  3391. write(hexstr(ch,8));
  3392. if ((i + 1) mod 8)= 0 then
  3393. startnewline:=true
  3394. else
  3395. if i <> pw^.len-1 then
  3396. write(', ');
  3397. end;
  3398. donewidestring(pw);
  3399. Writeln;
  3400. end;
  3401. constguid:
  3402. begin
  3403. write ([space,' IntfType : ']);
  3404. readderef('',constdef.TypeRef);
  3405. getdata(guid,sizeof(guid));
  3406. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3407. for i:=0 to 7 do
  3408. begin
  3409. write(hexstr(guid.d4[i],2));
  3410. if i=1 then write('-');
  3411. end;
  3412. writeln('}');
  3413. end
  3414. else
  3415. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3416. end;
  3417. end;
  3418. ibabsolutevarsym :
  3419. begin
  3420. def:=TPpuVarDef.Create(ParentDef);
  3421. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3422. Write ([space,' Relocated to ']);
  3423. b:=getbyte;
  3424. case absolutetyp(b) of
  3425. tovar :
  3426. readpropaccesslist(space+' Sym : ');
  3427. toasm :
  3428. Writeln(['Assembler name : ',getstring]);
  3429. toaddr :
  3430. begin
  3431. Write(['Address : ',getpuint]);
  3432. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3433. Write([' (Far: ',getbyte<>0,')']);
  3434. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3435. if getbyte<>0 then
  3436. Write([' (Far: TRUE, Segment=',getaword,')'])
  3437. else
  3438. Write([' (Far: FALSE)']);
  3439. Writeln;
  3440. end;
  3441. else
  3442. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3443. end;
  3444. end;
  3445. ibfieldvarsym :
  3446. begin
  3447. def:=TPpuFieldDef.Create(ParentDef);
  3448. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3449. writeln([space,' Address : ',getasizeint]);
  3450. if vo_has_mangledname in varoptions then
  3451. writeln([space,' Mangled name : ',getstring]);
  3452. end;
  3453. ibstaticvarsym :
  3454. begin
  3455. def:=TPpuVarDef.Create(ParentDef);
  3456. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3457. write ([space,' DefaultConst : ']);
  3458. readderef('');
  3459. if (vo_has_mangledname in varoptions) then
  3460. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3461. writeln([space,'AMangledname : ',getansistring])
  3462. else
  3463. writeln([space,'SMangledname : ',getstring]);
  3464. if vo_has_section in varoptions then
  3465. writeln(['Section name:',ppufile.getansistring]);
  3466. write ([space,' FieldVarSymDeref: ']);
  3467. readderef('');
  3468. end;
  3469. iblocalvarsym :
  3470. begin
  3471. readabstractvarsym('Local Variable symbol ',varoptions);
  3472. write ([space,' DefaultConst : ']);
  3473. readderef('');
  3474. end;
  3475. ibparavarsym :
  3476. begin
  3477. def:=TPpuParamDef.Create(ParentDef);
  3478. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3479. write ([space,' DefaultConst : ']);
  3480. readderef('',TPpuParamDef(def).DefaultValue);
  3481. writeln([space,' ParaNr : ',getword]);
  3482. writeln([space,' Univ : ',getboolean]);
  3483. writeln([space,' VarState : ',getbyte]);
  3484. writeln([space,' Refs : ',getbyte]);
  3485. if (vo_has_explicit_paraloc in varoptions) then
  3486. begin
  3487. readcgpara(space+' ');
  3488. end;
  3489. end;
  3490. ibenumsym :
  3491. begin
  3492. def:=TPpuConstDef.Create(nil);
  3493. readcommonsym('Enumeration symbol ',def);
  3494. write ([space,' Definition : ']);
  3495. readderef('');
  3496. TPpuConstDef(def).ConstType:=ctInt;
  3497. TPpuConstDef(def).VInt:=getlongint;
  3498. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3499. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3500. def.Parent:=ParentDef;
  3501. end;
  3502. ibsyssym :
  3503. begin
  3504. readcommonsym('Internal system symbol ');
  3505. writeln([space,' Internal Nr : ',getlongint]);
  3506. end;
  3507. ibmacrosym :
  3508. begin
  3509. readcommonsym('Macro symbol ');
  3510. writeln([space,' Defined: ',getboolean]);
  3511. writeln([space,' Compiler var: ',getboolean]);
  3512. len:=getlongint;
  3513. writeln([space,' Value length: ',len]);
  3514. if len > 0 then
  3515. begin
  3516. getmem(pc,len+1);
  3517. getdata(pc^,len);
  3518. (pc+len)^:= #0;
  3519. writeln([space,' Value: "',pc,'"']);
  3520. freemem(pc,len+1);
  3521. end;
  3522. end;
  3523. ibpropertysym :
  3524. begin
  3525. def:=TPpuPropDef.Create(ParentDef);
  3526. readcommonsym('Property ',def);
  3527. write ([space,' Prop Options : ']);
  3528. propoptions:=readpropertyoptions;
  3529. if ppo_overrides in propoptions then
  3530. begin
  3531. write ([space,' OverrideProp : ']);
  3532. readderef('');
  3533. end;
  3534. if ppo_defaultproperty in propoptions then
  3535. Include(TPpuPropDef(def).Options, poDefault);
  3536. write ([space,' Prop Type : ']);
  3537. readderef('',TPpuPropDef(def).PropType);
  3538. writeln([space,' Index : ',getlongint]);
  3539. writeln([space,' Default : ',getlongint]);
  3540. write ([space,' Index Type : ']);
  3541. readderef('');
  3542. { palt_none }
  3543. write ([space,' Noneaccess : ']);
  3544. readpropaccesslist('');
  3545. write ([space,' Readaccess : ']);
  3546. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3547. write ([space,' Writeaccess : ']);
  3548. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3549. write ([space,' Storedaccess : ']);
  3550. readpropaccesslist(space+' Sym: ');
  3551. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3552. begin
  3553. space:=' '+space;
  3554. readsymtable('parast',TPpuPropDef(def));
  3555. delete(space,1,4);
  3556. end;
  3557. end;
  3558. iberror :
  3559. begin
  3560. WriteError('!! Error in PPU');
  3561. exit;
  3562. end;
  3563. ibendsyms :
  3564. break;
  3565. else
  3566. begin
  3567. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3568. end;
  3569. end;
  3570. if (def <> nil) and (def.Parent = nil) then
  3571. def.Free;
  3572. if not EndOfEntry then
  3573. HasMoreInfos;
  3574. until false;
  3575. end;
  3576. end;
  3577. {****************************************************************************
  3578. Read defintions Part
  3579. ****************************************************************************}
  3580. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3581. { type tordtype is in symconst unit }
  3582. {
  3583. uvoid,
  3584. u8bit,u16bit,u32bit,u64bit,u128bit,
  3585. s8bit,s16bit,s32bit,s64bit,s128bit,
  3586. bool8bit,bool16bit,bool32bit,bool64bit,
  3587. uchar,uwidechar,scurrency
  3588. ); }
  3589. { type tobjecttyp is in symconst unit }
  3590. { type tvarianttype is in symconst unit }
  3591. { type thelpertype is in symconst unit }
  3592. var
  3593. b : byte;
  3594. otb : byte; { Object Type byte, needed later again }
  3595. l,j,tokenbufsize : longint;
  3596. tokenbuf : pbyte;
  3597. calloption : tproccalloption;
  3598. procoptions : tprocoptions;
  3599. implprocoptions: timplprocoptions;
  3600. defoptions: tdefoptions;
  3601. iexpr: Tconstexprint;
  3602. def: TPpuDef;
  3603. objdef: TPpuObjectDef absolute def;
  3604. arrdef: TPpuArrayDef absolute def;
  3605. enumdef: TPpuEnumDef absolute def;
  3606. setdef: TPpuSetDef absolute def;
  3607. orddef: TPpuOrdDef absolute def;
  3608. floatdef: TPpuFloatDef absolute def;
  3609. strdef: TPpuStringDef absolute def;
  3610. filedef: TPpuFileDef absolute def;
  3611. begin
  3612. with ppufile do
  3613. begin
  3614. if space<>'' then
  3615. Writeln([space,'------ ',s,' ------']);
  3616. if readentry<>ibstartdefs then
  3617. Writeln('!! ibstartdefs not found');
  3618. repeat
  3619. def:=nil;
  3620. b:=readentry;
  3621. case b of
  3622. ibpointerdef :
  3623. begin
  3624. def:=TPpuPointerDef.Create(ParentDef);
  3625. readcommondef('Pointer definition',defoptions,def);
  3626. write ([space,' Pointed Type : ']);
  3627. readderef('',TPpuPointerDef(def).Ptr);
  3628. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3629. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3630. begin
  3631. write([space,' X86 Pointer Type : ']);
  3632. b:=getbyte;
  3633. case tx86pointertyp(b) of
  3634. x86pt_near: writeln('Near');
  3635. x86pt_near_cs: writeln('Near ''CS''');
  3636. x86pt_near_ds: writeln('Near ''DS''');
  3637. x86pt_near_ss: writeln('Near ''SS''');
  3638. x86pt_near_es: writeln('Near ''ES''');
  3639. x86pt_near_fs: writeln('Near ''FS''');
  3640. x86pt_near_gs: writeln('Near ''GS''');
  3641. x86pt_far: writeln('Far');
  3642. x86pt_huge: writeln('Huge');
  3643. else
  3644. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3645. end;
  3646. end;
  3647. end;
  3648. iborddef :
  3649. begin
  3650. orddef:=TPpuOrdDef.Create(ParentDef);
  3651. readcommondef('Ordinal definition',defoptions,orddef);
  3652. write ([space,' Base type : ']);
  3653. b:=getbyte;
  3654. case tordtype(b) of
  3655. uvoid:
  3656. begin
  3657. writeln('uvoid');
  3658. orddef.OrdType:=otVoid;
  3659. end;
  3660. u8bit:
  3661. begin
  3662. writeln('u8bit');
  3663. orddef.OrdType:=otUInt;
  3664. orddef.Size:=1;
  3665. end;
  3666. u16bit:
  3667. begin
  3668. writeln('u16bit');
  3669. orddef.OrdType:=otUInt;
  3670. orddef.Size:=2;
  3671. end;
  3672. u32bit:
  3673. begin
  3674. writeln('u32bit');
  3675. orddef.OrdType:=otUInt;
  3676. orddef.Size:=4;
  3677. end;
  3678. u64bit:
  3679. begin
  3680. writeln('u64bit');
  3681. orddef.OrdType:=otUInt;
  3682. orddef.Size:=8;
  3683. end;
  3684. u128bit:
  3685. begin
  3686. writeln('u128bit');
  3687. orddef.OrdType:=otUInt;
  3688. orddef.Size:=16;
  3689. end;
  3690. s8bit:
  3691. begin
  3692. writeln('s8bit');
  3693. orddef.OrdType:=otSInt;
  3694. orddef.Size:=1;
  3695. end;
  3696. s16bit:
  3697. begin
  3698. writeln('s16bit');
  3699. orddef.OrdType:=otSInt;
  3700. orddef.Size:=2;
  3701. end;
  3702. s32bit:
  3703. begin
  3704. writeln('s32bit');
  3705. orddef.OrdType:=otSInt;
  3706. orddef.Size:=4;
  3707. end;
  3708. s64bit:
  3709. begin
  3710. writeln('s64bit');
  3711. orddef.OrdType:=otSInt;
  3712. orddef.Size:=8;
  3713. end;
  3714. s128bit:
  3715. begin
  3716. writeln('s128bit');
  3717. orddef.OrdType:=otSInt;
  3718. orddef.Size:=16;
  3719. end;
  3720. pasbool1:
  3721. begin
  3722. writeln('pasbool1');
  3723. orddef.OrdType:=otPasBool;
  3724. orddef.Size:=1;
  3725. end;
  3726. pasbool8:
  3727. begin
  3728. writeln('pasbool8');
  3729. orddef.OrdType:=otPasBool;
  3730. orddef.Size:=1;
  3731. end;
  3732. pasbool16:
  3733. begin
  3734. writeln('pasbool16');
  3735. orddef.OrdType:=otPasBool;
  3736. orddef.Size:=2;
  3737. end;
  3738. pasbool32:
  3739. begin
  3740. writeln('pasbool32');
  3741. orddef.OrdType:=otPasBool;
  3742. orddef.Size:=4;
  3743. end;
  3744. pasbool64:
  3745. begin
  3746. writeln('pasbool64');
  3747. orddef.OrdType:=otPasBool;
  3748. orddef.Size:=8;
  3749. end;
  3750. bool8bit:
  3751. begin
  3752. writeln('bool8bit');
  3753. orddef.OrdType:=otBool;
  3754. orddef.Size:=1;
  3755. end;
  3756. bool16bit:
  3757. begin
  3758. writeln('bool16bit');
  3759. orddef.OrdType:=otBool;
  3760. orddef.Size:=2;
  3761. end;
  3762. bool32bit:
  3763. begin
  3764. writeln('bool32bit');
  3765. orddef.OrdType:=otBool;
  3766. orddef.Size:=4;
  3767. end;
  3768. bool64bit:
  3769. begin
  3770. writeln('bool64bit');
  3771. orddef.OrdType:=otBool;
  3772. orddef.Size:=8;
  3773. end;
  3774. uchar:
  3775. begin
  3776. writeln('uchar');
  3777. orddef.OrdType:=otChar;
  3778. orddef.Size:=1;
  3779. end;
  3780. uwidechar:
  3781. begin
  3782. writeln('uwidechar');
  3783. orddef.OrdType:=otChar;
  3784. orddef.Size:=2;
  3785. end;
  3786. scurrency:
  3787. begin
  3788. writeln('scurrency');
  3789. orddef.OrdType:=otCurrency;
  3790. orddef.Size:=8;
  3791. end;
  3792. else
  3793. WriteWarning('Invalid base type: ' + IntToStr(b));
  3794. end;
  3795. iexpr:=getexprint;
  3796. orddef.RangeLow:=iexpr.svalue;
  3797. write([space,' Range : ',constexp.tostr(iexpr)]);
  3798. iexpr:=getexprint;
  3799. orddef.RangeHigh:=iexpr.svalue;
  3800. writeln([' to ',constexp.tostr(iexpr)]);
  3801. end;
  3802. ibfloatdef :
  3803. begin
  3804. floatdef:=TPpuFloatDef.Create(ParentDef);
  3805. readcommondef('Float definition',defoptions,floatdef);
  3806. write ([space,' Float type : ']);
  3807. b:=getbyte;
  3808. case b of
  3809. ftSingle:
  3810. begin
  3811. writeln('Single');
  3812. floatdef.FloatType:=pftSingle;
  3813. end;
  3814. ftDouble:
  3815. begin
  3816. writeln('Double');
  3817. floatdef.FloatType:=pftDouble;
  3818. end;
  3819. ftExtended:
  3820. begin
  3821. writeln('Extended');
  3822. floatdef.FloatType:=pftExtended;
  3823. end;
  3824. ftComp:
  3825. begin
  3826. writeln('Comp');
  3827. floatdef.FloatType:=pftComp;
  3828. end;
  3829. ftCurr:
  3830. begin
  3831. writeln('Currency');
  3832. floatdef.FloatType:=pftCurrency;
  3833. end;
  3834. ftFloat128:
  3835. begin
  3836. writeln('Float128');
  3837. floatdef.FloatType:=pftFloat128;
  3838. end;
  3839. else
  3840. WriteWarning('Invalid float type: ' + IntToStr(b));
  3841. end;
  3842. end;
  3843. ibarraydef :
  3844. begin
  3845. arrdef:=TPpuArrayDef.Create(ParentDef);
  3846. readcommondef('Array definition',defoptions,arrdef);
  3847. write ([space,' Element type : ']);
  3848. readderef('',arrdef.ElType);
  3849. write ([space,' Range Type : ']);
  3850. readderef('',arrdef.RangeType);
  3851. arrdef.RangeLow:=getasizeint;
  3852. arrdef.RangeHigh:=getasizeint;
  3853. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  3854. write ([space,' Options : ']);
  3855. readarraydefoptions(arrdef);
  3856. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3857. writeln([space,' Huge : ',(getbyte<>0)]);
  3858. readsymtable('symbols', arrdef);
  3859. end;
  3860. ibprocdef :
  3861. begin
  3862. def:=TPpuProcDef.Create(ParentDef);
  3863. readcommondef('Procedure definition',defoptions,def);
  3864. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  3865. if (po_has_mangledname in procoptions) then
  3866. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3867. writeln([space,' Mangled name : ',getansistring])
  3868. else
  3869. writeln([space,' Mangled name : ',getstring]);
  3870. writeln([space,' Number : ',getword]);
  3871. writeln([space,' Level : ',getbyte]);
  3872. write ([space,' Class : ']);
  3873. readderef('');
  3874. write ([space,' Procsym : ']);
  3875. readderef('', def.Ref);
  3876. write ([space,' File Pos : ']);
  3877. readposinfo(def);
  3878. write ([space,' Visibility : ']);
  3879. readvisibility(def);
  3880. write ([space,' SymOptions : ']);
  3881. readsymoptions(space+' ');
  3882. if (po_has_importdll in procoptions) then
  3883. writeln([space,' Import DLL : ',getstring]);
  3884. if (po_has_importname in procoptions) then
  3885. writeln([space,' Import Name : ',getstring]);
  3886. writeln([space,' Import Nr : ',getword]);
  3887. if (po_msgint in procoptions) then
  3888. writeln([space,' MsgInt : ',getlongint]);
  3889. if (po_msgstr in procoptions) then
  3890. writeln([space,' MsgStr : ',getstring]);
  3891. if (po_dispid in procoptions) then
  3892. writeln([space,' DispID: ',ppufile.getlongint]);
  3893. readprocimploptions(space,implprocoptions);
  3894. if (pio_has_inlininginfo in implprocoptions) then
  3895. begin
  3896. write ([space,' FuncretSym : ']);
  3897. readderef('');
  3898. readprocinfooptions(space);
  3899. end;
  3900. b:=ppufile.getbyte;
  3901. if b<>0 then
  3902. begin
  3903. write ([space,' Alias names : ']);
  3904. for j:=1 to b do
  3905. begin
  3906. write(ppufile.getstring);
  3907. if j<b then
  3908. write(', ');
  3909. end;
  3910. writeln;
  3911. end;
  3912. tokenbufsize:=ppufile.getlongint;
  3913. if tokenbufsize<>0 then
  3914. begin
  3915. space:=space + ' ';
  3916. write ([space,'Declaration token buffer : size = ',tokenbufsize]);
  3917. tokenbuf:=allocmem(tokenbufsize);
  3918. ppufile.getdata(tokenbuf^,tokenbufsize);
  3919. displaytokenbuffer(tokenbuf,tokenbufsize);
  3920. freemem(tokenbuf);
  3921. delete(space,1,4);
  3922. end;
  3923. if po_syscall_has_libsym in procoptions then
  3924. begin
  3925. { library symbol for AmigaOS/MorphOS/AROS }
  3926. write ([space,' Library symbol : ']);
  3927. readderef('');
  3928. end;
  3929. if not EndOfEntry then
  3930. HasMoreInfos;
  3931. space:=' '+space;
  3932. { parast }
  3933. readsymtable('parast', TPpuProcDef(def));
  3934. { localst }
  3935. if (pio_has_inlininginfo in implprocoptions) then
  3936. readsymtable('inline localst');
  3937. //else if (df_generic in defoptions) then
  3938. // readsymtable('generic localst'); { not yet merged }
  3939. if (pio_has_inlininginfo in implprocoptions) then
  3940. readnodetree;
  3941. delete(space,1,4);
  3942. end;
  3943. ibprocvardef :
  3944. begin
  3945. def:=TPpuProcTypeDef.Create(ParentDef);
  3946. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  3947. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  3948. writeln([space,' Symtable level :',ppufile.getbyte]);
  3949. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  3950. readderef('');
  3951. if not EndOfEntry then
  3952. HasMoreInfos;
  3953. space:=' '+space;
  3954. { parast }
  3955. readsymtable('parast',TPpuProcDef(def));
  3956. delete(space,1,4);
  3957. end;
  3958. ibshortstringdef :
  3959. begin
  3960. strdef:=TPpuStringDef.Create(ParentDef);
  3961. strdef.StrType:=stShort;
  3962. readcommondef('ShortString definition',defoptions,strdef);
  3963. strdef.Len:=getbyte;
  3964. writeln([space,' Length : ',strdef.Len]);
  3965. end;
  3966. ibwidestringdef :
  3967. begin
  3968. strdef:=TPpuStringDef.Create(ParentDef);
  3969. strdef.StrType:=stWide;
  3970. readcommondef('WideString definition',defoptions,strdef);
  3971. strdef.Len:=getasizeint;
  3972. writeln([space,' Length : ',strdef.Len]);
  3973. end;
  3974. ibunicodestringdef :
  3975. begin
  3976. strdef:=TPpuStringDef.Create(ParentDef);
  3977. strdef.StrType:=stUnicode;
  3978. readcommondef('UnicodeString definition',defoptions,strdef);
  3979. strdef.Len:=getasizeint;
  3980. writeln([space,' Length : ',strdef.Len]);
  3981. writeln([space,' Encoding : ',getword]);
  3982. end;
  3983. ibansistringdef :
  3984. begin
  3985. strdef:=TPpuStringDef.Create(ParentDef);
  3986. strdef.StrType:=stAnsi;
  3987. readcommondef('AnsiString definition',defoptions,strdef);
  3988. strdef.Len:=getasizeint;
  3989. writeln([space,' Length : ',strdef.Len]);
  3990. writeln([space,' Encoding : ',getword]);
  3991. end;
  3992. iblongstringdef :
  3993. begin
  3994. strdef:=TPpuStringDef.Create(ParentDef);
  3995. strdef.StrType:=stLong;
  3996. readcommondef('Longstring definition',defoptions,strdef);
  3997. strdef.Len:=getasizeint;
  3998. writeln([space,' Length : ',strdef.Len]);
  3999. end;
  4000. ibrecorddef :
  4001. begin
  4002. objdef:=TPpuRecordDef.Create(ParentDef);
  4003. readcommondef('Record definition',defoptions, objdef);
  4004. def.Name:=getstring;
  4005. writeln([space,' Name of Record : ',objdef.Name]);
  4006. writeln([space,' Import lib/pkg : ',getstring]);
  4007. write ([space,' Options : ']);
  4008. readobjectdefoptions(objdef);
  4009. if (df_copied_def in defoptions) then
  4010. begin
  4011. Include(TPpuRecordDef(def).Options, ooCopied);
  4012. write([space,' Copied from : ']);
  4013. readderef('',objdef.Ancestor);
  4014. end
  4015. else
  4016. begin
  4017. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4018. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4019. writeln([space,' PadAlign : ',shortint(getbyte)]);
  4020. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  4021. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4022. objdef.Size:=getasizeint;
  4023. writeln([space,' DataSize : ',objdef.Size]);
  4024. writeln([space,' PaddingSize : ',getword]);
  4025. readmanagementoperatoroptions(space,'Management operators');
  4026. end;
  4027. {read the record definitions and symbols}
  4028. if not(df_copied_def in current_defoptions) then
  4029. begin
  4030. space:=' '+space;
  4031. readrecordsymtable('fields',TPpuRecordDef(def));
  4032. Delete(space,1,4);
  4033. end;
  4034. if not EndOfEntry then
  4035. HasMoreInfos;
  4036. end;
  4037. ibobjectdef :
  4038. begin
  4039. objdef:=TPpuObjectDef.Create(ParentDef);
  4040. readcommondef('Object/Class definition',defoptions,objdef);
  4041. objdef.Name:=getstring;
  4042. writeln([space,' Name of Class : ',objdef.Name]);
  4043. writeln([space,' Import lib/pkg : ',getstring]);
  4044. write ([space,' Options : ']);
  4045. readobjectdefoptions(objdef);
  4046. otb:=getbyte;
  4047. write ([space,' Type : ']);
  4048. case tobjecttyp(otb) of
  4049. odt_class : writeln('class');
  4050. odt_object : writeln('object');
  4051. odt_interfacecom : writeln('interfacecom');
  4052. odt_interfacecorba : writeln('interfacecorba');
  4053. odt_cppclass : writeln('cppclass');
  4054. odt_dispinterface : writeln('dispinterface');
  4055. odt_objcclass : writeln('objcclass');
  4056. odt_objcprotocol : writeln('objcprotocol');
  4057. odt_helper : writeln('helper');
  4058. odt_objccategory : writeln('objccategory');
  4059. odt_javaclass : writeln('Java class');
  4060. odt_interfacejava : writeln('Java interface');
  4061. else WriteWarning('Invalid object type: ' + IntToStr(b));
  4062. end;
  4063. case tobjecttyp(otb) of
  4064. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  4065. objdef.ObjType:=otClass;
  4066. odt_object:
  4067. objdef.ObjType:=otObject;
  4068. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  4069. objdef.ObjType:=otInterface;
  4070. odt_helper:
  4071. objdef.ObjType:=otHelper;
  4072. end;
  4073. b:=getbyte;
  4074. write ([space,' Helper Type : ']);
  4075. case thelpertype(b) of
  4076. ht_none : writeln('none');
  4077. ht_class : writeln('class helper');
  4078. ht_record : writeln('record helper');
  4079. ht_type : writeln('type helper');
  4080. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4081. end;
  4082. writeln([space,' External name : ',getstring]);
  4083. objdef.Size:=getasizeint;
  4084. writeln([space,' DataSize : ',objdef.Size]);
  4085. writeln([space,' PaddingSize : ',getword]);
  4086. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4087. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4088. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4089. write ([space, ' VmtField : ']);
  4090. readderef('',nil);
  4091. write ([space, ' Ancestor Class : ']);
  4092. readderef('',objdef.Ancestor);
  4093. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4094. begin
  4095. { IIDGUID }
  4096. for j:=1to 16 do
  4097. getbyte;
  4098. objdef.IID:=getstring;
  4099. writeln([space,' IID String : ',objdef.IID]);
  4100. end;
  4101. l:=getlongint;
  4102. if l > 0 then
  4103. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4104. writeln([space,' Abstract methods : ',l]);
  4105. if tobjecttyp(otb)=odt_helper then
  4106. begin
  4107. write([space,' Helper parent : ']);
  4108. readderef('',objdef.HelperParent);
  4109. end;
  4110. l:=getlongint;
  4111. writeln([space,' VMT entries: ',l]);
  4112. for j:=1 to l do
  4113. begin
  4114. write([space,' ']);
  4115. readderef('');
  4116. write([space,' Visibility: ']);
  4117. readvisibility;
  4118. end;
  4119. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4120. begin
  4121. l:=getlongint;
  4122. writeln([space,' Impl Intf Count : ',l]);
  4123. for j:=1 to l do
  4124. begin
  4125. write ([space,' - Definition : ']);
  4126. readderef('');
  4127. write ([space,' - Getter Def : ']);
  4128. readderef('');
  4129. writeln([space,' IOffset : ',getlongint]);
  4130. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4131. end;
  4132. end;
  4133. if df_copied_def in current_defoptions then
  4134. begin
  4135. Include(objdef.Options, ooCopied);
  4136. writeln(' Copy of def: ');
  4137. readderef('',objdef.Ancestor);
  4138. end
  4139. else
  4140. begin
  4141. {read the record definitions and symbols}
  4142. space:=' '+space;
  4143. readrecordsymtable('fields',objdef);
  4144. Delete(space,1,4);
  4145. end;
  4146. if not EndOfEntry then
  4147. HasMoreInfos;
  4148. end;
  4149. ibfiledef :
  4150. begin
  4151. filedef:=TPpuFileDef.Create(ParentDef);
  4152. ReadCommonDef('File definition',defoptions,filedef);
  4153. write ([space,' Type : ']);
  4154. case getbyte of
  4155. 0 : begin
  4156. writeln('Text');
  4157. filedef.FileType:=ftText;
  4158. end;
  4159. 1 : begin
  4160. writeln('Typed');
  4161. filedef.FileType:=ftTyped;
  4162. write ([space,' File of Type : ']);
  4163. readderef('',filedef.TypeRef);
  4164. end;
  4165. 2 : begin
  4166. writeln('Untyped');
  4167. filedef.FileType:=ftUntyped;
  4168. end;
  4169. end;
  4170. end;
  4171. ibformaldef :
  4172. begin
  4173. def:=TPpuFormalDef.Create(ParentDef);
  4174. readcommondef('Generic definition (void-typ)',defoptions,def);
  4175. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4176. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4177. end;
  4178. ibundefineddef :
  4179. begin
  4180. def:=TPpuUndefinedDef.Create(ParentDef);
  4181. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4182. end;
  4183. ibenumdef :
  4184. begin
  4185. enumdef:=TPpuEnumDef.Create(ParentDef);
  4186. readcommondef('Enumeration type definition',defoptions,enumdef);
  4187. enumdef.ElLow:=getaint;
  4188. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4189. enumdef.ElHigh:=getaint;
  4190. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4191. enumdef.Size:=byte(getaint);
  4192. writeln([space,' Size : ',enumdef.Size]);
  4193. if df_copied_def in defoptions then
  4194. begin
  4195. write([space,'Base enumeration type : ']);
  4196. readderef('',enumdef.CopyFrom);
  4197. end
  4198. else
  4199. begin
  4200. space:=' '+space;
  4201. readsymtable('elements',enumdef);
  4202. delete(space,1,4);
  4203. end;
  4204. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4205. begin
  4206. write([space,' Class def : ']);
  4207. readderef('');
  4208. end;
  4209. end;
  4210. ibclassrefdef :
  4211. begin
  4212. def:=TPpuClassRefDef.Create(ParentDef);
  4213. readcommondef('Class reference definition',defoptions,def);
  4214. write ([space,' Pointed Type : ']);
  4215. readderef('',TPpuClassRefDef(def).ClassRef);
  4216. end;
  4217. ibsetdef :
  4218. begin
  4219. setdef:=TPpuSetDef.Create(ParentDef);
  4220. readcommondef('Set definition',defoptions,setdef);
  4221. write ([space,' Element type : ']);
  4222. readderef('',setdef.ElType);
  4223. setdef.Size:=getasizeint;
  4224. writeln([space,' Size : ',setdef.Size]);
  4225. setdef.SetBase:=getasizeint;
  4226. writeln([space,' Set Base : ',setdef.SetBase]);
  4227. setdef.SetMax:=getasizeint;
  4228. writeln([space,' Set Max : ',setdef.SetMax]);
  4229. end;
  4230. ibvariantdef :
  4231. begin
  4232. def:=TPpuVariantDef.Create(ParentDef);
  4233. readcommondef('Variant definition',defoptions,def);
  4234. write ([space,' Varianttype : ']);
  4235. b:=getbyte;
  4236. case tvarianttype(b) of
  4237. vt_normalvariant :
  4238. writeln('Normal');
  4239. vt_olevariant :
  4240. begin
  4241. TPpuVariantDef(def).IsOLE:=True;
  4242. writeln('OLE');
  4243. end
  4244. else
  4245. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4246. end;
  4247. end;
  4248. iberror :
  4249. begin
  4250. WriteError('!! Error in PPU');
  4251. exit;
  4252. end;
  4253. ibenddefs :
  4254. break;
  4255. else
  4256. begin
  4257. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4258. end;
  4259. end;
  4260. if (def <> nil) and (def.Parent = nil) then
  4261. def.Free;
  4262. if not EndOfEntry then
  4263. HasMoreInfos;
  4264. until false;
  4265. end;
  4266. end;
  4267. procedure readmoduleoptions(space : string);
  4268. type
  4269. { tmoduleoption type is in unit fmodule }
  4270. tmoduleoption = (mo_none,
  4271. mo_hint_deprecated,
  4272. mo_hint_platform,
  4273. mo_hint_library,
  4274. mo_hint_unimplemented,
  4275. mo_hint_experimental,
  4276. mo_has_deprecated_msg
  4277. );
  4278. tmoduleoptions = set of tmoduleoption;
  4279. tmoduleopt=record
  4280. mask : tmoduleoption;
  4281. str : string[30];
  4282. end;
  4283. const
  4284. moduleopts=ord(high(tmoduleoption));
  4285. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4286. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4287. (mask:mo_hint_platform; str:'Hint Platform'),
  4288. (mask:mo_hint_library; str:'Hint Library'),
  4289. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4290. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4291. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4292. );
  4293. var
  4294. moduleoptions : tmoduleoptions;
  4295. i : longint;
  4296. first : boolean;
  4297. begin
  4298. ppufile.getsmallset(moduleoptions);
  4299. if moduleoptions<>[] then
  4300. begin
  4301. first:=true;
  4302. for i:=1to moduleopts do
  4303. if (moduleopt[i].mask in moduleoptions) then
  4304. begin
  4305. if first then
  4306. first:=false
  4307. else
  4308. write(', ');
  4309. write(moduleopt[i].str);
  4310. end;
  4311. end;
  4312. writeln;
  4313. if mo_has_deprecated_msg in moduleoptions then
  4314. writeln([space,'Deprecated : ', ppufile.getstring]);
  4315. end;
  4316. {****************************************************************************
  4317. Read General Part
  4318. ****************************************************************************}
  4319. procedure readinterface(silent : boolean);
  4320. var
  4321. b : byte;
  4322. sourcenumber, i : longint;
  4323. feature : tfeature;
  4324. features : tfeatures;
  4325. s : string;
  4326. begin
  4327. with ppufile do
  4328. begin
  4329. repeat
  4330. b:=readentry;
  4331. case b of
  4332. ibmodulename :
  4333. begin
  4334. CurUnit.Name:=getstring;
  4335. if not silent then
  4336. Writeln(['Module Name: ',CurUnit.Name]);
  4337. end;
  4338. ibfeatures :
  4339. begin
  4340. getsmallset(features);
  4341. Writeln('Features: ');
  4342. for feature:=low(tfeatures) to high(tfeature) do
  4343. if feature in features then
  4344. begin
  4345. str(feature,s);
  4346. s:=copy(s,3,255);
  4347. writeln([s]);
  4348. end;
  4349. end;
  4350. ibmoduleoptions:
  4351. if not silent then
  4352. readmoduleoptions(' ');
  4353. ibsourcefiles :
  4354. begin
  4355. sourcenumber:=1;
  4356. if not silent then
  4357. while not EndOfEntry do
  4358. begin
  4359. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4360. Name:=getstring;
  4361. i:=getlongint;
  4362. if i >= 0 then
  4363. FileTime:=FileDateToDateTime(i);
  4364. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4365. end;
  4366. inc(sourcenumber);
  4367. end;
  4368. end;
  4369. {$IFDEF MACRO_DIFF_HINT}
  4370. ibusedmacros :
  4371. begin
  4372. if not silent then
  4373. while not EndOfEntry do
  4374. begin
  4375. Write('Conditional ',getstring);
  4376. if getboolean then
  4377. write(' defined at startup')
  4378. else
  4379. write(' not defined at startup');
  4380. if getboolean then
  4381. writeln(' was used')
  4382. else
  4383. writeln;
  4384. end;
  4385. end;
  4386. {$ENDIF}
  4387. ibloadunit :
  4388. if not silent then
  4389. ReadLoadUnit;
  4390. iblinkunitofiles :
  4391. if not silent then
  4392. ReadLinkContainer('Link unit object file: ');
  4393. iblinkunitstaticlibs :
  4394. if not silent then
  4395. ReadLinkContainer('Link unit static lib: ');
  4396. iblinkunitsharedlibs :
  4397. if not silent then
  4398. ReadLinkContainer('Link unit shared lib: ');
  4399. iblinkotherofiles :
  4400. if not silent then
  4401. ReadLinkContainer('Link other object file: ');
  4402. iblinkotherstaticlibs :
  4403. if not silent then
  4404. ReadLinkContainer('Link other static lib: ');
  4405. iblinkothersharedlibs :
  4406. if not silent then
  4407. ReadLinkContainer('Link other shared lib: ');
  4408. iblinkotherframeworks:
  4409. if not silent then
  4410. ReadLinkContainer('Link framework: ');
  4411. ibjvmnamespace:
  4412. Writeln('JVM name space: '+getString);
  4413. ibmainname:
  4414. if not silent then
  4415. Writeln(['Specified main program symbol name: ',getstring]);
  4416. ibImportSymbols :
  4417. if not silent then
  4418. ReadImportSymbols;
  4419. ibderefdata :
  4420. ReadDerefData;
  4421. ibderefmap :
  4422. ReadDerefMap;
  4423. ibwpofile :
  4424. if not silent then
  4425. ReadWpoFileInfo;
  4426. ibresources :
  4427. if not silent then
  4428. ReadContainer('Resource file: ');
  4429. iborderedsymbols:
  4430. if not silent then
  4431. ReadContainer('Ordered symbol: ');
  4432. iberror :
  4433. begin
  4434. WriteError('Error in PPU');
  4435. exit;
  4436. end;
  4437. ibendinterface :
  4438. break;
  4439. else
  4440. begin
  4441. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4442. end;
  4443. end;
  4444. until false;
  4445. end;
  4446. end;
  4447. {****************************************************************************
  4448. Read Implementation Part
  4449. ****************************************************************************}
  4450. procedure readimplementation;
  4451. var
  4452. b : byte;
  4453. begin
  4454. with ppufile do
  4455. begin
  4456. repeat
  4457. b:=readentry;
  4458. case b of
  4459. ibasmsymbols :
  4460. ReadAsmSymbols;
  4461. ibloadunit :
  4462. ReadLoadUnit;
  4463. ibunitimportsyms :
  4464. ReadUnitImportSyms;
  4465. iberror :
  4466. begin
  4467. WriteError('Error in PPU');
  4468. exit;
  4469. end;
  4470. ibendimplementation :
  4471. break;
  4472. else
  4473. begin
  4474. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4475. end;
  4476. end;
  4477. until false;
  4478. end;
  4479. end;
  4480. procedure dofile (filename : string);
  4481. begin
  4482. { reset }
  4483. space:='';
  4484. { fix filename }
  4485. if pos('.',filename)=0 then
  4486. filename:=filename+'.ppu';
  4487. ppufile:=tppudumpfile.create(filename);
  4488. if not ppufile.openfile then
  4489. begin
  4490. WriteError('IO-Error when opening : '+filename+', Skipping');
  4491. exit;
  4492. end;
  4493. { PPU File is open, check for PPU Id }
  4494. if not ppufile.CheckPPUID then
  4495. begin
  4496. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4497. exit;
  4498. end;
  4499. { Check PPU Version }
  4500. ppuversion:=ppufile.getversion;
  4501. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4502. if PPUVersion<16 then
  4503. begin
  4504. WriteError(Filename+' : Old PPU Formats (<v16) are not supported, Skipping');
  4505. exit;
  4506. end;
  4507. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4508. begin
  4509. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4510. exit;
  4511. end;
  4512. CurUnit:=TPpuUnitDef.Create(UnitList);
  4513. CurUnit.Version:=ppuversion;
  4514. { Write PPU Header Information }
  4515. if (verbose and v_header)<>0 then
  4516. begin
  4517. Writeln;
  4518. Writeln('Header');
  4519. Writeln('-------');
  4520. with ppufile.header do
  4521. begin
  4522. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4523. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4524. ppufile.header.common.compiler and $7f]);
  4525. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4526. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4527. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4528. Writeln(['FileSize (w/o header) : ',common.size]);
  4529. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4530. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4531. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4532. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4533. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4534. end;
  4535. end;
  4536. with ppufile.header do
  4537. begin
  4538. CurUnit.Crc:=checksum;
  4539. CurUnit.IntfCrc:=interface_checksum;
  4540. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4541. CurUnit.TargetOS:=Target2Str(common.target);
  4542. end;
  4543. {read the general stuff}
  4544. if (verbose and v_interface)<>0 then
  4545. begin
  4546. Writeln;
  4547. Writeln('Interface section');
  4548. Writeln('------------------');
  4549. readinterface(false);
  4550. end
  4551. { We need derefdata from Interface }
  4552. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4553. readinterface(true)
  4554. else
  4555. ppufile.skipuntilentry(ibendinterface);
  4556. Writeln;
  4557. Writeln('Interface symtable');
  4558. Writeln('----------------------');
  4559. readsymtableoptions('interface');
  4560. {read the definitions}
  4561. if (verbose and v_defs)<>0 then
  4562. begin
  4563. Writeln;
  4564. Writeln('Interface definitions');
  4565. Writeln('----------------------');
  4566. readdefinitions('interface', CurUnit);
  4567. end
  4568. else
  4569. ppufile.skipuntilentry(ibenddefs);
  4570. {read the symbols}
  4571. if (verbose and v_syms)<>0 then
  4572. begin
  4573. Writeln;
  4574. Writeln('Interface Symbols');
  4575. Writeln('------------------');
  4576. readsymbols('interface',CurUnit);
  4577. end
  4578. else
  4579. ppufile.skipuntilentry(ibendsyms);
  4580. {read the macro symbols}
  4581. if (verbose and v_syms)<>0 then
  4582. begin
  4583. Writeln;
  4584. Writeln('Interface Macro Symbols');
  4585. Writeln('-----------------------');
  4586. end;
  4587. if ppufile.readentry<>ibexportedmacros then
  4588. begin
  4589. WriteError('!! Error in PPU');
  4590. exit;
  4591. end;
  4592. if ppufile.getboolean then
  4593. begin
  4594. readsymtableoptions('interface macro');
  4595. {skip the definition section for macros (since they are never used) }
  4596. ppufile.skipuntilentry(ibenddefs);
  4597. {read the macro symbols}
  4598. if (verbose and v_syms)<>0 then
  4599. readsymbols('interface macro')
  4600. else
  4601. ppufile.skipuntilentry(ibendsyms);
  4602. end
  4603. else
  4604. Writeln('(no exported macros)');
  4605. {read the implementation stuff}
  4606. if (verbose and v_implementation)<>0 then
  4607. begin
  4608. Writeln;
  4609. Writeln('Implementation section');
  4610. Writeln('-----------------------');
  4611. readimplementation;
  4612. end
  4613. else
  4614. ppufile.skipuntilentry(ibendimplementation);
  4615. {read the static symtable}
  4616. Writeln;
  4617. Writeln('Implementation symtable');
  4618. Writeln('----------------------');
  4619. readsymtableoptions('implementation');
  4620. if (ppufile.header.common.flags and uf_local_symtable)<>0 then
  4621. begin
  4622. if (verbose and v_defs)<>0 then
  4623. begin
  4624. Writeln;
  4625. Writeln('Static definitions');
  4626. Writeln('----------------------');
  4627. readdefinitions('implementation', nil);
  4628. end
  4629. else
  4630. ppufile.skipuntilentry(ibenddefs);
  4631. {read the symbols}
  4632. if (verbose and v_syms)<>0 then
  4633. begin
  4634. Writeln;
  4635. Writeln('Static Symbols');
  4636. Writeln('------------------');
  4637. readsymbols('implementation');
  4638. end
  4639. else
  4640. ppufile.skipuntilentry(ibendsyms);
  4641. end;
  4642. ReadCreatedObjTypes;
  4643. FreeDerefdata;
  4644. {shutdown ppufile}
  4645. ppufile.closefile;
  4646. ppufile.free;
  4647. Writeln;
  4648. end;
  4649. procedure WriteLogo;
  4650. begin
  4651. writeln(Title+' Version '+version_string);
  4652. writeln(Copyright);
  4653. writeln;
  4654. end;
  4655. procedure help;
  4656. begin
  4657. WriteLogo;
  4658. writeln('usage: ppudump [options] <filename1> <filename2>...');
  4659. writeln;
  4660. writeln('[options] can be:');
  4661. writeln(' -F<format> Set output format to <format>');
  4662. writeln(' t - text format (default)');
  4663. writeln(' j - JSON format');
  4664. writeln(' x - XML format');
  4665. writeln(' -M Exit with ExitCode=2 if more information is available');
  4666. writeln(' -S Skip PPU version check. May lead to reading errors');
  4667. writeln(' -V<verbose> Set verbosity to <verbose>');
  4668. writeln(' H - Show header info');
  4669. writeln(' I - Show interface');
  4670. writeln(' M - Show implementation');
  4671. writeln(' S - Show interface symbols');
  4672. writeln(' D - Show interface definitions');
  4673. writeln(' A - Show all');
  4674. writeln(' -h, -? This helpscreen');
  4675. halt;
  4676. end;
  4677. var
  4678. startpara,
  4679. nrfile,i : longint;
  4680. para : string;
  4681. const
  4682. error_on_more : boolean = false;
  4683. begin
  4684. if paramcount<1 then
  4685. help;
  4686. { turn verbose on by default }
  4687. verbose:=v_all;
  4688. { read options }
  4689. startpara:=1;
  4690. while copy(paramstr(startpara),1,1)='-' do
  4691. begin
  4692. para:=paramstr(startpara);
  4693. case upcase(para[2]) of
  4694. 'F' : begin
  4695. FreeAndNil(pout);
  4696. if Length(para) > 2 then
  4697. case upcase(para[3]) of
  4698. 'T':
  4699. nostdout:=False;
  4700. 'J':
  4701. begin
  4702. nostdout:=True;
  4703. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  4704. end;
  4705. 'X':
  4706. begin
  4707. nostdout:=True;
  4708. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  4709. end;
  4710. else
  4711. begin
  4712. WriteError('Invalid output format: ' + para[3]);
  4713. Halt(1);
  4714. end;
  4715. end;
  4716. end;
  4717. 'M' : error_on_more:=true;
  4718. 'S' : SkipVersionCheck:=True;
  4719. 'V' : begin
  4720. verbose:=0;
  4721. for i:=3 to length(para) do
  4722. case upcase(para[i]) of
  4723. 'H' : verbose:=verbose or v_header;
  4724. 'I' : verbose:=verbose or v_interface;
  4725. 'M' : verbose:=verbose or v_implementation;
  4726. 'D' : verbose:=verbose or v_defs;
  4727. 'S' : verbose:=verbose or v_syms;
  4728. 'A' : verbose:=verbose or v_all;
  4729. end;
  4730. end;
  4731. 'H' : help;
  4732. '?' : help;
  4733. else
  4734. begin
  4735. WriteError('Invalid option: ' + para);
  4736. Halt(1);
  4737. end;
  4738. end;
  4739. inc(startpara);
  4740. end;
  4741. if not nostdout then
  4742. WriteLogo;
  4743. UnitList:=TPpuContainerDef.Create(nil);
  4744. try
  4745. UnitList.ItemsName:='';
  4746. { process files }
  4747. for nrfile:=startpara to paramcount do
  4748. dofile (paramstr(nrfile));
  4749. if not has_errors and (pout <> nil) then
  4750. begin
  4751. pout.Init;
  4752. UnitList.Write(pout);
  4753. pout.Done;
  4754. end;
  4755. finally
  4756. UnitList.Free;
  4757. pout.Free;
  4758. end;
  4759. if has_errors then
  4760. Halt(1);
  4761. if error_on_more and
  4762. (has_more_infos or has_warnings) then
  4763. Halt(2);
  4764. end.