ppudump.pp 163 KB

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