| Deutsch English Français Italiano |
|
<vjlh19$8j4k$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: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: transpiling to low level C
Date: Sun, 15 Dec 2024 00:05:13 -0300
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <vjlh19$8j4k$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 15 Dec 2024 04:05:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="75cbf010cfc8fccc260a6c4cc0d7f911";
logging-data="281748"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/STxH8W3SRyICgNER6Jg8/RDM/MmmGZXY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RgBLG47t8N0w8odfO+MN/aQsXc4=
Content-Language: en-GB
Bytes: 2819
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
- typedef
- enum
- Constant expressions (the final result is precomputed during earlier
stages)
- const
- I may also remove switch.
- struct are declared only at external scope
Most features from C99, C11, and C23 are not included.
However, features directly related to code generation may be supported,
in the future such as:
- restrict
- inline
- atomic
- _NoReturn
Current Status
This project is very new and still contains bugs.
When generating a constant like '(unsigned char) 1', the cast is
removed. The rationale is that type-specific representations aren't
necessary, as values are promoted automatically.
Similarly, 'nullptr' is replaced by '0' instead of '(void*)0'.
Constructs dependent on type (like 'sizeof', '_Generic', etc.) have
already been removed in earlier stages.
Example:
unsigned char c = u8'~';
Generated Code:
unsigned char c = 126;
Instead of:
unsigned char c = ((unsigned char)126);
For larger types like 'unsigned long long', a suffix is still included.
Initialization Strategy
Currently, I use 'memset' to initialize structures to zero. For
instance:
struct X x = {};
memset(&x, 0, 8 /*bytes*/);
Boolean Conversion
The behavior of converting integers to 'bool' is still incomplete.
For example:
bool b = 123;
Here, 'b' should have the value '1' but today it is 123.