ppudump.pp 165 KB

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