Merge pull request #8 from m1el/clang-format

added clang format
This commit is contained in:
m1el 2024-03-11 16:01:52 +02:00 committed by GitHub
commit aa45a8eba4
10 changed files with 476 additions and 465 deletions

View file

@ -1,12 +1,19 @@
CC = gcc
CFLAGS_EXTRA =
CFLAGS = -Wall -Wextra -Wpedantic -std=c17 -O3
CLANG_FORMAT_STYLE = '{ BasedOnStyle: Google, IndentWidth: 4 }'
.PHONY: clean build-dir hbas example
.PHONY: clean hbas example format check-format
hbas: build/hbas
example: build/example.hbf
format:
clang-format --style=${CLANG_FORMAT_STYLE} -i src/*
check-format:
clang-format --style=${CLANG_FORMAT_STYLE} -i --dry-run -Werror src/*
build:
mkdir -p build

View file

@ -212,10 +212,10 @@ AsmError assemble_instr(InstHt ht, char *input, size_t len, Token *tok,
uint64_t num_to_write;
if (meta.rel == 1 || meta.size == 8) {
if (tok->kind == TokIdent) {
if (ensure_push((ByteVec*)holes, sizeof(Hole), 1) != 0) {
if (ensure_push((ByteVec *)holes, sizeof(Hole), 1) != 0) {
return ErrOutOfMemory;
}
holes->buf[holes->len] = (Hole) {
holes->buf[holes->len] = (Hole){
.location = rv->len,
.origin = inst_start,
.str = &input[tok->start],
@ -242,8 +242,8 @@ AsmError assemble_instr(InstHt ht, char *input, size_t len, Token *tok,
}
num_to_write = (uint64_t)tmp;
}
AsmError err =
push_int_le(&rv->buf[rv->len], num_to_write, meta.size, meta.sign);
AsmError err = push_int_le(&rv->buf[rv->len], num_to_write,
meta.size, meta.sign);
if (err != ErrOk) {
return err;
}
@ -254,7 +254,8 @@ AsmError assemble_instr(InstHt ht, char *input, size_t len, Token *tok,
return ErrOk;
}
AsmError assemble(InstHt ht, char *input, size_t len, ByteVec *out, EInfo *einfo) {
AsmError assemble(InstHt ht, char *input, size_t len, ByteVec *out,
EInfo *einfo) {
ByteVec rv = {malloc(MIN_SIZE), MIN_SIZE, 0};
HoleVec holes = {malloc(MIN_SIZE * sizeof(Hole)), MIN_SIZE, 0};
LabelVec labels = {malloc(MIN_SIZE * sizeof(Label)), MIN_SIZE, 0};
@ -355,7 +356,8 @@ AsmError assemble(InstHt ht, char *input, size_t len, ByteVec *out, EInfo *einfo
sign = 1;
num_to_write -= hole->origin;
}
err = push_int_le(&rv.buf[hole->location], num_to_write, hole->size, sign);
err = push_int_le(&rv.buf[hole->location], num_to_write, hole->size,
sign);
if (err != 0) {
goto end;
}
@ -396,7 +398,8 @@ int main(int argc, char **argv) {
err = assemble(ht, input.buf, input.len, &out, &einfo);
if (err != 0) {
size_t column = einfo.token.start - einfo.line_start + 1;
fprintf(stderr, "failed to assemble, %s, line=%zu, col=%zu token=%.*s\n",
fprintf(stderr,
"failed to assemble, %s, line=%zu, col=%zu token=%.*s\n",
ERRORS[err], einfo.line, column, (int)einfo.token.len,
&input.buf[einfo.token.start]);
goto done;

View file

@ -23,7 +23,8 @@ Token token_ident(char *input, size_t len, size_t pos) {
while (pos < len) {
char chr = input[pos];
char chru = chr & ~0x20;
int good = chr == '_' || (chr >= '0' && chr <= '9') || (chru >= 'A' && chru <= 'Z');
int good = chr == '_' || (chr >= '0' && chr <= '9') ||
(chru >= 'A' && chru <= 'Z');
if (!good) {
break;
}