ppudump.pp 168 KB

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