toolchain: add a program for compiling ipc interface definitions

ifc can be used to compile .if files into self-contained header-only C
libraries, which can be used to send/receive messages that conform
to the described interface.
This commit is contained in:
2026-02-26 19:44:21 +00:00
parent e2b19c3e9a
commit b631fca0fd
25 changed files with 3692 additions and 9 deletions

60
toolchain/ifc/interface.c Normal file
View File

@@ -0,0 +1,60 @@
#include "interface.h"
#include "msg.h"
#include <blue/ds/string.h>
#include <stdlib.h>
#include <string.h>
struct interface_definition *interface_definition_create(const char *name)
{
struct interface_definition *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->if_name = b_strdup(name);
return out;
}
void interface_definition_destroy(struct interface_definition *iface)
{
b_queue_entry *entry = b_queue_pop_front(&iface->if_msg);
while (entry) {
struct msg_definition *msg
= b_unbox(struct msg_definition, entry, msg_entry);
msg_definition_destroy(msg);
entry = b_queue_pop_front(&iface->if_msg);
}
free(iface->if_name);
free(iface);
}
bool interface_definition_has_msg(
const struct interface_definition *iface,
const char *name)
{
b_queue_entry *entry = b_queue_first(&iface->if_msg);
while (entry) {
struct msg_definition *msg
= b_unbox(struct msg_definition, entry, msg_entry);
if (!strcmp(msg->msg_name, name)) {
return true;
}
entry = b_queue_next(entry);
}
return false;
}
void interface_definition_add_msg(
struct interface_definition *iface,
struct msg_definition *msg)
{
b_queue_push_back(&iface->if_msg, &msg->msg_entry);
}