ppudump.pp 167 KB

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