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:
52
toolchain/ifc/ctx.c
Normal file
52
toolchain/ifc/ctx.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "ctx.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void init_builtin_types(struct ctx *ctx)
|
||||
{
|
||||
for (size_t i = 0; i < TYPE_OTHER; i++) {
|
||||
ctx->ctx_builtin_types[i].ty_id = i;
|
||||
}
|
||||
}
|
||||
|
||||
struct ctx *ctx_create(void)
|
||||
{
|
||||
struct ctx *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
init_builtin_types(out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void ctx_destroy(struct ctx *ctx)
|
||||
{
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
const struct type *ctx_get_type(struct ctx *ctx, const char *name)
|
||||
{
|
||||
if (!strcmp(name, "string")) {
|
||||
return ctx_get_builtin_type(ctx, TYPE_STRING);
|
||||
}
|
||||
|
||||
if (!strcmp(name, "int")) {
|
||||
return ctx_get_builtin_type(ctx, TYPE_INT);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct type *ctx_get_builtin_type(struct ctx *ctx, enum type_id id)
|
||||
{
|
||||
if (id >= TYPE_OTHER) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &ctx->ctx_builtin_types[id];
|
||||
}
|
||||
Reference in New Issue
Block a user