Deutsch English Français Italiano |
<vjmehc$hnkg$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: transpiling to low level C Date: Sun, 15 Dec 2024 11:28:45 +0000 Organization: A noiseless patient Spider Lines: 56 Message-ID: <vjmehc$hnkg$1@dont-email.me> References: <vjlh19$8j4k$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 15 Dec 2024 12:28:45 +0100 (CET) Injection-Info: dont-email.me; posting-host="178d3803084f207cadffeb141ca52cd0"; logging-data="581264"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19b5ZmygFl48Utx3iNil/a1" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ITDXI9xaR5xJXgQVGii50hMAW/w= In-Reply-To: <vjlh19$8j4k$1@dont-email.me> Content-Language: en-GB Bytes: 2618 On 15/12/2024 03:05, Thiago Adams wrote: > > I am working on a C backend that generates simple C code. > > You can test it here: > http://thradams.com/cake/playground.html > > Objective > - Shift all the complexity of the C compiler to the frontend. > Why? This approach simplifies having one frontend and multiple backends. > - Use C as an intermediate language to feed a backend (any C compiler > can act as the backend). > The backend can then focus solely on code generation. > - Code is not portable > > Removed C89 Features > - Preprocessor > - sizeof If I try: printf("%zu\n", sizeof(void*)); it turns into: printf("%zu\n", 4U); Presumably this translator will only target 32-bit systems even if run on a 64-bit one? (My own C transpiler goes the other way and generates 'C64', requiring a 64-bit compiler. Earlier versions made it optional, but the output was then either C32 or C64; if someone else compiled it, they'd have to choose the right compiler option.) I don't know if that "%zu" format will be an issue. > - typedef > - enum > - Constant expressions (the final result is precomputed during earlier > stages) > - const > - I may also remove switch. You can do that. But it can also slow down certain programs. (TCC 0.9.26 generated seqential tests for switch, but on one benchmark that relied on it heavily, its code was slower than my dynamic interpreter.) If you think this might be too hard to compile later, you can choose to do the same. (As for parsing switch, you'd need to do that anyway, either in the transpiler, or the backend compiler.)