summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@mirocom.org>2026-05-23 01:28:05 -0400
committerIan Moffett <ian@mirocom.org>2026-05-23 01:28:05 -0400
commitc5f8f95059504748f07e0d3ca9d978669622428c (patch)
treecc64c48bb1e93c2df466f4fb007912628c319c91
initial commit
Signed-off-by: Ian Moffett <ian@mirocom.org>
-rw-r--r--.gitignore3
-rw-r--r--Makefile25
-rw-r--r--core/cescal.c60
-rw-r--r--core/readbuf.c46
-rw-r--r--core/state.c34
-rw-r--r--testbench/ret0.cescal8
6 files changed, 176 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9c442d3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+cescal
+*.o
+*.d
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5d497f9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2026, Chloe M.
+# 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 \
+ -Iinclude
+
+.PHONY: all
+all: cescal
+
+.PHONY: cescal
+cescal: $(OFILES)
+ $(CC) $^ -o $@
+
+-include $(DFILES)
+%.o: %.c
+ $(CC) -c $< $(CFLAGS) -o $@
diff --git a/core/cescal.c b/core/cescal.c
new file mode 100644
index 0000000..b9a2c17
--- /dev/null
+++ b/core/cescal.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "cescal/state.h"
+
+static void
+help(void)
+{
+ printf("usage: ./cescal [flags]\n");
+ printf("[-h] Display this help menu\n");
+}
+
+static int
+compile(const char *pathname)
+{
+ struct cescal_state st;
+
+ if (pathname == NULL) {
+ return -1;
+ }
+
+ if (state_init(&st, pathname) < 0) {
+ return -1;
+ }
+
+ state_close(&st);
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int opt;
+
+ if (argc < 2) {
+ printf("fatal: too few arguments\n");
+ help();
+ return -1;
+ }
+
+ while ((opt = getopt(argc, argv, "h")) != -1) {
+ switch (opt) {
+ case 'h':
+ help();
+ return -1;
+ }
+ }
+
+ while (optind < argc) {
+ if (compile(argv[optind++]) < 0) {
+ break;
+ }
+ }
+
+ return 0;
+}
diff --git a/core/readbuf.c b/core/readbuf.c
new file mode 100644
index 0000000..ee10362
--- /dev/null
+++ b/core/readbuf.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2026, Chloe M.
+ * Provided under the BSD-3 clause
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <errno.h>
+#include <unistd.h>
+#include "cescal/readbuf.h"
+
+int
+readbuf_init(struct readbuf *rb)
+{
+ if (rb == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ rb->size = 0;
+ rb->tail = 0;
+ return 0;
+}
+
+char
+readbuf_read(struct readbuf *rb, int fd)
+{
+ ssize_t nread = -1;
+
+ if (rb == NULL || fd < 0) {
+ errno = EINVAL;
+ return '\0';
+ }
+
+#define N_RESIDUAL(rb) ((rb)->size - (rb)->tail)
+ if (N_RESIDUAL(rb) == 0 || rb->size == 0) {
+ if ((nread = read(fd, rb->buf, READBUF_CAP)) <= 0)
+ return nread;
+
+ rb->size = nread;
+ rb->tail = 0;
+ }
+#undef N_RESIDUAL
+
+ return rb->buf[rb->tail++];
+}
diff --git a/core/state.c b/core/state.c
new file mode 100644
index 0000000..7d80acd
--- /dev/null
+++ b/core/state.c
@@ -0,0 +1,34 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include "cescal/state.h"
+
+int
+state_init(struct cescal_state *state, const char *pathname)
+{
+ if (state == NULL || pathname == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ state->in_fd = open(pathname, O_RDONLY);
+ if (state->in_fd < 0) {
+ return -1;
+ }
+
+ if (readbuf_init(&state->rb) < 0) {
+ close(state->in_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+state_close(struct cescal_state *state)
+{
+ close(state->in_fd);
+ state->in_fd = -1;
+}
diff --git a/testbench/ret0.cescal b/testbench/ret0.cescal
new file mode 100644
index 0000000..676db01
--- /dev/null
+++ b/testbench/ret0.cescal
@@ -0,0 +1,8 @@
+//
+// Copyright (c) 2026, Chloe M.
+// Provided under the BSD-3 clause
+//
+
+pub proc main() -> u32 begin
+ return 0;
+end