ppudump.pp 165 KB

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