Skip to content

Commit

Permalink
fix most clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
djwatson committed Oct 15, 2023
1 parent 361528f commit 085cba6
Show file tree
Hide file tree
Showing 13 changed files with 12,473 additions and 12,461 deletions.
8 changes: 4 additions & 4 deletions src/asm_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static void emit_arith_op(enum ARITH_CODES arith_code, enum OPCODES op_code,
}

static void emit_arith(enum ARITH_CODES arith_code, enum OPCODES op_code,
ir_ins *op, trace_s *trace, uint64_t offset, int *slot,
ir_ins *op, trace_s *trace, int64_t offset, int *slot,
uint32_t *next_spill) {
if (op->reg == REG_NONE) {
return;
Expand Down Expand Up @@ -494,7 +494,7 @@ static void emit_arith(enum ARITH_CODES arith_code, enum OPCODES op_code,
}

static void emit_cmp(enum jcc_cond cmp, ir_ins *op, trace_s *trace,
uint64_t offset, int *slot, uint32_t *next_spill) {
int64_t offset, int *slot, uint32_t *next_spill) {
maybe_assign_register(op->op1, trace, slot, next_spill);
maybe_assign_register(op->op2, trace, slot, next_spill);

Expand All @@ -519,7 +519,7 @@ static void emit_cmp(enum jcc_cond cmp, ir_ins *op, trace_s *trace,
}
}

static void emit_op_typecheck(uint8_t reg, uint8_t type, uint64_t offset) {
static void emit_op_typecheck(uint8_t reg, uint8_t type, int64_t offset) {
if (is_type_guard(type)) {
emit_jcc32(JNE, offset);
if (is_fixnum(get_type(type))) {
Expand Down Expand Up @@ -756,7 +756,7 @@ void asm_jit(trace_s *trace, snap_s *side_exit, trace_s *parent) {
slot[RDI] = 0; // scheme frame ptr.
slot[RBX] = 0; // allocation ptr.

uint64_t *snap_labels = NULL;
int64_t *snap_labels = NULL;
arrsetlen(snap_labels, arrlen(trace->snaps));

auto end = emit_offset();
Expand Down
24,835 changes: 12,417 additions & 12,418 deletions src/bootstrap.c

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/emit_x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void emit_ret() { *(--p) = 0xc3; }

// TODO(djwatson) clean this up. THe main issue is REX needs W=0.
// Also check R1 does full checks for rsp/rbp
void emit_cmp_mem32_imm32(uint32_t offset, uint8_t r1, int32_t imm) {
void emit_cmp_mem32_imm32(int32_t offset, uint8_t r1, int32_t imm) {
emit_imm32(imm);
assert(r1 != RSP);
assert(r1 != RBP);
Expand Down Expand Up @@ -130,13 +130,14 @@ void emit_cmp_reg_reg(uint8_t src, uint8_t dst) {
emit_rex(1, src >> 3, 0, dst >> 3);
}

void emit_jcc32(enum jcc_cond cond, uint64_t offset) {
int64_t off = (int64_t)offset - (int64_t)emit_offset();
void emit_jcc32(enum jcc_cond cond, int64_t offset) {
int64_t off = offset - (int64_t)emit_offset();
if ((int32_t)((int8_t)off) == off) {
*(--p) = (int8_t)off;
*(--p) = cond - 0x10;
} else {
emit_imm32(off);
// TODO assert that off fits in int32_t
emit_imm32((int32_t)off);
*(--p) = cond;
*(--p) = 0x0f;
}
Expand Down Expand Up @@ -283,7 +284,7 @@ void emit_cmovl(uint8_t dst, uint8_t src) {

/////////////////// memory

uint64_t emit_offset() { return (uint64_t)p; }
int64_t emit_offset() { return (int64_t)p; }

void emit_bind(uint64_t label, uint64_t jmp) {
assert(jmp);
Expand Down
6 changes: 3 additions & 3 deletions src/emit_x64.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ enum jcc_cond {

void emit_init();
void emit_cleanup();
uint64_t emit_offset();
int64_t emit_offset();
void emit_advance(int64_t offset);
void emit_bind(uint64_t label, uint64_t jmp);
void emit_check();
Expand All @@ -115,8 +115,8 @@ void emit_imm8(uint8_t imm);
void emit_imm32(int32_t imm);
void emit_reg_reg(uint8_t opcode, uint8_t src, uint8_t dst);
void emit_reg_reg2(uint8_t opcode, uint8_t src, uint8_t dst);
void emit_jcc32(enum jcc_cond cond, uint64_t offset);
void emit_jcc32(enum jcc_cond cond, int64_t offset);
void emit_op_imm32(uint8_t opcode, uint8_t r1, uint8_t r2, int32_t imm);
void emit_cmp_reg_imm32(uint8_t r, int32_t imm);
void emit_cmp_mem32_imm32(uint32_t offset, uint8_t r1, int32_t imm);
void emit_cmp_mem32_imm32(int32_t offset, uint8_t r1, int32_t imm);
void emit_arith_imm(enum ARITH_CODES op, uint8_t src, int32_t imm);
1 change: 1 addition & 0 deletions src/hawk.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ int main(int argc, char *argv[]) {
generate_exe(argv[i], tmp);
}
if (list || exe) {
free(tmp);
break;
}
printf("Running script %s\n", tmp);
Expand Down
3 changes: 2 additions & 1 deletion src/lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void lru_poke(lru *l, uint8_t node) {
uint8_t prev_newest = l->head;
if (node == prev_newest) {
return;
} else if (l->data[prev_newest].prev != node) {
}
if (l->data[prev_newest].prev != node) {
lru_remove(l, node);
lru_insert_before(l, node, l->head);
}
Expand Down
2 changes: 2 additions & 0 deletions src/opcodes.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 Dave Watson

#include "opcodes.h"

const char *ins_names[] = {
Expand Down
2 changes: 2 additions & 0 deletions src/opcodes.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2023 Dave Watson

#pragma once

#include "opcodes-gen.h"
Expand Down
8 changes: 4 additions & 4 deletions src/profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static uint64_t cnt = 0;
static uint64_t heap_ptr = 0;
static uint64_t heap_end = 0;

static size_t alloc_sz = 4096 * 16;
static size_t alloc_sz = 4096 * 16UL;

void *signal_safe_malloc(size_t sz) {
if ((heap_ptr + sz) < heap_end) {
Expand Down Expand Up @@ -51,7 +51,7 @@ typedef struct sample_s {

static sample *samples = nullptr;

static uint64_t profile_stack_sz = 0;
static int64_t profile_stack_sz = 0;
static uint32_t **profile_stack = nullptr;
static uint64_t profile_stack_max = 0;
static uint32_t *pc;
Expand All @@ -65,8 +65,8 @@ void profile_add_frame(uint32_t *ptr) {
} else {
profile_stack_max *= 2;
}
uint32_t **n = malloc(sizeof(int32_t *) * profile_stack_max);
memcpy(n, profile_stack, profile_stack_sz * sizeof(int32_t *));
uint32_t **n = malloc(sizeof(uint32_t *) * profile_stack_max);
memcpy(n, profile_stack, profile_stack_sz * sizeof(uint32_t *));
auto old = profile_stack;
profile_stack = n; // release
free(old);
Expand Down
37 changes: 21 additions & 16 deletions src/readbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ static gc_obj read_symbol(FILE *fptr, uint64_t num) {
}
static char str_buf[str_buf_len + 1 + sizeof(string_s)]
__attribute__((aligned(8)));
string_s *str = (string_s *)str_buf;
string_s *str = (string_s *)str_buf; // NOLINT

// It's a new symbol in this bc file
uint64_t len;
int64_t len;
if (8 != fread(&len, 1, 8, fptr) || len > str_buf_len) {
read_error();
}

*str = (string_s){STRING_TAG, 0, len << 3};
*str = (string_s){STRING_TAG, 0, tag_fixnum(len)};
if (fread(str->str, 1, len, fptr) != len) {
read_error();
}
Expand Down Expand Up @@ -95,13 +95,13 @@ static gc_obj read_ptr(FILE *fptr) {
read_error();
}
if (ptrtype == STRING_TAG) {
uint64_t len;
int64_t len;
if (fread(&len, 1, 8, fptr) != 8 || len > 512) {
read_error();
}
string_s *str = GC_malloc(16 + len + 1);
str->type = ptrtype;
str->len = len << 3;
str->len = tag_fixnum(len);
str->rc = 0;
if (fread(&str->str, 1, len, fptr) != len) {
read_error();
Expand All @@ -114,7 +114,7 @@ static gc_obj read_ptr(FILE *fptr) {
}

static gc_obj read_vector(FILE *fptr) {
uint64_t len;
int64_t len;
if (fread(&len, 1, 8, fptr) != 8 || len > (1UL << 29)) {
read_error();
}
Expand All @@ -130,7 +130,7 @@ static gc_obj read_vector(FILE *fptr) {

vector_s *v = GC_malloc(16 + len * sizeof(gc_obj));
v->type = VECTOR_TAG;
v->len = len << 3;
v->len = tag_fixnum(len);
v->rc = 0;
for (int64_t i = len - 1; i >= 0; i--) {
v->v[i] = vals[i];
Expand All @@ -141,15 +141,15 @@ static gc_obj read_vector(FILE *fptr) {
}

static gc_obj read_closure(FILE *fptr) {
uint64_t bcfunc_num;
int64_t bcfunc_num;
if (fread(&bcfunc_num, 1, 8, fptr) != 8) {
read_error();
}
closure_s *clo = GC_malloc(sizeof(closure_s) + 8);
clo->type = CLOSURE_TAG;
clo->rc = 0;
clo->len = 1 << 3;
clo->v[0] = bcfunc_num << 3; // Updated below.
clo->v[0] = tag_fixnum(bcfunc_num); // Updated below.
return tag_closure(clo);
}

Expand All @@ -160,16 +160,21 @@ static gc_obj read_const(FILE *fptr) {
}
auto type = val & TAG_MASK;
if (type == SYMBOL_TAG) {
return read_symbol(fptr, val >> 3);
} else if (type == FLONUM_TAG) {
return read_symbol(fptr, to_fixnum(val));
}
if (type == FLONUM_TAG) {
return read_flonum(fptr);
} else if (type == CONS_TAG) {
}
if (type == CONS_TAG) {
return read_cons(fptr);
} else if (type == PTR_TAG) {
}
if (type == PTR_TAG) {
return read_ptr(fptr);
} else if (type == VECTOR_TAG) {
}
if (type == VECTOR_TAG) {
return read_vector(fptr);
} else if (type == CLOSURE_TAG) {
}
if (type == CLOSURE_TAG) {
return read_closure(fptr);
}

Expand Down Expand Up @@ -316,7 +321,7 @@ static bcfunc *readbc(FILE *fptr) {
auto v = const_table[i];
if (is_closure(v)) {
auto clo = to_closure(v);
clo->v[0] = (long)funcs[func_offset + (clo->v[0] >> 3)];
clo->v[0] = (gc_obj)funcs[func_offset + (clo->v[0] >> 3)];
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

void add_snap(const uint16_t *regs, ptrdiff_t off, trace_s *trace, uint32_t *pc,
uint32_t depth, uint32_t stack_top) {
int32_t offset = off;
// TODO size check offset
int32_t offset = (int32_t)off; // NOLINT
snap_s snap;
snap.ir = arrlen(trace->ops);
snap.pc = pc;
Expand All @@ -24,7 +25,7 @@ void add_snap(const uint16_t *regs, ptrdiff_t off, trace_s *trace, uint32_t *pc,
snap.argcnt = 1;
snap.patchpoint = 0;
auto top = offset + stack_top + 1 /* offset */;
for (int16_t i = 0; i < top; i++) {
for (int32_t i = 0; i < top; i++) {
if (regs[i] != REGS_NONE) {
snap_entry_s entry;
entry.slot = (int16_t)(i - 1); // offset by one for callt
Expand Down
8 changes: 4 additions & 4 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void print_obj(gc_obj obj, FILE *file) {
} else if (obj == UNDEFINED_TAG) {
fputs("<undefined>", file);
} else if (is_char(obj)) {
fputc(obj >> 8, file);
fputc(to_char(obj), file);
} else {
fprintf(file, "Unknown immediate: %lx\n", obj);
}
Expand All @@ -233,9 +233,9 @@ void print_obj(gc_obj obj, FILE *file) {
}

EXPORT gc_obj from_c_str(const char *s) {
auto len = strlen(s);
string_s *str = GC_malloc(16 + len + 1);
*str = (string_s){STRING_TAG, 0, len << 3};
auto len = (int64_t)strlen(s);
string_s *str = GC_malloc(sizeof(string_s) + len + 1);
*str = (string_s){STRING_TAG, 0, tag_fixnum(len)};
memcpy(str->str, s, len);
str->str[len] = '\0';
return tag_string(str);
Expand Down
8 changes: 4 additions & 4 deletions src/unionfind.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
// Custom hashtable. I tried to use stb_ds, but it was too slow:
// insertion/hashing isn't as fast as crc32+linear probe.
static uf_item *map_find(uf *ht, int64_t key) {
int64_t start = _mm_crc32_u64(0, key);
auto start = _mm_crc32_u64(0, key);

int64_t sz_mask = ht->map_sz - 1;
auto sz_mask = ht->map_sz - 1;
for (uint64_t i = 0; i < ht->map_sz; i++) {
uint64_t slot = (i + start) & sz_mask;
if (ht->map[slot].key == key) {
Expand Down Expand Up @@ -54,8 +54,8 @@ static void map_insert(uf *ht, int64_t key, uint64_t value) {
}
}

int64_t start = _mm_crc32_u64(0, key);
int64_t sz_mask = ht->map_sz - 1;
auto start = _mm_crc32_u64(0, key);
auto sz_mask = ht->map_sz - 1;
for (uint64_t i = 0; i < ht->map_sz; i++) {
uint64_t slot = (i + start) & sz_mask;
if (ht->map[slot].key == 0) {
Expand Down

0 comments on commit 085cba6

Please sign in to comment.