ppudump.pp 172 KB

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