Recent

Author Topic: FPC intenals  (Read 88 times)

Borneq

  • Full Member
  • ***
  • Posts: 147
FPC intenals
« on: Today at 08:59:18 am »
Where can I find detailed info about ppu and obj formats, are tools for dump/disassembling it? FPC compiler can generate assembler sources? can optimize methods to inline?

af0815

  • Sr. Member
  • ****
  • Posts: 388
Re: FPC intenals
« Reply #1 on: Today at 09:06:22 am »
About info about the ppu format i have got the answer, there is no documentation (see https://forum.lazarus.freepascal.org/index.php/topic,47582.msg342026.html#msg342026 )
regards
Andreas

PascalDragon

  • Hero Member
  • *****
  • Posts: 726
  • Compiler Developer
Re: FPC intenals
« Reply #2 on: Today at 09:12:21 am »
Where can I find detailed info about ppu and obj formats,

There is no documentation for ppu files. You'll need to look at the source to understand them.

The object files that are generated have the same format as normal object files for the platform. These are among others COFF on Windows and ELF on Linux.

are tools for dump/disassembling it?

To dump ppu files you can use the ppudump utility that is provided with each FPC distribution. Please note that the used version must match the version of the ppu (meaning that you can't use a FPC 2.6.4 ppudump for a 3.3.1 ppu).

For the object files you can use the GNU utility objdump which allows you to display various information about the object file and also to disassemble them.

FPC compiler can generate assembler sources?

You can see the assembler sources if you pass -al when compiling. If you want to stop FPC from assembling and linking its files then you can use -sh which will keep the assembly files around and also generate a ppas.sh/ppas.bat which allows you to manually assemble/link the files.

can optimize methods to inline?

Yes, FPC can inline routine. Either you can manually declare a method as inline or enable auto inlining using -Ooautoinline. In both cases the method body needs to have been parsed before it is called otherwise the routine won't be inlined.

For example:

Code: Pascal  [Select]
  1. unit foo;
  2.  
  3. interface
  4.  
  5. procedure Test; inline;
  6. procedure TestA;
  7. procedure TestB;
  8.  
  9. implementation
  10.  
  11. procedure TestA;
  12. begin
  13.   Test; // this will not be inlined
  14. end;
  15.  
  16. procedure Test;
  17. begin
  18. end;
  19.  
  20. procedure TestB;
  21. begin
  22.   Test; // this will be inlined
  23. end;
  24.