Recent

Author Topic: Does FPC uses any intermediate representation?  (Read 641 times)

rishav

  • New Member
  • *
  • Posts: 10
Does FPC uses any intermediate representation?
« on: June 04, 2023, 10:42:49 pm »
Hi folks

I am working on a toy compiler and was wondering if I can use FPC as its backend. Does FPC uses any kind of IR that I can generate?
I read about the old Pascal codebases using p-code, but I couldn't find if there was a way for me to input pcode into fpc executable.

Bart

  • Hero Member
  • *****
  • Posts: 5067
    • Bart en Mariska's Webstek
Re: Does FPC uses any intermediate representation?
« Reply #1 on: June 04, 2023, 10:46:54 pm »
AFAIK: no.

Bart

TRon

  • Hero Member
  • *****
  • Posts: 1534
Re: Does FPC uses any intermediate representation?
« Reply #2 on: June 05, 2023, 08:59:55 am »
AFAIK: no.
Mnemonics ? though we could discuss if that can be considered intermediate

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10934
  • FPC developer.
Re: Does FPC uses any intermediate representation?
« Reply #3 on: June 05, 2023, 09:14:49 am »
No, it afaik goes from tree representation to asmlists, which is a kind of proto assembler

MarkMLl

  • Hero Member
  • *****
  • Posts: 6243
Re: Does FPC uses any intermediate representation?
« Reply #4 on: June 05, 2023, 10:29:28 am »
I think there's some sort of representation in the .ppu files in support of generics, but it should be considered private: it would be an extremely unwise programmer who dabbled in such things without the support of the core team.

It's easy enough to emit to and later interpret an intermediate format ** , but my own feeling is that one would be far better off learning an established form such as LLVM.

** Been there done that repeatedly. Make sure that the first opcode is a version identifier to keep the compiler and interpreter matched.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10934
  • FPC developer.
Re: Does FPC uses any intermediate representation?
« Reply #5 on: June 05, 2023, 08:17:40 pm »
Normal code is not in PPU's.   ppu's are in principle the parsed interface of the unit.

Exceptions are generics and exported inlined functions.

.ppu is indeed versioned, and a compiler only works with the current version. (the version it writes)  This is why investing in it is usually not worth it.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5200
  • Compiler Developer
Re: Does FPC uses any intermediate representation?
« Reply #6 on: June 05, 2023, 09:21:00 pm »
I am working on a toy compiler and was wondering if I can use FPC as its backend. Does FPC uses any kind of IR that I can generate?
I read about the old Pascal codebases using p-code, but I couldn't find if there was a way for me to input pcode into fpc executable.

No, FPC does not have any publicly usable intermediate representation. The closest is the generated node tree, but again, that's not available outside of the compiler.

I think there's some sort of representation in the .ppu files in support of generics, but it should be considered private: it would be an extremely unwise programmer who dabbled in such things without the support of the core team.

Generics simply have the token stream of the parsed tokens. Inlineable functions have a serialization of the node tree.

mercurhyo

  • Full Member
  • ***
  • Posts: 235
Re: Does FPC uses any intermediate representation?
« Reply #7 on: June 06, 2023, 09:27:44 pm »
pascalscript (installable lazarus package) uses P-code

try, debug, enjoy ! ;)

It is not only a pascal script interpreter, it 1st compile your pascal lines into P-Code then run and rerun as needed
« Last Edit: June 06, 2023, 09:31:55 pm by mercurhyo »
DEO MERCHVRIO - Linux, Win10pro - Ryzen9XT 24threads + Geforce Rtx 3080SUPRIM
god of financial gain, commerce, eloquence (and thus poetry), messages, communication (including divination), travelers, boundaries, luck, trickery and thieves; he also serves as the guide of souls to the underworld

 

TinyPortal © 2005-2018