Skip to content

Commit

Permalink
move WASM_RT core types definition into wasm-rt.h to remove redundancy.
Browse files Browse the repository at this point in the history
  • Loading branch information
talg committed Sep 21, 2022
1 parent 16cd36c commit 186d787
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
15 changes: 0 additions & 15 deletions src/template/wasm2c.top.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@

#include "wasm-rt.h"

/* TODO(binji): only use stdint.h types in header */
#ifndef WASM_RT_CORE_TYPES_DEFINED
#define WASM_RT_CORE_TYPES_DEFINED
typedef uint8_t u8;
typedef int8_t s8;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef float f32;
typedef double f64;
#endif

#ifdef __cplusplus
extern "C" {
#endif
19 changes: 5 additions & 14 deletions wasm2c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,6 @@ The generated header file looks something like this:

#include "wasm-rt.h"

...
#ifndef WASM_RT_CORE_TYPES_DEFINED
#define WASM_RT_CORE_TYPES_DEFINED

...

#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -186,14 +178,13 @@ u32 Z_facZ_fac(Z_fac_instance_t*, u32);
```
Let's look at each section. The outer `#ifndef` is standard C
boilerplate for a header. This `WASM_RT_CORE_TYPES_DEFINED` section
contains a number of definitions required for all WebAssembly
modules. The `extern "C"` part makes sure to not mangle the symbols if
using this header in C++.
boilerplate for a header. The `extern "C"` part makes sure to not mangle the
symbols if using this header in C++.
The included `wasm-rt.h` file also includes a number of relevant definitions.
First is the `wasm_rt_trap_t` enum, which is used to give the reason a trap
occurred.
First, is the `WASM_RT_CORE_TYPES_DEFINED` section contains a number of
definitions required for all WebAssembly modules. Next, is the
`wasm_rt_trap_t` enum, which is used to give the reason a trap occurred.
```c
typedef enum {
Expand Down
15 changes: 0 additions & 15 deletions wasm2c/examples/fac/fac.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@

#include "wasm-rt.h"

/* TODO(binji): only use stdint.h types in header */
#ifndef WASM_RT_CORE_TYPES_DEFINED
#define WASM_RT_CORE_TYPES_DEFINED
typedef uint8_t u8;
typedef int8_t s8;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;
typedef int64_t s64;
typedef float f32;
typedef double f64;
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down

0 comments on commit 186d787

Please sign in to comment.