commit
aa45a8eba4
9
Makefile
9
Makefile
|
@ -1,12 +1,19 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS_EXTRA =
|
CFLAGS_EXTRA =
|
||||||
CFLAGS = -Wall -Wextra -Wpedantic -std=c17 -O3
|
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
|
hbas: build/hbas
|
||||||
example: build/example.hbf
|
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:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
|
||||||
|
|
17
src/hbas.c
17
src/hbas.c
|
@ -212,10 +212,10 @@ AsmError assemble_instr(InstHt ht, char *input, size_t len, Token *tok,
|
||||||
uint64_t num_to_write;
|
uint64_t num_to_write;
|
||||||
if (meta.rel == 1 || meta.size == 8) {
|
if (meta.rel == 1 || meta.size == 8) {
|
||||||
if (tok->kind == TokIdent) {
|
if (tok->kind == TokIdent) {
|
||||||
if (ensure_push((ByteVec*)holes, sizeof(Hole), 1) != 0) {
|
if (ensure_push((ByteVec *)holes, sizeof(Hole), 1) != 0) {
|
||||||
return ErrOutOfMemory;
|
return ErrOutOfMemory;
|
||||||
}
|
}
|
||||||
holes->buf[holes->len] = (Hole) {
|
holes->buf[holes->len] = (Hole){
|
||||||
.location = rv->len,
|
.location = rv->len,
|
||||||
.origin = inst_start,
|
.origin = inst_start,
|
||||||
.str = &input[tok->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;
|
num_to_write = (uint64_t)tmp;
|
||||||
}
|
}
|
||||||
AsmError err =
|
AsmError err = push_int_le(&rv->buf[rv->len], num_to_write,
|
||||||
push_int_le(&rv->buf[rv->len], num_to_write, meta.size, meta.sign);
|
meta.size, meta.sign);
|
||||||
if (err != ErrOk) {
|
if (err != ErrOk) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,8 @@ AsmError assemble_instr(InstHt ht, char *input, size_t len, Token *tok,
|
||||||
return ErrOk;
|
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};
|
ByteVec rv = {malloc(MIN_SIZE), MIN_SIZE, 0};
|
||||||
HoleVec holes = {malloc(MIN_SIZE * sizeof(Hole)), MIN_SIZE, 0};
|
HoleVec holes = {malloc(MIN_SIZE * sizeof(Hole)), MIN_SIZE, 0};
|
||||||
LabelVec labels = {malloc(MIN_SIZE * sizeof(Label)), 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;
|
sign = 1;
|
||||||
num_to_write -= hole->origin;
|
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) {
|
if (err != 0) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +398,8 @@ int main(int argc, char **argv) {
|
||||||
err = assemble(ht, input.buf, input.len, &out, &einfo);
|
err = assemble(ht, input.buf, input.len, &out, &einfo);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
size_t column = einfo.token.start - einfo.line_start + 1;
|
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,
|
ERRORS[err], einfo.line, column, (int)einfo.token.len,
|
||||||
&input.buf[einfo.token.start]);
|
&input.buf[einfo.token.start]);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
@ -23,7 +23,8 @@ Token token_ident(char *input, size_t len, size_t pos) {
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
char chr = input[pos];
|
char chr = input[pos];
|
||||||
char chru = chr & ~0x20;
|
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) {
|
if (!good) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue