This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wrt/main.c
2023-02-07 11:22:47 +08:00

49 lines
992 B
C

#include <stdio.h>
#include <stdlib.h>
#include "utils/log.h"
#include "wrt/dl.h"
#include "wrt/wrt.h"
uint8_t *read_file(const char *filename, uint32_t *fsize) {
FILE *f = fopen(filename, "rb");
if (f == NULL) {
LOG_ERR("read_file: fopen failed");
return NULL;
}
fseek(f, 0, SEEK_END);
*fsize = ftell(f);
fseek(f, 0, SEEK_SET); // same as rewind(f);
uint8_t *buffer = malloc(*fsize + 1);
fread(buffer, *fsize, 1, f);
fclose(f);
buffer[*fsize] = 0;
return buffer;
}
void test_wrt() {
uint32_t buf_size;
uint8_t *buf = read_file("example.wasm", &buf_size);
WRTContext context;
wrt_platform_init(&context, malloc, free);
wrt_mem_init(&context, 512 * 1024, 128);
wrt_program_init(&context, buf, buf_size, NULL, 0);
wrt_wamr_init(&context, "entry", 8092, 8092);
wrt_run(&context);
wrt_free(&context);
free(buf);
}
int main() {
LOG_INFO("WRT Test");
test_wrt();
return 0;
}