Add .clang-format and reformat.

This commit is contained in:
Rui Ueyama 2018-08-25 20:53:49 +00:00
parent 24412d3a43
commit ee089f2501
7 changed files with 46 additions and 13 deletions

3
.clang-format Normal file
View File

@ -0,0 +1,3 @@
---
BasedOnStyle: LLVM
AllowShortFunctionsOnASingleLine: false

View File

@ -34,9 +34,17 @@ static IR *add_imm(int op, int lhs, int rhs) {
return ir;
}
static void kill(int r) { add(IR_KILL, r, -1); }
static void label(int x) { add(IR_LABEL, x, -1); }
static void jmp(int x) { add(IR_JMP, x, -1); }
static void kill(int r) {
add(IR_KILL, r, -1);
}
static void label(int x) {
add(IR_LABEL, x, -1);
}
static void jmp(int x) {
add(IR_JMP, x, -1);
}
static int gen_expr(Node *node);

4
main.c
View File

@ -1,6 +1,8 @@
#include "9cc.h"
void usage() { error("Usage: 9cc [-test] [-dump-ir1] [-dump-ir2] <file>"); }
void usage() {
error("Usage: 9cc [-test] [-dump-ir1] [-dump-ir2] <file>");
}
int main(int argc, char **argv) {
if (argc == 1)

14
parse.c
View File

@ -70,9 +70,17 @@ static Type *new_prim_ty(int ty, int size) {
return ret;
}
static Type *void_ty() { return new_prim_ty(VOID, 0); }
static Type *char_ty() { return new_prim_ty(CHAR, 1); }
static Type *int_ty() { return new_prim_ty(INT, 4); }
static Type *void_ty() {
return new_prim_ty(VOID, 0);
}
static Type *char_ty() {
return new_prim_ty(CHAR, 1);
}
static Type *int_ty() {
return new_prim_ty(INT, 4);
}
static bool consume(int ty) {
Token *t = tokens->data[pos];

View File

@ -46,14 +46,18 @@ static void append(Vector *v) {
vec_push(ctx->output, v->data[i]);
}
static void add(Token *t) { vec_push(ctx->output, t); }
static void add(Token *t) {
vec_push(ctx->output, t);
}
static Token *next() {
assert(ctx->pos < ctx->input->len);
return ctx->input->data[ctx->pos++];
}
static bool eof() { return ctx->pos == ctx->input->len; }
static bool eof() {
return ctx->pos == ctx->input->len;
}
static Token *get(int ty, char *msg) {
Token *t = next();
@ -67,7 +71,9 @@ static char *ident(char *msg) {
return t->name;
}
static Token *peek() { return ctx->input->data[ctx->pos]; }
static Token *peek() {
return ctx->input->data[ctx->pos];
}
static bool consume(int ty) {
if (peek()->ty != ty)

4
sema.c
View File

@ -95,7 +95,9 @@ noreturn static void bad_node(Node *node, char *msg) {
bad_token(node->token, msg);
}
static void warn_node(Node *node, char *msg) { warn_token(node->token, msg); }
static void warn_node(Node *node, char *msg) {
warn_token(node->token, msg);
}
static void check_lval(Node *node) {
int op = node->op;

8
util.c
View File

@ -85,7 +85,9 @@ void sb_add(StringBuilder *sb, char c) {
sb->data[sb->len++] = c;
}
void sb_append(StringBuilder *sb, char *s) { sb_append_n(sb, s, strlen(s)); }
void sb_append(StringBuilder *sb, char *s) {
sb_append_n(sb, s, strlen(s));
}
void sb_append_n(StringBuilder *sb, char *s, int len) {
sb_grow(sb, len);
@ -98,7 +100,9 @@ char *sb_get(StringBuilder *sb) {
return sb->data;
}
int roundup(int x, int align) { return (x + align - 1) & ~(align - 1); }
int roundup(int x, int align) {
return (x + align - 1) & ~(align - 1);
}
Type *ptr_to(Type *base) {
Type *ty = calloc(1, sizeof(Type));