Skip to content

Commit 04ecce3

Browse files
committed
Format
1 parent 493da1e commit 04ecce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+700
-615
lines changed

aarch64.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ const struct target AARCH64_TARGET = {
1919
.num_nonvolatile = 8,
2020
.num_reserved = 0},
2121
},
22-
AARCH64_FUNCTION_ALIGNMENT,
23-
aarch64_mangle,
24-
aarch64_lower,
25-
aarch64_codegen,
26-
aarch64_emit,
27-
write_macho,
28-
objdump_debug_disasm,
22+
AARCH64_FUNCTION_ALIGNMENT, aarch64_mangle, aarch64_lower, aarch64_codegen,
23+
aarch64_emit, write_macho, objdump_debug_disasm,
2924
aarch64_debug_print_codegen};

aarch64/codegen.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313
#define MOV_ALIAS(dest_reg, source_reg) \
1414
(struct aarch64_instr) { \
15-
.ty = AARCH64_INSTR_TY_ORR, .orr = { \
16-
.lhs = zero_reg_for_ty(dest_reg.ty), \
17-
.rhs = (source_reg), \
18-
.dest = (dest_reg), \
19-
.imm6 = 0 \
20-
} \
15+
.ty = AARCH64_INSTR_TY_ORR, .orr = {.lhs = zero_reg_for_ty(dest_reg.ty), \
16+
.rhs = (source_reg), \
17+
.dest = (dest_reg), \
18+
.imm6 = 0} \
2119
}
2220

2321
#define FP_MOV_ALIAS(dest_reg, source_reg) \
@@ -27,7 +25,6 @@
2725
.dest = (dest_reg), \
2826
} \
2927
}
30-
3128

3229
static enum aarch64_reg_ty gp_reg_ty_for_size(size_t size) {
3330
switch (size) {

aarch64/codegen.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ enum aarch64_reg_class {
164164

165165
enum aarch64_reg_attr_flags {
166166
AARCH64_REG_ATTR_FLAG_NONE = 0,
167-
AARCH64_REG_ATTR_FLAG_VOLATILE = 1, // v8-15 are upper half only volatile, we don't support this yet
167+
AARCH64_REG_ATTR_FLAG_VOLATILE =
168+
1, // v8-15 are upper half only volatile, we don't support this yet
168169
AARCH64_REG_ATTR_FLAG_ARG_REG = 2,
169170
AARCH64_REG_ATTR_FLAG_RET_REG = 4,
170171
AARCH64_REG_ATTR_FLAG_RESERVED = 8,
@@ -387,7 +388,8 @@ struct aarch64_instr {
387388
};
388389

389390
union {
390-
struct aarch64_addsub_ext addsub_ext, add_ext, adds_ext, sub_ext, subs_ext;
391+
struct aarch64_addsub_ext addsub_ext, add_ext, adds_ext, sub_ext,
392+
subs_ext;
391393
};
392394

393395
union {

aarch64/emitter.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ void aarch64_emit_adds(struct aarch64_emitter *emitter,
107107
/* Add & subtract (extended register) */
108108

109109
void aarch64_emit_sub_ext(struct aarch64_emitter *emitter,
110-
const struct aarch64_addsub_ext sub_ext);
110+
const struct aarch64_addsub_ext sub_ext);
111111
void aarch64_emit_subs_ext(struct aarch64_emitter *emitter,
112-
const struct aarch64_addsub_ext subs_ext);
112+
const struct aarch64_addsub_ext subs_ext);
113113
void aarch64_emit_add_ext(struct aarch64_emitter *emitter,
114-
const struct aarch64_addsub_ext add_ext);
114+
const struct aarch64_addsub_ext add_ext);
115115
void aarch64_emit_adds_ext(struct aarch64_emitter *emitter,
116-
const struct aarch64_addsub_ext adds_ext);
117-
116+
const struct aarch64_addsub_ext adds_ext);
118117

119118
/* Addressing (immediate) */
120119

aarch64/isa.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,23 @@
2828

2929
/* Loads & Stores */
3030

31-
#define LDR_STR_PAIR(opc, V, mode, L, imm7, Rt2, Rn, Rt) \
31+
#define LDR_STR_PAIR(opc, V, mode, L, imm7, Rt2, Rn, Rt) \
3232
(uint32_t)((U32(opc) << 30) | (U32(0b101) << 27) | (U32(V) << 26) | \
3333
(U32(mode) << 23) | (U32(L) << 22) | (U32(IMM(imm7, 7)) << 15) | \
3434
(U32(Rt2) << 10) | (U32(Rn) << 5) | U32(Rt))
3535

36-
#define STP_32(mode, fp, imm7, Rt2, Rn, Rt) \
36+
#define STP_32(mode, fp, imm7, Rt2, Rn, Rt) \
3737
LDR_STR_PAIR(0b00, fp, mode, 0, imm7, Rt2, Rn, Rt)
38-
#define LDP_32(mode, fp, imm7, Rt2, Rn, Rt) \
38+
#define LDP_32(mode, fp, imm7, Rt2, Rn, Rt) \
3939
LDR_STR_PAIR(0b00, fp, mode, 1, imm7, Rt2, Rn, Rt)
40-
#define STP_64(mode, fp, imm7, Rt2, Rn, Rt) \
40+
#define STP_64(mode, fp, imm7, Rt2, Rn, Rt) \
4141
LDR_STR_PAIR((fp ? 0b01 : 0b10), fp, mode, 0, imm7, Rt2, Rn, Rt)
42-
#define LDP_64(mode, fp, imm7, Rt2, Rn, Rt) \
42+
#define LDP_64(mode, fp, imm7, Rt2, Rn, Rt) \
4343
LDR_STR_PAIR((fp ? 0b01 : 0b10), fp, mode, 1, imm7, Rt2, Rn, Rt)
44-
#define STP_128(mode, fp, imm7, Rt2, Rn, Rt) \
44+
#define STP_128(mode, fp, imm7, Rt2, Rn, Rt) \
4545
LDR_STR_PAIR(0b10, fp, mode, 0, imm7, Rt2, Rn, Rt)
46-
#define LDP_128(mode, fp, imm7, Rt2, Rn, Rt) \
46+
#define LDP_128(mode, fp, imm7, Rt2, Rn, Rt) \
4747
LDR_STR_PAIR(0b10, fp, mode, 1, imm7, Rt2, Rn, Rt)
48-
4948

5049
#define LDR_LITERAL(opc, V, imm19, Rt) \
5150
(uin32_t)((U32(opc) << 30) | (U32(0b011) << 27) | (U32(V) << 26) | \
@@ -379,18 +378,19 @@
379378
#define SUBS_REG(sf, shift, imm6, Rm, Rn, Rd) \
380379
ADD_SUB_SHIFTED_REG(sf, 0b1, 0b1, shift, Rm, imm6, Rn, Rd)
381380

382-
#define ADD_SUB_EXTENDED_REG(sf, op, S, opt, Rm, option, imm3, Rn, Rd) \
381+
#define ADD_SUB_EXTENDED_REG(sf, op, S, opt, Rm, option, imm3, Rn, Rd) \
383382
(uint32_t)((U32(sf) << 31) | (U32(op) << 30) | (U32(S) << 29) | \
384-
(U32(0b01011) << 24) | (U32(opt) << 22) | (U32(0b1) << 21) | (U32(Rm) << 16) | \
385-
(U32(option) << 13) | (U32(IMM(imm3, 3)) << 10) | (U32(Rn) << 5) | U32(Rd))
383+
(U32(0b01011) << 24) | (U32(opt) << 22) | (U32(0b1) << 21) | \
384+
(U32(Rm) << 16) | (U32(option) << 13) | \
385+
(U32(IMM(imm3, 3)) << 10) | (U32(Rn) << 5) | U32(Rd))
386386

387-
#define ADD_EXT(sf, option, imm3, Rm, Rn, Rd) \
387+
#define ADD_EXT(sf, option, imm3, Rm, Rn, Rd) \
388388
ADD_SUB_EXTENDED_REG(sf, 0b0, 0b0, 0b00, Rm, option, imm3, Rn, Rd)
389-
#define SUB_EXT(sf, option, imm3, Rm, Rn, Rd) \
389+
#define SUB_EXT(sf, option, imm3, Rm, Rn, Rd) \
390390
ADD_SUB_EXTENDED_REG(sf, 0b1, 0b0, 0b00, Rm, option, imm3, Rn, Rd)
391-
#define ADDS_EXT(sf, option, imm3, Rm, Rn, Rd) \
391+
#define ADDS_EXT(sf, option, imm3, Rm, Rn, Rd) \
392392
ADD_SUB_EXTENDED_REG(sf, 0b0, 0b1, 0b00, Rm, option, imm3, Rn, Rd)
393-
#define SUBS_EXT(sf, option, imm3, Rm, Rn, Rd) \
393+
#define SUBS_EXT(sf, option, imm3, Rm, Rn, Rd) \
394394
ADD_SUB_EXTENDED_REG(sf, 0b1, 0b1, 0b00, Rm, option, imm3, Rn, Rd)
395395

396396
#define REG_2_SOURCE(sf, S, opcode, Rm, Rn, Rd) \

aarch64/lower.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ static void lower_call(struct ir_func *func, struct ir_op *op) {
325325
}
326326

327327
if (var_ty_is_aggregate(&op->var_ty)) {
328-
if (op->succ && op->succ->ty == IR_OP_TY_STORE_LCL && op->succ->store_lcl.value == op) {
328+
if (op->succ && op->succ->ty == IR_OP_TY_STORE_LCL &&
329+
op->succ->store_lcl.value == op) {
329330
op->lcl = op->succ->lcl;
330331
detach_ir_op(func, op->succ);
331332
}

alloc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void *arena_realloc(struct arena_allocator *allocator, void *ptr, size_t size) {
7777
return new;
7878
}
7979

80-
void *arena_alloc_init(struct arena_allocator *allocator, size_t size, void *data) {
80+
void *arena_alloc_init(struct arena_allocator *allocator, size_t size,
81+
void *data) {
8182
void *p = arena_alloc(allocator, size);
8283

8384
memcpy(p, data, size);

alloc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ void arena_allocator_free(struct arena_allocator **allocator);
1212
/* Alloc word-aligned block in arena */
1313
void *arena_alloc(struct arena_allocator *allocator, size_t size);
1414

15-
void *arena_alloc_init(struct arena_allocator *allocator, size_t size, void *data);
15+
void *arena_alloc_init(struct arena_allocator *allocator, size_t size,
16+
void *data);
1617

1718
/* Alloc space necessary for `str` (including null-terminator), then copy it
1819
into that space. Returns the start of the new allocation */

codegen.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ struct instr *alloc_instr(struct codegen_function *func) {
2626
return instr;
2727
}
2828

29-
3029
const char *mangle_str_cnst_name(struct arena_allocator *arena,
31-
const char *func_name, size_t id) {
30+
const char *func_name, size_t id) {
3231
// TODO: this should all really be handled by the mach-o file
3332
func_name = "str";
3433
size_t func_name_len = strlen(func_name);

codegen.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ struct instr {
8787

8888
struct instr *alloc_instr(struct codegen_function *func);
8989
const char *mangle_str_cnst_name(struct arena_allocator *arena,
90-
const char *func_name, size_t id);
91-
90+
const char *func_name, size_t id);
9291

9392
#endif

compiler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ enum compiler_create_result create_compiler(struct program *program,
6363

6464
(*compiler)->args = *args;
6565

66-
if (preproc_create(program, working_dir, args->num_include_paths, args->include_paths,
66+
if (preproc_create(program, working_dir, args->num_include_paths,
67+
args->include_paths,
6768
&(*compiler)->preproc) != PREPROC_CREATE_RESULT_SUCCESS) {
6869
err("failed to create preproc");
6970
return COMPILER_CREATE_RESULT_FAILURE;
@@ -124,7 +125,7 @@ enum compile_result compile(struct compiler *compiler) {
124125
if (strcmp(compiler->output, "stdout") == 0) {
125126
file = stdout;
126127
} else {
127-
file = fopen(compiler->output, "w");
128+
file = fopen(compiler->output, "w");
128129
}
129130

130131
if (!file) {

compiler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ enum compiler_create_result {
4747
COMPILER_CREATE_RESULT_FAILURE
4848
};
4949

50-
enum compile_result { COMPILE_RESULT_SUCCESS = 0, COMPILE_RESULT_BAD_FILE, COMPILE_RESULT_FAILURE };
50+
enum compile_result {
51+
COMPILE_RESULT_SUCCESS = 0,
52+
COMPILE_RESULT_BAD_FILE,
53+
COMPILE_RESULT_FAILURE
54+
};
5155

5256
enum compiler_create_result create_compiler(struct program *program,
5357
const char *output,

deque.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ void deque_ensure_capacity(struct deque *d, size_t capacity) {
4040
char *new_data = nonnull_malloc(new_capacity * d->element_size);
4141

4242
size_t head_cpy = MIN(d->len, d->capacity - d->head);
43-
memcpy(new_data, (char *)d->data + (d->element_size * d->head) , head_cpy * d->element_size);
43+
memcpy(new_data, (char *)d->data + (d->element_size * d->head),
44+
head_cpy * d->element_size);
4445

4546
if (head_cpy != d->len) {
4647
size_t tail_cpy = d->len - head_cpy;
47-
memcpy((char *)new_data + (d->element_size * head_cpy), d->data, tail_cpy * d->element_size);
48+
memcpy((char *)new_data + (d->element_size * head_cpy), d->data,
49+
tail_cpy * d->element_size);
4850
}
4951

5052
if (d->data) {
@@ -68,7 +70,8 @@ void *deque_push_front(struct deque *d, const void *data) {
6870
}
6971

7072
d->len++;
71-
return memcpy((char *)d->data + (d->head * d->element_size), data, d->element_size);
73+
return memcpy((char *)d->data + (d->head * d->element_size), data,
74+
d->element_size);
7275
}
7376

7477
void *deque_pop_back(struct deque *d) {
@@ -103,7 +106,6 @@ void deque_truncate(struct deque *d, size_t new_len) {
103106
d->len = new_len;
104107
}
105108

106-
107109
void *deque_push_back(struct deque *d, const void *data) {
108110
deque_extend(d, data, 1);
109111

@@ -129,11 +131,13 @@ void deque_extend(struct deque *d, const void *data, size_t num_elems) {
129131
// there is at most one discontinuity in the copy, so we split it into two
130132

131133
size_t head_cpy = MIN(num_elems, d->capacity - end);
132-
memcpy((char *)d->data + (end * d->element_size), data, d->element_size * head_cpy);
134+
memcpy((char *)d->data + (end * d->element_size), data,
135+
d->element_size * head_cpy);
133136

134137
if (head_cpy != num_elems) {
135138
size_t tail_cpy = num_elems - head_cpy;
136-
memcpy(d->data, (const char *)data + (head_cpy * d->element_size), d->element_size * tail_cpy);
139+
memcpy(d->data, (const char *)data + (head_cpy * d->element_size),
140+
d->element_size * tail_cpy);
137141
}
138142
}
139143

@@ -146,16 +150,18 @@ void deque_resize(struct deque *d, size_t size) {
146150
d->len = size;
147151
}
148152

149-
size_t deque_length(struct deque *d) {
150-
return d->len;
151-
}
153+
size_t deque_length(struct deque *d) { return d->len; }
152154

153155
size_t deque_element_size(struct deque *d) { return d->element_size; }
154156

155157
size_t deque_byte_size(struct deque *d) { return d->len * d->element_size; }
156158

157-
void *deque_head(struct deque *d) { return (char *)d->data + (d->head * d->element_size); }
158-
void *deque_tail(struct deque *d) { return (char *)d->data + (GET_IDX(d->len - 1) * d->element_size); }
159+
void *deque_head(struct deque *d) {
160+
return (char *)d->data + (d->head * d->element_size);
161+
}
162+
void *deque_tail(struct deque *d) {
163+
return (char *)d->data + (GET_IDX(d->len - 1) * d->element_size);
164+
}
159165

160166
void *deque_get(struct deque *d, size_t index) {
161167
debug_assert(index < d->len, "index out of bounds!");
@@ -166,11 +172,13 @@ void *deque_get(struct deque *d, size_t index) {
166172

167173
void deque_copy_to(struct deque *d, void *dest) {
168174
size_t head_cpy = MIN(d->len, d->capacity - d->head);
169-
memcpy(dest, (char *)d->data + (d->element_size * d->head) , head_cpy * d->element_size);
175+
memcpy(dest, (char *)d->data + (d->element_size * d->head),
176+
head_cpy * d->element_size);
170177

171178
if (head_cpy != d->len) {
172179
size_t tail_cpy = d->len - head_cpy;
173-
memcpy((char *)dest + (d->element_size * head_cpy), d->data, tail_cpy * d->element_size);
180+
memcpy((char *)dest + (d->element_size * head_cpy), d->data,
181+
tail_cpy * d->element_size);
174182
}
175183
}
176184

@@ -180,4 +188,3 @@ void deque_free(struct deque **d) {
180188
free(*d);
181189
*d = NULL;
182190
}
183-

deque.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ void deque_to_array(struct deque *d, void **data, size_t *len);
4444
void deque_free(struct deque **d);
4545

4646
#endif
47-

hash.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ static uint64_t folded_multiply(uint64_t l, uint64_t r) {
3333

3434
struct hasher hasher_create(void) {
3535
return (struct hasher){.accumulator = SEEDS[0],
36-
.sponge0 = 0,
37-
.sponge1 = 0,
38-
.sponge_len = 0,
39-
.fold_seed = SEEDS[1],
40-
.expand_seed0 = SEEDS[2],
41-
.expand_seed1 = SEEDS[3],
42-
.expand_seed2 = SEEDS[4]};
36+
.sponge0 = 0,
37+
.sponge1 = 0,
38+
.sponge_len = 0,
39+
.fold_seed = SEEDS[1],
40+
.expand_seed0 = SEEDS[2],
41+
.expand_seed1 = SEEDS[3],
42+
.expand_seed2 = SEEDS[4]};
4343
}
4444

4545
void hasher_hash_pointer(struct hasher *hasher, const void *value) {
@@ -65,7 +65,7 @@ void hasher_hash_integer(struct hasher *hasher, unsigned long long value,
6565
size_t shift = 128 - hasher->sponge_len;
6666

6767
uint64_t lo = hasher->sponge_len >= 64 ? 0 : value << hasher->sponge_len;
68-
uint64_t hi = shift >= 64 ? 0 : value >> shift ;
68+
uint64_t hi = shift >= 64 ? 0 : value >> shift;
6969

7070
hasher->sponge0 |= lo;
7171
hasher->sponge1 |= hi;

hash.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ void hasher_hash_bytes(struct hasher *hasher, const void *value, size_t length);
2525
hash_t hasher_finish(struct hasher *hasher);
2626

2727
#endif
28-

hashtbl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ bool hashtbl_iter_next(struct hashtbl_iter *hashtbl_iter,
5656
return false;
5757
}
5858

59-
struct bucket *bucket = vector_get(hashtbl->buckets, hashtbl_iter->bucket_idx);
59+
struct bucket *bucket =
60+
vector_get(hashtbl->buckets, hashtbl_iter->bucket_idx);
6061

61-
while (vector_empty(bucket->elems) && ++hashtbl_iter->bucket_idx < num_buckets) {
62+
while (vector_empty(bucket->elems) &&
63+
++hashtbl_iter->bucket_idx < num_buckets) {
6264
hashtbl_iter->elem_idx = 0;
6365
bucket = vector_get(hashtbl->buckets, hashtbl_iter->bucket_idx);
6466
}
@@ -102,8 +104,8 @@ struct hashtbl *hashtbl_create_str_keyed(size_t element_size) {
102104
}
103105

104106
struct hashtbl *hashtbl_create_sized_str_keyed(size_t element_size) {
105-
return hashtbl_create(sizeof(struct sized_str), element_size, hashtbl_hash_sized_str,
106-
hashtbl_eq_sized_str);
107+
return hashtbl_create(sizeof(struct sized_str), element_size,
108+
hashtbl_hash_sized_str, hashtbl_eq_sized_str);
107109
}
108110

109111
void hashtbl_insert_with_hash(struct hashtbl *hashtbl, const void *key,
@@ -153,7 +155,6 @@ static void hashtbl_rebuild(struct hashtbl *hashtbl) {
153155
vector_free(&buckets);
154156
}
155157

156-
157158
struct lookup_internal {
158159
void *triple;
159160
struct bucket *bucket;
@@ -278,4 +279,3 @@ bool hashtbl_eq_sized_str(const void *l, const void *r) {
278279

279280
return strncmp(sl->str, sr->str, sl->len) == 0;
280281
}
281-

0 commit comments

Comments
 (0)