Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #167545

Re: Cake - C23 to C99 transpiler

From Bart <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: Cake - C23 to C99 transpiler
Date 2022-09-08 00:51 +0100
Organization Aioe.org NNTP Server
Message-ID <tfbaqq$tl9$1@gioia.aioe.org> (permalink)
References (2 earlier) <aac059b9-a9b3-4365-8c94-0c39102798cen@googlegroups.com> <tf9v6j$7gjv$1@dont-email.me> <836c6515-87f5-42b2-98b0-8308173a9120n@googlegroups.com> <tfaa7f$qcg$1@gioia.aioe.org> <cecefea6-c480-4bd2-a102-94576974289en@googlegroups.com>

Show all headers | View raw


On 07/09/2022 23:28, Thiago Adams wrote:
> On Wednesday, September 7, 2022 at 11:35:51 AM UTC-3, Bart wrote:
>> On 07/09/2022 13:45, Thiago Adams wrote:
>>> On Wednesday, September 7, 2022 at 8:27:30 AM UTC-3, Vir Campestris wrote:
>>>> On 06/09/2022 18:08, Thiago Adams wrote:
>>>>> I need to choose a backend now.
>>>> If your intent is to produce C99 shouldn't you be testing against every
>>>> compiler you can get your hands on, rather than picking one?
>>>
>>> Here "I need to choose a backend now." I was talking about
>>> a x86 or intermediate backend or create a interpreter.
>>>
>>> But choosing a compiler target for C.. yes it also is possible.
>>> Some features may exist (like thread storage) and be different
>>> depending on the compiler . So choosing the target compiler the
>>> generator could generate code for that specific feature.
>> The Seed7 language, if you were to build it from C sources, comes with
>> nearly 20 different makefiles for different compilers and platforms.
>>
>> There's also a configure program which creates and runs some 100
>> different test programs to collate information about the C
>> implementation, resulting in a configuration header file describing the
>> environment.
>>
>> Since Seed7 also uses C as a target language, I can't remember if that
>> config file was for the compiler, or compiling the generated C
>> intermediates, or both.
>>
>> Use C as a target is not that simple!
>>
>> When I used to target C, I produced a single C source for the entire
>> program, but there were three versions, since it didn't have conditional
>> elements:
>>
>> * For Windows
>> * For Linux
>> * For a Neutral OS (runs on either but with limitations)
>>
>> I think also the code assumed a 64-bit implementation; a 32-bit target,
>> if I was to still bother with it, would need separate versions.
>>
>> I used to try and support half a dozen C compilers, which was hard as
>> they all had different limitations. Now I support only tcc and gcc.
>>
>> No special options are required (other than ones like -O2 and -o for
>> gcc), and no special extensions (a few things expected to be in C99 like
>> anonymous structs and unions).
>>
>> The main limitation of tcc (a significant one for me) is that it doesn't
>> support '$' in identifiers; most C compilers do. Which means taking
>> account of that in code generators.
> 
> I have two output modes:
> 
> 1 - One preserves all macros includes etc.. and makes edition/add/deletion
> at the current source code. The generated code can be used in different
> platforms. Some changes are only at active "if groups".
> 
> 2 - Generate code like compiler "sees". Macros are removed and this is useful
> for direct compilation. Generated code is discarded after compilation.
> 
> I think a x86 emulator for instance can be useful for me..because I can practice
> code generation and see what is necessary and at same time have an interpreter.

I think interpreting x64 code (don't bother with 32-bit x86) is an 
unnecessary complication (it would also be a major project of its own, 
and may still involve generating binary x64 machine code).

Interpretation, if you want that, could either be done from an AST 
representation, or from some intermediate VM language that you devise.

> This could be a separated project as well and I would create something like a linker
> for the interpreted languages. There are many things I don't understand and I would
> like to someday have the compiler generating the exe like tcc. Many small c compilers
> don't generate the exe and depends on gcc for instance.

Actually, gcc doesn't generate EXE either, or not directly. It produces 
a temporary .s file containing assembly code (in the ghastly AT&T 
syntax), then invokes the assembler 'as' to produce an object file (.o 
or .obj).

Finally, the 'ld' linker is invoked to turn the object file into an 
executable.

So, while direct exe generation is desirable in that there are no 
dependencies, it's a lot of work.

It's best to start by generating textual ASM code if compiling to native 
code.

Tiny C cuts quite a few corners, for example there is no intermediate 
ASM to even look at, and it has fewer passes than are recommended for a 
compiler.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Cake -  C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-08-18 18:44 -0700
  Re: Cake - C23 to C99 transpiler Blue-Maned_Hawk <bluemanedhawk@example.invalid> - 2022-09-06 02:48 -0400
    Re: Cake - C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-09-06 10:08 -0700
      Re: Cake - C23 to C99 transpiler Vir Campestris <vir.campestris@invalid.invalid> - 2022-09-07 12:27 +0100
        Re: Cake - C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-09-07 05:45 -0700
          Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-07 15:35 +0100
            Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 16:38 +0100
              Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-07 17:04 +0100
                Re: Cake - C23 to C99 transpiler Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-09-07 19:14 +0300
                Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 17:31 +0100
                Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-07 17:40 +0100
                Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 17:49 +0100
                Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-07 19:27 +0100
                Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 20:02 +0100
                Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-07 21:03 +0100
                Re: Cake - C23 to C99 transpiler Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-07 13:52 -0700
                Re: Cake - C23 to C99 transpiler Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-09-14 07:14 -0700
                Re: Cake - C23 to C99 transpiler Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-14 10:59 -0700
                Re: Cake - C23 to C99 transpiler Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-09-15 23:46 -0700
                Re: Cake - C23 to C99 transpiler David Brown <david.brown@hesbynett.no> - 2022-09-07 20:17 +0200
                Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 19:58 +0100
                Re: Cake - C23 to C99 transpiler Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-07 13:26 -0700
                Re: Cake - C23 to C99 transpiler Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-09-07 23:42 +0100
                Re: Cake - C23 to C99 transpiler Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-09-14 06:45 -0700
                Re: Cake - C23 to C99 transpiler Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-09-14 06:40 -0700
                Re: Cake - C23 to C99 transpiler Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-09-07 10:28 -0700
                Re: Cake - C23 to C99 transpiler David Brown <david.brown@hesbynett.no> - 2022-09-07 20:05 +0200
            Re: Cake - C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-09-07 15:28 -0700
              Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-08 00:51 +0100
                Re: Cake - C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-09-08 05:20 -0700
                Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-08 16:41 +0100
                Re: Cake - C23 to C99 transpiler scott@slp53.sl.home (Scott Lurndal) - 2022-09-08 16:43 +0000
                Re: Cake - C23 to C99 transpiler Bart <bc@freeuk.com> - 2022-09-08 19:23 +0100
                Re: Cake - C23 to C99 transpiler Thiago Adams <thiago.adams@gmail.com> - 2022-09-08 09:59 -0700

csiph-web