Skip to content

Commit 44d3d59

Browse files
authored
v: support a new CPU architecture s390x (#24107)
1 parent 592615c commit 44d3d59

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

vlib/v/ast/types.v

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub enum Language {
5151
arm32 // 32-bit arm
5252
rv64 // 64-bit risc-v
5353
rv32 // 32-bit risc-v
54+
s390x
5455
wasm32
5556
}
5657

@@ -75,6 +76,9 @@ pub fn pref_arch_to_table_language(pref_arch pref.Arch) Language {
7576
.i386 {
7677
.i386
7778
}
79+
.s390x {
80+
.s390x
81+
}
7882
.js_node, .js_browser, .js_freestanding {
7983
.js
8084
}

vlib/v/gen/c/cheaders.v

+18-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ static char __CLOSURE_GET_DATA_BYTES[] = {
143143
0x03, 0xA5, 0x0F, 0x00, // lw a0, 0(t6)
144144
0x67, 0x80, 0x00, 0x00 // ret
145145
};
146+
#elif defined (__V_s390x)
147+
static char __closure_thunk[] = {
148+
0xC0, 0x30, 0xFF, 0xFF, 0xE0, 0x00, // larl %r3, -16384
149+
0xE3, 0x40, 0x30, 0x00, 0x00, 0x04, // lg %r4, 0(%r3)
150+
0xE3, 0x30, 0x30, 0x08, 0x00, 0x04, // lg %r3, 8(%r3)
151+
0x07, 0xF3, // br %r3
152+
};
153+
static char __CLOSURE_GET_DATA_BYTES[] = {
154+
0xB9, 0x04, 0x00, 0x24, // lgr %r2, %r4
155+
0x07, 0xFE, // br %r14
156+
};
146157
#endif
147158
148159
static void*(*__CLOSURE_GET_DATA)(void) = 0;
@@ -301,6 +312,12 @@ const c_common_macros = '
301312
#define __V_architecture 6
302313
#endif
303314
315+
#if defined(__s390x__)
316+
#define __V_s390x 1
317+
#undef __V_architecture
318+
#define __V_architecture 7
319+
#endif
320+
304321
// Using just __GNUC__ for detecting gcc, is not reliable because other compilers define it too:
305322
#ifdef __GNUC__
306323
#define __V_GCC__
@@ -658,7 +675,7 @@ static void* g_live_info = NULL;
658675

659676
const c_builtin_types = '
660677
//================================== builtin types ================================*/
661-
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || (defined(__riscv_xlen) && __riscv_xlen == 64)
678+
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || (defined(__riscv_xlen) && __riscv_xlen == 64) || defined(__s390x__)
662679
typedef int64_t vint_t;
663680
#else
664681
typedef int32_t vint_t;

vlib/v/gen/c/comptime.v

+3
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,9 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) !strin
12801280
'rv64', 'riscv64' {
12811281
return '__V_rv64'
12821282
}
1283+
's390x' {
1284+
return '__V_s390x'
1285+
}
12831286
// bitness:
12841287
'x64' {
12851288
return 'TARGET_IS_64BIT'

vlib/v/pref/arch.c.v

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub enum Arch {
88
rv64 // 64-bit risc-v
99
rv32 // 32-bit risc-v
1010
i386
11+
s390x
1112
js_node
1213
js_browser
1314
js_freestanding
@@ -48,6 +49,9 @@ pub fn arch_from_string(arch_str string) !Arch {
4849
'x86_32', 'x32', 'i386', 'IA-32', 'ia-32', 'ia32' { // i386 recommended
4950
return .i386
5051
}
52+
's390x' {
53+
return .s390x
54+
}
5155
'js', 'js_node' {
5256
return .js_node
5357
}

0 commit comments

Comments
 (0)