Re: Implementing built-in functions with LLVM, help needed
Thu, 6 Oct 2022 15:15:44 -0000 (UTC)

          From comp.compilers

Related articles
Implementing built-in functions with LLVM, help needed (Ivan Espinosa) (2022-10-03)
Re: Implementing built-in functions with LLVM, help needed (2022-10-06)
Implementing built-in functions with LLVM, help needed (Christopher F Clark) (2022-10-07)
Re: Implementing built-in functions with LLVM, help needed (Hans-Peter Diettrich) (2022-10-07)
Re: Implementing built-in functions with LLVM, help needed (2022-10-13)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: Thu, 6 Oct 2022 15:15:44 -0000 (UTC)
Organization: NNTP Server
References: 22-10-019
Injection-Info:; posting-host=""; logging-data="58896"; mail-complaints-to=""
Keywords: Pascal, design
Posted-Date: 07 Oct 2022 13:04:15 EDT

Ivan Espinosa <> wrote:
> Hello,
> I'm currently working on a personal project about a front-end compiler
> for some sort of the old Pascal version to produce LLVM code. I'm kind
> of new to this amazing topic, and I would like to know how should I
> implement functions like writeln, read, etc. It would be very useful
> if somebody could help me with this giving some ideas or resources so
> I can work in that.

Built in functions in Pascal have special syntax, so you need
approprate code in parser to recognize them. Easy trick is to
have more general parsing for _all_ functions, but generate
error after parsing when non-builtin function tries to use
syntax reserved for builtins. Writeln, etc. allow variable
number of arguments, but meaning is defined be equvalent
sequence of one-argument calls. Your compiler needs to
effectively replace single multiargument call by seqence
of one or two argument calls. Basic fixed argument functions
can be written in C or Pascal (if you have extentions to do
system calls or calls to C library). There is extra difficulty:
standard Pascal does not allow overloading for user defined
functions, but buitin functions are overloaded. You can
solve this in ad-hoc manner, having table which for each
combination of arguments to builtin functions gives corresponding
function in runtime library (in this apprach functions in runtime
library have different names than builtins). This is essentially
how GNU Pascal handles builtin calls. More elegant would be
to support function/procedure overloading as compiler
extention and write runtime library in extended language.
However, in classic Pascal there is only handful of builtion
functions so ad-hoc apprach _may_ be easier. OTOH IME implementing
some feature inside compiler takes 5-10 times as much work as
putting it in runtime library (when possible), and if you
had overloading adding builtins would be much easier. Implementing
general overloading requires some effort, depending on number
of builtins and on specific implementaion choices it may be less
or more work than ad-hoc approach to builtins.

                                                            Waldek Hebisch

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.