Skip to content

Commit

Permalink
move some prototypes from context.h to exec.h
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jun 17, 2023
1 parent b71fa2d commit fb14fb1
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string.h>

#include "cell.h"
#include "context.h"
#include "exec_context.h"
#include "type.h"

uint32_t
Expand Down
41 changes: 0 additions & 41 deletions lib/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "toywasm_config.h"

#include "cell.h"
#include "exec_context.h"
#include "platform.h"

struct localtype;
Expand All @@ -23,19 +22,6 @@ enum ctrlframe_op {
FRAME_OP_INVOKE = 0xff,
};

/* For funcframe.funcidx */
#define FUNCIDX_INVALID UINT32_MAX

/* for exec_stats */
#define STAT_INC(s) (s)++

/* use shorter interval for userland thread */
#if defined(TOYWASM_USE_USER_SCHED) || !defined(TOYWASM_PREALLOC_SHARED_MEMORY)
#define CHECK_INTERRUPT_INTERVAL_MS 50
#else
#define CHECK_INTERRUPT_INTERVAL_MS 300
#endif

struct context {
struct exec_context *exec;
struct validation_context *validation;
Expand All @@ -57,30 +43,3 @@ const uint8_t *pc2ptr(const struct module *m, uint32_t pc) __purefunc;
int resulttype_alloc(uint32_t ntypes, const enum valtype *types,
struct resulttype **resultp);
void resulttype_free(struct resulttype *p);

/* execution */

int trap(struct exec_context *ctx, const char *fmt, ...)
__attribute__((__format__(__printf__, 2, 3)));
int trap_with_id(struct exec_context *ctx, enum trapid id, const char *fmt,
...) __attribute__((__format__(__printf__, 3, 4)));
int memory_getptr(struct exec_context *ctx, uint32_t memidx, uint32_t ptr,
uint32_t offset, uint32_t size, void **pp);
int memory_getptr2(struct exec_context *ctx, uint32_t memidx, uint32_t ptr,
uint32_t offset, uint32_t size, void **pp, bool *movedp);
struct toywasm_mutex;
int memory_atomic_getptr(struct exec_context *ctx, uint32_t memidx,
uint32_t ptr, uint32_t offset, uint32_t size,
void **pp, struct toywasm_mutex **lockp);
void memory_atomic_unlock(struct toywasm_mutex *lock);
int frame_enter(struct exec_context *ctx, struct instance *inst,
uint32_t funcidx, const struct expr_exec_info *ei,
const struct localtype *localtype,
const struct resulttype *paramtype, uint32_t nresults,
const struct cell *params);
void frame_clear(struct funcframe *frame);
void frame_exit(struct exec_context *ctx);
struct cell *frame_locals(const struct exec_context *ctx,
const struct funcframe *frame) __purefunc;

uint32_t find_type_annotation(struct exec_context *ectx, const uint8_t *p);
33 changes: 33 additions & 0 deletions lib/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
#include <stdbool.h>
#include <stdint.h>

#include "exec_context.h"
#include "valtype.h"

/* use shorter interval for userland thread */
#if defined(TOYWASM_USE_USER_SCHED) || !defined(TOYWASM_PREALLOC_SHARED_MEMORY)
#define CHECK_INTERRUPT_INTERVAL_MS 50
#else
#define CHECK_INTERRUPT_INTERVAL_MS 300
#endif

struct cell;
struct expr;
struct exec_context;
Expand Down Expand Up @@ -51,6 +59,31 @@ int invoke(struct funcinst *finst, const struct resulttype *paramtype,

int check_interrupt(struct exec_context *ctx);

int trap(struct exec_context *ctx, const char *fmt, ...)
__attribute__((__format__(__printf__, 2, 3)));
int trap_with_id(struct exec_context *ctx, enum trapid id, const char *fmt,
...) __attribute__((__format__(__printf__, 3, 4)));
int memory_getptr(struct exec_context *ctx, uint32_t memidx, uint32_t ptr,
uint32_t offset, uint32_t size, void **pp);
int memory_getptr2(struct exec_context *ctx, uint32_t memidx, uint32_t ptr,
uint32_t offset, uint32_t size, void **pp, bool *movedp);
struct toywasm_mutex;
int memory_atomic_getptr(struct exec_context *ctx, uint32_t memidx,
uint32_t ptr, uint32_t offset, uint32_t size,
void **pp, struct toywasm_mutex **lockp);
void memory_atomic_unlock(struct toywasm_mutex *lock);
int frame_enter(struct exec_context *ctx, struct instance *inst,
uint32_t funcidx, const struct expr_exec_info *ei,
const struct localtype *localtype,
const struct resulttype *paramtype, uint32_t nresults,
const struct cell *params);
void frame_clear(struct funcframe *frame);
void frame_exit(struct exec_context *ctx);
struct cell *frame_locals(const struct exec_context *ctx,
const struct funcframe *frame) __purefunc;

uint32_t find_type_annotation(struct exec_context *ectx, const uint8_t *p);

/* debug */
void print_trace(const struct exec_context *ctx);
void print_memory(const struct exec_context *ctx, const struct instance *inst,
Expand Down
6 changes: 6 additions & 0 deletions lib/exec_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ struct exec_context {
struct exec_stat stats;
};

/* For funcframe.funcidx */
#define FUNCIDX_INVALID UINT32_MAX

/* for exec_stats */
#define STAT_INC(s) (s)++

void exec_context_init(struct exec_context *ctx, struct instance *inst);
void exec_context_clear(struct exec_context *ctx);
void exec_context_print_stats(struct exec_context *ctx);
2 changes: 1 addition & 1 deletion lib/host_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdlib.h>
#include <string.h>

#include "context.h"
#include "exec.h"
#include "host_instance.h"
#include "instance.h"
#include "type.h"
Expand Down
1 change: 0 additions & 1 deletion lib/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string.h>

#include "bitmap.h"
#include "context.h"
#include "exec.h"
#include "instance.h"
#include "module.h"
Expand Down
1 change: 0 additions & 1 deletion lib/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <inttypes.h>

#include "cluster.h"
#include "context.h"
#include "suspend.h"
#include "timeutil.h"
#include "xlog.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/usched.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <assert.h>

#include "context.h"
#include "exec.h"
#include "instance.h"
#include "timeutil.h"
#include "usched.h"
Expand Down
1 change: 1 addition & 0 deletions lib/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "context.h"
#include "options.h"
#include "report.h"
#include "type.h"
#include "util.h"
#include "validation.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/waitlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include <time.h>

#include "context.h"
#include "exec.h"
#include "lock.h"
#include "timeutil.h"

Expand Down
1 change: 0 additions & 1 deletion libwasi/wasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include <sys/random.h> /* getrandom */
#endif

#include "context.h"
#include "endian.h"
#include "exec.h"
#include "lock.h"
Expand Down
1 change: 0 additions & 1 deletion libwasi/wasi_fdtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <inttypes.h>
#include <stdlib.h>

#include "context.h"
#include "exec.h"
#include "timeutil.h"
#include "wasi_impl.h"
Expand Down
2 changes: 1 addition & 1 deletion libwasi/wasi_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <string.h>

#include "cluster.h"
#include "context.h"
#include "endian.h"
#include "exec.h"
#include "idalloc.h"
#include "instance.h"
#include "lock.h"
Expand Down

0 comments on commit fb14fb1

Please sign in to comment.