Skip to content

Commit d12537f

Browse files
committed
meson.build: enable to build Wasm backend
Enable to use tcg/wasm as the TCG backend for the WebAssembly (wasm64) build. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
1 parent efa6937 commit d12537f

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

include/accel/tcg/getpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define ACCEL_TCG_GETPC_H
1010

1111
/* GETPC is the true target of the return instruction that we'll execute. */
12-
#ifdef CONFIG_TCG_INTERPRETER
12+
#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
1313
extern __thread uintptr_t tci_tb_ptr;
1414
# define GETPC() tci_tb_ptr
1515
#else

include/tcg/helper-info.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef TCG_HELPER_INFO_H
1010
#define TCG_HELPER_INFO_H
1111

12-
#ifdef CONFIG_TCG_INTERPRETER
12+
#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
1313
#include <ffi.h>
1414
#endif
1515
#include "tcg-target-reg-bits.h"
@@ -48,7 +48,7 @@ struct TCGHelperInfo {
4848
const char *name;
4949

5050
/* Used with g_once_init_enter. */
51-
#ifdef CONFIG_TCG_INTERPRETER
51+
#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
5252
ffi_cif *cif;
5353
#else
5454
uintptr_t init;

include/tcg/tcg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ static inline size_t tcg_current_code_size(TCGContext *s)
963963
#define TB_EXIT_IDXMAX 1
964964
#define TB_EXIT_REQUESTED 3
965965

966-
#ifdef CONFIG_TCG_INTERPRETER
966+
#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
967967
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
968968
#else
969969
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);

meson.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,9 @@ if have_tcg
920920
if not get_option('tcg_interpreter')
921921
error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
922922
endif
923-
elif host_arch == 'wasm32' or host_arch == 'wasm64'
923+
elif host_arch == 'wasm32'
924924
if not get_option('tcg_interpreter')
925-
error('WebAssembly host requires --enable-tcg-interpreter')
925+
error('wasm32 host requires --enable-tcg-interpreter')
926926
endif
927927
elif get_option('tcg_interpreter')
928928
warning('Use of the TCG interpreter is not recommended on this host')
@@ -938,6 +938,8 @@ if have_tcg
938938
tcg_arch = 'i386'
939939
elif host_arch == 'ppc64'
940940
tcg_arch = 'ppc'
941+
elif host_arch == 'wasm64'
942+
tcg_arch = 'wasm'
941943
endif
942944
add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch,
943945
language: all_languages)

tcg/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ if get_option('tcg_interpreter')
2020
method: 'pkg-config')
2121
tcg_ss.add(libffi)
2222
tcg_ss.add(files('tci.c'))
23+
elif host_os == 'emscripten'
24+
libffi = dependency('libffi', version: '>=3.0', required: true,
25+
method: 'pkg-config')
26+
specific_ss.add(libffi)
27+
specific_ss.add(files('wasm.c'))
2328
endif
2429

2530
tcg_ss.add(when: libdw, if_true: files('debuginfo.c'))

tcg/region.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool in_code_gen_buffer(const void *p)
9494
return (size_t)(p - region.start_aligned) <= region.total_size;
9595
}
9696

97-
#ifndef CONFIG_TCG_INTERPRETER
97+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
9898
static int host_prot_read_exec(void)
9999
{
100100
#if defined(CONFIG_LINUX) && defined(HOST_AARCH64) && defined(PROT_BTI)
@@ -569,7 +569,7 @@ static int alloc_code_gen_buffer_anon(size_t size, int prot,
569569
return prot;
570570
}
571571

572-
#ifndef CONFIG_TCG_INTERPRETER
572+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
573573
#ifdef CONFIG_POSIX
574574
#include "qemu/memfd.h"
575575

@@ -667,11 +667,11 @@ static int alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)
667667
return PROT_READ | PROT_WRITE;
668668
}
669669
#endif /* CONFIG_DARWIN */
670-
#endif /* CONFIG_TCG_INTERPRETER */
670+
#endif /* !CONFIG_TCG_INTERPRETER && !EMSCRIPTEN */
671671

672672
static int alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
673673
{
674-
#ifndef CONFIG_TCG_INTERPRETER
674+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
675675
# ifdef CONFIG_DARWIN
676676
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
677677
# endif
@@ -813,7 +813,7 @@ void tcg_region_init(size_t tb_size, int splitwx, unsigned max_threads)
813813
* Work with the page protections set up with the initial mapping.
814814
*/
815815
need_prot = PROT_READ | PROT_WRITE;
816-
#ifndef CONFIG_TCG_INTERPRETER
816+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
817817
if (tcg_splitwx_diff == 0) {
818818
need_prot |= host_prot_read_exec();
819819
}

tcg/tcg.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ TCGv_env tcg_env;
256256
const void *tcg_code_gen_epilogue;
257257
uintptr_t tcg_splitwx_diff;
258258

259-
#ifndef CONFIG_TCG_INTERPRETER
259+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
260260
tcg_prologue_fn *tcg_qemu_tb_exec;
261261
#endif
262262

@@ -1443,7 +1443,7 @@ static TCGHelperInfo info_helper_st128_mmu = {
14431443
| dh_typemask(ptr, 5) /* uintptr_t ra */
14441444
};
14451445

1446-
#ifdef CONFIG_TCG_INTERPRETER
1446+
#if defined(CONFIG_TCG_INTERPRETER) || defined(EMSCRIPTEN)
14471447
static ffi_type *typecode_to_ffi(int argmask)
14481448
{
14491449
/*
@@ -1520,7 +1520,7 @@ static ffi_cif *init_ffi_layout(TCGHelperInfo *info)
15201520
#else
15211521
#define HELPER_INFO_INIT(I) (&(I)->init)
15221522
#define HELPER_INFO_INIT_VAL(I) 1
1523-
#endif /* CONFIG_TCG_INTERPRETER */
1523+
#endif /* CONFIG_TCG_INTERPRETER || EMSCRIPTEN */
15241524

15251525
static inline bool arg_slot_reg_p(unsigned arg_slot)
15261526
{
@@ -1897,7 +1897,7 @@ void tcg_prologue_init(void)
18971897
s->code_buf = s->code_gen_ptr;
18981898
s->data_gen_ptr = NULL;
18991899

1900-
#ifndef CONFIG_TCG_INTERPRETER
1900+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
19011901
tcg_qemu_tb_exec = (tcg_prologue_fn *)tcg_splitwx_to_rx(s->code_ptr);
19021902
#endif
19031903

@@ -1916,7 +1916,7 @@ void tcg_prologue_init(void)
19161916
prologue_size = tcg_current_code_size(s);
19171917
perf_report_prologue(s->code_gen_ptr, prologue_size);
19181918

1919-
#ifndef CONFIG_TCG_INTERPRETER
1919+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
19201920
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
19211921
(uintptr_t)s->code_buf, prologue_size);
19221922
#endif
@@ -1953,7 +1953,7 @@ void tcg_prologue_init(void)
19531953
}
19541954
}
19551955

1956-
#ifndef CONFIG_TCG_INTERPRETER
1956+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
19571957
/*
19581958
* Assert that goto_ptr is implemented completely, setting an epilogue.
19591959
* For tci, we use NULL as the signal to return from the interpreter,
@@ -7055,7 +7055,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
70557055
return i;
70567056
}
70577057

7058-
#ifndef CONFIG_TCG_INTERPRETER
7058+
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(EMSCRIPTEN)
70597059
/* flush instruction cache */
70607060
flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf),
70617061
(uintptr_t)s->code_buf,

0 commit comments

Comments
 (0)