ppudump.pp 166 KB

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