ppudump.pp 161 KB

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