Implementing built-in functions with LLVM, help needed

Christopher F Clark <christopher.f.clark@compiler-resources.com>
Fri, 7 Oct 2022 08:56:19 +0300

          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: Christopher F Clark <christopher.f.clark@compiler-resources.com>
Newsgroups: comp.compilers
Date: Fri, 7 Oct 2022 08:56:19 +0300
Organization: Compilers Central
References: 22-10-019
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="59827"; mail-complaints-to="abuse@iecc.com"
Keywords: Pascal, design
Posted-Date: 07 Oct 2022 13:05:51 EDT

I'm surprised no one has chimed in yet, so I will.


> How should I implement functions like writeln, read, etc?


I presume you have a design for "user defined" functions and
procedures. If not, you need that first. That is roughly how you pass
in parameters and receive return values. Usually there is a convention
(often defined by the OS or these days the C compiler) that one
follows to do that.


But once you have that, you can call functions. And, if it is a
convention suitable for C, it specifies how you handle variadic
functions, functions that take a variable number of arguments like
writeln. Now, you may need some Pascal specific wrinkles because the
Pascal language supports things like variables from the parent scope
(a subset of the closure concept) and for writeln knowing the type of
the variable passed so that you can format it properly
("descriptors").


Still, the ability to call functions is the key thing you need to do.
Once, you have that, you implement the "builtin" functions as
functions. If your Pascal code is complete enough you can do it in
Pascal, but quite often you do it in another (often lower level
language like C). You don't actually generate the code directly from
LLVM, other than doing a function call. Of perhaps a set of function
calls, e.g. writeln might be call the "to_string" function for each
parameter and then passing all those parameters to a function that
writes a series of strings. But, both of those are simply functions
that you call, not generally inline code sequences.


--
******************************************************************************
Chris Clark email: christopher.f.clark@compiler-resources.com
Compiler Resources, Inc. Web Site: http://world.std.com/~compres
23 Bailey Rd voice: (508) 435-5016
Berlin, MA 01503 USA twitter: @intel_chris
------------------------------------------------------------------------------


Post a followup to this message

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