Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"When the going gets tough, the tough get empirical." -- Jon Carroll


devel / comp.compilers / Re: Implementing built-in functions with LLVM, help needed

SubjectAuthor
* Implementing built-in functions with LLVM, help neededIvan Espinosa
+- Re: Implementing built-in functions with LLVM, help neededantispam
`* Implementing built-in functions with LLVM, help neededChristopher F Clark
 +- Re: Implementing built-in functions with LLVM, help neededHans-Peter Diettrich
 `- Re: Implementing built-in functions with LLVM, help neededantispam

1
Implementing built-in functions with LLVM, help needed

<22-10-019@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=573&group=comp.compilers#573

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: ivanmtz...@gmail.com (Ivan Espinosa)
Newsgroups: comp.compilers
Subject: Implementing built-in functions with LLVM, help needed
Date: Mon, 3 Oct 2022 15:13:04 -0700 (PDT)
Organization: Compilers Central
Lines: 14
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <22-10-019@comp.compilers>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="24315"; mail-complaints-to="abuse@iecc.com"
Keywords: LLVM, question
Posted-Date: 03 Oct 2022 20:24:44 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Ivan Espinosa - Mon, 3 Oct 2022 22:13 UTC

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.

Thank you all!
Gerardo Espinosa

PD: Here is the link to my project code
https://github.com/IvanMtze/JAPC

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

<22-10-020@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=574&group=comp.compilers#574

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: antis...@math.uni.wroc.pl
Newsgroups: comp.compilers
Subject: Re: Implementing built-in functions with LLVM, help needed
Date: Thu, 6 Oct 2022 15:15:44 -0000 (UTC)
Organization: Aioe.org NNTP Server
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <22-10-020@comp.compilers>
References: <22-10-019@comp.compilers>
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
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: antis...@math.uni.wroc.pl - Thu, 6 Oct 2022 15:15 UTC

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

Implementing built-in functions with LLVM, help needed

<22-10-022@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=576&group=comp.compilers#576

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: christop...@compiler-resources.com (Christopher F Clark)
Newsgroups: comp.compilers
Subject: Implementing built-in functions with LLVM, help needed
Date: Fri, 7 Oct 2022 08:56:19 +0300
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <22-10-022@comp.compilers>
References: <22-10-019@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
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
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: Christopher F Clark - Fri, 7 Oct 2022 05:56 UTC

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
------------------------------------------------------------------------------

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

<22-10-024@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=578&group=comp.compilers#578

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: DrDiettr...@netscape.net (Hans-Peter Diettrich)
Newsgroups: comp.compilers
Subject: Re: Implementing built-in functions with LLVM, help needed
Date: Fri, 7 Oct 2022 20:59:49 +0200
Organization: Compilers Central
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <22-10-024@comp.compilers>
References: <22-10-019@comp.compilers> <22-10-022@comp.compilers>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="26864"; mail-complaints-to="abuse@iecc.com"
Keywords: Pascal, design
Posted-Date: 08 Oct 2022 20:12:04 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
In-Reply-To: <22-10-022@comp.compilers>
 by: Hans-Peter Diettrich - Fri, 7 Oct 2022 18:59 UTC

On 10/7/22 7:56 AM, Christopher F Clark wrote:

> Still, the ability to call functions is the key thing you need to do.

And the compiler has to decide whether an argument type is okay, can be
converted, or is incompatible with a function definition. So IMO
handling of polymorphic and variadic functions is a matter of
organisation of function argument types.

DoDi

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

<22-10-027@comp.compilers>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=580&group=comp.compilers#580

  copy link   Newsgroups: comp.compilers
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From: antis...@math.uni.wroc.pl
Newsgroups: comp.compilers
Subject: Re: Implementing built-in functions with LLVM, help needed
Date: Thu, 13 Oct 2022 14:08:15 -0000 (UTC)
Organization: Aioe.org NNTP Server
Sender: news@iecc.com
Approved: comp.compilers@iecc.com
Message-ID: <22-10-027@comp.compilers>
References: <22-10-019@comp.compilers> <22-10-022@comp.compilers>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="75194"; mail-complaints-to="abuse@iecc.com"
Keywords: Pascal, history
Posted-Date: 13 Oct 2022 10:19:32 EDT
X-submission-address: compilers@iecc.com
X-moderator-address: compilers-request@iecc.com
X-FAQ-and-archives: http://compilers.iecc.com
 by: antis...@math.uni.wroc.pl - Thu, 13 Oct 2022 14:08 UTC

Christopher F Clark <christopher.f.clark@compiler-resources.com> wrote:
> 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.

Treating writeln via variable argument call is wrong. Compiler
is supposed to split writeln into separate simpler statements.
This leads to subtle difference, folks trying to implement
Pascal via C-like approach at some moment learn the difference
and fix their compilers, but it is better to get it right the
first time.

> 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").

Syntax of buitins is different that normal calls, that is easy
to handle in parser but must be done before call. And builtins
are overloaded, in dialects with many builtins handling of
overloading may take most of implementation.

> Still, the ability to call functions is the key thing you need to do.

Sure.

--
Waldek Hebisch

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor