ppudump.pp 166 KB

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