Skip to content

Commit

Permalink
get rid of structs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Jan 7, 2025
1 parent aca087b commit 9b484e1
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 47 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VXCC is licenced under the [permissive Apache 2.0 license with LLVM Exceptions](
- easy to implement code generation for any architecture
- make it easy for people to learn about compiler backends
- good-ish optimizations
- beat QBE
- beat QBE in terms of generated code speed

## **non**-goals
- reach complexity of GCC or even LLVM
Expand All @@ -33,7 +33,6 @@ VXCC is licenced under the [permissive Apache 2.0 license with LLVM Exceptions](
| x86 codegen | ![#33cc33](https://placehold.co/15x15/33cc33/33cc33.png) | done but will be re-made |
| codegen of basic code involving loops | ![#33cc33](https://placehold.co/15x15/33cc33/33cc33.png) | done |
| basic optimizations | ![#33cc33](https://placehold.co/15x15/33cc33/33cc33.png) | done |
| struct support | ![#ff9900](https://placehold.co/15x15/ff9900/ff9900.png) | soon |
| proper register allocator & ISEL rework | ![#ff9900](https://placehold.co/15x15/ff9900/ff9900.png) | soon |
| floating point numbers | ![#cc0000](https://placehold.co/15x15/cc0000/cc0000.png) | planned |

Expand Down
2 changes: 1 addition & 1 deletion build_c
Submodule build_c updated 1 files
+1 −1 slowdb
6 changes: 5 additions & 1 deletion frontend_dev_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,9 @@ You should never use these operations:
- `GOTO`, `COND`: using these disables a lot of optimizations.
- `TAILCALL`: just always use `CALL` instead
Structs are currently not handled by VXCC, which means that like in LLVM, you have to take care of struct calling conventions yourself (if you need them).
You don't need those for most (if not all) C standard library functions, because they only apply if you pass or return a struct by value.
If you don't need them for linking with existing C code, you can just "invent" your own calling convention for structs, like passing all members as arguments.
## Step 6: compile the CU
See `vx_CU_compile()`. Note however, that object file output is not yet implemented.
See `vx_CU_compile()`. Note however, that object file output currently requires `nasm` in the `PATH`.
1 change: 0 additions & 1 deletion ir/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const char *vx_IrName_str[VX_IR_NAME__LAST] = {

[VX_IR_NAME_ID] = "id",
[VX_IR_NAME_TYPE] = "type",
[VX_IR_NAME_STRUCT] = "struct",
};

void vx_IrValue_dump(vx_IrValue value, FILE *out, const size_t indent) {
Expand Down
6 changes: 0 additions & 6 deletions ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ size_t vx_IrType_size(vx_CU* cu, vx_IrBlock* inCtx, vx_IrType *ty) {
case VX_IR_TYPE_KIND_BASE:
return ty->base.size;

case VX_IR_TYPE_KIND_CIR_STRUCT:
for (size_t i = 0; i < ty->cir_struct.members_len; i ++) {
total += vx_IrType_size(cu, inCtx, ty->cir_struct.members[i]);
}
return total;

case VX_IR_TYPE_FUNC:
return vx_IrType_size(cu, inCtx, cu->info.get_ptr_ty(cu, inCtx));

Expand Down
14 changes: 0 additions & 14 deletions ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ static const char * vx_OptIrVar_debug(vx_OptIrVar var) {

typedef struct vx_IrType_s vx_IrType;

// only in C IR
typedef struct {
vx_IrType **members;
size_t members_len;

bool pack;
size_t align;
} vx_IrTypeCIRStruct;

typedef struct {
bool sizeless;
size_t size;
Expand All @@ -95,9 +86,6 @@ typedef struct {
} vx_IrTypeFunc;

typedef enum {
// present in: cir
VX_IR_TYPE_KIND_CIR_STRUCT,

// present in: cir, ssa
VX_IR_TYPE_KIND_BASE,
VX_IR_TYPE_FUNC,
Expand All @@ -110,7 +98,6 @@ struct vx_IrType_s {

union {
vx_IrTypeBase base;
vx_IrTypeCIRStruct cir_struct;
vx_IrTypeFunc func;
};
};
Expand Down Expand Up @@ -437,7 +424,6 @@ typedef enum {
VX_IR_NAME_LOOP_STRIDE,

VX_IR_NAME_IDX,
VX_IR_NAME_STRUCT,
VX_IR_NAME_TYPE,
VX_IR_NAME_ELSIZE,
VX_IR_NAME_OFF,
Expand Down
22 changes: 0 additions & 22 deletions ir/ops.cdef
Original file line number Diff line number Diff line change
Expand Up @@ -666,28 +666,6 @@ enum_entry_prefix "VX_IR_OP_"
sideEffect false
;

entry GETELEM args "struct: struct var, idx: index of member"
debug "getelem"
descr "get element from struct"
inlineCost 2
execCost 2
endsFlow false
hasEffect true
volatile false
sideEffect false
;

entry SETELEM args "struct: old struct var, idx: index of member, val: new value of member"
debug "setelem"
descr "set element from struct by returning a struct with the modified values"
inlineCost 2
execCost 2
endsFlow false
hasEffect true
volatile false
sideEffect false
;

entry IF args "cond: ()->bool, then: ()->R, (else: ()->R)"
debug "if"
descr "if"
Expand Down

0 comments on commit 9b484e1

Please sign in to comment.