ppudump.pp 165 KB

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