Skip to content

Commit

Permalink
Separate validation stuff from context.h to validation.h
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Jan 30, 2023
1 parent f492801 commit 3ee3c36
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 78 deletions.
79 changes: 1 addition & 78 deletions lib/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "report.h"
#include "vec.h"

enum valtype;
struct localtype;
struct module;

enum ctrlframe_op {
FRAME_OP_BLOCK = 0x02,
Expand Down Expand Up @@ -81,50 +81,6 @@ enum trapid {
TRAP_UNALIGNED_ATOMIC_OPERATION,
};

struct validation_context {
/* ctrl frames */
struct ctrlframe *cframes;
uint32_t ncframes;

/* operand stack */

enum valtype *valtypes;
uint32_t nvaltypes;
uint32_t ncells;

struct module *module;
struct expr_exec_info *ei;

uint32_t nlocals;
enum valtype *locals;

bool const_expr;

bool has_datacount;
uint32_t ndatas_in_datacount;

struct report *report;

/*
* C.refs
*
* https://webassembly.github.io/spec/core/valid/conventions.html#context
* > References: the list of function indices that occur in
* > the module outside functions and can hence be used to
* > form references inside them.
*
* Functions in this list can have references and thus can be
* called with call.indirect. Having this list before looking
* at the code section can benefit 1-pass compilation.
*
* https://github.com/WebAssembly/reference-types/issues/31
* https://github.com/WebAssembly/reference-types/issues/76
*/
struct bitmap *refs;

const struct load_options *options;
};

enum exec_event {
EXEC_EVENT_NONE,
EXEC_EVENT_CALL,
Expand Down Expand Up @@ -260,36 +216,3 @@ void exec_context_clear(struct exec_context *ctx);
void exec_context_print_stats(struct exec_context *ctx);

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

/* validation */

int push_valtype(enum valtype type, struct validation_context *ctx);
int pop_valtype(enum valtype expected_type, enum valtype *typep,
struct validation_context *ctx);

int push_valtypes(const struct resulttype *types,
struct validation_context *ctx);
int pop_valtypes(const struct resulttype *types,
struct validation_context *ctx);
int peek_valtypes(const struct resulttype *types,
struct validation_context *ctx);

int push_ctrlframe(uint32_t pc, enum ctrlframe_op op, uint32_t jumpslot,
struct resulttype *start_types,
struct resulttype *end_types,
struct validation_context *ctx);
int pop_ctrlframe(uint32_t pc, bool is_else, struct ctrlframe *cframe,
struct validation_context *ctx);
void mark_unreachable(struct validation_context *ctx);
const struct resulttype *label_types(struct ctrlframe *cframe);
int validation_failure(struct validation_context *ctx, const char *fmt, ...)
__attribute__((__format__(__printf__, 2, 3)));
struct resulttype *returntype(struct validation_context *ctx);
void validation_context_init(struct validation_context *ctx);
void validation_context_clear(struct validation_context *ctx);
void ctrlframe_clear(struct ctrlframe *cframe);
int target_label_types(struct validation_context *ctx, uint32_t labelidx,
const struct resulttype **rtp);

int record_type_annotation(struct validation_context *vctx, const uint8_t *p,
enum valtype t);
1 change: 1 addition & 0 deletions lib/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "load_context.h"
#include "type.h"
#include "util.h"
#include "validation.h"
#include "xlog.h"

static int
Expand Down
1 change: 1 addition & 0 deletions lib/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "platform.h"
#include "type.h"
#include "util.h"
#include "validation.h"
#include "xlog.h"

/*
Expand Down
1 change: 1 addition & 0 deletions lib/validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "options.h"
#include "type.h"
#include "util.h"
#include "validation.h"
#include "xlog.h"

int
Expand Down
78 changes: 78 additions & 0 deletions lib/validation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
enum valtype;

struct validation_context {
/* ctrl frames */
struct ctrlframe *cframes;
uint32_t ncframes;

/* operand stack */

enum valtype *valtypes;
uint32_t nvaltypes;
uint32_t ncells;

struct module *module;
struct expr_exec_info *ei;

uint32_t nlocals;
enum valtype *locals;

bool const_expr;

bool has_datacount;
uint32_t ndatas_in_datacount;

struct report *report;

/*
* C.refs
*
* https://webassembly.github.io/spec/core/valid/conventions.html#context
* > References: the list of function indices that occur in
* > the module outside functions and can hence be used to
* > form references inside them.
*
* Functions in this list can have references and thus can be
* called with call.indirect. Having this list before looking
* at the code section can benefit 1-pass compilation.
*
* https://github.com/WebAssembly/reference-types/issues/31
* https://github.com/WebAssembly/reference-types/issues/76
*/
struct bitmap *refs;

const struct load_options *options;
};

/* validation */

int push_valtype(enum valtype type, struct validation_context *ctx);
int pop_valtype(enum valtype expected_type, enum valtype *typep,
struct validation_context *ctx);

int push_valtypes(const struct resulttype *types,
struct validation_context *ctx);
int pop_valtypes(const struct resulttype *types,
struct validation_context *ctx);
int peek_valtypes(const struct resulttype *types,
struct validation_context *ctx);

int push_ctrlframe(uint32_t pc, enum ctrlframe_op op, uint32_t jumpslot,
struct resulttype *start_types,
struct resulttype *end_types,
struct validation_context *ctx);
int pop_ctrlframe(uint32_t pc, bool is_else, struct ctrlframe *cframe,
struct validation_context *ctx);
void mark_unreachable(struct validation_context *ctx);
const struct resulttype *label_types(struct ctrlframe *cframe);
int validation_failure(struct validation_context *ctx, const char *fmt, ...)
__attribute__((__format__(__printf__, 2, 3)));
struct resulttype *returntype(struct validation_context *ctx);
void validation_context_init(struct validation_context *ctx);
void validation_context_clear(struct validation_context *ctx);
void ctrlframe_clear(struct ctrlframe *cframe);
int target_label_types(struct validation_context *ctx, uint32_t labelidx,
const struct resulttype **rtp);

int record_type_annotation(struct validation_context *vctx, const uint8_t *p,
enum valtype t);

0 comments on commit 3ee3c36

Please sign in to comment.