Skip to content

Commit fa5ce41

Browse files
committed
Use clang-format-18 to format source files
1 parent 7ecf573 commit fa5ce41

File tree

17 files changed

+215
-173
lines changed

17 files changed

+215
-173
lines changed

core/iwasm/common/wasm_native.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,10 @@ wasm_runtime_get_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst_comm)
486486

487487
void
488488
wasm_runtime_set_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst_comm,
489-
WASINNGlobalContext *wasi_nn_ctx)
489+
WASINNGlobalContext *wasi_nn_ctx)
490490
{
491-
wasm_native_set_context(module_inst_comm, g_wasi_nn_context_key, wasi_nn_ctx);
491+
wasm_native_set_context(module_inst_comm, g_wasi_nn_context_key,
492+
wasi_nn_ctx);
492493
}
493494

494495
static void
@@ -611,7 +612,8 @@ wasm_native_init()
611612
#endif /* WASM_ENABLE_LIB_RATS */
612613

613614
#if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
614-
g_wasi_nn_context_key = wasm_native_create_context_key(wasi_nn_context_dtor);
615+
g_wasi_nn_context_key =
616+
wasm_native_create_context_key(wasi_nn_context_dtor);
615617
if (g_wasi_nn_context_key == NULL) {
616618
goto fail;
617619
}

core/iwasm/common/wasm_runtime_common.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,25 +1700,25 @@ wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p)
17001700
struct wasi_nn_graph_registry;
17011701

17021702
void
1703-
wasm_runtime_wasi_nn_graph_registry_args_set_defaults(struct wasi_nn_graph_registry *args)
1703+
wasm_runtime_wasi_nn_graph_registry_args_set_defaults(
1704+
struct wasi_nn_graph_registry *args)
17041705
{
17051706
memset(args, 0, sizeof(*args));
17061707
}
17071708

17081709
bool
1709-
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry, const char* encoding,
1710-
const char* target, uint32_t n_graphs,
1711-
const char** graph_paths)
1710+
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
1711+
const char *encoding, const char *target,
1712+
uint32_t n_graphs, const char **graph_paths)
17121713
{
1713-
if (!registry || !encoding || !target || !graph_paths)
1714-
{
1714+
if (!registry || !encoding || !target || !graph_paths) {
17151715
return false;
17161716
}
17171717
registry->encoding = strdup(encoding);
17181718
registry->target = strdup(target);
17191719
registry->n_graphs = n_graphs;
1720-
registry->graph_paths = (uint32_t**)malloc(sizeof(uint32_t*) * n_graphs);
1721-
memset(registry->graph_paths, 0, sizeof(uint32_t*) * n_graphs);
1720+
registry->graph_paths = (uint32_t **)malloc(sizeof(uint32_t *) * n_graphs);
1721+
memset(registry->graph_paths, 0, sizeof(uint32_t *) * n_graphs);
17221722
for (uint32_t i = 0; i < registry->n_graphs; i++)
17231723
registry->graph_paths[i] = strdup(graph_paths[i]);
17241724

@@ -1740,12 +1740,11 @@ wasi_nn_graph_registry_create(struct wasi_nn_graph_registry **registryp)
17401740
void
17411741
wasi_nn_graph_registry_destroy(struct wasi_nn_graph_registry *registry)
17421742
{
1743-
if (registry)
1744-
{
1743+
if (registry) {
17451744
for (uint32_t i = 0; i < registry->n_graphs; i++)
1746-
if (registry->graph_paths[i])
1747-
{
1748-
// wasi_nn_graph_registry_unregister_graph(registry, registry->name[i]);
1745+
if (registry->graph_paths[i]) {
1746+
// wasi_nn_graph_registry_unregister_graph(registry,
1747+
// registry->name[i]);
17491748
free(registry->graph_paths[i]);
17501749
}
17511750
if (registry->encoding)
@@ -8153,27 +8152,27 @@ wasm_runtime_check_and_update_last_used_shared_heap(
81538152
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
81548153
bool
81558154
wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
8156-
const char* encoding, const char* target,
8157-
const uint32_t n_graphs, char* graph_paths[],
8158-
char *error_buf, uint32_t error_buf_size)
8155+
const char *encoding, const char *target,
8156+
const uint32_t n_graphs,
8157+
char *graph_paths[], char *error_buf,
8158+
uint32_t error_buf_size)
81598159
{
81608160
WASINNGlobalContext *ctx;
81618161
bool ret = false;
81628162

81638163
ctx = runtime_malloc(sizeof(*ctx), module_inst, error_buf, error_buf_size);
81648164
if (!ctx)
81658165
return false;
8166-
8166+
81678167
ctx->encoding = strdup(encoding);
81688168
ctx->target = strdup(target);
81698169
ctx->n_graphs = n_graphs;
8170-
ctx->loaded = (uint32_t*)malloc(sizeof(uint32_t) * n_graphs);
8170+
ctx->loaded = (uint32_t *)malloc(sizeof(uint32_t) * n_graphs);
81718171
memset(ctx->loaded, 0, sizeof(uint32_t) * n_graphs);
8172-
8173-
ctx->graph_paths = (uint32_t**)malloc(sizeof(uint32_t*) * n_graphs);
8174-
memset(ctx->graph_paths, 0, sizeof(uint32_t*) * n_graphs);
8175-
for (uint32_t i = 0; i < n_graphs; i++)
8176-
{
8172+
8173+
ctx->graph_paths = (uint32_t **)malloc(sizeof(uint32_t *) * n_graphs);
8174+
memset(ctx->graph_paths, 0, sizeof(uint32_t *) * n_graphs);
8175+
for (uint32_t i = 0; i < n_graphs; i++) {
81778176
ctx->graph_paths[i] = strdup(graph_paths[i]);
81788177
}
81798178

@@ -8187,10 +8186,10 @@ wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
81878186
void
81888187
wasm_runtime_destroy_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst)
81898188
{
8190-
WASINNGlobalContext *wasi_nn_global_ctx = wasm_runtime_get_wasi_nn_global_ctx(module_inst);
8189+
WASINNGlobalContext *wasi_nn_global_ctx =
8190+
wasm_runtime_get_wasi_nn_global_ctx(module_inst);
81918191

8192-
for (uint32 i = 0; i < wasi_nn_global_ctx->n_graphs; i++)
8193-
{
8192+
for (uint32 i = 0; i < wasi_nn_global_ctx->n_graphs; i++) {
81948193
// All graphs will be unregistered in deinit()
81958194
if (wasi_nn_global_ctx->graph_paths[i])
81968195
free(wasi_nn_global_ctx->graph_paths[i]);
@@ -8206,7 +8205,8 @@ wasm_runtime_destroy_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst)
82068205
}
82078206

82088207
uint32_t
8209-
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(WASINNGlobalContext *wasi_nn_global_ctx)
8208+
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(
8209+
WASINNGlobalContext *wasi_nn_global_ctx)
82108210
{
82118211
if (wasi_nn_global_ctx)
82128212
return wasi_nn_global_ctx->n_graphs;
@@ -8215,7 +8215,8 @@ wasm_runtime_get_wasi_nn_global_ctx_ngraphs(WASINNGlobalContext *wasi_nn_global_
82158215
}
82168216

82178217
char *
8218-
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx)
8218+
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(
8219+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx)
82198220
{
82208221
if (wasi_nn_global_ctx && (idx < wasi_nn_global_ctx->n_graphs))
82218222
return wasi_nn_global_ctx->graph_paths[idx];
@@ -8224,7 +8225,8 @@ wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(WASINNGlobalContext *wasi_nn_g
82248225
}
82258226

82268227
uint32_t
8227-
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx)
8228+
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(
8229+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx)
82288230
{
82298231
if (wasi_nn_global_ctx && (idx < wasi_nn_global_ctx->n_graphs))
82308232
return wasi_nn_global_ctx->loaded[idx];
@@ -8233,25 +8235,28 @@ wasm_runtime_get_wasi_nn_global_ctx_loaded_i(WASINNGlobalContext *wasi_nn_global
82338235
}
82348236

82358237
uint32_t
8236-
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx, uint32_t value)
8238+
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(
8239+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx, uint32_t value)
82378240
{
82388241
if (wasi_nn_global_ctx && (idx < wasi_nn_global_ctx->n_graphs))
82398242
wasi_nn_global_ctx->loaded[idx] = value;
82408243

82418244
return 0;
82428245
}
82438246

8244-
char*
8245-
wasm_runtime_get_wasi_nn_global_ctx_encoding(WASINNGlobalContext *wasi_nn_global_ctx)
8247+
char *
8248+
wasm_runtime_get_wasi_nn_global_ctx_encoding(
8249+
WASINNGlobalContext *wasi_nn_global_ctx)
82468250
{
82478251
if (wasi_nn_global_ctx)
82488252
return wasi_nn_global_ctx->encoding;
82498253

82508254
return NULL;
82518255
}
82528256

8253-
char*
8254-
wasm_runtime_get_wasi_nn_global_ctx_target(WASINNGlobalContext *wasi_nn_global_ctx)
8257+
char *
8258+
wasm_runtime_get_wasi_nn_global_ctx_target(
8259+
WASINNGlobalContext *wasi_nn_global_ctx)
82558260
{
82568261
if (wasi_nn_global_ctx)
82578262
return wasi_nn_global_ctx->target;

core/iwasm/common/wasm_runtime_common.h

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,12 @@ typedef struct WASMModuleInstMemConsumption {
547547

548548
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
549549
typedef struct WASINNGlobalContext {
550-
char* encoding;
551-
char* target;
550+
char *encoding;
551+
char *target;
552552

553553
uint32_t n_graphs;
554554
uint32_t *loaded;
555-
char** graph_paths;
555+
char **graph_paths;
556556
} WASINNGlobalContext;
557557
#endif
558558

@@ -625,10 +625,10 @@ wasm_runtime_get_exec_env_tls(void);
625625

626626
#if (WASM_ENABLE_WASI_EPHEMERAL_NN != 0)
627627
struct wasi_nn_graph_registry {
628-
char* encoding;
629-
char* target;
628+
char *encoding;
629+
char *target;
630630

631-
char** graph_paths;
631+
char **graph_paths;
632632
uint32_t n_graphs;
633633
};
634634

@@ -811,9 +811,9 @@ wasm_runtime_instantiation_args_set_wasi_nn_graph_registry(
811811
struct InstantiationArgs2 *p, struct wasi_nn_graph_registry *registry);
812812

813813
WASM_RUNTIME_API_EXTERN bool
814-
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry, const char* encoding,
815-
const char* target, uint32_t n_graphs,
816-
const char** graph_paths);
814+
wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
815+
const char *encoding, const char *target,
816+
uint32_t n_graphs, const char **graph_paths);
817817
#endif
818818

819819
/* See wasm_export.h for description */
@@ -1471,34 +1471,41 @@ wasm_runtime_check_and_update_last_used_shared_heap(
14711471
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
14721472
WASM_RUNTIME_API_EXTERN bool
14731473
wasm_runtime_init_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
1474-
const char* encoding, const char* target,
1475-
const uint32_t n_graphs, char* graph_paths[],
1476-
char *error_buf, uint32_t error_buf_size);
1474+
const char *encoding, const char *target,
1475+
const uint32_t n_graphs,
1476+
char *graph_paths[], char *error_buf,
1477+
uint32_t error_buf_size);
14771478

14781479
WASM_RUNTIME_API_EXTERN void
14791480
wasm_runtime_destroy_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst);
14801481

14811482
WASM_RUNTIME_API_EXTERN void
14821483
wasm_runtime_set_wasi_nn_global_ctx(WASMModuleInstanceCommon *module_inst,
1483-
WASINNGlobalContext *wasi_ctx);
1484+
WASINNGlobalContext *wasi_ctx);
14841485

14851486
WASM_RUNTIME_API_EXTERN uint32_t
1486-
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(WASINNGlobalContext *wasi_nn_global_ctx);
1487+
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(
1488+
WASINNGlobalContext *wasi_nn_global_ctx);
14871489

14881490
WASM_RUNTIME_API_EXTERN char *
1489-
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx);
1491+
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(
1492+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx);
14901493

14911494
WASM_RUNTIME_API_EXTERN uint32_t
1492-
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx);
1495+
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(
1496+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx);
14931497

14941498
WASM_RUNTIME_API_EXTERN uint32_t
1495-
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx, uint32_t value);
1499+
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(
1500+
WASINNGlobalContext *wasi_nn_global_ctx, uint32_t idx, uint32_t value);
14961501

1497-
WASM_RUNTIME_API_EXTERN char*
1498-
wasm_runtime_get_wasi_nn_global_ctx_encoding(WASINNGlobalContext *wasi_nn_global_ctx);
1502+
WASM_RUNTIME_API_EXTERN char *
1503+
wasm_runtime_get_wasi_nn_global_ctx_encoding(
1504+
WASINNGlobalContext *wasi_nn_global_ctx);
14991505

1500-
WASM_RUNTIME_API_EXTERN char*
1501-
wasm_runtime_get_wasi_nn_global_ctx_target(WASINNGlobalContext *wasi_nn_global_ctx);
1506+
WASM_RUNTIME_API_EXTERN char *
1507+
wasm_runtime_get_wasi_nn_global_ctx_target(
1508+
WASINNGlobalContext *wasi_nn_global_ctx);
15021509
#endif
15031510

15041511
#ifdef __cplusplus

core/iwasm/include/wasm_export.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ typedef struct InstantiationArgs {
291291

292292
struct InstantiationArgs2;
293293
struct WASINNGlobalContext;
294-
typedef struct WASINNGlobalContext *wasi_nn_global_context;
294+
typedef struct WASINNGlobalContext *wasi_nn_global_context;
295295

296296
#ifndef WASM_VALKIND_T_DEFINED
297297
#define WASM_VALKIND_T_DEFINED
@@ -809,43 +809,51 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool(
809809
// struct InstantiationArgs2 *p, struct wasi_nn_graph_registry *registry);
810810

811811
// WASM_RUNTIME_API_EXTERN bool
812-
// wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry, const char* encoding,
812+
// wasi_nn_graph_registry_set_args(struct wasi_nn_graph_registry *registry,
813+
// const char* encoding,
813814
// const char* target, uint32_t n_graphs,
814815
// const char** graph_paths);
815816

816817
WASM_RUNTIME_API_EXTERN bool
817818
wasm_runtime_init_wasi_nn_global_ctx(wasm_module_inst_t module_inst,
818-
const char* encoding, const char* target,
819-
const uint32_t n_graphs, char* graph_paths[],
820-
char *error_buf, uint32_t error_buf_size);
819+
const char *encoding, const char *target,
820+
const uint32_t n_graphs,
821+
char *graph_paths[], char *error_buf,
822+
uint32_t error_buf_size);
821823

822824
WASM_RUNTIME_API_EXTERN void
823825
wasm_runtime_destroy_wasi_nn_global_ctx(wasm_module_inst_t module_inst);
824826

825827
WASM_RUNTIME_API_EXTERN void
826828
wasm_runtime_set_wasi_nn_global_ctx(wasm_module_inst_t module_inst,
827-
wasi_nn_global_context wasi_ctx);
829+
wasi_nn_global_context wasi_ctx);
828830

829831
WASM_RUNTIME_API_EXTERN wasi_nn_global_context
830832
wasm_runtime_get_wasi_nn_global_ctx(const wasm_module_inst_t module_inst);
831833

832834
WASM_RUNTIME_API_EXTERN uint32_t
833-
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(wasi_nn_global_context wasi_nn_global_ctx);
835+
wasm_runtime_get_wasi_nn_global_ctx_ngraphs(
836+
wasi_nn_global_context wasi_nn_global_ctx);
834837

835838
WASM_RUNTIME_API_EXTERN char *
836-
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx);
839+
wasm_runtime_get_wasi_nn_global_ctx_graph_paths_i(
840+
wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx);
837841

838842
WASM_RUNTIME_API_EXTERN uint32_t
839-
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx);
843+
wasm_runtime_get_wasi_nn_global_ctx_loaded_i(
844+
wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx);
840845

841846
WASM_RUNTIME_API_EXTERN uint32_t
842-
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx, uint32_t value);
847+
wasm_runtime_set_wasi_nn_global_ctx_loaded_i(
848+
wasi_nn_global_context wasi_nn_global_ctx, uint32_t idx, uint32_t value);
843849

844-
WASM_RUNTIME_API_EXTERN char*
845-
wasm_runtime_get_wasi_nn_global_ctx_encoding(wasi_nn_global_context wasi_nn_global_ctx);
850+
WASM_RUNTIME_API_EXTERN char *
851+
wasm_runtime_get_wasi_nn_global_ctx_encoding(
852+
wasi_nn_global_context wasi_nn_global_ctx);
846853

847-
WASM_RUNTIME_API_EXTERN char*
848-
wasm_runtime_get_wasi_nn_global_ctx_target(wasi_nn_global_context wasi_nn_global_ctx);
854+
WASM_RUNTIME_API_EXTERN char *
855+
wasm_runtime_get_wasi_nn_global_ctx_target(
856+
wasi_nn_global_context wasi_nn_global_ctx);
849857

850858
/**
851859
* Instantiate a WASM module, with specified instantiation arguments

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,13 +3301,14 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
33013301
#endif
33023302

33033303
#if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
3304-
/* Store graphs' path into ctx. Graphs will be loaded until user app calls load_by_name */
3304+
/* Store graphs' path into ctx. Graphs will be loaded until user app calls
3305+
* load_by_name */
33053306
// Do not consider load() for now
33063307
struct wasi_nn_graph_registry *nn_registry = &args->nn_registry;
33073308
if (!wasm_runtime_init_wasi_nn_global_ctx(
33083309
(WASMModuleInstanceCommon *)module_inst, nn_registry->encoding,
3309-
nn_registry->target, nn_registry->n_graphs, nn_registry->graph_paths,
3310-
error_buf, error_buf_size)) {
3310+
nn_registry->target, nn_registry->n_graphs,
3311+
nn_registry->graph_paths, error_buf, error_buf_size)) {
33113312
goto fail;
33123313
}
33133314
#endif

0 commit comments

Comments
 (0)