ppudump.pp 173 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431
  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. lineendingtype:=tlineendingtype(tokenreadenum(sizeof(tlineendingtype)));
  2030. whitespacetrimcount:=gettokenbufword;
  2031. whitespacetrimauto:=boolean(gettokenbufbyte);
  2032. {$POP}
  2033. endpos:=tbi;
  2034. if endpos-startpos<>expected_size then
  2035. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  2036. end;
  2037. end;
  2038. procedure dump_new_settings;
  2039. (* tsettings = record
  2040. alignment : talignmentinfo;
  2041. globalswitches : tglobalswitches;
  2042. targetswitches : ttargetswitches;
  2043. moduleswitches : tmoduleswitches;
  2044. localswitches : tlocalswitches;
  2045. modeswitches : tmodeswitches;
  2046. optimizerswitches : toptimizerswitches;
  2047. { generate information necessary to perform these wpo's during a subsequent compilation }
  2048. genwpoptimizerswitches: twpoptimizerswitches;
  2049. { perform these wpo's using information generated during a previous compilation }
  2050. dowpoptimizerswitches: twpoptimizerswitches;
  2051. debugswitches : tdebugswitches;
  2052. { 0: old behaviour for sets <=256 elements
  2053. >0: round to this size }
  2054. setalloc,
  2055. packenum : shortint;
  2056. packrecords : shortint;
  2057. maxfpuregisters : shortint;
  2058. cputype,
  2059. optimizecputype,
  2060. asmcputype : tcputype;
  2061. fputype : tfputype;
  2062. asmmode : tasmmode;
  2063. interfacetype : tinterfacetypes;
  2064. defproccall : tproccalloption;
  2065. sourcecodepage : tstringencoding;
  2066. minfpconstprec : tfloattype;
  2067. disabledircache : boolean;
  2068. tlsmodel : ttlsmodel;
  2069. {$if defined(i8086)}
  2070. x86memorymodel : tx86memorymodel;
  2071. {$endif defined(i8086)}
  2072. {$if defined(ARM)}
  2073. instructionset : tinstructionset;
  2074. {$endif defined(ARM)}
  2075. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  2076. llvmversion: tllvmversion;
  2077. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  2078. { CPU targets with microcontroller support can add a controller specific unit }
  2079. controllertype : tcontrollertype;
  2080. { WARNING: this pointer cannot be written as such in record token }
  2081. pmessage : pmessagestaterecord;
  2082. end; *)
  2083. const
  2084. targetswitchname : array[ttargetswitch] of string[77] =
  2085. { global target-specific switches }
  2086. ('Target None', {ts_none}
  2087. { generate code that results in smaller TOCs than normal (AIX) }
  2088. 'Small TOC', {ts_small_toc}
  2089. { for the JVM target: generate integer array initializations via string
  2090. constants in order to reduce the generated code size (Java routines
  2091. are limited to 64kb of bytecode) }
  2092. 'JVM compact int array init', {ts_compact_int_array_init}
  2093. { for the JVM target: intialize enum fields in constructors with the
  2094. enum class instance corresponding to ordinal value 0 (not done by
  2095. default because this initialization can only be performed after the
  2096. inherited constructors have run, and if they call a virtual method
  2097. of the current class, then this virtual method may already have
  2098. initialized that field with another value and the constructor
  2099. initialization will result in data loss }
  2100. 'JVM enum field init', {ts_jvm_enum_field_init}
  2101. { when automatically generating getters/setters for properties, use
  2102. these strings as prefixes for the generated getters/setter names }
  2103. 'Auto getter prefix', {ts_auto_getter_prefix}
  2104. 'Auto setter prefix', {ts_auto_setter_predix}
  2105. 'Thumb interworking', {ts_thumb_interworking,}
  2106. { lowercase the first character of routine names, used to generate
  2107. names that are compliant with Java coding standards from code
  2108. written according to Delphi coding standards }
  2109. 'LowerCase proc start', {ts_lowercase_proc_start,}
  2110. { initialise local variables on the JVM target so you won't get
  2111. accidental uses of uninitialised values }
  2112. 'Init locals', {ts_init_locals}
  2113. { emit a CLD instruction before using the x86 string instructions }
  2114. 'Emit CLD instruction', {ts_cld}
  2115. { increment BP before pushing it in the function prologue and decrement
  2116. it after popping it in the function epilogue, iff the function is
  2117. going to terminate with a far ret. Thus, the BP value pushed on the
  2118. stack becomes odd if the function is far and even if the function is
  2119. near. This allows walking the BP chain on the stack and e.g.
  2120. obtaining a stack trace even if the program uses a mixture of near
  2121. and far calls. This is also required for Win16 real mode, because it
  2122. allows Windows to move code segments around (in order to defragment
  2123. memory) and then walk through the stacks of all running programs and
  2124. update the segment values of the segment that has moved. }
  2125. 'Use odd BP for far procs', {ts_x86_far_procs_push_odd_bp}
  2126. 'No exception support', {ts_wasm_no_exceptions}
  2127. 'Branchful exceptions support', {ts_wasm_bf_exceptions}
  2128. 'Native WebAssembly exceptions with exnref support', {ts_wasm_native_exnref_exceptions}
  2129. 'Native WebAssembly legacy exceptions support', {ts_wasm_native_legacy_exceptions}
  2130. 'WebAssembly threads support', {ts_wasm_threads}
  2131. 'Use WebAssembly saturating (nontrapping) float to int conversion instructions' {ts_wasm_saturating_float_to_int}
  2132. );
  2133. moduleswitchname : array[tmoduleswitch] of string[40] =
  2134. ('Module None', {cs_modulenone,}
  2135. { parser }
  2136. 'Floating Point Emulation',{ cs_fp_emulation}
  2137. 'Extended syntax', {cs_extsyntax}
  2138. { support }
  2139. 'Goto allowed', {cs_support_goto}
  2140. 'Macro support', {cs_support_macro}
  2141. 'C operator support', {cs_support_c_operators}
  2142. { generation }
  2143. 'Profile', {cs_profile}
  2144. 'Debug information', {cs_debuginfo}
  2145. 'Compilation of System unit', {cs_compilesystem}
  2146. 'Line information', {cs_lineinfo}
  2147. 'Implicit exceptions', {cs_implicit_exceptions}
  2148. 'Explicit CodePage', {cs_explicit_codepage}
  2149. 'System CodePage', {cs_system_codepage}
  2150. { linking }
  2151. 'Create smart units', {cs_create_smart}
  2152. 'Create dynamic', {cs_create_dynamic}
  2153. 'Create PIC code', {cs_create_pic}
  2154. { browser switches are back }
  2155. 'Browser', {cs_browser}
  2156. 'Local Browser', {cs_local_browser}
  2157. { target specific }
  2158. 'Executable Stack', {cs_executable_stack}
  2159. { i8086 specific }
  2160. 'Huge code', {cs_huge_code}
  2161. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  2162. { Record usage of checkpointer experimental feature }
  2163. 'CheckPointer used', {cs_checkpointer_called}
  2164. 'Supports LLVM Link-Time Optimization' {cs_lto}
  2165. ,'Enable LLVM Address Sanitizer'
  2166. );
  2167. globalswitchname : array[tglobalswitch] of string[73] =
  2168. ('Global None',{cs_globalnone}
  2169. { parameter switches }
  2170. 'Check unit name', {cs_check_unit_name}
  2171. 'Constructor name', {cs_constructor_name}
  2172. 'Support exceptions',{cs_support_exceptions}
  2173. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  2174. 'Transparent file names', {cs_transparent_file_names}
  2175. { units }
  2176. 'Load Objpas Unit', {cs_load_objpas_unit}
  2177. 'Load GPC unit', {cs_load_gpc_unit}
  2178. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  2179. 'Support Vectors', {cs_support_vectors}
  2180. { debuginfo }
  2181. 'Use HeapTRc unit', {cs_use_heaptrc}
  2182. 'Use line information', {cs_use_lineinfo}
  2183. 'Use GDB Valgrind', {cs_gdb_valgrind}
  2184. 'No regalloc', {cs_no_regalloc}
  2185. 'Stabs preserve cases', {cs_stabs_preservecase}
  2186. { assembling }
  2187. 'Leave assembler file', {cs_asm_leave}
  2188. 'Use external assembler', {cs_asm_extern}
  2189. 'Use pipes to call assembler', {cs_asm_pipe}
  2190. 'Add source infos into assembler files', {cs_asm_source}
  2191. 'Add RTTI infos into assembler files', {cs_asm_rtti_source}
  2192. 'Add register allocation into assembler files', {cs_asm_regalloc}
  2193. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  2194. 'Add node information into assembler files', {cs_asm_nodes}
  2195. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  2196. { linking }
  2197. 'Skip linking stage', {cs_link_nolink}
  2198. 'Link static', {cs_link_static}
  2199. 'Link smart', {cs_link_smart}
  2200. 'Link shared', {cs_link_shared}
  2201. 'Link deffile', {cs_link_deffile}
  2202. 'Strip after linking', {cs_link_strip}
  2203. 'Use linker static flag',{cs_link_staticflag}
  2204. 'Link on target OS',{cs_link_on_target}
  2205. 'Use external linker', {cs_link_extern}
  2206. 'Link opt vtable', {cs_link_opt_vtable}
  2207. 'Link opt used sections', {cs_link_opt_used_sections}
  2208. 'Link debug to separate file',{cs_link_separate_dbg_file}
  2209. 'Create linker map', {cs_link_map}
  2210. 'Link to pthread', {cs_link_pthread}
  2211. 'Link no default lib order', {cs_link_no_default_lib_order}
  2212. 'Link using native linker', {cs_link_native}
  2213. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  2214. 'Link using vlink', {cs_link_vlink}
  2215. 'Discard _START code', {cs_link_discard_start}
  2216. 'Discard code initializing the zero register and stack pointer', {cs_link_discard_zeroreg_sp}
  2217. 'Discard initializing data', {cs_link_discard_copydata}
  2218. 'Discard jump to PASCALMAIN', {cs_link_discard_jmp_main}
  2219. 'Link-Time Optimization disabled for system unit', {cs_lto_nosystem}
  2220. 'Assemble on target OS', {cs_asemble_on_target}
  2221. 'Use a memory model to support >2GB static data on 64 Bit target', {cs_large}
  2222. 'Generate UF2 binary', {cs_generate_uf2}
  2223. 'Link using ld.lld GNU compatible LLVM linker' {cs_link_lld}
  2224. );
  2225. localswitchname : array[tlocalswitch] of string[50] =
  2226. { Switches which can be changed locally }
  2227. ('Local None', {cs_localnone}
  2228. { codegen }
  2229. 'Check overflow', {cs_check_overflow}
  2230. 'Check range', {cs_check_range}
  2231. 'Check object error', {cs_check_object}
  2232. 'Check I/O error', {cs_check_io}
  2233. 'Check stack', {cs_check_stack}
  2234. 'Check pointer', {cs_checkpointer}
  2235. 'Check ordinal size', {cs_check_ordinal_size}
  2236. 'Generate stackframes', {cs_generate_stackframes}
  2237. 'Do assertions', {cs_do_assertion}
  2238. 'Generate RTTI', {cs_generate_rtti}
  2239. 'Full boolean evaluaion', {cs_full_boolean_eval}
  2240. 'Typed constant are writable', {cs_typed_const_writable}
  2241. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  2242. 'Do inline', {cs_do_inline}
  2243. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  2244. 'IEEE errors', {cs_ieee_errors}
  2245. 'Check low address loading', {cs_check_low_addr_load}
  2246. 'Imported data', {cs_imported_data}
  2247. 'Excess precision', {cs_excessprecision}
  2248. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  2249. 'Check all case coverage', {cs_check_all_case_coverage}
  2250. { mmx }
  2251. 'Allow MMX instructions', {cs_mmx}
  2252. 'Use MMX saturation', {cs_mmx_saturation}
  2253. { parser }
  2254. 'Use typed addresses', {cs_typed_addresses}
  2255. 'Use strict var strings', {cs_strict_var_strings}
  2256. 'Use reference counted strings', {cs_refcountedstrings}
  2257. 'Use bit-packing', {cs_bitpacking}
  2258. 'Use var property setter', {cs_varpropsetter}
  2259. 'Use scoped enums',{cs_scopedenums}
  2260. 'Use pointer math', {cs_pointermath}
  2261. 'Open string', {cs_openstring}
  2262. { macpas specific}
  2263. 'MACPAS exteranl variable', {cs_external_var}
  2264. 'MACPAS externally visible', {cs_externally_visible}
  2265. { jvm specific }
  2266. 'JVM check var copyout', {cs_check_var_copyout}
  2267. 'Zero based strings', {cs_zerobasedstrings}
  2268. { i8086 specific }
  2269. 'i8086 force FAR calls', {cs_force_far_calls}
  2270. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2271. 'i8086 huge pointer comparison', {cs_hugeptr_comparison_normalization}
  2272. 'enforce legacy ifend behaviour' {cs_legacyifend}
  2273. );
  2274. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  2275. modeswitchname : array[tmodeswitch] of string[50] =
  2276. ('m_none',
  2277. { generic }
  2278. 'm_fpc','m_objfpc','m_delphi','m_tp7','m_mac','m_iso','m_extpas',
  2279. {$ifdef gpc_mode}'m_gpc',{$endif}
  2280. { more specific }
  2281. 'm_class', { delphi class model }
  2282. 'm_objpas', { load objpas unit }
  2283. 'm_result', { result in functions }
  2284. 'm_string_pchar', { pchar 2 string conversion }
  2285. 'm_cvar_support', { cvar variable directive }
  2286. 'm_nested_comment', { nested comments }
  2287. 'm_tp_procvar', { tp style procvars (no @ needed) }
  2288. 'm_mac_procvar', { macpas style procvars }
  2289. 'm_repeat_forward', { repeating forward declarations is needed }
  2290. 'm_pointer_2_procedure', { allows the assignement of pointers to
  2291. procedure variables }
  2292. 'm_autoderef', { does auto dereferencing of struct. vars }
  2293. 'm_initfinal', { initialization/finalization for units }
  2294. 'm_default_ansistring', { ansistring turned on by default }
  2295. 'm_out', { support the calling convention OUT }
  2296. 'm_default_para', { support default parameters }
  2297. 'm_hintdirective', { support hint directives }
  2298. 'm_duplicate_names', { allow locals/paras to have duplicate names of globals }
  2299. 'm_property', { allow properties }
  2300. 'm_default_inline', { allow inline proc directive }
  2301. 'm_except', { allow exception-related keywords }
  2302. 'm_objectivec1', { support interfacing with Objective-C (1.0) }
  2303. 'm_objectivec2', { support interfacing with Objective-C (2.0) }
  2304. 'm_nested_procvars', { support nested procedural variables }
  2305. 'm_non_local_goto', { support non local gotos (like iso pascal) }
  2306. 'm_advanced_records', { advanced record syntax with visibility sections, methods and properties }
  2307. 'm_isolike_unary_minus', { unary minus like in iso pascal: same precedence level as binary minus/plus }
  2308. 'm_systemcodepage', { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  2309. 'm_final_fields', { allows declaring fields as "final", which means they must be initialised
  2310. in the (class) constructor and are constant from then on (same as final
  2311. fields in Java) }
  2312. 'm_default_unicodestring', { makes the default string type in $h+ mode unicodestring rather than
  2313. ansistring; similarly, char becomes unicodechar rather than ansichar }
  2314. 'm_type_helpers', { allows the declaration of "type helper" for all supported types
  2315. (primitive types, records, classes, interfaces) }
  2316. 'm_blocks', { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  2317. 'm_isolike_io', { I/O as it required by an ISO compatible compiler }
  2318. 'm_isolike_program_para',{ program parameters as it required by an ISO compatible compiler }
  2319. 'm_isolike_mod', { mod operation as it is required by an iso compatible compiler }
  2320. 'm_array_operators', { use Delphi compatible array operators instead of custom ones ("+") }
  2321. 'm_multi_helpers', { helpers can appear in multiple scopes simultaneously }
  2322. 'm_array2dynarray', { regular arrays can be implicitly converted to dynamic arrays }
  2323. 'm_prefixed_attributes', { enable attributes that are defined before the type they belong to }
  2324. 'm_underscoreisseparator',{ _ can be used as separator to group digits in numbers }
  2325. 'm_implicit_function_specialization', { attempt to specialize generic function by inferring types from parameters }
  2326. 'm_function_references', { enable Delphi-style function references }
  2327. 'm_anonymous_functions', { enable Delphi-style anonymous functions }
  2328. 'm_multiline_strings' { multi-line strings denoted with '`' are enabled and valid }
  2329. );
  2330. { optimizer }
  2331. optimizerswitchname : array[toptimizerswitch] of string[50] =
  2332. ('cs_opt_level1',
  2333. 'cs_opt_level2',
  2334. 'cs_opt_level3',
  2335. 'cs_opt_level4',
  2336. 'cs_opt_regvar',
  2337. 'cs_opt_uncertain',
  2338. 'cs_opt_size',
  2339. 'cs_opt_stackframe',
  2340. 'cs_opt_peephole',
  2341. 'cs_opt_loopunroll',
  2342. 'cs_opt_tailrecursion',
  2343. 'cs_opt_nodecse',
  2344. 'cs_opt_nodedfa',
  2345. 'cs_opt_loopstrength',
  2346. 'cs_opt_scheduler',
  2347. 'cs_opt_autoinline',
  2348. 'cs_useebp',
  2349. 'cs_userbp',
  2350. 'cs_opt_reorder_fields',
  2351. 'cs_opt_fastmath',
  2352. { Allow removing expressions whose result is not used, even when this
  2353. can change program behaviour (range check errors disappear',
  2354. access violations due to invalid pointer derefences disappear, ...).
  2355. Note: it does not (and must not) remove expressions that have
  2356. explicit side-effects, only implicit side-effects (like the ones
  2357. mentioned before) can disappear.
  2358. }
  2359. 'cs_opt_dead_values',
  2360. { compiler checks for empty procedures/methods and removes calls to them if possible }
  2361. 'cs_opt_remove_empty_proc',
  2362. 'cs_opt_constant_propagate',
  2363. 'cs_opt_dead_store_eliminate',
  2364. 'cs_opt_forcenostackframe',
  2365. 'cs_opt_use_load_modify_store',
  2366. 'cs_opt_unused_para',
  2367. 'cs_opt_consts',
  2368. 'cs_opt_forloop'
  2369. );
  2370. var
  2371. globalswitch : tglobalswitch;
  2372. targetswitch : ttargetswitch;
  2373. moduleswitch : tmoduleswitch;
  2374. localswitch : tlocalswitch;
  2375. modeswitch : tmodeswitch;
  2376. optimizerswitch : toptimizerswitch;
  2377. globalswitches : tglobalswitches;
  2378. targetswitches : ttargetswitches;
  2379. moduleswitches : tmoduleswitches;
  2380. localswitches : tlocalswitches;
  2381. modeswitches : tmodeswitches;
  2382. optimizerswitches : toptimizerswitches;
  2383. begin
  2384. {alignment : talignmentinfo;}
  2385. {talignmentinfo = packed record}
  2386. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2387. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2388. { alignment for labels after unconditional jumps, this must be a power of two }
  2389. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2390. { max. alignment for labels after unconditional jumps:
  2391. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2392. the next smaller power of two of jumpalign }
  2393. writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax));
  2394. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2395. writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign));
  2396. { max. alignment for labels where two flows of the program flow coalesce
  2397. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2398. the next smaller power of two of coalescealign }
  2399. writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax));
  2400. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2401. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2402. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2403. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2404. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2405. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2406. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2407. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2408. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2409. globalswitches:=new_settings.globalswitches;
  2410. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2411. if globalswitch in globalswitches then
  2412. begin
  2413. writeln('global switch: '+globalswitchname[globalswitch]);
  2414. exclude(globalswitches,globalswitch);
  2415. end;
  2416. if (globalswitches <> []) then
  2417. writeln('Unknown global switch');
  2418. targetswitches:=new_settings.targetswitches;
  2419. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2420. if targetswitch in targetswitches then
  2421. begin
  2422. writeln('target switch: '+targetswitchname[targetswitch]);
  2423. exclude(targetswitches,targetswitch);
  2424. end;
  2425. if (targetswitches <> []) then
  2426. writeln('Unknown target switch');
  2427. moduleswitches:=new_settings.moduleswitches;
  2428. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2429. if moduleswitch in moduleswitches then
  2430. begin
  2431. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2432. exclude(moduleswitches,moduleswitch);
  2433. end;
  2434. if (moduleswitches <> []) then
  2435. writeln('Unknown module switch');
  2436. localswitches:=new_settings.localswitches;
  2437. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2438. if localswitch in localswitches then
  2439. begin
  2440. writeln('local switch: '+localswitchname[localswitch]);
  2441. exclude(localswitches,localswitch);
  2442. end;
  2443. if (localswitches <> []) then
  2444. writeln('Unknown local switch');
  2445. modeswitches:=new_settings.modeswitches;
  2446. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2447. if modeswitch in modeswitches then
  2448. begin
  2449. writeln(['mode switch: ',modeswitchname[modeswitch]]);
  2450. exclude(modeswitches,modeswitch);
  2451. end;
  2452. if (modeswitches <> []) then
  2453. writeln('Unknown mode switch');
  2454. optimizerswitches:=new_settings.optimizerswitches;
  2455. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2456. if optimizerswitch in optimizerswitches then
  2457. begin
  2458. writeln(['optimizer switch: ',optimizerswitchname[optimizerswitch]]);
  2459. exclude(optimizerswitches,optimizerswitch);
  2460. end;
  2461. if (optimizerswitches <> []) then
  2462. writeln('Unknown optimizer switch');
  2463. writeln(['Set allocation size ',new_settings.setalloc]);
  2464. writeln(['Pack enums ',new_settings.packenum]);
  2465. writeln(['Pack records ',new_settings.packrecords]);
  2466. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2467. writeln('Verbosity '+hexstr(new_settings.verbosity,8));
  2468. writeln(['CPU type ',new_settings.cputype]);
  2469. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2470. writeln(['FPU type ',new_settings.fputype]);
  2471. writeln(['ASM mode ',new_settings.asmmode]);
  2472. end;
  2473. var
  2474. linestr,genstr : string;
  2475. token : ttoken;
  2476. copy_size, stbi, last_col, new_col : longint;
  2477. last_line,new_line : dword;
  2478. len : sizeint;
  2479. wstring : widestring;
  2480. astring : ansistring;
  2481. begin
  2482. tbi:=0;
  2483. last_line:=0;
  2484. last_col:=0;
  2485. linestr:='';
  2486. genstr:='';
  2487. fillchar(new_settings,sizeof(new_settings),#0);
  2488. fillchar(prev_settings,sizeof(prev_settings),#0);
  2489. write([space,' Tokens: ']);
  2490. while tbi<tokenbufsize do
  2491. begin
  2492. token:=readtoken;
  2493. if token<>_GENERICSPECIALTOKEN then
  2494. begin
  2495. if token <= high(ttoken) then
  2496. begin
  2497. write(arraytokeninfo[token].str);
  2498. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2499. _INTCONST,_REALNUMBER, _ID]) then
  2500. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2501. end
  2502. else
  2503. begin
  2504. HasMoreInfos;
  2505. write('Error in Token List');
  2506. break;
  2507. end;
  2508. {idtoken:=}readtoken;
  2509. end;
  2510. case token of
  2511. _CWCHAR,
  2512. _CWSTRING :
  2513. begin
  2514. len:=gettokenbufsizeint;
  2515. setlength(wstring,len);
  2516. move(tokenbuf[tbi],wstring[1],len*2);
  2517. write([' ''',wstring,'''']);
  2518. StrAppend(linestr,' ''');
  2519. StrAppend(linestr,wstring);
  2520. StrAppend(linestr,'''');
  2521. inc(tbi,len*2);
  2522. end;
  2523. _CSTRING:
  2524. begin
  2525. len:=gettokenbufsizeint;
  2526. setlength(astring,len);
  2527. if len>0 then
  2528. move(tokenbuf[tbi],astring[1],len);
  2529. write([' ''',astring,'''']);
  2530. StrAppend(linestr,' ''');
  2531. StrAppend(linestr,astring);
  2532. StrAppend(linestr,'''');
  2533. inc(tbi,len);
  2534. end;
  2535. _CCHAR:
  2536. begin
  2537. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2538. StrAppend(linestr,' ''');
  2539. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2540. StrAppend(linestr,'''');
  2541. inc(tbi,tokenbuf[tbi]+1);
  2542. end;
  2543. _INTCONST,
  2544. _REALNUMBER :
  2545. begin
  2546. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2547. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2548. inc(tbi,tokenbuf[tbi]+1);
  2549. end;
  2550. _ID :
  2551. begin
  2552. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2553. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2554. inc(tbi,tokenbuf[tbi]+1);
  2555. end;
  2556. _GENERICSPECIALTOKEN:
  2557. begin
  2558. { Short version of column change,
  2559. byte or $80 used }
  2560. if (tokenbuf[tbi] and $80)<>0 then
  2561. begin
  2562. new_col:=tokenbuf[tbi] and $7f;
  2563. write(['Col: ',new_col]);
  2564. if length(linestr)<new_col-1 then
  2565. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2566. inc(tbi);
  2567. last_col:=new_col;
  2568. end
  2569. else
  2570. case tspecialgenerictoken(tokenbuf[tbi]) of
  2571. ST_LOADSETTINGS:
  2572. begin
  2573. inc(tbi);
  2574. write([space,'Settings: ']);
  2575. fillchar(new_settings,sizeof(new_settings),#0);
  2576. { This does not load pmessage pointer }
  2577. new_settings.pmessage:=nil;
  2578. { TSettings size depends in target...
  2579. We first read the size of the copied part }
  2580. { Still not cross endian ready :( }
  2581. copy_size:=gettokenbufsizeint;
  2582. stbi:=tbi;
  2583. tokenreadsettings(new_settings, copy_size);
  2584. tbi:=stbi+copy_size;
  2585. if CompareByte(new_settings,prev_settings,copy_size)<>0 then
  2586. begin
  2587. dump_new_settings;
  2588. writeln;
  2589. end
  2590. else
  2591. begin
  2592. writeln('Unchanged');
  2593. end;
  2594. prev_settings:=new_settings;
  2595. end;
  2596. ST_LOADMESSAGES:
  2597. begin
  2598. inc(tbi);
  2599. mesgnb:=gettokenbufsizeint;;
  2600. writeln([space,mesgnb,' messages: ']);
  2601. if (tbi+2*sizeof(longint)*mesgnb>tokenbufsize) then
  2602. begin
  2603. WriteError('!! Error: number of messages incompatible with token buffer size');
  2604. end;
  2605. for nb:=1 to mesgnb do
  2606. begin
  2607. msgvalue:=gettokenbuflongint;
  2608. state:=tmsgstate(gettokenbuflongint);
  2609. writeln(['#',msgvalue,' ',state]);
  2610. end;
  2611. end;
  2612. ST_LINE:
  2613. begin
  2614. inc(tbi);
  2615. new_line:=gettokenbufdword;
  2616. if (new_line<>last_line) then
  2617. begin
  2618. StrAppend(genstr,linestr+LineEnding);
  2619. linestr:='';
  2620. end;
  2621. writeln(['Line: ',new_line]);
  2622. last_line:=new_line;
  2623. end;
  2624. ST_COLUMN:
  2625. begin
  2626. inc(tbi);
  2627. new_col:=gettokenbufword;
  2628. write(['Col: ',new_col]);
  2629. if length(linestr)<new_col - 1 then
  2630. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2631. last_col:=new_col;
  2632. end;
  2633. ST_FILEINDEX:
  2634. begin
  2635. inc(tbi);
  2636. StrAppend(genstr,linestr+LineEnding);
  2637. linestr:='';
  2638. write(['File: ',gettokenbufword]);
  2639. end;
  2640. else
  2641. begin
  2642. HasMoreInfos;
  2643. write('Error in Token List');
  2644. break;
  2645. end;
  2646. end;
  2647. end;
  2648. else ; { empty else to avoid warning }
  2649. end;
  2650. if tbi<tokenbufsize then
  2651. write(',');
  2652. end;
  2653. if (tbi>tokenbufsize) then
  2654. begin
  2655. WriteError('!! Error: read past of token buffer size');
  2656. end
  2657. else
  2658. writeln;
  2659. StrAppend(genstr,linestr);
  2660. writeln(['##',genstr,'##']);
  2661. end;
  2662. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  2663. type
  2664. tdefopt=record
  2665. mask : tdefoption;
  2666. str : string[30];
  2667. end;
  2668. tdefstateinfo=record
  2669. mask : tdefstate;
  2670. str : string[30];
  2671. end;
  2672. tgenconstrflag=record
  2673. mask : tgenericconstraintflag;
  2674. str : string[30];
  2675. end;
  2676. const
  2677. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  2678. (mask:df_unique; str:'Unique Type'),
  2679. (mask:df_generic; str:'Generic'),
  2680. (mask:df_specialization; str:'Specialization'),
  2681. (mask:df_copied_def; str:'Copied Typedef'),
  2682. (mask:df_genconstraint; str:'Generic Constraint'),
  2683. { this should never happen for defs stored to a ppu file }
  2684. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  2685. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  2686. (mask:df_internal; str:'Internal'),
  2687. (mask:df_has_global_ref; str:'Has Global Ref'),
  2688. (mask:df_has_generic_fields; str:'Has generic fields'),
  2689. (mask:df_llvm_no_typename; str:'LLVM no typename')
  2690. );
  2691. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  2692. (mask:ds_vmt_written; str:'VMT Written'),
  2693. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  2694. (mask:ds_init_table_used; str:'InitTable Used'),
  2695. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  2696. (mask:ds_init_table_written; str:'InitTable Written'),
  2697. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  2698. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  2699. );
  2700. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  2701. (mask:gcf_constructor; str:'Constructor'),
  2702. (mask:gcf_class; str:'Class'),
  2703. (mask:gcf_record; str:'Record')
  2704. );
  2705. var
  2706. defstates : tdefstates;
  2707. i, nb, len : longint;
  2708. first : boolean;
  2709. min_size, tokenbufsize : longint;
  2710. tokenbuf : pbyte;
  2711. genconstr : tgenericconstraintflags;
  2712. begin
  2713. i:=ppufile.getlongint;
  2714. if Def <> nil then
  2715. Def.Id:=i;
  2716. writeln([space,'** Definition Id ',i,' **']);
  2717. writeln([space,s]);
  2718. write ([space,' Type symbol : ']);
  2719. if Def <> nil then
  2720. readderef('', Def.Ref)
  2721. else
  2722. readderef('');
  2723. write ([space,' DefOptions : ']);
  2724. ppufile.getset(tppuset2(defoptions));
  2725. if defoptions<>[] then
  2726. begin
  2727. first:=true;
  2728. for i:=1to high(defopt) do
  2729. if (defopt[i].mask in defoptions) then
  2730. begin
  2731. if first then
  2732. first:=false
  2733. else
  2734. write(', ');
  2735. write(defopt[i].str);
  2736. end;
  2737. end;
  2738. writeln;
  2739. write ([space,' DefStates : ']);
  2740. ppufile.getset(tppuset1(defstates));
  2741. if defstates<>[] then
  2742. begin
  2743. first:=true;
  2744. for i:=1 to high(defstate) do
  2745. if (defstate[i].mask in defstates) then
  2746. begin
  2747. if first then
  2748. first:=false
  2749. else
  2750. write(', ');
  2751. write(defstate[i].str);
  2752. end;
  2753. end;
  2754. writeln;
  2755. if df_unique in defoptions then
  2756. begin
  2757. write ([space,' OriginalDef : ']);
  2758. readderef(space);
  2759. end;
  2760. if df_genconstraint in defoptions then
  2761. begin
  2762. ppufile.getset(tppuset1(genconstr));
  2763. write ([space,' GenConstraints : ']);
  2764. if genconstr<>[] then
  2765. begin
  2766. first:=true;
  2767. for i:=1 to high(genconstrflag) do
  2768. if (genconstrflag[i].mask in genconstr) then
  2769. begin
  2770. if first then
  2771. first:=false
  2772. else
  2773. write(', ');
  2774. write(genconstrflag[i].str);
  2775. end;
  2776. end;
  2777. writeln;
  2778. len:=ppufile.getlongint;
  2779. if len>0 then
  2780. begin
  2781. space:=' '+space;
  2782. writeln([space,'------ constraint defs begin ------']);
  2783. for i:=0 to len-1 do
  2784. begin
  2785. writeln([space,'------ constraint def ',i,' ------']);
  2786. readderef(space);
  2787. end;
  2788. writeln([space,'------ constraint defs end ------']);
  2789. delete(space,1,4);
  2790. end;
  2791. end;
  2792. if [df_generic,df_specialization]*defoptions<>[] then
  2793. begin
  2794. nb:=ppufile.getlongint;
  2795. writeln([space,'has ',nb,' parameters']);
  2796. if nb>0 then
  2797. begin
  2798. for i:=0 to nb-1 do
  2799. begin
  2800. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2801. readderef(space);
  2802. end;
  2803. end;
  2804. end;
  2805. if df_generic in defoptions then
  2806. begin
  2807. tokenbufsize:=ppufile.getlongint;
  2808. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2809. tokenbuf:=allocmem(tokenbufsize);
  2810. ppufile.getdata(tokenbuf^,tokenbufsize);
  2811. displaytokenbuffer(tokenbuf,tokenbufsize);
  2812. freemem(tokenbuf);
  2813. end;
  2814. if df_specialization in defoptions then
  2815. begin
  2816. write ([space,' Orig. GenericDef : ']);
  2817. readderef('');
  2818. end;
  2819. space:=space+' ';
  2820. readattrs(def);
  2821. delete(space,1,4);
  2822. current_defoptions:=defoptions;
  2823. end;
  2824. { Read abstract procdef and return if inline procdef }
  2825. { type tproccalloption is in globtype unit }
  2826. { type tproctypeoption is in globtype unit }
  2827. { type tprocoption is in globtype unit }
  2828. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2829. type
  2830. tproccallopt=record
  2831. mask : tproccalloption;
  2832. str : string[30];
  2833. end;
  2834. tproctypeopt=record
  2835. mask : tproctypeoption;
  2836. str : string[30];
  2837. end;
  2838. tprocopt=record
  2839. mask : tprocoption;
  2840. str : string[34];
  2841. end;
  2842. const
  2843. {proccalloptionStr is also in globtype unit }
  2844. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2845. (mask:potype_proginit; str:'ProgInit'),
  2846. (mask:potype_unitinit; str:'UnitInit'),
  2847. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2848. (mask:potype_constructor; str:'Constructor'),
  2849. (mask:potype_destructor; str:'Destructor'),
  2850. (mask:potype_operator; str:'Operator'),
  2851. (mask:potype_procedure; str:'Procedure'),
  2852. (mask:potype_function; str:'Function'),
  2853. (mask:potype_class_constructor; str:'Class Constructor'),
  2854. (mask:potype_class_destructor; str:'Class Destructor'),
  2855. { Dispinterface property accessors }
  2856. (mask:potype_propgetter; str:'Property Getter'),
  2857. (mask:potype_propsetter; str:'Property Setter'),
  2858. (mask:potype_exceptfilter; str:'SEH filter'),
  2859. (mask:potype_mainstub; str:'main stub'),
  2860. (mask:potype_pkgstub; str:'package stub'),
  2861. (mask:potype_libmainstub; str:'library main stub')
  2862. );
  2863. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2864. (mask:po_classmethod; str:'ClassMethod'),
  2865. (mask:po_virtualmethod; str:'VirtualMethod'),
  2866. (mask:po_abstractmethod; str:'AbstractMethod'),
  2867. (mask:po_finalmethod; str:'FinalMethod'),
  2868. (mask:po_staticmethod; str:'StaticMethod'),
  2869. (mask:po_overridingmethod;str:'OverridingMethod'),
  2870. (mask:po_methodpointer; str:'MethodPointer'),
  2871. (mask:po_interrupt; str:'Interrupt'),
  2872. (mask:po_iocheck; str:'IOCheck'),
  2873. (mask:po_assembler; str:'Assembler'),
  2874. (mask:po_msgstr; str:'MsgStr'),
  2875. (mask:po_msgint; str:'MsgInt'),
  2876. (mask:po_exports; str:'Exports'),
  2877. (mask:po_external; str:'External'),
  2878. (mask:po_overload; str:'Overload'),
  2879. (mask:po_varargs; str:'VarArgs'),
  2880. (mask:po_internconst; str:'InternConst'),
  2881. (mask:po_addressonly; str:'AddressOnly'),
  2882. (mask:po_public; str:'Public'),
  2883. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2884. (mask:po_reintroduce; str:'ReIntroduce'),
  2885. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2886. (mask:po_nostackframe; str:'NoStackFrame'),
  2887. (mask:po_has_mangledname; str:'HasMangledName'),
  2888. (mask:po_has_public_name; str:'HasPublicName'),
  2889. (mask:po_forward; str:'Forward'),
  2890. (mask:po_global; str:'Global'),
  2891. (mask:po_syscall; str:'Syscall'),
  2892. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2893. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2894. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2895. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2896. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2897. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2898. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2899. (mask:po_inline; str:'Inline'),
  2900. (mask:po_compilerproc; str:'CompilerProc'),
  2901. (mask:po_has_importdll; str:'HasImportDLL'),
  2902. (mask:po_has_importname; str:'HasImportName'),
  2903. (mask:po_kylixlocal; str:'KylixLocal'),
  2904. (mask:po_dispid; str:'DispId'),
  2905. (mask:po_weakexternal; str:'WeakExternal'),
  2906. (mask:po_objc; str:'ObjC'),
  2907. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2908. (mask:po_optional; str: 'Optional'),
  2909. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2910. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2911. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2912. (mask:po_rtlproc; str: 'RTL procedure'),
  2913. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2914. (mask:po_far; str: 'Far'),
  2915. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2916. (mask:po_noreturn; str: 'No return'),
  2917. (mask:po_is_function_ref; str: 'Function reference'),
  2918. (mask:po_is_block; str: 'C "Block"'),
  2919. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2920. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2921. (mask:po_noinline; str: 'Never inline'),
  2922. (mask:po_variadic; str: 'C VarArgs with array-of-const para'),
  2923. (mask:po_objc_related_result_type; str: 'Objective-C related result type'),
  2924. (mask:po_anonymous; str: 'Anonymous'),
  2925. (mask:po_wasm_funcref; str: 'WebAssembly funcref'),
  2926. (mask:po_wasm_suspending; str: 'WebAssembly suspending')
  2927. );
  2928. var
  2929. proctypeoption : tproctypeoption;
  2930. i : longint;
  2931. first : boolean;
  2932. begin
  2933. write([space,' Return type : ']);
  2934. readderef('', ProcDef.ReturnType);
  2935. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2936. case proctypeoption of
  2937. potype_function: Include(ProcDef.Options, poFunction);
  2938. potype_procedure: Include(ProcDef.Options, poProcedure);
  2939. potype_constructor: Include(ProcDef.Options, poConstructor);
  2940. potype_destructor: Include(ProcDef.Options, poDestructor);
  2941. potype_operator: Include(ProcDef.Options, poOperator);
  2942. end;
  2943. write([space,' TypeOption : ']);
  2944. first:=true;
  2945. for i:=1 to high(proctypeopt) do
  2946. if (proctypeopt[i].mask=proctypeoption) then
  2947. begin
  2948. if first then
  2949. first:=false
  2950. else
  2951. write(', ');
  2952. write(proctypeopt[i].str);
  2953. end;
  2954. writeln;
  2955. proccalloption:=tproccalloption(ppufile.getbyte);
  2956. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2957. ppufile.getset(tppuset8(procoptions));
  2958. if procoptions<>[] then
  2959. begin
  2960. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2961. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2962. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2963. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2964. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2965. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2966. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2967. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2968. write([space,' Options : ']);
  2969. first:=true;
  2970. for i:=1 to high(procopt) do
  2971. if (procopt[i].mask in procoptions) then
  2972. begin
  2973. if first then
  2974. first:=false
  2975. else
  2976. write(', ');
  2977. write(procopt[i].str);
  2978. end;
  2979. writeln;
  2980. end;
  2981. if (po_explicitparaloc in procoptions) then
  2982. begin
  2983. readcgpara(space);
  2984. end;
  2985. end;
  2986. { type tvaroption is in unit symconst }
  2987. { register variable }
  2988. { type tvarregable is in unit symconst }
  2989. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2990. type
  2991. tvaropt=record
  2992. mask : tvaroption;
  2993. str : string[30];
  2994. end;
  2995. const
  2996. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  2997. (mask:vo_is_external; str:'External'),
  2998. (mask:vo_is_dll_var; str:'DLLVar'),
  2999. (mask:vo_is_thread_var; str:'ThreadVar'),
  3000. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  3001. (mask:vo_is_const; str:'Constant'),
  3002. (mask:vo_is_public; str:'Public'),
  3003. (mask:vo_is_high_para; str:'HighValue'),
  3004. (mask:vo_is_funcret; str:'Funcret'),
  3005. (mask:vo_is_self; str:'Self'),
  3006. (mask:vo_is_vmt; str:'VMT'),
  3007. (mask:vo_is_result; str:'Result'),
  3008. (mask:vo_is_parentfp; str:'ParentFP'),
  3009. (mask:vo_is_loop_counter; str:'LoopCounter'),
  3010. (mask:vo_is_hidden_para; str:'Hidden'),
  3011. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  3012. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  3013. (mask:vo_has_mangledname; str:'HasMangledName'),
  3014. (mask:vo_is_typed_const; str:'TypedConst'),
  3015. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  3016. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  3017. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  3018. (mask:vo_is_msgsel;str:'MsgSel'),
  3019. (mask:vo_is_weak_external;str:'WeakExternal'),
  3020. (mask:vo_is_first_field;str:'IsFirstField'),
  3021. (mask:vo_volatile; str:'Volatile'),
  3022. (mask:vo_has_section; str:'HasSection'),
  3023. (mask:vo_force_finalize; str:'ForceFinalize'),
  3024. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  3025. (mask:vo_is_far; str:'IsFar'),
  3026. (mask:vo_has_global_ref; str:'HasGlobalRef'),
  3027. (mask:vo_is_internal; str:'IsInternal')
  3028. );
  3029. type
  3030. tvaraccessdesc=record
  3031. mask: tvarsymaccessflag;
  3032. str: string[30];
  3033. end;
  3034. const
  3035. varaccessstr : array[ord(low(tvarsymaccessflag))..ord(high(tvarsymaccessflag))] of tvaraccessdesc=(
  3036. (mask: vsa_addr_taken; str:'Address taken'),
  3037. (mask: vsa_different_scope; str:'Accessed from different scope')
  3038. );
  3039. var
  3040. i : longint;
  3041. accessflag: tvarsymaccessflag;
  3042. varsymaccessflags: tvarsymaccessflags;
  3043. first : boolean;
  3044. begin
  3045. readcommonsym(s, VarDef);
  3046. i:=ppufile.getbyte;
  3047. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  3048. with TPpuParamDef(VarDef) do
  3049. case tvarspez(i) of
  3050. vs_value: Spez:=psValue;
  3051. vs_var: Spez:=psVar;
  3052. vs_out: Spez:=psOut;
  3053. vs_const: Spez:=psConst;
  3054. vs_constref: Spez:=psConstRef;
  3055. end;
  3056. writeln([space,' Spez : ',Varspez2Str(i)]);
  3057. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  3058. ppufile.getset(tppuset1(varsymaccessflags));
  3059. write([space, ' Access Flags : ']);
  3060. first:=true;
  3061. for i:=low(varaccessstr) to high(varaccessstr) do
  3062. begin
  3063. if varaccessstr[i].mask in varsymaccessflags then
  3064. begin
  3065. if first then
  3066. first:=false
  3067. else
  3068. write([', ']);
  3069. write([varaccessstr[i].str]);
  3070. end
  3071. end;
  3072. writeln;
  3073. write ([space,' Var Type : ']);
  3074. if VarDef <> nil then
  3075. readderef('',VarDef.VarType)
  3076. else
  3077. readderef('');
  3078. ppufile.getset(tppuset4(varoptions));
  3079. if varoptions<>[] then
  3080. begin
  3081. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  3082. TPpuParamDef(VarDef).Spez:=psHidden;
  3083. write([space,' Options : ']);
  3084. first:=true;
  3085. for i:=1 to high(varopt) do
  3086. if (varopt[i].mask in varoptions) then
  3087. begin
  3088. if first then
  3089. first:=false
  3090. else
  3091. write(', ');
  3092. write(varopt[i].str);
  3093. end;
  3094. writeln;
  3095. end;
  3096. end;
  3097. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  3098. type
  3099. tsymopt=record
  3100. mask : tobjectoption;
  3101. str : string[30];
  3102. end;
  3103. const
  3104. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  3105. (mask:oo_is_forward; str:'IsForward'),
  3106. (mask:oo_is_abstract; str:'IsAbstract'),
  3107. (mask:oo_is_sealed; str:'IsSealed'),
  3108. (mask:oo_has_virtual; str:'HasVirtual'),
  3109. (mask:oo_has_private; str:'HasPrivate'),
  3110. (mask:oo_has_protected; str:'HasProtected'),
  3111. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  3112. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  3113. (mask:oo_has_constructor; str:'HasConstructor'),
  3114. (mask:oo_has_destructor; str:'HasDestructor'),
  3115. (mask:oo_has_vmt; str:'HasVMT'),
  3116. (mask:oo_has_msgstr; str:'HasMsgStr'),
  3117. (mask:oo_has_msgint; str:'HasMsgInt'),
  3118. (mask:oo_can_have_published; str:'CanHavePublished'),
  3119. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  3120. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  3121. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  3122. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  3123. (mask:oo_is_external; str:'External'),
  3124. (mask:oo_is_formal; str:'Formal'),
  3125. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  3126. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  3127. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  3128. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  3129. (mask:oo_has_new_destructor; str:'HasNewDestructor'),
  3130. (mask:oo_is_funcref; str:'IsFuncRef'),
  3131. (mask:oo_is_invokable; str:'IsInvokable'),
  3132. (mask:oo_is_capturer; str:'IsCapturer'),
  3133. (mask:oo_inherits_not_specialized; str:'InheritedNotSpecialized')
  3134. );
  3135. var
  3136. i : longint;
  3137. first : boolean;
  3138. begin
  3139. ppufile.getset(tppuset4(current_objectoptions));
  3140. if current_objectoptions<>[] then
  3141. begin
  3142. if ObjDef <> nil then
  3143. begin
  3144. if oo_is_abstract in current_objectoptions then
  3145. Include(ObjDef.Options, ooIsAbstract);
  3146. end;
  3147. first:=true;
  3148. for i:=1 to high(symopt) do
  3149. if (symopt[i].mask in current_objectoptions) then
  3150. begin
  3151. if first then
  3152. first:=false
  3153. else
  3154. write(', ');
  3155. write(symopt[i].str);
  3156. end;
  3157. end;
  3158. writeln;
  3159. end;
  3160. procedure readextendedrtti;
  3161. type
  3162. tvisopt=record
  3163. mask : trtti_visibility;
  3164. str : string[10];
  3165. end;
  3166. const
  3167. visopt : array[0..ord(high(trtti_visibility))] of tvisopt=(
  3168. (mask:rv_private; str:'Private'),
  3169. (mask:rv_protected; str:'Protected'),
  3170. (mask:rv_public; str:'Public'),
  3171. (mask:rv_published; str:'Published')
  3172. );
  3173. type
  3174. toptionopt=record
  3175. mask : trtti_option;
  3176. str : string[10];
  3177. end;
  3178. const
  3179. voptionopt : array[0..ord(high(trtti_option))] of toptionopt=(
  3180. (mask:ro_methods; str:'Methods'),
  3181. (mask:ro_fields; str:'Fields'),
  3182. (mask:ro_properties; str:'Properties')
  3183. );
  3184. var
  3185. clause: string;
  3186. visibilities: trtti_visibilities;
  3187. first: boolean;
  3188. i, ro: integer;
  3189. begin
  3190. clause:='';
  3191. case trtti_clause(ppufile.getbyte) of
  3192. rtc_none: clause:='None';
  3193. rtc_inherit: clause:='Inherit';
  3194. rtc_explicit: clause:='Explicit';
  3195. end;
  3196. writeln([space,' Clause : ',clause]);
  3197. for ro:=0 to high(voptionopt) do
  3198. begin
  3199. ppufile.getset(tppuset1(visibilities));
  3200. if visibilities<>[] then
  3201. begin
  3202. write([space,' ',voptionopt[ro].str,' : ']);
  3203. first:=true;
  3204. for i:=0 to high(visopt) do
  3205. if visopt[i].mask in visibilities then
  3206. begin
  3207. if first then
  3208. first:=false
  3209. else
  3210. write(', ');
  3211. write(visopt[i].str);
  3212. end;
  3213. if not first then
  3214. writeln;
  3215. end;
  3216. end;
  3217. end;
  3218. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  3219. type
  3220. tpiopt=record
  3221. mask : timplprocoption;
  3222. str : string[30];
  3223. end;
  3224. const
  3225. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  3226. (mask:pio_empty; str:'IsEmpty'),
  3227. (mask:pio_has_inlininginfo; str:'HasInliningInfo'),
  3228. (mask:pio_inline_not_possible; str:'InlineNotPossible'),
  3229. (mask:pio_nested_access; str:'NestedAccess'),
  3230. (mask:pio_thunk; str:'Thunk'),
  3231. (mask:pio_fastmath; str:'FastMath'),
  3232. (mask:pio_inline_forbidden; str:'InlineForbidden')
  3233. );
  3234. var
  3235. i: timplprocoption;
  3236. first: boolean;
  3237. begin
  3238. ppufile.getset(tppuset1(implprocoptions));
  3239. if implprocoptions<>[] then
  3240. begin
  3241. first:=true;
  3242. write([space,' Options : ']);
  3243. for i:=low(piopt) to high(piopt) do
  3244. begin
  3245. if i in implprocoptions then
  3246. begin
  3247. if first then
  3248. first:=false
  3249. else
  3250. write(', ');
  3251. write(piopt[i].str);
  3252. end;
  3253. end;
  3254. writeln;
  3255. end;
  3256. end;
  3257. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  3258. { type tarraydefoption is in unit symconst }
  3259. const
  3260. symopt : array[tarraydefoption] of string = (
  3261. { ado_IsConvertedPointer } 'ConvertedPointer',
  3262. { ado_IsDynamicArray } 'IsDynamicArray',
  3263. { ado_IsVariant } 'IsVariant',
  3264. { ado_IsConstructor } 'IsConstructor',
  3265. { ado_IsArrayOfConst } 'ArrayOfConst',
  3266. { ado_IsConstString } 'ConstString',
  3267. { ado_IsBitPacked } 'BitPacked',
  3268. { ado_IsVector } 'Vector',
  3269. { ado_IsGeneric } 'Generic',
  3270. { ado_OpenArray } 'OpenArray'
  3271. );
  3272. var
  3273. symoptions: tarraydefoptions;
  3274. i: tarraydefoption;
  3275. first: boolean;
  3276. begin
  3277. ppufile.getset(tppuset2(symoptions));
  3278. if symoptions<>[] then
  3279. begin
  3280. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  3281. first:=true;
  3282. for i:=Low(symopt) to high(symopt) do
  3283. if (i in symoptions) then
  3284. begin
  3285. if first then
  3286. first:=false
  3287. else
  3288. write(', ');
  3289. write(symopt[i]);
  3290. end;
  3291. end;
  3292. writeln;
  3293. end;
  3294. (* options for properties
  3295. tpropertyoption=(ppo_none,
  3296. ppo_indexed,
  3297. ppo_defaultproperty,
  3298. ppo_stored,
  3299. ppo_hasparameters,
  3300. ppo_implements,
  3301. ppo_enumerator_current,
  3302. ppo_overrides,
  3303. ppo_dispid_write { no longer used }
  3304. );
  3305. tpropertyoptions=set of tpropertyoption;
  3306. *)
  3307. function readpropertyoptions:tpropertyoptions;
  3308. { type tarraydefoption is in unit symconst }
  3309. type
  3310. tpropopt=record
  3311. mask : tpropertyoption;
  3312. str : string[30];
  3313. end;
  3314. const
  3315. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  3316. (mask:ppo_indexed;str:'indexed'),
  3317. (mask:ppo_defaultproperty;str:'default'),
  3318. (mask:ppo_stored;str:'stored'),
  3319. (mask:ppo_hasparameters;str:'has parameters'),
  3320. (mask:ppo_implements;str:'implements'),
  3321. (mask:ppo_enumerator_current;str:'enumerator current'),
  3322. (mask:ppo_overrides;str:'overrides'),
  3323. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  3324. );
  3325. var
  3326. i : longint;
  3327. first : boolean;
  3328. begin
  3329. ppufile.getset(tppuset2(result));
  3330. if result<>[] then
  3331. begin
  3332. first:=true;
  3333. for i:=1 to high(symopt) do
  3334. if (symopt[i].mask in result) then
  3335. begin
  3336. if first then
  3337. first:=false
  3338. else
  3339. write(', ');
  3340. write(symopt[i].str);
  3341. end;
  3342. end;
  3343. writeln;
  3344. end;
  3345. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  3346. { type is in unit symconst }
  3347. { Management operator options
  3348. tmanagementoperator=(
  3349. mop_none,
  3350. mop_initialize,
  3351. mop_finalize,
  3352. mop_addref,
  3353. mop_copy);
  3354. }
  3355. type
  3356. tmopopt=record
  3357. mask : tmanagementoperator;
  3358. str : string[10];
  3359. end;
  3360. const
  3361. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  3362. (mask:mop_initialize;str:'initialize'),
  3363. (mask:mop_finalize;str:'finalize'),
  3364. (mask:mop_addref;str:'addref'),
  3365. (mask:mop_copy;str:'copy')
  3366. );
  3367. var
  3368. i : longint;
  3369. first : boolean;
  3370. begin
  3371. ppufile.getset(tppuset1(result));
  3372. if result<>[] then
  3373. begin
  3374. first:=true;
  3375. for i:=1 to high(managementoperatoropt) do
  3376. if (managementoperatoropt[i].mask in result) then
  3377. begin
  3378. if first then
  3379. begin
  3380. write(space);
  3381. write(name);
  3382. write(': ');
  3383. first:=false;
  3384. end
  3385. else
  3386. write(', ');
  3387. write(managementoperatoropt[i].str);
  3388. end;
  3389. if not first then
  3390. writeln;
  3391. end;
  3392. end;
  3393. procedure readnodetree;
  3394. var
  3395. l : longint;
  3396. p : pointer;
  3397. begin
  3398. with ppufile do
  3399. begin
  3400. if space<>'' then
  3401. Writeln([space,'------ nodetree ------']);
  3402. if readentry=ibnodetree then
  3403. begin
  3404. l:=entrysize;
  3405. Writeln([space,'Tree size : ',l]);
  3406. { Read data to prevent error that entry is not completly read }
  3407. getmem(p,l);
  3408. getdata(p^,l);
  3409. freemem(p);
  3410. end
  3411. else
  3412. begin
  3413. WriteError('!! ibnodetree not found');
  3414. end;
  3415. end;
  3416. end;
  3417. procedure ReadCreatedObjTypes;
  3418. var
  3419. i,j,
  3420. len,
  3421. bssize: longint;
  3422. bs: pbyte;
  3423. begin
  3424. if ppufile.readentry<>ibcreatedobjtypes then
  3425. begin
  3426. WriteError('!! ibcreatedobjtypes entry not found');
  3427. ppufile.skipdata(ppufile.entrysize);
  3428. exit
  3429. end;
  3430. writeln;
  3431. writeln([space,'WPO info']);
  3432. writeln([space,'--------']);
  3433. len:=ppufile.getlongint;
  3434. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  3435. space:=space+' ';
  3436. for i:=0 to len-1 do
  3437. readderef(space);
  3438. setlength(space,length(space)-2);
  3439. len:=ppufile.getlongint;
  3440. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  3441. space:=space+' ';
  3442. for i:=0 to len-1 do
  3443. readderef(space);
  3444. setlength(space,length(space)-2);
  3445. len:=ppufile.getlongint;
  3446. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  3447. space:=space+' ';
  3448. for i:=0 to len-1 do
  3449. readderef(space);
  3450. setlength(space,length(space)-2);
  3451. len:=ppufile.getlongint;
  3452. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3453. space:=space+' ';
  3454. for i:=0 to len-1 do
  3455. begin
  3456. write([space,'Class def : ']);
  3457. readderef('');
  3458. write([space+' ','Called vmtentries : ']);
  3459. bssize:=ppufile.getlongint;
  3460. getmem(bs,bssize);
  3461. ppufile.readdata(bs^,bssize);
  3462. for j:=0 to bssize*8-1 do
  3463. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3464. write([j,', ']);
  3465. writeln;
  3466. freemem(bs);
  3467. end;
  3468. setlength(space,length(space)-2);
  3469. end;
  3470. {****************************************************************************
  3471. Read Symbols Part
  3472. ****************************************************************************}
  3473. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3474. function _finddef(symdef: TPpuDef): TPpuDef;
  3475. begin
  3476. Result:=nil;
  3477. if symdef.Ref.IsCurUnit then
  3478. begin;
  3479. Result:=CurUnit.FindById(symdef.Ref.Id);
  3480. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3481. begin
  3482. Result.Name:=symdef.Name;
  3483. Result.FilePos:=symdef.FilePos;
  3484. end
  3485. else
  3486. Result:=nil;
  3487. end;
  3488. end;
  3489. type
  3490. pguid = ^tguid;
  3491. tguid = packed record
  3492. D1: LongWord;
  3493. D2: Word;
  3494. D3: Word;
  3495. D4: array[0..7] of Byte;
  3496. end;
  3497. var
  3498. b : byte;
  3499. pc : pchar;
  3500. ch : dword;
  3501. startnewline : boolean;
  3502. i,j,len : longint;
  3503. prettyname, ss : ansistring;
  3504. ws: widestring;
  3505. guid : tguid;
  3506. realvalue : ppureal;
  3507. doublevalue : double;
  3508. singlevalue : single;
  3509. realstr : shortstring;
  3510. extended : TSplit80bitReal;
  3511. pw : tcompilerwidestring;
  3512. varoptions : tvaroptions;
  3513. propoptions : tpropertyoptions;
  3514. iexp: Tconstexprint;
  3515. def: TPpuDef;
  3516. constdef: TPpuConstDef absolute def;
  3517. begin
  3518. with ppufile do
  3519. begin
  3520. if space<>'' then
  3521. Writeln([space,'------ ',s,' ------']);
  3522. if readentry=ibstartsyms then
  3523. begin
  3524. Writeln([space,'Symtable count: ',getlongint]);
  3525. end
  3526. else
  3527. Writeln('!! ibstartsym not found');
  3528. repeat
  3529. def:=nil;
  3530. b:=readentry;
  3531. case b of
  3532. ibunitsym :
  3533. readcommonsym('Unit symbol ');
  3534. ibnamespacesym :
  3535. begin
  3536. readcommonsym('NameSpace symbol ');
  3537. write([space,' Hidden Unit : ']);
  3538. readderef('');
  3539. end;
  3540. iblabelsym :
  3541. readcommonsym('Label symbol ');
  3542. ibtypesym :
  3543. begin
  3544. def:=TPpuTypeRef.Create(nil);
  3545. readcommonsym('Type symbol ',def);
  3546. write([space,' Result Type : ']);
  3547. readderef('', def.Ref);
  3548. if _finddef(def) = nil then
  3549. def.Parent:=ParentDef;
  3550. prettyname:=getansistring;
  3551. if prettyname<>'' then
  3552. begin
  3553. write([space,' Pretty Name : ']);
  3554. Writeln(prettyname);
  3555. end;
  3556. end;
  3557. ibprocsym :
  3558. begin
  3559. def:=TPpuDef.Create(nil);
  3560. readcommonsym('Procedure symbol ', def);
  3561. len:=ppufile.getword;
  3562. for i:=1 to len do
  3563. begin
  3564. write([space,' Definition : ']);
  3565. readderef('', def.Ref);
  3566. _finddef(def);
  3567. end;
  3568. if def.GenericDummy then
  3569. begin
  3570. len:=ppufile.getword;
  3571. for i:=1 to len do
  3572. begin
  3573. write([space,' Gen Ovld : ']);
  3574. readderef('',def.Ref);
  3575. _finddef(def);
  3576. end;
  3577. end;
  3578. end;
  3579. ibconstsym :
  3580. begin
  3581. constdef:=TPpuConstDef.Create(ParentDef);
  3582. readcommonsym('Constant symbol ',constdef);
  3583. b:=getbyte;
  3584. case tconsttyp(b) of
  3585. constord :
  3586. begin
  3587. write ([space,' OrdinalType : ']);
  3588. readderef('',constdef.TypeRef);
  3589. iexp:=getexprint;
  3590. constdef.ConstType:=ctInt;
  3591. constdef.VInt:=iexp.svalue;
  3592. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3593. end;
  3594. constpointer :
  3595. begin
  3596. write ([space,' PointerType : ']);
  3597. readderef('',constdef.TypeRef);
  3598. constdef.ConstType:=ctInt;
  3599. constdef.VInt:=int64(getptruint);
  3600. writeln([space,' Value : ',constdef.VInt])
  3601. end;
  3602. conststring,
  3603. constresourcestring :
  3604. begin
  3605. write ([space,' StringType : ']);
  3606. readderef('',constdef.TypeRef);
  3607. len:=getlongint;
  3608. getmem(pc,len+1);
  3609. getdata(pc^,len);
  3610. (pc+len)^:= #0;
  3611. writeln([space,' Length : ',len]);
  3612. writeln([space,' Value : "',pc,'"']);
  3613. constdef.ConstType:=ctStr;
  3614. SetString(constdef.VStr, pc, len);
  3615. constdef.VStr:=UTF8Encode(constdef.VStr);
  3616. freemem(pc,len+1);
  3617. end;
  3618. constreal :
  3619. begin
  3620. constdef.ConstType:=ctFloat;
  3621. write ([space,' RealType : ']);
  3622. readderef('',constdef.TypeRef);
  3623. write([space,' Value : ']);
  3624. if entryleft=sizeof(ppureal) then
  3625. begin
  3626. realvalue:=getrealsize(sizeof(ppureal));
  3627. constdef.VFloat:=realvalue;
  3628. system.str(realvalue,realstr);
  3629. writeln([realstr]);
  3630. end
  3631. else if entryleft=sizeof(double) then
  3632. begin
  3633. doublevalue:=getrealsize(sizeof(double));
  3634. constdef.VFloat:=doublevalue;
  3635. system.str(doublevalue,realstr);
  3636. writeln([realstr]);
  3637. end
  3638. else if entryleft=sizeof(single) then
  3639. begin
  3640. singlevalue:=getrealsize(sizeof(single));
  3641. constdef.VFloat:=singlevalue;
  3642. system.str(singlevalue,realstr);
  3643. writeln([realstr]);
  3644. end
  3645. else if entryleft=10 then
  3646. begin
  3647. getdata(extended,entryleft);
  3648. ss:=Real80bitToStr(extended,constdef.VFloat);
  3649. writeln(ss);
  3650. end
  3651. else
  3652. begin
  3653. realvalue:=0.0;
  3654. WriteError('Error reading real value');
  3655. end;
  3656. end;
  3657. constset :
  3658. begin
  3659. constdef.ConstType:=ctSet;
  3660. write ([space,' Set Type : ']);
  3661. readderef('',constdef.TypeRef);
  3662. for i:=1to 4 do
  3663. begin
  3664. write ([space,' Value : ']);
  3665. for j:=1to 8 do
  3666. begin
  3667. if j>1 then
  3668. write(',');
  3669. b:=getbyte;
  3670. if ppufile.change_endian then
  3671. b:=reverse_byte(b);
  3672. write(hexstr(b,2));
  3673. constdef.VSet[i*j-1]:=b;
  3674. end;
  3675. writeln;
  3676. end;
  3677. end;
  3678. constnil:
  3679. begin
  3680. write([space,' NIL pointer :']);
  3681. readderef('',constdef.TypeRef);
  3682. constdef.ConstType:=ctPtr;
  3683. constdef.VInt:=0;
  3684. end;
  3685. constwstring :
  3686. begin
  3687. initwidestring(pw);
  3688. setlengthwidestring(pw,getlongint);
  3689. if widecharsize=2 then
  3690. { don't use getdata, because the compilerwidechars may have to
  3691. be byteswapped
  3692. }
  3693. begin
  3694. for i:=0 to pw.len-1 do
  3695. pw.data[i]:=ppufile.getword;
  3696. SetString(ws, PWideChar(pw.data), pw.len);
  3697. constdef.VStr:=UTF8Encode(ws);
  3698. constdef.ConstType:=ctStr;
  3699. end
  3700. else if widecharsize=4 then
  3701. begin
  3702. for i:=0 to pw.len-1 do
  3703. pw.data[i]:=cardinal(ppufile.getlongint);
  3704. end
  3705. else
  3706. begin
  3707. WriteError('Unsupported tcompilerwidechar size');
  3708. end;
  3709. Write([space,'Wide string type']);
  3710. startnewline:=true;
  3711. for i:=0 to pw.len-1 do
  3712. begin
  3713. if startnewline then
  3714. begin
  3715. writeln;
  3716. write(space);
  3717. startnewline:=false;
  3718. end;
  3719. ch:=pw.data[i];
  3720. if widecharsize=2 then
  3721. write(hexstr(ch,4))
  3722. else
  3723. write(hexstr(ch,8));
  3724. if ((i + 1) mod 8)= 0 then
  3725. startnewline:=true
  3726. else
  3727. if i <> pw.len-1 then
  3728. write(', ');
  3729. end;
  3730. donewidestring(pw);
  3731. Writeln;
  3732. end;
  3733. constguid:
  3734. begin
  3735. write ([space,' IntfType : ']);
  3736. readderef('',constdef.TypeRef);
  3737. getdata(guid,sizeof(guid));
  3738. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3739. for i:=0 to 7 do
  3740. begin
  3741. write(hexstr(guid.d4[i],2));
  3742. if i=1 then write('-');
  3743. end;
  3744. writeln('}');
  3745. end
  3746. else
  3747. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3748. end;
  3749. end;
  3750. ibabsolutevarsym :
  3751. begin
  3752. def:=TPpuVarDef.Create(ParentDef);
  3753. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3754. Write ([space,' Relocated to ']);
  3755. b:=getbyte;
  3756. case absolutetyp(b) of
  3757. tovar :
  3758. readpropaccesslist(space+' Sym : ');
  3759. toasm :
  3760. Writeln(['Assembler name : ',getstring]);
  3761. toaddr :
  3762. begin
  3763. Write(['Address : ',getpuint]);
  3764. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3765. Write([' (Far: ',getbyte<>0,')']);
  3766. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3767. if getbyte<>0 then
  3768. Write([' (Far: TRUE, Segment=',getaword,')'])
  3769. else
  3770. Write([' (Far: FALSE)']);
  3771. Writeln;
  3772. end;
  3773. else
  3774. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3775. end;
  3776. end;
  3777. ibfieldvarsym :
  3778. begin
  3779. def:=TPpuFieldDef.Create(ParentDef);
  3780. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3781. writeln([space,' Address : ',getasizeint]);
  3782. if vo_has_mangledname in varoptions then
  3783. writeln([space,' Mangled name : ',getstring]);
  3784. end;
  3785. ibstaticvarsym :
  3786. begin
  3787. def:=TPpuVarDef.Create(ParentDef);
  3788. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3789. write ([space,' DefaultConst : ']);
  3790. readderef('');
  3791. if (vo_has_mangledname in varoptions) then
  3792. writeln([space,'Mangledname : ',readsymstr(ppufile)]);
  3793. if vo_has_section in varoptions then
  3794. writeln(['Section name:',ppufile.getansistring]);
  3795. write ([space,' FieldVarSymDeref: ']);
  3796. readderef('');
  3797. end;
  3798. iblocalvarsym :
  3799. begin
  3800. readabstractvarsym('Local Variable symbol ',varoptions);
  3801. write ([space,' DefaultConst : ']);
  3802. readderef('');
  3803. end;
  3804. ibparavarsym :
  3805. begin
  3806. def:=TPpuParamDef.Create(ParentDef);
  3807. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3808. write ([space,' DefaultConst : ']);
  3809. readderef('',TPpuParamDef(def).DefaultValue);
  3810. writeln([space,' ParaNr : ',getword]);
  3811. writeln([space,' Univ : ',getboolean]);
  3812. writeln([space,' VarState : ',getbyte]);
  3813. writeln([space,' Refs : ',getbyte]);
  3814. if (vo_has_explicit_paraloc in varoptions) then
  3815. begin
  3816. readcgpara(space+' ');
  3817. end;
  3818. end;
  3819. ibenumsym :
  3820. begin
  3821. def:=TPpuConstDef.Create(nil);
  3822. readcommonsym('Enumeration symbol ',def);
  3823. write ([space,' Definition : ']);
  3824. readderef('');
  3825. TPpuConstDef(def).ConstType:=ctInt;
  3826. TPpuConstDef(def).VInt:=getlongint;
  3827. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3828. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3829. def.Parent:=ParentDef;
  3830. end;
  3831. ibsyssym :
  3832. begin
  3833. readcommonsym('Internal system symbol ');
  3834. writeln([space,' Internal Nr : ',getlongint]);
  3835. end;
  3836. ibmacrosym :
  3837. begin
  3838. readcommonsym('Macro symbol ');
  3839. writeln([space,' Defined: ',getboolean]);
  3840. writeln([space,' Compiler var: ',getboolean]);
  3841. len:=getlongint;
  3842. writeln([space,' Value length: ',len]);
  3843. if len > 0 then
  3844. begin
  3845. getmem(pc,len+1);
  3846. getdata(pc^,len);
  3847. (pc+len)^:= #0;
  3848. writeln([space,' Value: "',pc,'"']);
  3849. freemem(pc,len+1);
  3850. end;
  3851. end;
  3852. ibpropertysym :
  3853. begin
  3854. def:=TPpuPropDef.Create(ParentDef);
  3855. readcommonsym('Property ',def);
  3856. write ([space,' Prop Options : ']);
  3857. propoptions:=readpropertyoptions;
  3858. if ppo_overrides in propoptions then
  3859. begin
  3860. write ([space,' OverrideProp : ']);
  3861. readderef('');
  3862. end;
  3863. if ppo_defaultproperty in propoptions then
  3864. Include(TPpuPropDef(def).Options, poDefault);
  3865. write ([space,' Prop Type : ']);
  3866. readderef('',TPpuPropDef(def).PropType);
  3867. writeln([space,' Index : ',getlongint]);
  3868. writeln([space,' Default : ',getlongint]);
  3869. write ([space,' Index Type : ']);
  3870. readderef('');
  3871. { palt_none }
  3872. write ([space,' Noneaccess : ']);
  3873. readpropaccesslist('');
  3874. write ([space,' Readaccess : ']);
  3875. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3876. write ([space,' Writeaccess : ']);
  3877. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3878. write ([space,' Storedaccess : ']);
  3879. readpropaccesslist(space+' Sym: ');
  3880. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3881. begin
  3882. space:=' '+space;
  3883. readsymtable('parast',TPpuPropDef(def));
  3884. delete(space,1,4);
  3885. end;
  3886. end;
  3887. iberror :
  3888. begin
  3889. WriteError('!! Error in PPU');
  3890. exit;
  3891. end;
  3892. ibendsyms :
  3893. break;
  3894. else
  3895. begin
  3896. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3897. end;
  3898. end;
  3899. if assigned(def) then
  3900. readsymsubentries(def);
  3901. if (def <> nil) and (def.Parent = nil) then
  3902. def.Free;
  3903. if not EndOfEntry then
  3904. HasMoreInfos;
  3905. until false;
  3906. end;
  3907. end;
  3908. {****************************************************************************
  3909. Read defintions Part
  3910. ****************************************************************************}
  3911. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3912. { type tordtype is in symconst unit }
  3913. {
  3914. uvoid,
  3915. u8bit,u16bit,u32bit,u64bit,u128bit,
  3916. s8bit,s16bit,s32bit,s64bit,s128bit,
  3917. bool8bit,bool16bit,bool32bit,bool64bit,
  3918. uchar,uwidechar,scurrency,customint
  3919. ); }
  3920. { type tobjecttyp is in symconst unit }
  3921. { type tvarianttype is in symconst unit }
  3922. { type thelpertype is in symconst unit }
  3923. var
  3924. b : byte;
  3925. otb : byte; { Object Type byte, needed later again }
  3926. l,j,tokenbufsize : longint;
  3927. tokenbuf : pbyte;
  3928. calloption : tproccalloption;
  3929. procoptions : tprocoptions;
  3930. implprocoptions: timplprocoptions;
  3931. defoptions: tdefoptions;
  3932. iexpr: Tconstexprint;
  3933. def: TPpuDef;
  3934. objdef: TPpuObjectDef absolute def;
  3935. arrdef: TPpuArrayDef absolute def;
  3936. enumdef: TPpuEnumDef absolute def;
  3937. setdef: TPpuSetDef absolute def;
  3938. orddef: TPpuOrdDef absolute def;
  3939. floatdef: TPpuFloatDef absolute def;
  3940. strdef: TPpuStringDef absolute def;
  3941. filedef: TPpuFileDef absolute def;
  3942. begin
  3943. with ppufile do
  3944. begin
  3945. if space<>'' then
  3946. Writeln([space,'------ ',s,' ------']);
  3947. if readentry<>ibstartdefs then
  3948. Writeln('!! ibstartdefs not found');
  3949. repeat
  3950. def:=nil;
  3951. b:=readentry;
  3952. case b of
  3953. ibpointerdef :
  3954. begin
  3955. def:=TPpuPointerDef.Create(ParentDef);
  3956. readcommondef('Pointer definition',defoptions,def);
  3957. write ([space,' Pointed Type : ']);
  3958. readderef('',TPpuPointerDef(def).Ptr);
  3959. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3960. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3961. begin
  3962. write([space,' X86 Pointer Type : ']);
  3963. b:=getbyte;
  3964. case tx86pointertyp(b) of
  3965. x86pt_near: writeln('Near');
  3966. x86pt_near_cs: writeln('Near ''CS''');
  3967. x86pt_near_ds: writeln('Near ''DS''');
  3968. x86pt_near_ss: writeln('Near ''SS''');
  3969. x86pt_near_es: writeln('Near ''ES''');
  3970. x86pt_near_fs: writeln('Near ''FS''');
  3971. x86pt_near_gs: writeln('Near ''GS''');
  3972. x86pt_far: writeln('Far');
  3973. x86pt_huge: writeln('Huge');
  3974. else
  3975. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3976. end;
  3977. end;
  3978. if tsystemcpu(ppufile.header.common.cpu)=cpu_wasm32 then
  3979. writeln([space,' WASM externref : ',(getbyte<>0)]);
  3980. end;
  3981. iborddef :
  3982. begin
  3983. orddef:=TPpuOrdDef.Create(ParentDef);
  3984. readcommondef('Ordinal definition',defoptions,orddef);
  3985. write ([space,' Base type : ']);
  3986. b:=getbyte;
  3987. case tordtype(b) of
  3988. uvoid:
  3989. begin
  3990. writeln('uvoid');
  3991. orddef.OrdType:=otVoid;
  3992. end;
  3993. u8bit:
  3994. begin
  3995. writeln('u8bit');
  3996. orddef.OrdType:=otUInt;
  3997. orddef.Size:=1;
  3998. end;
  3999. u16bit:
  4000. begin
  4001. writeln('u16bit');
  4002. orddef.OrdType:=otUInt;
  4003. orddef.Size:=2;
  4004. end;
  4005. u32bit:
  4006. begin
  4007. writeln('u32bit');
  4008. orddef.OrdType:=otUInt;
  4009. orddef.Size:=4;
  4010. end;
  4011. u64bit:
  4012. begin
  4013. writeln('u64bit');
  4014. orddef.OrdType:=otUInt;
  4015. orddef.Size:=8;
  4016. end;
  4017. u128bit:
  4018. begin
  4019. writeln('u128bit');
  4020. orddef.OrdType:=otUInt;
  4021. orddef.Size:=16;
  4022. end;
  4023. s8bit:
  4024. begin
  4025. writeln('s8bit');
  4026. orddef.OrdType:=otSInt;
  4027. orddef.Size:=1;
  4028. end;
  4029. s16bit:
  4030. begin
  4031. writeln('s16bit');
  4032. orddef.OrdType:=otSInt;
  4033. orddef.Size:=2;
  4034. end;
  4035. s32bit:
  4036. begin
  4037. writeln('s32bit');
  4038. orddef.OrdType:=otSInt;
  4039. orddef.Size:=4;
  4040. end;
  4041. s64bit:
  4042. begin
  4043. writeln('s64bit');
  4044. orddef.OrdType:=otSInt;
  4045. orddef.Size:=8;
  4046. end;
  4047. s128bit:
  4048. begin
  4049. writeln('s128bit');
  4050. orddef.OrdType:=otSInt;
  4051. orddef.Size:=16;
  4052. end;
  4053. pasbool1:
  4054. begin
  4055. writeln('pasbool1');
  4056. orddef.OrdType:=otPasBool;
  4057. orddef.Size:=1;
  4058. end;
  4059. pasbool8:
  4060. begin
  4061. writeln('pasbool8');
  4062. orddef.OrdType:=otPasBool;
  4063. orddef.Size:=1;
  4064. end;
  4065. pasbool16:
  4066. begin
  4067. writeln('pasbool16');
  4068. orddef.OrdType:=otPasBool;
  4069. orddef.Size:=2;
  4070. end;
  4071. pasbool32:
  4072. begin
  4073. writeln('pasbool32');
  4074. orddef.OrdType:=otPasBool;
  4075. orddef.Size:=4;
  4076. end;
  4077. pasbool64:
  4078. begin
  4079. writeln('pasbool64');
  4080. orddef.OrdType:=otPasBool;
  4081. orddef.Size:=8;
  4082. end;
  4083. bool8bit:
  4084. begin
  4085. writeln('bool8bit');
  4086. orddef.OrdType:=otBool;
  4087. orddef.Size:=1;
  4088. end;
  4089. bool16bit:
  4090. begin
  4091. writeln('bool16bit');
  4092. orddef.OrdType:=otBool;
  4093. orddef.Size:=2;
  4094. end;
  4095. bool32bit:
  4096. begin
  4097. writeln('bool32bit');
  4098. orddef.OrdType:=otBool;
  4099. orddef.Size:=4;
  4100. end;
  4101. bool64bit:
  4102. begin
  4103. writeln('bool64bit');
  4104. orddef.OrdType:=otBool;
  4105. orddef.Size:=8;
  4106. end;
  4107. uchar:
  4108. begin
  4109. writeln('uchar');
  4110. orddef.OrdType:=otChar;
  4111. orddef.Size:=1;
  4112. end;
  4113. uwidechar:
  4114. begin
  4115. writeln('uwidechar');
  4116. orddef.OrdType:=otChar;
  4117. orddef.Size:=2;
  4118. end;
  4119. scurrency:
  4120. begin
  4121. writeln('scurrency');
  4122. orddef.OrdType:=otCurrency;
  4123. orddef.Size:=8;
  4124. end;
  4125. customint:
  4126. begin
  4127. writeln('customint');
  4128. orddef.OrdType:=otSint;
  4129. orddef.Size:=sizeof(ASizeInt);
  4130. end
  4131. else
  4132. WriteWarning('Invalid base type: ' + IntToStr(b));
  4133. end;
  4134. iexpr:=getexprint;
  4135. orddef.RangeLow:=iexpr.svalue;
  4136. write([space,' Range : ',constexp.tostr(iexpr)]);
  4137. iexpr:=getexprint;
  4138. orddef.RangeHigh:=iexpr.svalue;
  4139. writeln([' to ',constexp.tostr(iexpr)]);
  4140. end;
  4141. ibfloatdef :
  4142. begin
  4143. floatdef:=TPpuFloatDef.Create(ParentDef);
  4144. readcommondef('Float definition',defoptions,floatdef);
  4145. write ([space,' Float type : ']);
  4146. b:=getbyte;
  4147. case b of
  4148. ftSingle:
  4149. begin
  4150. writeln('Single');
  4151. floatdef.FloatType:=pftSingle;
  4152. end;
  4153. ftDouble:
  4154. begin
  4155. writeln('Double');
  4156. floatdef.FloatType:=pftDouble;
  4157. end;
  4158. ftExtended:
  4159. begin
  4160. writeln('Extended');
  4161. floatdef.FloatType:=pftExtended;
  4162. end;
  4163. ftComp:
  4164. begin
  4165. writeln('Comp');
  4166. floatdef.FloatType:=pftComp;
  4167. end;
  4168. ftCurr:
  4169. begin
  4170. writeln('Currency');
  4171. floatdef.FloatType:=pftCurrency;
  4172. end;
  4173. ftFloat128:
  4174. begin
  4175. writeln('Float128');
  4176. floatdef.FloatType:=pftFloat128;
  4177. end;
  4178. else
  4179. WriteWarning('Invalid float type: ' + IntToStr(b));
  4180. end;
  4181. end;
  4182. ibarraydef :
  4183. begin
  4184. arrdef:=TPpuArrayDef.Create(ParentDef);
  4185. readcommondef('Array definition',defoptions,arrdef);
  4186. write ([space,' Element type : ']);
  4187. readderef('',arrdef.ElType);
  4188. write ([space,' Range Type : ']);
  4189. readderef('',arrdef.RangeType);
  4190. arrdef.RangeLow:=getasizeint;
  4191. arrdef.RangeHigh:=getasizeint;
  4192. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  4193. write ([space,' Options : ']);
  4194. readarraydefoptions(arrdef);
  4195. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  4196. writeln([space,' Huge : ',(getbyte<>0)]);
  4197. readsymtable('symbols', arrdef);
  4198. end;
  4199. ibprocdef :
  4200. begin
  4201. def:=TPpuProcDef.Create(ParentDef);
  4202. readcommondef('Procedure definition',defoptions,def);
  4203. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  4204. if (po_has_mangledname in procoptions) then
  4205. writeln([space,' Mangled name : ',readsymstr(ppufile)]);
  4206. writeln([space,' Number : ',getword]);
  4207. writeln([space,' Level : ',getbyte]);
  4208. write ([space,' Class : ']);
  4209. readderef('');
  4210. write ([space,' Procsym : ']);
  4211. readderef('', def.Ref);
  4212. write ([space,' File Pos : ']);
  4213. readposinfo(def);
  4214. write ([space,' Visibility : ']);
  4215. readvisibility(def);
  4216. write ([space,' SymOptions : ']);
  4217. readsymoptions(space+' ');
  4218. if (po_has_importdll in procoptions) then
  4219. writeln([space,' Import DLL : ',getstring]);
  4220. if (po_has_importname in procoptions) then
  4221. writeln([space,' Import Name : ',getstring]);
  4222. writeln([space,' Import Nr : ',getword]);
  4223. if (po_msgint in procoptions) then
  4224. writeln([space,' MsgInt : ',getlongint]);
  4225. if (po_msgstr in procoptions) then
  4226. writeln([space,' MsgStr : ',getstring]);
  4227. if (po_dispid in procoptions) then
  4228. writeln([space,' DispID: ',ppufile.getlongint]);
  4229. readprocimploptions(space,implprocoptions);
  4230. if (pio_has_inlininginfo in implprocoptions) then
  4231. begin
  4232. write ([space,' FuncretSym : ']);
  4233. readderef('');
  4234. readprocinfooptions(space);
  4235. end;
  4236. b:=ppufile.getbyte;
  4237. if b<>0 then
  4238. begin
  4239. write ([space,' Alias names : ']);
  4240. for j:=1 to b do
  4241. begin
  4242. write(ppufile.getstring);
  4243. if j<b then
  4244. write(', ');
  4245. end;
  4246. writeln;
  4247. end;
  4248. tokenbufsize:=ppufile.getlongint;
  4249. if tokenbufsize<>0 then
  4250. begin
  4251. space:=space + ' ';
  4252. write ([space,'Declaration token buffer : size = ',tokenbufsize]);
  4253. tokenbuf:=allocmem(tokenbufsize);
  4254. ppufile.getdata(tokenbuf^,tokenbufsize);
  4255. displaytokenbuffer(tokenbuf,tokenbufsize);
  4256. freemem(tokenbuf);
  4257. delete(space,1,4);
  4258. end;
  4259. if po_syscall_has_libsym in procoptions then
  4260. begin
  4261. { library symbol for AmigaOS/MorphOS/AROS }
  4262. write ([space,' Library symbol : ']);
  4263. readderef('');
  4264. end;
  4265. if not EndOfEntry then
  4266. HasMoreInfos;
  4267. space:=' '+space;
  4268. { parast }
  4269. readsymtable('parast', TPpuProcDef(def));
  4270. { localst }
  4271. if (pio_has_inlininginfo in implprocoptions) then
  4272. readsymtable('inline localst')
  4273. else if (df_generic in defoptions) then
  4274. readsymtable('generic localst');
  4275. if (pio_has_inlininginfo in implprocoptions) then
  4276. readnodetree;
  4277. delete(space,1,4);
  4278. end;
  4279. ibprocvardef :
  4280. begin
  4281. def:=TPpuProcTypeDef.Create(ParentDef);
  4282. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  4283. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  4284. writeln([space,' Symtable level :',ppufile.getbyte]);
  4285. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4286. readderef('');
  4287. if not EndOfEntry then
  4288. HasMoreInfos;
  4289. space:=' '+space;
  4290. { parast }
  4291. readsymtable('parast',TPpuProcDef(def));
  4292. delete(space,1,4);
  4293. end;
  4294. ibshortstringdef :
  4295. begin
  4296. strdef:=TPpuStringDef.Create(ParentDef);
  4297. strdef.StrType:=stShort;
  4298. readcommondef('ShortString definition',defoptions,strdef);
  4299. strdef.Len:=getbyte;
  4300. writeln([space,' Length : ',strdef.Len]);
  4301. end;
  4302. ibwidestringdef :
  4303. begin
  4304. strdef:=TPpuStringDef.Create(ParentDef);
  4305. strdef.StrType:=stWide;
  4306. readcommondef('WideString definition',defoptions,strdef);
  4307. strdef.Len:=getasizeint;
  4308. writeln([space,' Length : ',strdef.Len]);
  4309. end;
  4310. ibunicodestringdef :
  4311. begin
  4312. strdef:=TPpuStringDef.Create(ParentDef);
  4313. strdef.StrType:=stUnicode;
  4314. readcommondef('UnicodeString definition',defoptions,strdef);
  4315. strdef.Len:=getasizeint;
  4316. writeln([space,' Length : ',strdef.Len]);
  4317. writeln([space,' Encoding : ',getword]);
  4318. end;
  4319. ibansistringdef :
  4320. begin
  4321. strdef:=TPpuStringDef.Create(ParentDef);
  4322. strdef.StrType:=stAnsi;
  4323. readcommondef('AnsiString definition',defoptions,strdef);
  4324. strdef.Len:=getasizeint;
  4325. writeln([space,' Length : ',strdef.Len]);
  4326. writeln([space,' Encoding : ',getword]);
  4327. end;
  4328. iblongstringdef :
  4329. begin
  4330. strdef:=TPpuStringDef.Create(ParentDef);
  4331. strdef.StrType:=stLong;
  4332. readcommondef('Longstring definition',defoptions,strdef);
  4333. strdef.Len:=getasizeint;
  4334. writeln([space,' Length : ',strdef.Len]);
  4335. end;
  4336. ibrecorddef :
  4337. begin
  4338. objdef:=TPpuRecordDef.Create(ParentDef);
  4339. readcommondef('Record definition',defoptions, objdef);
  4340. def.Name:=getstring;
  4341. writeln([space,' Name of Record : ',objdef.Name]);
  4342. writeln([space,' Import lib/pkg : ',getstring]);
  4343. write ([space,' Options : ']);
  4344. readobjectdefoptions(objdef);
  4345. writeln([space,' Extended RTTI : ']);
  4346. readextendedrtti;
  4347. if (df_copied_def in defoptions) then
  4348. begin
  4349. Include(TPpuRecordDef(def).Options, ooCopied);
  4350. write([space,' Copied from : ']);
  4351. readderef('',objdef.Ancestor);
  4352. end
  4353. else
  4354. begin
  4355. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4356. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4357. writeln([space,' PadAlign : ',shortint(getbyte)]);
  4358. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  4359. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4360. objdef.Size:=getasizeint;
  4361. writeln([space,' DataSize : ',objdef.Size]);
  4362. writeln([space,' PaddingSize : ',getword]);
  4363. readmanagementoperatoroptions(space,'Management operators');
  4364. end;
  4365. {read the record definitions and symbols}
  4366. if not(df_copied_def in current_defoptions) then
  4367. begin
  4368. space:=' '+space;
  4369. readrecordsymtable('fields',TPpuRecordDef(def));
  4370. Delete(space,1,4);
  4371. end;
  4372. if not EndOfEntry then
  4373. HasMoreInfos;
  4374. end;
  4375. ibobjectdef :
  4376. begin
  4377. objdef:=TPpuObjectDef.Create(ParentDef);
  4378. readcommondef('Object/Class definition',defoptions,objdef);
  4379. objdef.Name:=getstring;
  4380. writeln([space,' Name of Class : ',objdef.Name]);
  4381. writeln([space,' Import lib/pkg : ',getstring]);
  4382. write ([space,' Options : ']);
  4383. readobjectdefoptions(objdef);
  4384. writeln([space,' Extended RTTI : ']);
  4385. readextendedrtti;
  4386. otb:=getbyte;
  4387. write ([space,' Type : ']);
  4388. case tobjecttyp(otb) of
  4389. odt_class : writeln('class');
  4390. odt_object : writeln('object');
  4391. odt_interfacecom : writeln('interfacecom');
  4392. odt_interfacecorba : writeln('interfacecorba');
  4393. odt_cppclass : writeln('cppclass');
  4394. odt_dispinterface : writeln('dispinterface');
  4395. odt_objcclass : writeln('objcclass');
  4396. odt_objcprotocol : writeln('objcprotocol');
  4397. odt_helper : writeln('helper');
  4398. odt_objccategory : writeln('objccategory');
  4399. odt_javaclass : writeln('Java class');
  4400. odt_interfacejava : writeln('Java interface');
  4401. else WriteWarning('Invalid object type: ' + IntToStr(b));
  4402. end;
  4403. case tobjecttyp(otb) of
  4404. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  4405. objdef.ObjType:=otClass;
  4406. odt_object:
  4407. objdef.ObjType:=otObject;
  4408. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  4409. objdef.ObjType:=otInterface;
  4410. odt_helper:
  4411. objdef.ObjType:=otHelper;
  4412. end;
  4413. b:=getbyte;
  4414. write ([space,' Helper Type : ']);
  4415. case thelpertype(b) of
  4416. ht_none : writeln('none');
  4417. ht_class : writeln('class helper');
  4418. ht_record : writeln('record helper');
  4419. ht_type : writeln('type helper');
  4420. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4421. end;
  4422. writeln([space,' External name : ',getstring]);
  4423. objdef.Size:=getasizeint;
  4424. writeln([space,' DataSize : ',objdef.Size]);
  4425. writeln([space,' PaddingSize : ',getword]);
  4426. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4427. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4428. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4429. write ([space, ' VmtField : ']);
  4430. readderef('',nil);
  4431. write ([space, ' Ancestor Class : ']);
  4432. readderef('',objdef.Ancestor);
  4433. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4434. begin
  4435. { IIDGUID }
  4436. for j:=1to 16 do
  4437. getbyte;
  4438. objdef.IID:=getstring;
  4439. writeln([space,' IID String : ',objdef.IID]);
  4440. end;
  4441. l:=getlongint;
  4442. if l > 0 then
  4443. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4444. writeln([space,' Abstract methods : ',l]);
  4445. if tobjecttyp(otb)=odt_helper then
  4446. begin
  4447. write([space,' Helper parent : ']);
  4448. readderef('',objdef.HelperParent);
  4449. end;
  4450. l:=getlongint;
  4451. writeln([space,' VMT entries: ',l]);
  4452. for j:=1 to l do
  4453. begin
  4454. write([space,' ']);
  4455. readderef('');
  4456. write([space,' Visibility: ']);
  4457. readvisibility;
  4458. end;
  4459. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4460. begin
  4461. l:=getlongint;
  4462. writeln([space,' Impl Intf Count : ',l]);
  4463. for j:=1 to l do
  4464. begin
  4465. write ([space,' - Definition : ']);
  4466. readderef('');
  4467. write ([space,' - Getter Def : ']);
  4468. readderef('');
  4469. writeln([space,' IOffset : ',getlongint]);
  4470. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4471. end;
  4472. end;
  4473. if df_copied_def in current_defoptions then
  4474. begin
  4475. Include(objdef.Options, ooCopied);
  4476. writeln(' Copy of def: ');
  4477. readderef('',objdef.Ancestor);
  4478. end
  4479. else
  4480. begin
  4481. {read the record definitions and symbols}
  4482. space:=' '+space;
  4483. readrecordsymtable('fields',objdef);
  4484. Delete(space,1,4);
  4485. end;
  4486. if not EndOfEntry then
  4487. HasMoreInfos;
  4488. end;
  4489. ibfiledef :
  4490. begin
  4491. filedef:=TPpuFileDef.Create(ParentDef);
  4492. ReadCommonDef('File definition',defoptions,filedef);
  4493. write ([space,' Type : ']);
  4494. case getbyte of
  4495. 0 : begin
  4496. writeln('Text');
  4497. filedef.FileType:=ftText;
  4498. end;
  4499. 1 : begin
  4500. writeln('Typed');
  4501. filedef.FileType:=ftTyped;
  4502. write ([space,' File of Type : ']);
  4503. readderef('',filedef.TypeRef);
  4504. end;
  4505. 2 : begin
  4506. writeln('Untyped');
  4507. filedef.FileType:=ftUntyped;
  4508. end;
  4509. end;
  4510. end;
  4511. ibformaldef :
  4512. begin
  4513. def:=TPpuFormalDef.Create(ParentDef);
  4514. readcommondef('Generic definition (void-typ)',defoptions,def);
  4515. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4516. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4517. end;
  4518. ibundefineddef :
  4519. begin
  4520. def:=TPpuUndefinedDef.Create(ParentDef);
  4521. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4522. end;
  4523. ibenumdef :
  4524. begin
  4525. enumdef:=TPpuEnumDef.Create(ParentDef);
  4526. readcommondef('Enumeration type definition',defoptions,enumdef);
  4527. enumdef.ElLow:=getaint;
  4528. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4529. enumdef.ElHigh:=getaint;
  4530. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4531. enumdef.Size:=byte(getaint);
  4532. writeln([space,' Size : ',enumdef.Size]);
  4533. if df_copied_def in defoptions then
  4534. begin
  4535. write([space,'Base enumeration type : ']);
  4536. readderef('',enumdef.CopyFrom);
  4537. end
  4538. else
  4539. begin
  4540. space:=' '+space;
  4541. readsymtable('elements',enumdef);
  4542. delete(space,1,4);
  4543. end;
  4544. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4545. begin
  4546. write([space,' Class def : ']);
  4547. readderef('');
  4548. end;
  4549. end;
  4550. ibclassrefdef :
  4551. begin
  4552. def:=TPpuClassRefDef.Create(ParentDef);
  4553. readcommondef('Class reference definition',defoptions,def);
  4554. write ([space,' Pointed Type : ']);
  4555. readderef('',TPpuClassRefDef(def).ClassRef);
  4556. end;
  4557. ibsetdef :
  4558. begin
  4559. setdef:=TPpuSetDef.Create(ParentDef);
  4560. readcommondef('Set definition',defoptions,setdef);
  4561. write ([space,' Element type : ']);
  4562. readderef('',setdef.ElType);
  4563. setdef.Size:=getasizeint;
  4564. writeln([space,' Size : ',setdef.Size]);
  4565. setdef.SetBase:=getasizeint;
  4566. writeln([space,' Set Base : ',setdef.SetBase]);
  4567. setdef.SetLow:=getasizeint;
  4568. writeln([space,' Set Low : ',setdef.SetLow]);
  4569. setdef.SetMax:=getasizeint;
  4570. writeln([space,' Set Max : ',setdef.SetMax]);
  4571. end;
  4572. ibvariantdef :
  4573. begin
  4574. def:=TPpuVariantDef.Create(ParentDef);
  4575. readcommondef('Variant definition',defoptions,def);
  4576. write ([space,' Varianttype : ']);
  4577. b:=getbyte;
  4578. case tvarianttype(b) of
  4579. vt_normalvariant :
  4580. writeln('Normal');
  4581. vt_olevariant :
  4582. begin
  4583. TPpuVariantDef(def).IsOLE:=True;
  4584. writeln('OLE');
  4585. end
  4586. else
  4587. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4588. end;
  4589. end;
  4590. iberror :
  4591. begin
  4592. WriteError('!! Error in PPU');
  4593. exit;
  4594. end;
  4595. ibenddefs :
  4596. break;
  4597. else
  4598. begin
  4599. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4600. end;
  4601. end;
  4602. if assigned(def) then
  4603. readdefsubentries(def);
  4604. if (def <> nil) and (def.Parent = nil) then
  4605. def.Free;
  4606. if not EndOfEntry then
  4607. HasMoreInfos;
  4608. until false;
  4609. end;
  4610. end;
  4611. procedure readmoduleoptions(space : string);
  4612. type
  4613. { tmoduleoption type is in unit fmodule }
  4614. tmoduleoption = (mo_none,
  4615. mo_hint_deprecated,
  4616. mo_hint_platform,
  4617. mo_hint_library,
  4618. mo_hint_unimplemented,
  4619. mo_hint_experimental,
  4620. mo_has_deprecated_msg
  4621. );
  4622. tmoduleoptions = set of tmoduleoption;
  4623. tmoduleopt=record
  4624. mask : tmoduleoption;
  4625. str : string[30];
  4626. end;
  4627. const
  4628. moduleopts=ord(high(tmoduleoption));
  4629. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4630. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4631. (mask:mo_hint_platform; str:'Hint Platform'),
  4632. (mask:mo_hint_library; str:'Hint Library'),
  4633. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4634. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4635. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4636. );
  4637. var
  4638. moduleoptions : tmoduleoptions;
  4639. i : longint;
  4640. first : boolean;
  4641. begin
  4642. ppufile.getset(tppuset1(moduleoptions));
  4643. if moduleoptions<>[] then
  4644. begin
  4645. first:=true;
  4646. for i:=1to moduleopts do
  4647. if (moduleopt[i].mask in moduleoptions) then
  4648. begin
  4649. if first then
  4650. first:=false
  4651. else
  4652. write(', ');
  4653. write(moduleopt[i].str);
  4654. end;
  4655. end;
  4656. writeln;
  4657. if mo_has_deprecated_msg in moduleoptions then
  4658. writeln([space,'Deprecated : ', ppufile.getstring]);
  4659. end;
  4660. {****************************************************************************
  4661. Read General Part
  4662. ****************************************************************************}
  4663. procedure readinterface(silent : boolean);
  4664. var
  4665. b : byte;
  4666. sourcenumber, i : longint;
  4667. feature : tfeature;
  4668. features : tfeatures;
  4669. s : string;
  4670. begin
  4671. with ppufile do
  4672. begin
  4673. repeat
  4674. b:=readentry;
  4675. case b of
  4676. ibmodulename :
  4677. begin
  4678. CurUnit.Name:=getstring;
  4679. if not silent then
  4680. Writeln(['Module Name: ',CurUnit.Name]);
  4681. end;
  4682. ibfeatures :
  4683. begin
  4684. getset(tppuset4(features));
  4685. Writeln('Features: ');
  4686. for feature:=low(tfeatures) to high(tfeature) do
  4687. if feature in features then
  4688. begin
  4689. str(feature,s);
  4690. s:=copy(s,3,255);
  4691. writeln([s]);
  4692. end;
  4693. end;
  4694. ibmoduleoptions:
  4695. if not silent then
  4696. readmoduleoptions(' ');
  4697. ibsourcefiles :
  4698. begin
  4699. sourcenumber:=1;
  4700. if not silent then
  4701. while not EndOfEntry do
  4702. begin
  4703. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4704. Name:=getstring;
  4705. i:=getlongint;
  4706. try
  4707. if i >= 0 then
  4708. FileTime:=FileDateToDateTime(i);
  4709. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4710. except
  4711. end;
  4712. end;
  4713. inc(sourcenumber);
  4714. end;
  4715. end;
  4716. {$IFDEF MACRO_DIFF_HINT}
  4717. ibusedmacros :
  4718. begin
  4719. if not silent then
  4720. while not EndOfEntry do
  4721. begin
  4722. Write('Conditional ',getstring);
  4723. if getboolean then
  4724. write(' defined at startup')
  4725. else
  4726. write(' not defined at startup');
  4727. if getboolean then
  4728. writeln(' was used')
  4729. else
  4730. writeln;
  4731. end;
  4732. end;
  4733. {$ENDIF}
  4734. ibloadunit :
  4735. if not silent then
  4736. ReadLoadUnit;
  4737. iblinkunitofiles :
  4738. if not silent then
  4739. ReadLinkContainer('Link unit object file: ');
  4740. iblinkunitstaticlibs :
  4741. if not silent then
  4742. ReadLinkContainer('Link unit static lib: ');
  4743. iblinkunitsharedlibs :
  4744. if not silent then
  4745. ReadLinkContainer('Link unit shared lib: ');
  4746. iblinkotherofiles :
  4747. if not silent then
  4748. ReadLinkContainer('Link other object file: ');
  4749. iblinkotherstaticlibs :
  4750. if not silent then
  4751. ReadLinkContainer('Link other static lib: ');
  4752. iblinkothersharedlibs :
  4753. if not silent then
  4754. ReadLinkContainer('Link other shared lib: ');
  4755. iblinkotherframeworks:
  4756. if not silent then
  4757. ReadLinkContainer('Link framework: ');
  4758. ibjvmnamespace:
  4759. Writeln('JVM name space: '+getString);
  4760. ibmainname:
  4761. if not silent then
  4762. Writeln(['Specified main program symbol name: ',getstring]);
  4763. ibImportSymbols :
  4764. if not silent then
  4765. ReadImportSymbols;
  4766. ibderefdata :
  4767. ReadDerefData;
  4768. ibderefmap :
  4769. ReadDerefMap;
  4770. ibwpofile :
  4771. if not silent then
  4772. ReadWpoFileInfo;
  4773. ibresources :
  4774. if not silent then
  4775. ReadContainer('Resource file: ');
  4776. iborderedsymbols:
  4777. if not silent then
  4778. ReadContainer('Ordered symbol: ');
  4779. iberror :
  4780. begin
  4781. WriteError('Error in PPU');
  4782. exit;
  4783. end;
  4784. ibendinterface :
  4785. break;
  4786. else
  4787. begin
  4788. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4789. end;
  4790. end;
  4791. until false;
  4792. end;
  4793. end;
  4794. {****************************************************************************
  4795. Read Implementation Part
  4796. ****************************************************************************}
  4797. procedure readimplementation;
  4798. var
  4799. b : byte;
  4800. begin
  4801. with ppufile do
  4802. begin
  4803. repeat
  4804. b:=readentry;
  4805. case b of
  4806. ibasmsymbols :
  4807. ReadAsmSymbols;
  4808. ibloadunit :
  4809. ReadLoadUnit;
  4810. ibunitimportsyms :
  4811. ReadUnitImportSyms;
  4812. iberror :
  4813. begin
  4814. WriteError('Error in PPU');
  4815. exit;
  4816. end;
  4817. ibendimplementation :
  4818. break;
  4819. else
  4820. begin
  4821. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4822. end;
  4823. end;
  4824. until false;
  4825. end;
  4826. end;
  4827. function parseextraheader(module: TPpuModuleDef; ppufile: tppufile): boolean;
  4828. var
  4829. b: byte;
  4830. begin
  4831. result:=false;
  4832. b:=ppufile.readentry;
  4833. if b<>ibextraheader then
  4834. exit;
  4835. CurUnit.LongVersion:=cardinal(ppufile.getlongint);
  4836. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4837. ppufile.getset(tppuset4(CurUnit.ModuleFlags));
  4838. result:=ppufile.EndOfEntry and (CurUnit.LongVersion=CurrentPPULongVersion);
  4839. if mf_symansistr in CurUnit.ModuleFlags then
  4840. SymAnsiStr:=true;
  4841. end;
  4842. procedure dofile (filename : string);
  4843. begin
  4844. { reset }
  4845. space:='';
  4846. { fix filename }
  4847. if pos('.',filename)=0 then
  4848. filename:=filename+'.ppu';
  4849. ppufile:=tppudumpfile.create(filename);
  4850. if not ppufile.openfile then
  4851. begin
  4852. WriteError('IO-Error when opening : '+filename+', Skipping');
  4853. exit;
  4854. end;
  4855. { PPU File is open, check for PPU Id }
  4856. if not ppufile.CheckPPUID then
  4857. begin
  4858. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4859. exit;
  4860. end;
  4861. { Check PPU Version }
  4862. ppuversion:=ppufile.getversion;
  4863. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4864. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4865. begin
  4866. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4867. exit;
  4868. end;
  4869. CurUnit:=TPpuModuleDef.Create(UnitList);
  4870. CurUnit.Version:=ppuversion;
  4871. if not parseextraheader(CurUnit, ppufile) then
  4872. begin
  4873. WriteError(Format('Unsupported PPU sub-version %d. Expecting PPU sub-version %d.', [CurUnit.LongVersion, CurrentPPULongVersion]));
  4874. end;
  4875. { Write PPU Header Information }
  4876. if (verbose and v_header)<>0 then
  4877. begin
  4878. Writeln;
  4879. Writeln('Header');
  4880. Writeln('-------');
  4881. with ppufile.header do
  4882. begin
  4883. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4884. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4885. ppufile.header.common.compiler and $7f]);
  4886. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4887. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4888. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4889. Writeln(['FileSize (w/o header) : ',common.size]);
  4890. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4891. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4892. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4893. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4894. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4895. end;
  4896. end;
  4897. with ppufile.header do
  4898. begin
  4899. CurUnit.Crc:=checksum;
  4900. CurUnit.IntfCrc:=interface_checksum;
  4901. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4902. CurUnit.TargetOS:=Target2Str(common.target);
  4903. end;
  4904. {read the general stuff}
  4905. if (verbose and v_interface)<>0 then
  4906. begin
  4907. Writeln;
  4908. Writeln('Interface section');
  4909. Writeln('------------------');
  4910. readinterface(false);
  4911. end
  4912. { We need derefdata from Interface }
  4913. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4914. readinterface(true)
  4915. else
  4916. ppufile.skipuntilentry(ibendinterface);
  4917. Writeln;
  4918. Writeln('Interface symtable');
  4919. Writeln('----------------------');
  4920. readsymtableoptions('interface');
  4921. {read the definitions}
  4922. if (verbose and v_defs)<>0 then
  4923. begin
  4924. Writeln;
  4925. Writeln('Interface definitions');
  4926. Writeln('----------------------');
  4927. readdefinitions('interface', CurUnit);
  4928. end
  4929. else
  4930. ppufile.skipuntilentry(ibenddefs);
  4931. {read the symbols}
  4932. if (verbose and v_syms)<>0 then
  4933. begin
  4934. Writeln;
  4935. Writeln('Interface Symbols');
  4936. Writeln('------------------');
  4937. readsymbols('interface',CurUnit);
  4938. end
  4939. else
  4940. ppufile.skipuntilentry(ibendsyms);
  4941. {read the macro symbols}
  4942. if (verbose and v_syms)<>0 then
  4943. begin
  4944. Writeln;
  4945. Writeln('Interface Macro Symbols');
  4946. Writeln('-----------------------');
  4947. end;
  4948. if ppufile.readentry<>ibexportedmacros then
  4949. begin
  4950. WriteError('!! Error in PPU');
  4951. exit;
  4952. end;
  4953. if ppufile.getboolean then
  4954. begin
  4955. readsymtableoptions('interface macro');
  4956. {skip the definition section for macros (since they are never used) }
  4957. ppufile.skipuntilentry(ibenddefs);
  4958. {read the macro symbols}
  4959. if (verbose and v_syms)<>0 then
  4960. readsymbols('interface macro')
  4961. else
  4962. ppufile.skipuntilentry(ibendsyms);
  4963. end
  4964. else
  4965. Writeln('(no exported macros)');
  4966. {read the implementation stuff}
  4967. if (verbose and v_implementation)<>0 then
  4968. begin
  4969. Writeln;
  4970. Writeln('Implementation section');
  4971. Writeln('-----------------------');
  4972. readimplementation;
  4973. end
  4974. else
  4975. ppufile.skipuntilentry(ibendimplementation);
  4976. {read the static symtable}
  4977. Writeln;
  4978. Writeln('Implementation symtable');
  4979. Writeln('----------------------');
  4980. readsymtableoptions('implementation');
  4981. if (mf_local_symtable in CurUnit.ModuleFlags) then
  4982. begin
  4983. if (verbose and v_defs)<>0 then
  4984. begin
  4985. Writeln;
  4986. Writeln('Static definitions');
  4987. Writeln('----------------------');
  4988. readdefinitions('implementation', nil);
  4989. end
  4990. else
  4991. ppufile.skipuntilentry(ibenddefs);
  4992. {read the symbols}
  4993. if (verbose and v_syms)<>0 then
  4994. begin
  4995. Writeln;
  4996. Writeln('Static Symbols');
  4997. Writeln('------------------');
  4998. readsymbols('implementation');
  4999. end
  5000. else
  5001. ppufile.skipuntilentry(ibendsyms);
  5002. end;
  5003. ReadCreatedObjTypes;
  5004. FreeDerefdata;
  5005. {shutdown ppufile}
  5006. ppufile.closefile;
  5007. ppufile.free;
  5008. Writeln;
  5009. end;
  5010. procedure WriteLogo;
  5011. begin
  5012. writeln(Title+' Version '+version_string);
  5013. writeln(Copyright);
  5014. writeln;
  5015. end;
  5016. procedure help;
  5017. begin
  5018. WriteLogo;
  5019. writeln('usage: ppudump [options] <filename1> <filename2>...');
  5020. writeln;
  5021. writeln('[options] can be:');
  5022. writeln(' -F<format> Set output format to <format>');
  5023. writeln(' t - text format (default)');
  5024. writeln(' j - JSON format');
  5025. writeln(' x - XML format');
  5026. writeln(' -M Exit with ExitCode=2 if more information is available');
  5027. writeln(' -S Skip PPU version check. May lead to reading errors');
  5028. writeln(' -V<verbose> Set verbosity to <verbose>');
  5029. writeln(' H - Show header info');
  5030. writeln(' I - Show interface');
  5031. writeln(' M - Show implementation');
  5032. writeln(' S - Show interface symbols');
  5033. writeln(' D - Show interface definitions');
  5034. writeln(' A - Show all');
  5035. writeln(' -h, -? This helpscreen');
  5036. halt;
  5037. end;
  5038. var
  5039. startpara,
  5040. nrfile,i : longint;
  5041. para : string;
  5042. const
  5043. error_on_more : boolean = false;
  5044. begin
  5045. if paramcount<1 then
  5046. help;
  5047. { turn verbose on by default }
  5048. verbose:=v_all;
  5049. { read options }
  5050. startpara:=1;
  5051. while copy(paramstr(startpara),1,1)='-' do
  5052. begin
  5053. para:=paramstr(startpara);
  5054. case upcase(para[2]) of
  5055. 'F' : begin
  5056. FreeAndNil(pout);
  5057. if Length(para) > 2 then
  5058. case upcase(para[3]) of
  5059. 'T':
  5060. nostdout:=False;
  5061. 'J':
  5062. begin
  5063. nostdout:=True;
  5064. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  5065. end;
  5066. 'X':
  5067. begin
  5068. nostdout:=True;
  5069. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  5070. end;
  5071. else
  5072. begin
  5073. WriteError('Invalid output format: ' + para[3]);
  5074. Halt(1);
  5075. end;
  5076. end;
  5077. end;
  5078. 'M' : error_on_more:=true;
  5079. 'S' : SkipVersionCheck:=True;
  5080. 'V' : begin
  5081. verbose:=0;
  5082. for i:=3 to length(para) do
  5083. case upcase(para[i]) of
  5084. 'H' : verbose:=verbose or v_header;
  5085. 'I' : verbose:=verbose or v_interface;
  5086. 'M' : verbose:=verbose or v_implementation;
  5087. 'D' : verbose:=verbose or v_defs;
  5088. 'S' : verbose:=verbose or v_syms;
  5089. 'A' : verbose:=verbose or v_all;
  5090. end;
  5091. end;
  5092. 'H' : help;
  5093. '?' : help;
  5094. else
  5095. begin
  5096. WriteError('Invalid option: ' + para);
  5097. Halt(1);
  5098. end;
  5099. end;
  5100. inc(startpara);
  5101. end;
  5102. if not nostdout then
  5103. WriteLogo;
  5104. UnitList:=TPpuContainerDef.Create(nil);
  5105. try
  5106. UnitList.ItemsName:='';
  5107. { process files }
  5108. for nrfile:=startpara to paramcount do
  5109. dofile (paramstr(nrfile));
  5110. if not has_errors and (pout <> nil) then
  5111. begin
  5112. pout.Init;
  5113. UnitList.Write(pout);
  5114. pout.Done;
  5115. end;
  5116. finally
  5117. UnitList.Free;
  5118. pout.Free;
  5119. end;
  5120. if has_errors then
  5121. Halt(1);
  5122. if error_on_more and
  5123. (has_more_infos or has_warnings) then
  5124. Halt(2);
  5125. end.