ppudump.pp 167 KB

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