From bbf7c7a44d04651d6646c22f6c537011a9376746 Mon Sep 17 00:00:00 2001 From: "alexander.nutz" Date: Tue, 14 May 2024 06:56:02 +0200 Subject: [PATCH] c --- build.sh | 9 +++++++-- ir/dump.c | 4 ++-- ir/ir.h | 5 ++++- main.c | 8 +++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 062f1a5..2527e88 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,9 @@ #!/usr/bin/bash set -e +: ${CFLAGS:="-Wall -Wextra -Wno-unused -Wpedantic -Werror -std=c11"} +: ${CC:="clang"} + FILES="main.c ir/opt/*.c ir/*.c common/*.c ir/transform/*.c" -CFLAGS="-Wall -Wextra -Wno-unused -Wpedantic -Werror -std=c11" # shellcheck disable=SC2086 @@ -9,12 +11,15 @@ if [[ $1 == "analyze" ]]; then echo "analyzing..." clang --analyze -Xclang -analyzer-werror $CFLAGS $FILES elif [[ $1 == "info" ]]; then + echo clang: clang --version echo cflags: $CFLAGS echo files: $FILES + echo cc: + $CC --version else echo "compile Debug" - clang -g -ggdb -O0 $CFLAGS $FILES -o vxcc + $CC -g -ggdb -O0 $CFLAGS $FILES -o vxcc fi # shellcheck enable=SC2086 diff --git a/ir/dump.c b/ir/dump.c index 160eaf3..9df49e3 100644 --- a/ir/dump.c +++ b/ir/dump.c @@ -84,7 +84,7 @@ void vx_IrValue_dump(vx_IrValue value, FILE *out, const size_t indent) { break; case VX_IR_VAL_TYPE: { - fprintf(out, "type"); // TODO + fprintf(out, "type %s", value.ty->debugName); } break; @@ -151,7 +151,7 @@ void vx_IrOp_dump(const vx_IrOp *op, FILE *out, size_t indent) { if (j > 0) fputc(',', out); const vx_IrTypedVar var = op->outs[j]; - fprintf(out, "%s %%%zu", "t" /* TODO var.type */, var.var); + fprintf(out, "%s %%%zu", var.type->debugName, var.var); } if (op->outs_len > 0) diff --git a/ir/ir.h b/ir/ir.h index 089ceb0..4fe424f 100644 --- a/ir/ir.h +++ b/ir/ir.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../common.h" @@ -67,7 +68,7 @@ struct vx_IrType_s { }; static vx_IrType* vx_IrType_heap(void) { - return (vx_IrType*) malloc(sizeof(vx_IrType)); + return (vx_IrType*) memset(malloc(sizeof(vx_IrType)), 0, sizeof(vx_IrType)); } struct vx_IrBlock_s; @@ -153,7 +154,9 @@ typedef struct { long long imm_int; double imm_flt; vx_IrVar var; + vx_IrBlock *block; + vx_IrType *ty; }; } vx_IrValue; diff --git a/main.c b/main.c index 64b3561..ff77f64 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ #include "ir/opt.h" #include "ir/cir.h" -static vx_IrType *ty_int = NULL; +static vx_IrType *ty_int; static int ir_test(void) { vx_IrBlock block; @@ -150,6 +150,12 @@ static int cir_test(void) { } int main(void) { + ty_int = vx_IrType_heap(); + ty_int->debugName = "i32"; + ty_int->kind = VX_IR_TYPE_KIND_BASE; + ty_int->base.align = 4; + ty_int->base.size = 4; + printf("C-IR test:\n"); if (cir_test() != 0) return 1;