Skip to content

Commit 4872e3c

Browse files
authored
cgen,ast: add s390x assembly support + test (#24129)
1 parent b1ab54b commit 4872e3c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

vlib/v/ast/ast.v

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,13 @@ pub const riscv_with_number_register_list = {
18261826
'a#': 8
18271827
}
18281828

1829+
pub const s390x_no_number_register_list = []string{}
1830+
pub const s390x_with_number_register_list = {
1831+
'f#': 16
1832+
'r#': 16
1833+
'v#': 32
1834+
}
1835+
18291836
pub struct DebuggerStmt {
18301837
pub:
18311838
pos token.Pos
@@ -2631,6 +2638,13 @@ pub fn all_registers(mut t Table, arch pref.Arch) map[string]ScopeObject {
26312638
res[k] = v
26322639
}
26332640
}
2641+
.s390x {
2642+
s390x := gen_all_registers(mut t, s390x_no_number_register_list, s390x_with_number_register_list,
2643+
64)
2644+
for k, v in s390x {
2645+
res[k] = v
2646+
}
2647+
}
26342648
.wasm32 {
26352649
// no registers
26362650
}

vlib/v/gen/c/cgen.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,8 @@ fn (mut g Gen) asm_stmt(stmt ast.AsmStmt) {
31663166
g.write(' ')
31673167
}
31683168
// swap destination and operands for att syntax, not for arm64
3169-
if template.args.len != 0 && !template.is_directive && stmt.arch != .arm64 {
3169+
if template.args.len != 0 && !template.is_directive && stmt.arch != .arm64
3170+
&& stmt.arch != .s390x {
31703171
template.args.prepend(template.args.last())
31713172
template.args.delete(template.args.len - 1)
31723173
}
@@ -3243,6 +3244,8 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) {
32433244
ast.IntegerLiteral {
32443245
if stmt.arch == .arm64 {
32453246
g.write('#${arg.val}')
3247+
} else if stmt.arch == .s390x {
3248+
g.write('${arg.val}')
32463249
} else {
32473250
g.write('\$${arg.val}')
32483251
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// vtest build: gcc
2+
fn test_inline_asm() {
3+
a, mut b := 10, 0
4+
asm s390x {
5+
lgr r2, a
6+
lgr b, r2
7+
; +r (b)
8+
; r (a)
9+
; r2
10+
}
11+
assert a == b
12+
13+
mut c := 0
14+
asm s390x {
15+
lgfi c, 5
16+
; +r (c)
17+
}
18+
assert c == 5
19+
20+
d, e, mut f := 10, 2, 0
21+
asm s390x {
22+
lgr f, d
23+
ar f, e
24+
ahi f, 5
25+
; +r (f)
26+
; r (d)
27+
r (e)
28+
}
29+
assert d == 10
30+
assert e == 2
31+
assert f == 17
32+
}

0 commit comments

Comments
 (0)