ppudump.pp 161 KB

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