diff options
| author | Ian M. <ian@aptel.org> | 2026-10-03 04:02:54 +0000 |
|---|---|---|
| committer | Ian M. <ian@aptel.org> | 2026-10-03 04:02:54 +0000 |
| commit | 8e838a73368d5f26fee796d6ddb065e21449e989 (patch) | |
| tree | 656757670ad91f0fa52b87eb71599a36e56fadae | |
initial commit
Signed-off-by: Ian M. <ian@aptel.org>
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 23 | ||||
| -rw-r--r-- | core/atas.c | 72 | ||||
| -rw-r--r-- | core/state.c | 34 | ||||
| -rw-r--r-- | head/atas/state.h | 38 |
5 files changed, 170 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f125dd4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.d +/atas diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f1c21e --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# +# Copyright (c) 2026, Apollo Telephone Laboratories. +# Provided under the BSD-3 clause. +# + +CFILES = $(shell find core/ -name "*.c") +OFILES = $(CFILES:.c=.o) +DFILES = $(CFILES:.c=.d) + +CC = gcc +CFLAGS = \ + -Wall \ + -pedantic \ + -MMD \ + -Ihead + +.PHONY: all +all: $(OFILES) + $(CC) $(OFILES) -o atas + +-include $(DFILES) +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ diff --git a/core/atas.c b/core/atas.c new file mode 100644 index 0000000..9585a26 --- /dev/null +++ b/core/atas.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#include <stdio.h> +#include <unistd.h> +#include "atas/state.h" + +/* + * Display help options + */ +static void +help(void) +{ + printf("-- AT ISA assembler --\n"); + printf("usage: ./atas [flags] [input file]\n"); + printf("[-h] Display this help menu\n"); +} + +/* + * Begin assembling a specified input file + * + * @in_file: Path to input file to assemble + */ +static void +atas_assemble(const char *in_file) +{ + struct atas_state state; + int error; + + if (in_file == NULL) { + return; + } + + error = atas_state_init(in_file, &state); + if (error < 0) { + perror("atas_state_init"); + return; + } + + atas_state_destroy(&state); +} + +int +main(int argc, char **argv) +{ + const char *in_path; + int opt; + + if (argc < 2) { + printf("fatal: too few arguments\n"); + return -1; + } + + while ((opt = getopt(argc, argv, "hv")) != -1) { + switch (opt) { + case 'h': + help(); + return 0; + } + } + + if (optind == argc) { + printf("fatal: expected input file\n"); + return -1; + } + + in_path = argv[optind]; + atas_assemble(in_path); + return 0; +} diff --git a/core/state.c b/core/state.c new file mode 100644 index 0000000..8c3dea1 --- /dev/null +++ b/core/state.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#include <atas/state.h> +#include <errno.h> + +int +atas_state_init(const char *in_file, struct atas_state *state) +{ + if (in_file == NULL || state == NULL) { + errno = EINVAL; + return -1; + } + + state->in_file = fopen(in_file, "r"); + if (state->in_file == NULL) { + return -1; + } + + return 0; +} + +void +atas_state_destroy(struct atas_state *state) +{ + if (state == NULL) { + return; + } + + fclose(state->in_file); + state->in_file = NULL; +} diff --git a/head/atas/state.h b/head/atas/state.h new file mode 100644 index 0000000..6e1fed9 --- /dev/null +++ b/head/atas/state.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#ifndef ATAS_STATE_H +#define ATAS_STATE_H 1 + +#include <stdint.h> +#include <stdio.h> + +/* + * Represents the assembler state machine + * + * @in_file: Input file + */ +struct atas_state { + FILE *in_file; +}; + +/* + * Initialize the ATAS state machine + * + * @in_file: Input file to be assembled + * @state: State machine result + * + * Returns zero on success + */ +int atas_state_init(const char *in_file, struct atas_state *state); + +/* + * Destroy an initialized state machine + * + * @state: State machine to destroy + */ +void atas_state_destroy(struct atas_state *state); + +#endif /* !ATAS_STATE_H */ |
