ppudump.pp 165 KB

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