commit
aa45a8eba4
9
Makefile
9
Makefile
|
@ -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
|
||||
|
||||
|
|
13
src/hbas.c
13
src/hbas.c
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue