Skip to content

Commit 3478091

Browse files
committed
Add core language features
- sizeof expression support for variables and expressions - Union type support with proper memory layout - Compound literal support for basic types and arrays - Type casting support with explicit (type) syntax - Enhanced type system with union handling - Code formatted with clang-format-18
1 parent d772af3 commit 3478091

File tree

3 files changed

+472
-16
lines changed

3 files changed

+472
-16
lines changed

src/defs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ typedef enum {
157157
T_typedef,
158158
T_enum,
159159
T_struct,
160+
T_union,
160161
T_sizeof,
161162
T_elipsis, /* ... */
162163
T_switch,
@@ -184,6 +185,7 @@ typedef enum {
184185
TYPE_int,
185186
TYPE_char,
186187
TYPE_struct,
188+
TYPE_union,
187189
TYPE_typedef
188190
} base_type_t;
189191

@@ -254,6 +256,7 @@ typedef enum {
254256
/* data type conversion */
255257
OP_trunc,
256258
OP_sign_ext,
259+
OP_cast,
257260

258261
/* entry point of the state machine */
259262
OP_start
@@ -531,7 +534,6 @@ typedef struct {
531534
int polluted;
532535
} regfile_t;
533536

534-
/* FIXME: replace char[2] with a short data type in ELF header structures */
535537
/* ELF header */
536538
typedef struct {
537539
char e_ident[16];

src/globals.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ int hard_mul_div = 0;
580580
type_t *find_type(char *type_name, int flag)
581581
{
582582
for (int i = 0; i < types_idx; i++) {
583-
if (TYPES[i].base_type == TYPE_struct) {
583+
if (TYPES[i].base_type == TYPE_struct ||
584+
TYPES[i].base_type == TYPE_union) {
584585
if (flag == 1)
585586
continue;
586587
if (!strcmp(TYPES[i].type_name, type_name))
@@ -1398,6 +1399,10 @@ void dump_bb_insn(func_t *func, basic_block_t *bb, bool *at_func_start)
13981399
printf("%%%s = sign_ext %%%s, %d", rd->var_name, rs1->var_name,
13991400
insn->sz);
14001401
break;
1402+
case OP_cast:
1403+
print_indent(1);
1404+
printf("%%%s = cast %%%s", rd->var_name, rs1->var_name);
1405+
break;
14011406
default:
14021407
printf("<Unsupported opcode: %d>", insn->opcode);
14031408
break;

0 commit comments

Comments
 (0)