toolchain: xpcg: update libfx usage

This commit is contained in:
2026-05-30 10:12:28 +01:00
parent c87e094d7d
commit 87fe2d20ec
13 changed files with 66 additions and 51 deletions
+1 -1
View File
@@ -4,4 +4,4 @@ file(GLOB sources
add_executable(xpcg ${sources}) add_executable(xpcg ${sources})
target_link_libraries(xpcg FX::Core FX::Ds FX::Cmd FX::Io) target_link_libraries(xpcg FX::Runtime FX::Collections FX::Cmdline FX::Io)
+23 -21
View File
@@ -4,7 +4,7 @@
#include "../../msg.h" #include "../../msg.h"
#include "../../type.h" #include "../../type.h"
#include <fx/core/hash.h> #include <fx/hash.h>
#include <fx/io/file.h> #include <fx/io/file.h>
#include <fx/io/path.h> #include <fx/io/path.h>
#include <stdarg.h> #include <stdarg.h>
@@ -55,12 +55,12 @@ static int emit_header_guard_start(
{ {
fx_string *header_guard = fx_string_create(); fx_string *header_guard = fx_string_create();
fx_string_append_cstrf(header_guard, "%s_H_", iface->if_name); fx_string_append_cstrf(header_guard, "%s_H_", iface->if_name);
fx_string_toupper(header_guard); fx_string_transform_uppercase(header_guard);
emit(ctx, emit(ctx,
"#ifndef %s\n#define %s\n\n", "#ifndef %s\n#define %s\n\n",
fx_string_ptr(header_guard), fx_string_get_cstr(header_guard),
fx_string_ptr(header_guard)); fx_string_get_cstr(header_guard));
fx_string_unref(header_guard); fx_string_unref(header_guard);
return 0; return 0;
} }
@@ -115,14 +115,14 @@ static int emit_interface_id_macros(
{ {
fx_string *iface_define_name = fx_string_create(); fx_string *iface_define_name = fx_string_create();
fx_string_append_cstr(iface_define_name, iface->if_name); fx_string_append_cstr(iface_define_name, iface->if_name);
fx_string_toupper(iface_define_name); fx_string_transform_uppercase(iface_define_name);
uint32_t protocol_id = iface->if_id; uint32_t protocol_id = iface->if_id;
emit(ctx, emit(ctx,
"/* %s protocol ID */\n#define INTERFACE_%s 0x%08xU\n\n", "/* %s protocol ID */\n#define INTERFACE_%s 0x%08xU\n\n",
iface->if_name, iface->if_name,
fx_string_ptr(iface_define_name), fx_string_get_cstr(iface_define_name),
protocol_id); protocol_id);
fx_string_unref(iface_define_name); fx_string_unref(iface_define_name);
@@ -138,7 +138,9 @@ static int emit_interface_id_macros(
iface->if_name, iface->if_name,
msg->msg_name); msg->msg_name);
emit(ctx, "/* %s message ID */\n", fx_string_ptr(msg_name)); emit(ctx,
"/* %s message ID */\n",
fx_string_get_cstr(msg_name));
uint16_t msg_id = msg->msg_id; uint16_t msg_id = msg->msg_id;
fx_string_clear(msg_name); fx_string_clear(msg_name);
@@ -147,10 +149,10 @@ static int emit_interface_id_macros(
"%s_%s", "%s_%s",
iface->if_name, iface->if_name,
msg->msg_name); msg->msg_name);
fx_string_toupper(msg_name); fx_string_transform_uppercase(msg_name);
emit(ctx, emit(ctx,
"#define MSG_%s 0x%04xU\n", "#define MSG_%s 0x%04xU\n",
fx_string_ptr(msg_name), fx_string_get_cstr(msg_name),
msg_id); msg_id);
entry = fx_queue_next(entry); entry = fx_queue_next(entry);
@@ -316,9 +318,9 @@ static int emit_interface_msg_function_send_impl(
const struct msg_definition *msg) const struct msg_definition *msg)
{ {
fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name); fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name);
fx_string_toupper(iface_ucase); fx_string_transform_uppercase(iface_ucase);
fx_string *msg_ucase = fx_string_create_from_cstr(msg->msg_name); fx_string *msg_ucase = fx_string_create_from_cstr(msg->msg_name);
fx_string_toupper(msg_ucase); fx_string_transform_uppercase(msg_ucase);
emit(ctx, emit(ctx,
"struct %s_%s_msg msg_data = {0};\n", "struct %s_%s_msg msg_data = {0};\n",
@@ -327,9 +329,9 @@ static int emit_interface_msg_function_send_impl(
emit(ctx, emit(ctx,
"xpc_msg_header_init(&msg_data.msg_header, INTERFACE_%s, " "xpc_msg_header_init(&msg_data.msg_header, INTERFACE_%s, "
"MSG_%s_%s);\n", "MSG_%s_%s);\n",
fx_string_ptr(iface_ucase), fx_string_get_cstr(iface_ucase),
fx_string_ptr(iface_ucase), fx_string_get_cstr(iface_ucase),
fx_string_ptr(msg_ucase)); fx_string_get_cstr(msg_ucase));
fx_string_unref(iface_ucase); fx_string_unref(iface_ucase);
fx_string_unref(msg_ucase); fx_string_unref(msg_ucase);
@@ -896,13 +898,13 @@ static int emit_interface_dispatcher_impl(
const struct interface_definition *iface) const struct interface_definition *iface)
{ {
fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name); fx_string *iface_ucase = fx_string_create_from_cstr(iface->if_name);
fx_string_toupper(iface_ucase); fx_string_transform_uppercase(iface_ucase);
fx_string *msg_ucase = fx_string_create(); fx_string *msg_ucase = fx_string_create();
emit(ctx, emit(ctx,
"if (msg->msg_header.hdr_interface != INTERFACE_%s) return " "if (msg->msg_header.hdr_interface != INTERFACE_%s) return "
"KERN_INVALID_ARGUMENT;\n\n", "KERN_INVALID_ARGUMENT;\n\n",
fx_string_ptr(iface_ucase)); fx_string_get_cstr(iface_ucase));
emit(ctx, "kern_status_t status = KERN_OK;\n"); emit(ctx, "kern_status_t status = KERN_OK;\n");
emit(ctx, "switch (msg->msg_header.hdr_func) {\n"); emit(ctx, "switch (msg->msg_header.hdr_func) {\n");
@@ -914,12 +916,12 @@ static int emit_interface_dispatcher_impl(
fx_string_clear(msg_ucase); fx_string_clear(msg_ucase);
fx_string_append_cstr(msg_ucase, msg->msg_name); fx_string_append_cstr(msg_ucase, msg->msg_name);
fx_string_toupper(msg_ucase); fx_string_transform_uppercase(msg_ucase);
emit(ctx, emit(ctx,
"case MSG_%s_%s: {\n", "case MSG_%s_%s: {\n",
fx_string_ptr(iface_ucase), fx_string_get_cstr(iface_ucase),
fx_string_ptr(msg_ucase)); fx_string_get_cstr(msg_ucase));
emit_indent(ctx); emit_indent(ctx);
emit_interface_dispatcher_impl_msg(ctx, iface, msg); emit_interface_dispatcher_impl_msg(ctx, iface, msg);
emit(ctx, "break;\n"); emit(ctx, "break;\n");
@@ -1121,8 +1123,8 @@ static int emit_header(
emit_include(ctx, "xpc/string.h", true); emit_include(ctx, "xpc/string.h", true);
emit_include(ctx, "xpc/buffer.h", true); emit_include(ctx, "xpc/buffer.h", true);
emit_include(ctx, "xpc/context.h", true); emit_include(ctx, "xpc/context.h", true);
emit_include(ctx, "mango/msg.h", true); emit_include(ctx, "magenta/msg.h", true);
emit_include(ctx, "mango/types.h", true); emit_include(ctx, "magenta/types.h", true);
emit(ctx, "\n"); emit(ctx, "\n");
emit_interface_id_macros(ctx, iface); emit_interface_id_macros(ctx, iface);
+1 -1
View File
@@ -2,7 +2,7 @@
#include "msg.h" #include "msg.h"
#include <fx/ds/string.h> #include <fx/string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef XPCG_INTERFACE_H_ #ifndef XPCG_INTERFACE_H_
#define XPCG_INTERFACE_H_ #define XPCG_INTERFACE_H_
#include <fx/core/queue.h> #include <fx/queue.h>
struct msg_definition; struct msg_definition;
+8 -8
View File
@@ -3,13 +3,12 @@
#include "line-source.h" #include "line-source.h"
#include "token.h" #include "token.h"
#include <fx/core/hash.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/ds/dict.h>
#include <fx/ds/number.h>
#include <fx/ds/string.h>
#include <ctype.h> #include <ctype.h>
#include <fx/collections/hashtable.h>
#include <fx/hash.h>
#include <fx/misc.h>
#include <fx/queue.h>
#include <fx/string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -24,7 +23,8 @@
(fx_wchar_is_alnum(c) || c == '.' || c == '-' || c == '_') (fx_wchar_is_alnum(c) || c == '.' || c == '-' || c == '_')
#define IS_VALID_IDENT_START_CHAR(c) \ #define IS_VALID_IDENT_START_CHAR(c) \
(fx_wchar_is_alpha(c) || c == '.' || c == '_') (fx_wchar_is_alpha(c) || c == '.' || c == '_')
#define IS_VALID_REG_START_CHAR(c) (fx_wchar_is_alnum(c) || c == '.' || c == '_') #define IS_VALID_REG_START_CHAR(c) \
(fx_wchar_is_alnum(c) || c == '.' || c == '_')
static struct lex_token_def symbols[] = { static struct lex_token_def symbols[] = {
LEX_TOKEN_DEF(SYM_COMMA, ","), LEX_TOKEN_DEF(SYM_COMMA, ","),
@@ -414,7 +414,7 @@ static enum status read_number(struct lex *lex, bool negate)
return push_int(lex, 0); return push_int(lex, 0);
} }
const char *s = fx_string_ptr(str); const char *s = fx_string_get_cstr(str);
char *ep = NULL; char *ep = NULL;
/* negative numbers will be lexed as a hyphen followed by a positive /* negative numbers will be lexed as a hyphen followed by a positive
+3 -3
View File
@@ -4,9 +4,9 @@
#include "status.h" #include "status.h"
#include "token.h" #include "token.h"
#include <fx/core/queue.h> #include <fx/collections/hashtable.h>
#include <fx/ds/dict.h> #include <fx/queue.h>
#include <fx/ds/string.h> #include <fx/string.h>
#include <stdint.h> #include <stdint.h>
struct lex { struct lex {
+8 -5
View File
@@ -71,7 +71,7 @@ static enum status refill_linebuf(struct line_source *src)
fx_string_replace_all_with_stringstream(line, s); fx_string_replace_all_with_stringstream(line, s);
fx_stringstream_unref(s); fx_stringstream_unref(s);
fx_array_append(src->s_lines, line); fx_array_push_back(src->s_lines, FX_VALUE_OBJECT(line));
fx_string_unref(line); fx_string_unref(line);
src->s_linebuf = line; src->s_linebuf = line;
@@ -96,7 +96,7 @@ static int peek(struct line_source *src)
return -ERR_EOF; return -ERR_EOF;
} }
fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr).v_int; fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr)->v_wchar;
return c; return c;
} }
@@ -116,7 +116,7 @@ static int advance(struct line_source *src)
return -ERR_EOF; return -ERR_EOF;
} }
fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr).v_int; fx_wchar c = fx_iterator_get_value(src->s_linebuf_ptr)->v_wchar;
fx_iterator_move_next(src->s_linebuf_ptr); fx_iterator_move_next(src->s_linebuf_ptr);
src->s_cursor.c_col++; src->s_cursor.c_col++;
@@ -148,11 +148,14 @@ enum status line_source_get_row(
row--; row--;
if (row >= fx_array_size(src->s_lines)) { if (row >= fx_array_get_size(src->s_lines)) {
return ERR_EOF; return ERR_EOF;
} }
fx_string *line = fx_array_at(src->s_lines, row); const fx_value *line_v = fx_array_get_ref(src->s_lines, row);
fx_string *line = NULL;
fx_value_get_object(line_v, &line);
*out = line; *out = line;
return SUCCESS; return SUCCESS;
+4 -4
View File
@@ -4,15 +4,15 @@
#include "file-span.h" #include "file-span.h"
#include "status.h" #include "status.h"
#include <fx/core/stream.h> #include <fx/collections/array.h>
#include <fx/ds/array.h> #include <fx/stream.h>
#include <fx/ds/string.h> #include <fx/string.h>
struct line_source { struct line_source {
fx_stream *s_stream; fx_stream *s_stream;
const char *s_path; const char *s_path;
fx_string *s_linebuf; fx_string *s_linebuf;
fx_iterator *s_linebuf_ptr; const fx_iterator *s_linebuf_ptr;
fx_array *s_lines; fx_array *s_lines;
struct file_cell s_cursor; struct file_cell s_cursor;
+12 -4
View File
@@ -6,7 +6,7 @@
#include "msg.h" #include "msg.h"
#include "parse.h" #include "parse.h"
#include <fx/cmd.h> #include <fx/cmdline/cmd.h>
#include <fx/io/file.h> #include <fx/io/file.h>
#include <fx/io/path.h> #include <fx/io/path.h>
@@ -70,7 +70,12 @@ static int xpcg(
const fx_array *args) const fx_array *args)
{ {
const char *path = NULL; const char *path = NULL;
fx_arglist_get_string(opt, FX_COMMAND_INVALID_ID, ARG_SRCPATH, 0, &path); fx_arglist_get_string(
opt,
FX_COMMAND_INVALID_ID,
ARG_SRCPATH,
0,
&path);
if (!path) { if (!path) {
fx_arglist_report_missing_args( fx_arglist_report_missing_args(
opt, opt,
@@ -81,8 +86,11 @@ static int xpcg(
} }
fx_file *file = NULL; fx_file *file = NULL;
fx_result result fx_result result = fx_file_open(
= fx_file_open(NULL, FX_RV_PATH(path), FX_FILE_READ_ONLY, &file); NULL,
FX_RV_PATH(path),
FX_FILE_READ_ONLY,
&file);
if (fx_result_is_error(result)) { if (fx_result_is_error(result)) {
fx_throw(result); fx_throw(result);
return -1; return -1;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "msg.h" #include "msg.h"
#include <fx/ds/string.h> #include <fx/string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef XPCG_MSG_H_ #ifndef XPCG_MSG_H_
#define XPCG_MSG_H_ #define XPCG_MSG_H_
#include <fx/core/queue.h> #include <fx/queue.h>
struct type; struct type;
+2
View File
@@ -1,5 +1,7 @@
#include "token.h" #include "token.h"
#include <stdlib.h>
void token_destroy(struct token *tok) void token_destroy(struct token *tok)
{ {
switch (tok->tok_value_type) { switch (tok->tok_value_type) {
+1 -1
View File
@@ -3,7 +3,7 @@
#include "file-span.h" #include "file-span.h"
#include <fx/core/queue.h> #include <fx/queue.h>
#define TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : TOK_NONE) #define TOKEN_TYPE(tok) ((tok) ? (tok)->tok_type : TOK_NONE)
#define TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0) #define TOKEN_IS(tok, type) ((tok) && ((tok)->tok_type & (type)) != 0)