Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed May 14, 2024
1 parent 360695b commit bbf7c7a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
#!/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

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
4 changes: 2 additions & 2 deletions ir/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../common.h"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -153,7 +154,9 @@ typedef struct {
long long imm_int;
double imm_flt;
vx_IrVar var;

vx_IrBlock *block;
vx_IrType *ty;
};
} vx_IrValue;

Expand Down
8 changes: 7 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bbf7c7a

Please sign in to comment.