ppudump.pp 157 KB

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