Add parsing of export table
This commit is contained in:
parent
2b3c39d18c
commit
64f9409f9c
41
wai.c
41
wai.c
|
@ -28,6 +28,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
enum section {
|
||||
Section_Custom,
|
||||
|
@ -51,10 +52,24 @@ struct stack {
|
|||
size_t count;
|
||||
};
|
||||
|
||||
#define MAX_FUNCTIONS 128
|
||||
enum export_desc {
|
||||
Export_Func,
|
||||
Export_Table,
|
||||
Export_Mem,
|
||||
Export_Global,
|
||||
};
|
||||
|
||||
struct export_t {
|
||||
u_char name[128];
|
||||
size_t name_length;
|
||||
uint32_t index;
|
||||
enum export_desc description;
|
||||
};
|
||||
|
||||
struct module {
|
||||
struct type_t *types;
|
||||
u_char *funcs[128];
|
||||
u_char *funcs[MAX_FUNCTIONS];
|
||||
struct table_t *tables;
|
||||
struct mem_t *mems;
|
||||
struct global_t *globals;
|
||||
|
@ -62,7 +77,7 @@ struct module {
|
|||
struct data_t *datas;
|
||||
struct start_t *start;
|
||||
struct import_t *imports;
|
||||
struct export_t *exports;
|
||||
struct export_t exports[MAX_FUNCTIONS];
|
||||
u_char *binary;
|
||||
struct stack stack;
|
||||
int scope;
|
||||
|
@ -271,19 +286,27 @@ int parse_section(struct module *module, u_char *binary, int len) {
|
|||
case Section_Export:
|
||||
printf("section: exports\n");
|
||||
int num_exports = binary[i];
|
||||
|
||||
if(num_exports > MAX_FUNCTIONS) {
|
||||
printf("Number of exports exceeds maximum number of functions in a module (%d)", MAX_FUNCTIONS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
incr(i, len);
|
||||
for (int exports_i = 0; exports_i < num_exports; exports_i++) {
|
||||
int string_len = binary[i];
|
||||
struct export_t *export = &module->exports[i];
|
||||
|
||||
export->name_length = binary[i];
|
||||
incr(i, len);
|
||||
printf("export name: ");
|
||||
for (int si = 0; si < string_len; si++) {
|
||||
putchar(binary[i]);
|
||||
|
||||
for (int si = 0; si < export->name_length; si++) {
|
||||
export->name[si] = binary[i];
|
||||
incr(i, len);
|
||||
}
|
||||
putchar('\n');
|
||||
// export kind
|
||||
export->description = (int) binary[i];
|
||||
incr(i, len);
|
||||
// export func index
|
||||
export->index = (uint32_t) binary[i];
|
||||
printf("export name: %s of type %d\n", export->name, export->description);
|
||||
incr(i, len);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue