Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
john-h-k committed Dec 13, 2024
1 parent 3d5ea54 commit c02a84a
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 117 deletions.
34 changes: 17 additions & 17 deletions aarch64/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@

#define MOV_ALIAS(dest_reg, source_reg) \
(struct aarch64_instr) { \
.ty = AARCH64_INSTR_TY_ORR, .orr = { \
.lhs = zero_reg_for_ty(dest_reg.ty), \
.rhs = (source_reg), \
.dest = (dest_reg), \
.imm6 = 0 \
} \
.ty = AARCH64_INSTR_TY_ORR, .orr = {.lhs = zero_reg_for_ty(dest_reg.ty), \
.rhs = (source_reg), \
.dest = (dest_reg), \
.imm6 = 0} \
}

#define FP_MOV_ALIAS(dest_reg, source_reg) \
Expand Down Expand Up @@ -2698,8 +2696,9 @@ static int sort_entries_by_id(const void *a, const void *b) {
}
}

static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs, size_t offset,
struct ir_var_value *value, char *data) {
static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs,
size_t offset, struct ir_var_value *value,
char *data) {
if (!value || value->ty == IR_VAR_VALUE_TY_ZERO) {
return;
}
Expand Down Expand Up @@ -2742,7 +2741,8 @@ static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs,
case IR_VAR_TY_TY_FUNC:
bug("func can not have data as a global var");

// FIXME: some bugs here around using compiler-ptr-size when we mean to use target-ptr-size
// FIXME: some bugs here around using compiler-ptr-size when we mean to use
// target-ptr-size

case IR_VAR_TY_TY_POINTER:
case IR_VAR_TY_TY_ARRAY:
Expand All @@ -2751,12 +2751,10 @@ static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs,
case IR_VAR_VALUE_TY_FLT:
bug("doesn't make sense");
case IR_VAR_VALUE_TY_ADDR: {
struct relocation reloc = {
.ty = RELOCATION_TY_POINTER,
.size = 3,
.address = offset,
.symbol_index = value->addr.glb->id
};
struct relocation reloc = {.ty = RELOCATION_TY_POINTER,
.size = 3,
.address = offset,
.symbol_index = value->addr.glb->id};

vector_push_back(relocs, &reloc);

Expand All @@ -2773,7 +2771,8 @@ static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs,
case IR_VAR_VALUE_TY_VALUE_LIST:
for (size_t i = 0; i < value->value_list.num_values; i++) {
size_t value_offset = value->value_list.offsets[i];
codegen_write_var_value(iru, relocs, offset + value_offset, &value->value_list.values[i],
codegen_write_var_value(iru, relocs, offset + value_offset,
&value->value_list.values[i],
&data[value_offset]);
}
break;
Expand All @@ -2786,7 +2785,8 @@ static void codegen_write_var_value(struct ir_unit *iru, struct vector *relocs,
"expected value list");
for (size_t i = 0; i < value->value_list.num_values; i++) {
size_t field_offset = value->value_list.offsets[i];
codegen_write_var_value(iru, relocs, offset + field_offset, &value->value_list.values[i],
codegen_write_var_value(iru, relocs, offset + field_offset,
&value->value_list.values[i],
&data[field_offset]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion aarch64/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ struct aarch64_instr {
};

union {
struct aarch64_reg_1_source reg_1_source, fmov, fcvt, ucvtf, scvtf, fneg, fabs, fsqrt;
struct aarch64_reg_1_source reg_1_source, fmov, fcvt, ucvtf, scvtf, fneg,
fabs, fsqrt;
};

union {
Expand Down
16 changes: 7 additions & 9 deletions aarch64/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,15 @@ void aarch64_emit_fneg(struct aarch64_emitter *emitter,
}

void aarch64_emit_fsqrt(struct aarch64_emitter *emitter,
const struct aarch64_reg_1_source fsqrt) {
aarch64_emit_instr(
emitter, FSQRT(FTYPE_FOR_REG(fsqrt.dest), fsqrt.source.idx, fsqrt.dest.idx));

const struct aarch64_reg_1_source fsqrt) {
aarch64_emit_instr(emitter, FSQRT(FTYPE_FOR_REG(fsqrt.dest), fsqrt.source.idx,
fsqrt.dest.idx));
}

void aarch64_emit_fabs(struct aarch64_emitter *emitter,
const struct aarch64_reg_1_source fabs) {
aarch64_emit_instr(
emitter, FABS(FTYPE_FOR_REG(fabs.dest), fabs.source.idx, fabs.dest.idx));

}

void aarch64_emit_fabs(struct aarch64_emitter *emitter,
Expand Down Expand Up @@ -322,14 +320,14 @@ void aarch64_emit_fdiv(struct aarch64_emitter *emitter,
}

void aarch64_emit_fmaxnm(struct aarch64_emitter *emitter,
const struct aarch64_reg_2_source fmax) {
const struct aarch64_reg_2_source fmax) {
aarch64_emit_instr(emitter, FMAXNM(FTYPE_FOR_REG(fmax.dest), fmax.rhs.idx,
fmax.lhs.idx, fmax.dest.idx));
fmax.lhs.idx, fmax.dest.idx));
}
void aarch64_emit_fminnm(struct aarch64_emitter *emitter,
const struct aarch64_reg_2_source fmin) {
const struct aarch64_reg_2_source fmin) {
aarch64_emit_instr(emitter, FMINNM(FTYPE_FOR_REG(fmin.dest), fmin.rhs.idx,
fmin.lhs.idx, fmin.dest.idx));
fmin.lhs.idx, fmin.dest.idx));
}

/* Register moves */
Expand Down
6 changes: 3 additions & 3 deletions aarch64/emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void aarch64_emit_fmov(struct aarch64_emitter *emitter,
void aarch64_emit_fneg(struct aarch64_emitter *emitter,
const struct aarch64_reg_1_source fneg);
void aarch64_emit_fsqrt(struct aarch64_emitter *emitter,
const struct aarch64_reg_1_source fsqrt);
const struct aarch64_reg_1_source fsqrt);
void aarch64_emit_fabs(struct aarch64_emitter *emitter,
const struct aarch64_reg_1_source fabs);

Expand All @@ -54,9 +54,9 @@ void aarch64_emit_fdiv(struct aarch64_emitter *emitter,
const struct aarch64_reg_2_source fdiv);

void aarch64_emit_fmaxnm(struct aarch64_emitter *emitter,
const struct aarch64_reg_2_source fmaxnm);
const struct aarch64_reg_2_source fmaxnm);
void aarch64_emit_fminnm(struct aarch64_emitter *emitter,
const struct aarch64_reg_2_source fminnm);
const struct aarch64_reg_2_source fminnm);

/* Register moves */

Expand Down
1 change: 0 additions & 1 deletion aarch64/isa.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
#define FNEG(ftype, Rn, Rd) FP_1_REG(0b0, 0b0, ftype, 0b000010, Rn, Rd)
#define FSQRT(ftype, Rn, Rd) FP_1_REG(0b0, 0b0, ftype, 0b000011, Rn, Rd)


/* Two reg FP data processing */

#define FP_CMP(M, S, ftype, Rm, op, Rn, opcode2) \
Expand Down
12 changes: 5 additions & 7 deletions compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ static const struct target *get_target(const struct compile_args *args) {
bug("unexpected target in `get_target`");
}

enum compiler_create_result create_compiler(struct program *program,
const char *output,
const char *path,
const struct compile_args *args,
struct compiler **compiler) {
enum compiler_create_result
create_compiler(struct program *program, const char *output, const char *path,
const struct compile_args *args, struct compiler **compiler) {
*compiler = nonnull_malloc(sizeof(**compiler));

(*compiler)->args = *args;
Expand All @@ -77,8 +75,8 @@ enum compiler_create_result create_compiler(struct program *program,
}

const struct target *target = get_target(args);
if (typechk_create(target, args, (*compiler)->parser, &(*compiler)->typechk) !=
TYPECHK_CREATE_RESULT_SUCCESS) {
if (typechk_create(target, args, (*compiler)->parser,
&(*compiler)->typechk) != TYPECHK_CREATE_RESULT_SUCCESS) {
err("failed to create typechk");
return COMPILER_CREATE_RESULT_FAILURE;
}
Expand Down
10 changes: 2 additions & 8 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ struct path_components path_components(const char *path) {
const char *last_slash = strrchr(path, '/');

if (last_slash == NULL) {
return (struct path_components){
.dir = ".",
.file = strdup(path)
};
return (struct path_components){.dir = ".", .file = strdup(path)};
}

size_t dir_len = last_slash - path;
Expand All @@ -23,10 +20,7 @@ struct path_components path_components(const char *path) {
strncpy(dir, path, dir_len);
dir[dir_len] = '\0';

return (struct path_components){
.dir = dir,
.file = strdup(file_part)
};
return (struct path_components){.dir = dir, .file = strdup(file_part)};
}

char *path_combine(const char *l, const char *r) {
Expand Down
4 changes: 2 additions & 2 deletions ir/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ static struct ir_op *build_ir_for_unaryop(struct ir_func_builder *irb,
: TD_ASSG_TY_SUB;
goto inc_dec;

inc_dec : {
inc_dec: {
// if we are decrementing a pointer/array, we need to make sure we don't
// build an expr that is PTR - PTR as this will do a "pointer subtract"
// rather than "pointer minus integer" so we give the constant a
Expand Down Expand Up @@ -1513,7 +1513,7 @@ static struct ir_op *build_ir_for_assg(struct ir_func_builder *irb,
ty = TD_BINARY_OP_TY_RSHIFT;
goto compound_assg;

compound_assg : {
compound_assg: {
struct ir_op *assignee = build_ir_for_expr(irb, stmt, assg->assignee);

struct ir_op *lhs;
Expand Down
3 changes: 2 additions & 1 deletion ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ struct ir_op_call {
size_t num_args;
struct ir_op **args;

// must be preserved because of unspecified functions e.g `int foo(); foo(7, 8.3)`
// must be preserved because of unspecified functions e.g `int foo();
// foo(7, 8.3)`
struct ir_var_ty *arg_var_tys;
};

Expand Down
20 changes: 11 additions & 9 deletions macos/mach-o.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static void write_mach_header(FILE *file, const struct compile_args *args) {
((x & 0xFF) << 16) | ((y & 0x0F) << 8) | (z & 0x0F)
#define ENCODE_SDK(x, y, z) ((x & 0xFF) << 16) | ((y & 0x0F) << 8) | (z & 0x0F)

static struct reloc_info
build_reloc_info(const struct build_object_args *args, const size_t *entry_offsets) {
static struct reloc_info build_reloc_info(const struct build_object_args *args,
const size_t *entry_offsets) {
struct reloc_info info = {
.text_relocs = vector_create(sizeof(struct relocation)),
.data_relocs = vector_create(sizeof(struct relocation)),
Expand Down Expand Up @@ -298,7 +298,9 @@ static void write_segment_command(FILE *file,

struct reloc_info info = build_reloc_info(args, entry_offsets);
size_t relocs_offset = segment.fileoff + total_size;
size_t total_reloc_instrs = info.num_text_reloc_instrs + info.num_data_reloc_instrs + info.num_const_data_reloc_instrs;
size_t total_reloc_instrs = info.num_text_reloc_instrs +
info.num_data_reloc_instrs +
info.num_const_data_reloc_instrs;

struct section_64 text;
memset(&text, 0, sizeof(text));
Expand Down Expand Up @@ -338,8 +340,8 @@ static void write_segment_command(FILE *file,
const_data.size = total_const_size;
const_data.offset = segment.fileoff + text.size + cstrings.size;
const_data.align = LOG2(const_align);
const_data.reloff =
text.reloff + (sizeof(struct relocation_info) * info.num_text_reloc_instrs);
const_data.reloff = text.reloff + (sizeof(struct relocation_info) *
info.num_text_reloc_instrs);
const_data.nreloc = info.num_const_data_reloc_instrs;
const_data.flags = S_REGULAR;
const_data.reserved1 = 0;
Expand All @@ -354,8 +356,8 @@ static void write_segment_command(FILE *file,
data.size = total_data_size;
data.offset = segment.fileoff + text.size + cstrings.size + const_data.size;
data.align = LOG2(data_align);
data.reloff = const_data.reloff +
(sizeof(struct relocation_info) * info.num_const_data_reloc_instrs);
data.reloff = const_data.reloff + (sizeof(struct relocation_info) *
info.num_const_data_reloc_instrs);
data.nreloc = info.num_data_reloc_instrs;
data.flags = S_REGULAR;
data.reserved1 = 0;
Expand All @@ -374,8 +376,8 @@ static void write_segment_command(FILE *file,
memset(&symtab, 0, sizeof(symtab));
symtab.cmd = LC_SYMTAB;
symtab.cmdsize = sizeof(symtab);
symtab.symoff = relocs_offset +
sizeof(struct relocation_info) * total_reloc_instrs;
symtab.symoff =
relocs_offset + sizeof(struct relocation_info) * total_reloc_instrs;
symtab.nsyms = args->num_entries;
symtab.stroff = symtab.symoff + sizeof(struct nlist_64) * symtab.nsyms;

Expand Down
15 changes: 9 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static bool parse_target_flag(const char *flag,
}

static bool parse_c_standard(const char *flag,
enum compile_c_standard *c_standard) {
enum compile_c_standard *c_standard) {
if (strcmp(flag, "c11") == 0) {
*c_standard = COMPILE_C_STANDARD_C11;
return true;
Expand Down Expand Up @@ -223,16 +223,17 @@ static bool parse_output(const char *str, char **output) {
return false;
}


static bool parse_fixed_timestamp(const char *str, const char **fixed_timestamp) {
static bool parse_fixed_timestamp(const char *str,
const char **fixed_timestamp) {
size_t len = strlen(str);

if (len >= 19) {
*fixed_timestamp = str;
return true;
}

err("`fixed_timestamp` must be exactly at least 19 chars (for symmetry with `asctime`)");
err("`fixed_timestamp` must be exactly at least 19 chars (for symmetry with "
"`asctime`)");
return false;
}
static enum parse_args_result parse_args(int argc, char **argv,
Expand All @@ -254,7 +255,9 @@ static enum parse_args_result parse_args(int argc, char **argv,

// allows both '-Tfoo' and '-T foo' by using the next argument if the current
// one is empty (after prefix) if it uses the next argument it skips it
#define GET_ARGUMENT(v) v = (!(v) || (v)[0] || i + 1 == argc ? ((v) && (v)[0] == '=' ? (v) + 1 : v) : argv[++i])
#define GET_ARGUMENT(v) \
v = (!(v) || (v)[0] || i + 1 == argc ? ((v) && (v)[0] == '=' ? (v) + 1 : v) \
: argv[++i])

const char *log = try_get_arg(arg, "-L");
GET_ARGUMENT(log);
Expand Down
4 changes: 2 additions & 2 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ static bool parse_typedef_name(struct parser *parser,
return true;
}


enum type_specifier_mode {
TYPE_SPECIFIER_MODE_ALLOW_TYPEDEFS,
TYPE_SPECIFIER_MODE_DISALLOW_TYPEDEFS
Expand All @@ -513,7 +512,8 @@ static bool parse_type_specifier(struct parser *parser,
return true;
}

if (mode == TYPE_SPECIFIER_MODE_ALLOW_TYPEDEFS && parse_typedef_name(parser, &type_specifier->typedef_name)) {
if (mode == TYPE_SPECIFIER_MODE_ALLOW_TYPEDEFS &&
parse_typedef_name(parser, &type_specifier->typedef_name)) {
type_specifier->ty = AST_TYPE_SPECIFIER_TYPEDEF_NAME;
return true;
}
Expand Down
1 change: 0 additions & 1 deletion preproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,6 @@ void preproc_next_token(struct preproc *preproc, struct preproc_token *token) {
struct sized_str ident = {.str = def_name.text,
.len = text_span_len(&def_name.span)};


hashtbl_remove(preproc->defines, &ident);
} else if (token_streq(directive, "include")) {
preproc->in_angle_string_context = true;
Expand Down
12 changes: 5 additions & 7 deletions preproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ enum preproc_create_result { PREPROC_CREATE_RESULT_SUCCESS = 0 };

struct preproc;

enum preproc_create_result preproc_create(struct program *program,
const char *path,
size_t num_include_paths,
const char **include_paths,
// for debugging: fixes the value of __TIME__ and __DATE__
const char *fixed_timestamp,
struct preproc **preproc);
enum preproc_create_result
preproc_create(struct program *program, const char *path,
size_t num_include_paths, const char **include_paths,
// for debugging: fixes the value of __TIME__ and __DATE__
const char *fixed_timestamp, struct preproc **preproc);

struct preprocessed_program {
const char *text;
Expand Down
4 changes: 3 additions & 1 deletion program.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "program.h"

#include "util.h"

#include <limits.h>

#define POS_CHECK(p) debug_assert((p).col != TEXT_POS_INVALID_COL, "invalid text pos")
#define POS_CHECK(p) \
debug_assert((p).col != TEXT_POS_INVALID_COL, "invalid text pos")

bool text_pos_eq(const void *l, const void *r) {
const struct text_pos *l_pos = l;
Expand Down
Loading

0 comments on commit c02a84a

Please sign in to comment.