ppudump.pp 144 KB

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