ppudump.pp 168 KB

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