ppudump.pp 166 KB

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