ppudump.pp 165 KB

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