ppudump.pp 165 KB

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