Does FPC uses any intermediate representation? lazarus / 21-General ---------------------------------------------------------------------- rishav · 2023-06-04 20:42 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 · 2023-06-04 20:46 AFAIK: no. Bart ---------------------------------------------------------------------- TRon · 2023-06-05 06:59 Quote from: Bart on June 04, 2023, 10:46:54 pmAFAIK: no. Mnemonics ? though we could discuss if that can be considered intermediate ---------------------------------------------------------------------- marcov · 2023-06-05 07:14 No, it afaik goes from tree representation to asmlists, which is a kind of proto assembler ---------------------------------------------------------------------- MarkMLl · 2023-06-05 08:29 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 ---------------------------------------------------------------------- marcov · 2023-06-05 18:17 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 · 2023-06-05 19:21 Quote from: rishav on June 04, 2023, 10:42:49 pmI 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. Quote from: MarkMLl on June 05, 2023, 10:29:28 amI 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 · 2023-06-06 19:27 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