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


Groups > comp.lang.c > #167549

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 16:41 +0100
Organization Aioe.org NNTP Server
Message-ID <tfd2em$1als$1@gioia.aioe.org> (permalink)
References (4 earlier) <836c6515-87f5-42b2-98b0-8308173a9120n@googlegroups.com> <tfaa7f$qcg$1@gioia.aioe.org> <cecefea6-c480-4bd2-a102-94576974289en@googlegroups.com> <tfbaqq$tl9$1@gioia.aioe.org> <76dca35b-fe93-46ee-99b6-ac1cefa72098n@googlegroups.com>

Show all headers | View raw


On 08/09/2022 13:20, Thiago Adams wrote:
> On Wednesday, September 7, 2022 at 8:52:13 PM UTC-3, Bart wrote:

>> 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.
> 
> The emulation of x86 or x64 would not be complete.. I was thinking in just
> have some elements that are similar and makes useful in the future to generate
> real machine assembler.  For instance, using some virtual registers and similar function call.
> Also making data sections and using a stack of bytes.

So it's a VM.

> 
>>> 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.
> 
> I think MSVC has a separated linker but not sure if object files have
> a intermediate step like gcc.
>   
>> 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.
> 
> The problem with this textual ASM is that it works in just one assembler right?
> for instance nasm or gcc or masm.


There are syntax differences between different assemblers, but they're 
not great. (Only gcc's 'gas' or 'AT&T' format is very different, but 
even that has an option to accept the more standard Intel-style format.)

If you were to generate ASM in a simple fashion, such as directly 
writing the text so that those differences are hardcoded throughout your 
program, then switching assemblers would be a lot of work.

The method I use is to generate a more independent representation of x64 
code, then I just need a different routine to dump that data structure 
into ASM source. So a few hundred lines instead of a few thousand.

But also bear in mind that even x64 code will vary according to 
platform, because of ABI differences.

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