Re: Implementing built-in functions with LLVM, help needed

antispam@math.uni.wroc.pl
Thu, 6 Oct 2022 15:15:44 -0000 (UTC)

          From comp.compilers

Related articles
Implementing built-in functions with LLVM, help needed ivanmtze96@gmail.com (Ivan Espinosa) (2022-10-03)
Re: Implementing built-in functions with LLVM, help needed antispam@math.uni.wroc.pl (2022-10-06)
Implementing built-in functions with LLVM, help needed christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-10-07)
Re: Implementing built-in functions with LLVM, help needed DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-10-07)
Re: Implementing built-in functions with LLVM, help needed antispam@math.uni.wroc.pl (2022-10-13)
| List of all articles for this month |
From: antispam@math.uni.wroc.pl
Newsgroups: comp.compilers
Date: Thu, 6 Oct 2022 15:15:44 -0000 (UTC)
Organization: Aioe.org NNTP Server
References: 22-10-019
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="58896"; mail-complaints-to="abuse@iecc.com"
Keywords: Pascal, design
Posted-Date: 07 Oct 2022 13:04:15 EDT

Ivan Espinosa <ivanmtze96@gmail.com> 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.