ppudump.pp 165 KB

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