Liste des Groupes | Revenir à cl c |
On 27/11/2024 09:38, Thiago Adams wrote:I tried this sample with clang and -S -emit-llvm to see if it generates structs. The answer is yes.On 27/11/2024 09:10, Bart wrote:I was wondering if is possible to write C programs without struct/union?On 27/11/2024 11:57, Bart wrote:On 27/11/2024 01:52, Thiago Adams wrote:>I also use ILs for my compilers, but I write my own backends. I've worked on two diifferent kinds. One looks like a HLL, and only exists for my language. So this original source:>
I did this experiment.
struct X {
int a, b;
};
void F1() {
struct X x;
x.a = 1;
x.b = 2;
printf("%d, %d", x.a, x.b);
}
The equivalent C89 program in a subset without structs count be
#define M(T, obj, OFF) *((T*)(((char*)&(obj)) + (OFF)))
void F2() {
char x[8];
M(int, x, 0 /*offset of a*/) = 1;
M(int, x, 4 /*offset of b*/) = 2;
printf("\n");
printf("%d, %d", M(int, x, 0), M(int, x, 4));
}
The char array represents the struct X memory, then we have to find the offset of the members and cast to their types.
Does your IL have structs?
The QBE IL has aggregates types. I think this removes the front end calculate the the offsets.
https://c9x.me/compile/doc/il.html#Aggregate-Types
Les messages affichés proviennent d'usenet.