From 6bc486400cad367c9ed9b6c70832701469900017 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 13 Aug 2024 22:50:45 +0200 Subject: [PATCH] Add globals to `-P` output. --- src/compiler/json_output.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/compiler/json_output.c b/src/compiler/json_output.c index b1a3e49ac..72238619f 100644 --- a/src/compiler/json_output.c +++ b/src/compiler/json_output.c @@ -236,7 +236,20 @@ static inline void emit_types(FILE *file) } fputs("\n\t}\n", file); } - +static inline void emit_globals(FILE *file) +{ + fputs("\t\"globals\": [\n", file); + { + bool first = true; + FOREACH_DECL(Decl *decl, compiler.context.module_list) + if (decl->decl_kind != DECL_VAR || decl->var.kind != VARDECL_GLOBAL) continue; + if (decl_is_hidden(decl)) continue; + INERT_COMMA; + PRINTF("\t\t\"%s::%s\"", module->name->module, decl->name); + FOREACH_DECL_END; + } + PRINTF("\n\t],"); +} static inline void emit_functions(FILE *file) { fputs("\t\"functions\": {\n", file); @@ -269,6 +282,7 @@ static inline void emit_json_to_file(FILE *file) emit_modules(file); emit_types(file); emit_functions(file); + emit_globals(file); fputs("\n}", file); }