toolchain: xpcg: replace bluelib with fx
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
#include "../../msg.h"
|
||||
#include "../../type.h"
|
||||
|
||||
#include <blue/core/hash.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <fx/core/hash.h>
|
||||
#include <fx/io/file.h>
|
||||
#include <fx/io/path.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct emit_ctx {
|
||||
b_stream *ctx_out;
|
||||
fx_stream *ctx_out;
|
||||
size_t ctx_max_handle_params;
|
||||
};
|
||||
|
||||
@@ -19,23 +19,23 @@ static void emit(struct emit_ctx *ctx, const char *format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
b_stream_write_vfmt(ctx->ctx_out, NULL, format, arg);
|
||||
fx_stream_write_vfmt(ctx->ctx_out, NULL, format, arg);
|
||||
va_end(arg);
|
||||
}
|
||||
|
||||
static void emit_indent(struct emit_ctx *ctx)
|
||||
{
|
||||
b_stream_push_indent(ctx->ctx_out, 4);
|
||||
fx_stream_push_indent(ctx->ctx_out, 4);
|
||||
}
|
||||
|
||||
static void emit_indent_zero(struct emit_ctx *ctx)
|
||||
{
|
||||
b_stream_push_indent(ctx->ctx_out, -100);
|
||||
fx_stream_push_indent(ctx->ctx_out, -100);
|
||||
}
|
||||
|
||||
static void emit_unindent(struct emit_ctx *ctx)
|
||||
{
|
||||
b_stream_pop_indent(ctx->ctx_out);
|
||||
fx_stream_pop_indent(ctx->ctx_out);
|
||||
}
|
||||
|
||||
static int emit_include(struct emit_ctx *ctx, const char *path, bool system)
|
||||
@@ -53,15 +53,15 @@ static int emit_header_guard_start(
|
||||
struct emit_ctx *ctx,
|
||||
const struct interface_definition *iface)
|
||||
{
|
||||
b_string *header_guard = b_string_create();
|
||||
b_string_append_cstrf(header_guard, "%s_H_", iface->if_name);
|
||||
b_string_toupper(header_guard);
|
||||
fx_string *header_guard = fx_string_create();
|
||||
fx_string_append_cstrf(header_guard, "%s_H_", iface->if_name);
|
||||
fx_string_toupper(header_guard);
|
||||
|
||||
emit(ctx,
|
||||
"#ifndef %s\n#define %s\n\n",
|
||||
b_string_ptr(header_guard),
|
||||
b_string_ptr(header_guard));
|
||||
b_string_unref(header_guard);
|
||||
fx_string_ptr(header_guard),
|
||||
fx_string_ptr(header_guard));
|
||||
fx_string_unref(header_guard);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,15 +76,15 @@ static int emit_header_guard_end(
|
||||
static size_t get_msg_handle_params(const struct msg_definition *msg)
|
||||
{
|
||||
size_t count = 0;
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
const struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
if (param->p_type->ty_id == TYPE_HANDLE) {
|
||||
count++;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return count;
|
||||
@@ -93,17 +93,17 @@ static size_t get_msg_handle_params(const struct msg_definition *msg)
|
||||
static size_t get_max_handle_params(const struct interface_definition *iface)
|
||||
{
|
||||
size_t count = 0;
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
size_t msg_count = get_msg_handle_params(msg);
|
||||
|
||||
if (msg_count > count) {
|
||||
count = msg_count;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return count;
|
||||
@@ -113,51 +113,51 @@ static int emit_interface_id_macros(
|
||||
struct emit_ctx *ctx,
|
||||
const struct interface_definition *iface)
|
||||
{
|
||||
b_string *iface_define_name = b_string_create();
|
||||
b_string_append_cstr(iface_define_name, iface->if_name);
|
||||
b_string_toupper(iface_define_name);
|
||||
fx_string *iface_define_name = fx_string_create();
|
||||
fx_string_append_cstr(iface_define_name, iface->if_name);
|
||||
fx_string_toupper(iface_define_name);
|
||||
|
||||
uint32_t protocol_id = iface->if_id;
|
||||
|
||||
emit(ctx,
|
||||
"/* %s protocol ID */\n#define INTERFACE_%s 0x%08xU\n\n",
|
||||
iface->if_name,
|
||||
b_string_ptr(iface_define_name),
|
||||
fx_string_ptr(iface_define_name),
|
||||
protocol_id);
|
||||
b_string_unref(iface_define_name);
|
||||
fx_string_unref(iface_define_name);
|
||||
|
||||
b_string *msg_name = b_string_create();
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_string *msg_name = fx_string_create();
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
b_string_clear(msg_name);
|
||||
b_string_append_cstrf(
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
fx_string_clear(msg_name);
|
||||
fx_string_append_cstrf(
|
||||
msg_name,
|
||||
"%s.%s",
|
||||
iface->if_name,
|
||||
msg->msg_name);
|
||||
|
||||
emit(ctx, "/* %s message ID */\n", b_string_ptr(msg_name));
|
||||
emit(ctx, "/* %s message ID */\n", fx_string_ptr(msg_name));
|
||||
uint16_t msg_id = msg->msg_id;
|
||||
|
||||
b_string_clear(msg_name);
|
||||
b_string_append_cstrf(
|
||||
fx_string_clear(msg_name);
|
||||
fx_string_append_cstrf(
|
||||
msg_name,
|
||||
"%s_%s",
|
||||
iface->if_name,
|
||||
msg->msg_name);
|
||||
b_string_toupper(msg_name);
|
||||
fx_string_toupper(msg_name);
|
||||
emit(ctx,
|
||||
"#define MSG_%s 0x%04xU\n",
|
||||
b_string_ptr(msg_name),
|
||||
fx_string_ptr(msg_name),
|
||||
msg_id);
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, "\n");
|
||||
b_string_unref(msg_name);
|
||||
fx_string_unref(msg_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -181,8 +181,7 @@ static int emit_msg_struct_member(
|
||||
break;
|
||||
case TYPE_STRING:
|
||||
case TYPE_BUFFER:
|
||||
emit(ctx, "uint16_t %s_offset;\n", param->p_name);
|
||||
emit(ctx, "uint16_t %s_len;\n", param->p_name);
|
||||
emit(ctx, "uint32_t %s_len;\n", param->p_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -195,33 +194,41 @@ static int emit_msg_struct_params(
|
||||
struct emit_ctx *ctx,
|
||||
const struct msg_definition *msg)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
const struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
case TYPE_BUFFER:
|
||||
emit(ctx, "uint32_t %s_offset;\n", param->p_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit_msg_struct_member(ctx, param);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
const struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
emit(ctx, "uint16_t %s_offset;\n", param->p_name);
|
||||
emit(ctx, "uint16_t %s_max;\n", param->p_name);
|
||||
emit(ctx, "uint32_t %s_offset;\n", param->p_name);
|
||||
emit(ctx, "uint32_t %s_max;\n", param->p_name);
|
||||
break;
|
||||
case TYPE_BUFFER:
|
||||
emit(ctx, "uint16_t %s_offset;\n", param->p_name);
|
||||
emit(ctx, "uint32_t %s_offset;\n", param->p_name);
|
||||
emit(ctx, "uint32_t %s_max;\n", param->p_name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -231,12 +238,13 @@ static int emit_msg_struct_results(
|
||||
struct emit_ctx *ctx,
|
||||
const struct msg_definition *msg)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_results);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
const struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
|
||||
emit_msg_struct_member(ctx, param);
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -247,7 +255,7 @@ static int emit_interface_msg_struct(
|
||||
const struct interface_definition *iface,
|
||||
const struct msg_definition *msg)
|
||||
{
|
||||
b_string *tmp = b_string_create();
|
||||
fx_string *tmp = fx_string_create();
|
||||
|
||||
emit(ctx, "struct %s_%s_msg {\n", iface->if_name, msg->msg_name);
|
||||
emit_indent(ctx);
|
||||
@@ -280,7 +288,7 @@ static int emit_interface_msg_struct(
|
||||
emit_unindent(ctx);
|
||||
emit(ctx, "};\n");
|
||||
|
||||
b_string_unref(tmp);
|
||||
fx_string_unref(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -288,14 +296,14 @@ static int emit_interface_msg_structs(
|
||||
struct emit_ctx *ctx,
|
||||
const struct interface_definition *iface)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
|
||||
emit_interface_msg_struct(ctx, iface, msg);
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, "\n");
|
||||
@@ -307,10 +315,10 @@ static int emit_interface_msg_function_send_impl(
|
||||
const struct interface_definition *iface,
|
||||
const struct msg_definition *msg)
|
||||
{
|
||||
b_string *iface_ucase = b_string_create_from_cstr(iface->if_name);
|
||||
b_string_toupper(iface_ucase);
|
||||
b_string *msg_ucase = b_string_create_from_cstr(msg->msg_name);
|
||||
b_string_toupper(msg_ucase);
|
||||
fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name);
|
||||
fx_string_toupper(iface_ucase);
|
||||
fx_string *msg_ucase = fx_string_create_from_cstr(msg->msg_name);
|
||||
fx_string_toupper(msg_ucase);
|
||||
|
||||
emit(ctx,
|
||||
"struct %s_%s_msg msg_data = {0};\n",
|
||||
@@ -319,12 +327,12 @@ static int emit_interface_msg_function_send_impl(
|
||||
emit(ctx,
|
||||
"xpc_msg_header_init(&msg_data.msg_header, INTERFACE_%s, "
|
||||
"MSG_%s_%s);\n",
|
||||
b_string_ptr(iface_ucase),
|
||||
b_string_ptr(iface_ucase),
|
||||
b_string_ptr(msg_ucase));
|
||||
fx_string_ptr(iface_ucase),
|
||||
fx_string_ptr(iface_ucase),
|
||||
fx_string_ptr(msg_ucase));
|
||||
|
||||
b_string_unref(iface_ucase);
|
||||
b_string_unref(msg_ucase);
|
||||
fx_string_unref(iface_ucase);
|
||||
fx_string_unref(msg_ucase);
|
||||
|
||||
emit(ctx, "uint32_t in_offset = sizeof msg_data;\n\n");
|
||||
emit(ctx, "uint32_t out_offset = sizeof msg_data;\n\n");
|
||||
@@ -332,10 +340,10 @@ static int emit_interface_msg_function_send_impl(
|
||||
size_t nr_req_handles = 0;
|
||||
size_t nr_resp_handles = 0;
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
case TYPE_SIZE:
|
||||
@@ -380,13 +388,13 @@ static int emit_interface_msg_function_send_impl(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
case TYPE_BUFFER:
|
||||
@@ -407,7 +415,7 @@ static int emit_interface_msg_function_send_impl(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, "kern_iovec_t req_iov[] = {\n");
|
||||
@@ -415,10 +423,10 @@ static int emit_interface_msg_function_send_impl(
|
||||
emit(ctx, "IOVEC(&msg_data, sizeof msg_data),\n");
|
||||
size_t nr_req_iov = 1;
|
||||
|
||||
entry = b_queue_first(&msg->msg_params);
|
||||
entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
@@ -433,7 +441,7 @@ static int emit_interface_msg_function_send_impl(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit_unindent(ctx);
|
||||
@@ -450,10 +458,10 @@ static int emit_interface_msg_function_send_impl(
|
||||
emit(ctx, "IOVEC(&msg_data, sizeof msg_data),\n");
|
||||
size_t nr_resp_iov = 1;
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
@@ -468,7 +476,7 @@ static int emit_interface_msg_function_send_impl(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit_unindent(ctx);
|
||||
@@ -515,10 +523,10 @@ static int emit_interface_msg_function_send_impl(
|
||||
"if (msg_data.msg_header.hdr_status != KERN_OK) return "
|
||||
"msg_data.msg_header.hdr_status;\n\n");
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_HANDLE:
|
||||
emit(ctx, "*out_%s = ", param->p_name);
|
||||
@@ -544,7 +552,7 @@ static int emit_interface_msg_function_send_impl(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, "return status;\n");
|
||||
@@ -567,10 +575,10 @@ static int emit_interface_msg_function_send(
|
||||
|
||||
emit(ctx, "kern_handle_t port");
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
emit(ctx, ",\n");
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
@@ -596,13 +604,13 @@ static int emit_interface_msg_function_send(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
emit(ctx, ",\n");
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
@@ -632,7 +640,7 @@ static int emit_interface_msg_function_send(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, ")");
|
||||
@@ -673,10 +681,10 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
"status = xpc_msg_read(msg, 0, &" MSG_STRUCT_NAME
|
||||
", sizeof " MSG_STRUCT_NAME ");\n");
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
emit(ctx,
|
||||
@@ -721,13 +729,13 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
emit(ctx, "int %s = 0;\n", param->p_name);
|
||||
@@ -767,16 +775,16 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, "status = vtable->%s(\n", msg->msg_name);
|
||||
emit_indent(ctx);
|
||||
emit(ctx, "ctx,\n&msg->msg_sender");
|
||||
entry = b_queue_first(&msg->msg_params);
|
||||
entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_STRING:
|
||||
@@ -788,15 +796,15 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
emit(ctx, ",\n&%s", param->p_name);
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx, ",\narg);\n");
|
||||
@@ -808,12 +816,13 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
|
||||
emit(ctx, MSG_STRUCT_NAME ".msg_header.hdr_status = 0;\n");
|
||||
size_t handle_index = 0;
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_INT:
|
||||
case TYPE_SIZE:
|
||||
case TYPE_OFFSET:
|
||||
emit(ctx,
|
||||
MSG_STRUCT_NAME ".msg_response.%s = %s;\n",
|
||||
@@ -831,7 +840,7 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit(ctx,
|
||||
@@ -840,10 +849,10 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
|
||||
emit(ctx, "kern_msg_handle_t out_handles[] = {\n");
|
||||
emit_indent(ctx);
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
switch (param->p_type->ty_id) {
|
||||
case TYPE_HANDLE:
|
||||
emit(ctx,
|
||||
@@ -854,7 +863,7 @@ static int emit_interface_dispatcher_impl_msg(
|
||||
break;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
emit_unindent(ctx);
|
||||
emit(ctx, "};\n");
|
||||
@@ -870,41 +879,41 @@ static int emit_interface_dispatcher_impl(
|
||||
struct emit_ctx *ctx,
|
||||
const struct interface_definition *iface)
|
||||
{
|
||||
b_string *iface_ucase = b_string_create_from_cstr(iface->if_name);
|
||||
b_string_toupper(iface_ucase);
|
||||
b_string *msg_ucase = b_string_create();
|
||||
fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name);
|
||||
fx_string_toupper(iface_ucase);
|
||||
fx_string *msg_ucase = fx_string_create();
|
||||
|
||||
emit(ctx,
|
||||
"if (msg->msg_header.hdr_interface != INTERFACE_%s) return "
|
||||
"KERN_INVALID_ARGUMENT;\n\n",
|
||||
b_string_ptr(iface_ucase));
|
||||
fx_string_ptr(iface_ucase));
|
||||
|
||||
emit(ctx, "kern_status_t status = KERN_OK;\n");
|
||||
emit(ctx, "switch (msg->msg_header.hdr_func) {\n");
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
|
||||
b_string_clear(msg_ucase);
|
||||
b_string_append_cstr(msg_ucase, msg->msg_name);
|
||||
b_string_toupper(msg_ucase);
|
||||
fx_string_clear(msg_ucase);
|
||||
fx_string_append_cstr(msg_ucase, msg->msg_name);
|
||||
fx_string_toupper(msg_ucase);
|
||||
|
||||
emit(ctx,
|
||||
"case MSG_%s_%s: {\n",
|
||||
b_string_ptr(iface_ucase),
|
||||
b_string_ptr(msg_ucase));
|
||||
fx_string_ptr(iface_ucase),
|
||||
fx_string_ptr(msg_ucase));
|
||||
emit_indent(ctx);
|
||||
emit_interface_dispatcher_impl_msg(ctx, iface, msg);
|
||||
emit(ctx, "break;\n");
|
||||
emit_unindent(ctx);
|
||||
emit(ctx, "}\n");
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
b_string_unref(iface_ucase);
|
||||
fx_string_unref(iface_ucase);
|
||||
|
||||
emit(ctx, "default:\n");
|
||||
emit_indent(ctx);
|
||||
@@ -953,10 +962,10 @@ static int emit_interface_functions(
|
||||
const struct interface_definition *iface,
|
||||
bool prototype_only)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
|
||||
emit_interface_msg_function_send(
|
||||
ctx,
|
||||
@@ -964,7 +973,7 @@ static int emit_interface_functions(
|
||||
msg,
|
||||
prototype_only);
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit_interface_dispatcher(ctx, iface, prototype_only);
|
||||
@@ -983,10 +992,10 @@ static int emit_interface_vtable_entry(
|
||||
emit(ctx, "const xpc_endpoint_t *sender");
|
||||
|
||||
size_t i = 0;
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
fx_queue_entry *entry = fx_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
emit(ctx, ",\n");
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
@@ -1013,13 +1022,13 @@ static int emit_interface_vtable_entry(
|
||||
}
|
||||
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
entry = b_queue_first(&msg->msg_results);
|
||||
entry = fx_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
= fx_unbox(struct msg_parameter, entry, p_entry);
|
||||
emit(ctx, ",\n");
|
||||
|
||||
switch (param->p_type->ty_id) {
|
||||
@@ -1046,7 +1055,7 @@ static int emit_interface_vtable_entry(
|
||||
}
|
||||
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
@@ -1068,14 +1077,14 @@ static int emit_interface_vtable(
|
||||
emit(ctx, "struct %s_vtable {\n", iface->if_name);
|
||||
emit_indent(ctx);
|
||||
|
||||
b_queue_entry *entry = b_queue_first(&iface->if_msg);
|
||||
fx_queue_entry *entry = fx_queue_first(&iface->if_msg);
|
||||
while (entry) {
|
||||
const struct msg_definition *msg
|
||||
= b_unbox(struct msg_definition, entry, msg_entry);
|
||||
= fx_unbox(struct msg_definition, entry, msg_entry);
|
||||
|
||||
emit_interface_vtable_entry(ctx, iface, msg);
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
emit_unindent(ctx);
|
||||
@@ -1118,16 +1127,16 @@ static int emit_header(
|
||||
static int emit_interface(const struct interface_definition *iface)
|
||||
{
|
||||
char path[4096];
|
||||
b_file *file = NULL;
|
||||
fx_file *file = NULL;
|
||||
|
||||
snprintf(path, sizeof path, "%s.h", iface->if_name);
|
||||
b_result result = b_file_open(
|
||||
fx_result result = fx_file_open(
|
||||
NULL,
|
||||
B_RV_PATH(path),
|
||||
B_FILE_WRITE_ONLY | B_FILE_CREATE | B_FILE_TRUNCATE,
|
||||
FX_RV_PATH(path),
|
||||
FX_FILE_WRITE_ONLY | FX_FILE_CREATE | FX_FILE_TRUNCATE,
|
||||
&file);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_throw(result);
|
||||
fprintf(stderr, "cannot create C header file %s\n", path);
|
||||
return -1;
|
||||
}
|
||||
@@ -1138,7 +1147,7 @@ static int emit_interface(const struct interface_definition *iface)
|
||||
};
|
||||
|
||||
int err = emit_header(&ctx, iface);
|
||||
b_file_unref(file);
|
||||
fx_file_unref(file);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user