ppudump.pp 165 KB

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