1 | The following changes since commit 8f860d2633baf9c2b6261f703f86e394c6bc22ca: | 1 | The following changes since commit 67e41fe0cfb62e6cdfa659f0155417d17e5274ea: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-04-30' into staging (2021-04-30 16:02:00 +0100) | 3 | Merge tag 'pull-ppc-20220104' of https://github.com/legoater/qemu into staging (2022-01-04 07:23:27 -0800) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20210501 | 7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220104 |
8 | 8 | ||
9 | for you to fetch changes up to af93ccacc772019298be4c3e47251cdaa60d0c21: | 9 | for you to fetch changes up to d7478d4229f0a2b2817a55487e6b17081099fae4: |
10 | 10 | ||
11 | decodetree: Extend argument set syntax to allow types (2021-05-01 11:45:35 -0700) | 11 | common-user: Fix tail calls to safe_syscall_set_errno_tail (2022-01-04 15:41:03 -0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Include cleanups. | 14 | Fix for safe_syscall_base. |
15 | Decodetree enhancements for power10. | 15 | Fix for folding of vector add/sub. |
16 | Fix build on loongarch64 with gcc 8. | ||
17 | Remove decl for qemu_run_machine_init_done_notifiers. | ||
16 | 18 | ||
17 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
18 | Luis Fernando Fujita Pires (1): | 20 | Philippe Mathieu-Daudé (1): |
19 | decodetree: Add support for 64-bit instructions | 21 | linux-user: Fix trivial build error on loongarch64 hosts |
20 | 22 | ||
21 | Philippe Mathieu-Daudé (1): | 23 | Richard Henderson (2): |
22 | exec: Remove accel/tcg/ from include paths | 24 | tcg/optimize: Fix folding of vector ops |
25 | common-user: Fix tail calls to safe_syscall_set_errno_tail | ||
23 | 26 | ||
24 | Richard Henderson (3): | 27 | Xiaoyao Li (1): |
25 | decodetree: Introduce whex and whexC helpers | 28 | sysemu: Cleanup qemu_run_machine_init_done_notifiers() |
26 | decodetree: More use of f-strings | ||
27 | decodetree: Extend argument set syntax to allow types | ||
28 | 29 | ||
29 | docs/devel/decodetree.rst | 11 ++- | 30 | include/sysemu/sysemu.h | 1 - |
30 | meson.build | 1 - | 31 | linux-user/host/loongarch64/host-signal.h | 4 +-- |
31 | include/exec/helper-gen.h | 4 +- | 32 | tcg/optimize.c | 49 +++++++++++++++++++++++------- |
32 | include/exec/helper-proto.h | 4 +- | 33 | common-user/host/i386/safe-syscall.inc.S | 1 + |
33 | include/exec/helper-tcg.h | 4 +- | 34 | common-user/host/mips/safe-syscall.inc.S | 1 + |
34 | tests/decode/succ_argset_type1.decode | 1 + | 35 | common-user/host/x86_64/safe-syscall.inc.S | 1 + |
35 | scripts/decodetree.py | 172 +++++++++++++++++++--------------- | 36 | 6 files changed, 42 insertions(+), 15 deletions(-) |
36 | 7 files changed, 112 insertions(+), 85 deletions(-) | ||
37 | create mode 100644 tests/decode/succ_argset_type1.decode | ||
38 | 37 | diff view generated by jsdifflib |
1 | From: Luis Fernando Fujita Pires <luis.pires@eldorado.org.br> | 1 | Bitwise operations are easy to fold, because the operation is |
---|---|---|---|
2 | identical regardless of element size. But add and sub need | ||
3 | extra element size info that is not currently propagated. | ||
2 | 4 | ||
3 | Allow '64' to be specified for the instruction width command line params | 5 | Fixes: 2f9f08ba43d |
4 | and use the appropriate extract and deposit functions in that case. | 6 | Cc: qemu-stable@nongnu.org |
5 | 7 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/799 | |
6 | This will be used to implement the new 64-bit Power ISA 3.1 instructions. | ||
7 | |||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> | ||
10 | Message-Id: <CP2PR80MB3668E123E2EFDB0ACD3A46F1DA759@CP2PR80MB3668.lamprd80.prod.outlook.com> | ||
11 | [rth: Drop the change to the field type; use bitop_width instead of separate | ||
12 | variables for extract/deposit; use "ull" for 64-bit constants.] | ||
13 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 10 | --- |
16 | scripts/decodetree.py | 21 ++++++++++++++------- | 11 | tcg/optimize.c | 49 ++++++++++++++++++++++++++++++++++++++----------- |
17 | 1 file changed, 14 insertions(+), 7 deletions(-) | 12 | 1 file changed, 38 insertions(+), 11 deletions(-) |
18 | 13 | ||
19 | diff --git a/scripts/decodetree.py b/scripts/decodetree.py | 14 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
20 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/scripts/decodetree.py | 16 | --- a/tcg/optimize.c |
22 | +++ b/scripts/decodetree.py | 17 | +++ b/tcg/optimize.c |
23 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) |
24 | import getopt | 19 | CASE_OP_32_64(mul): |
25 | 20 | return x * y; | |
26 | insnwidth = 32 | 21 | |
27 | +bitop_width = 32 | 22 | - CASE_OP_32_64(and): |
28 | insnmask = 0xffffffff | 23 | + CASE_OP_32_64_VEC(and): |
29 | variablewidth = False | 24 | return x & y; |
30 | fields = {} | 25 | |
31 | @@ -XXX,XX +XXX,XX @@ def whexC(val): | 26 | - CASE_OP_32_64(or): |
32 | """Return a hex string for val padded for insnwidth, | 27 | + CASE_OP_32_64_VEC(or): |
33 | and with the proper suffix for a C constant.""" | 28 | return x | y; |
34 | suffix = '' | 29 | |
35 | - if val >= 0x80000000: | 30 | - CASE_OP_32_64(xor): |
36 | + if val >= 0x100000000: | 31 | + CASE_OP_32_64_VEC(xor): |
37 | + suffix = 'ull' | 32 | return x ^ y; |
38 | + elif val >= 0x80000000: | 33 | |
39 | suffix = 'u' | 34 | case INDEX_op_shl_i32: |
40 | return whex(val) + suffix | 35 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) |
41 | 36 | case INDEX_op_rotl_i64: | |
42 | @@ -XXX,XX +XXX,XX @@ def __str__(self): | 37 | return rol64(x, y & 63); |
43 | return str(self.pos) + ':' + s + str(self.len) | 38 | |
44 | 39 | - CASE_OP_32_64(not): | |
45 | def str_extract(self): | 40 | + CASE_OP_32_64_VEC(not): |
46 | - if self.sign: | 41 | return ~x; |
47 | - extr = 'sextract32' | 42 | |
48 | - else: | 43 | CASE_OP_32_64(neg): |
49 | - extr = 'extract32' | 44 | return -x; |
50 | - return f'{extr}(insn, {self.pos}, {self.len})' | 45 | |
51 | + global bitop_width | 46 | - CASE_OP_32_64(andc): |
52 | + s = 's' if self.sign else '' | 47 | + CASE_OP_32_64_VEC(andc): |
53 | + return f'{s}extract{bitop_width}(insn, {self.pos}, {self.len})' | 48 | return x & ~y; |
54 | 49 | ||
55 | def __eq__(self, other): | 50 | - CASE_OP_32_64(orc): |
56 | return self.sign == other.sign and self.mask == other.mask | 51 | + CASE_OP_32_64_VEC(orc): |
57 | @@ -XXX,XX +XXX,XX @@ def __str__(self): | 52 | return x | ~y; |
58 | return str(self.subs) | 53 | |
59 | 54 | CASE_OP_32_64(eqv): | |
60 | def str_extract(self): | 55 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
61 | + global bitop_width | 56 | return false; |
62 | ret = '0' | 57 | } |
63 | pos = 0 | 58 | |
64 | for f in reversed(self.subs): | 59 | +static bool fold_commutative(OptContext *ctx, TCGOp *op) |
65 | @@ -XXX,XX +XXX,XX @@ def str_extract(self): | 60 | +{ |
66 | if pos == 0: | 61 | + swap_commutative(op->args[0], &op->args[1], &op->args[2]); |
67 | ret = ext | 62 | + return false; |
68 | else: | 63 | +} |
69 | - ret = f'deposit32({ret}, {pos}, {32 - pos}, {ext})' | 64 | + |
70 | + ret = f'deposit{bitop_width}({ret}, {pos}, {bitop_width - pos}, {ext})' | 65 | static bool fold_const2_commutative(OptContext *ctx, TCGOp *op) |
71 | pos += f.len | 66 | { |
72 | return ret | 67 | swap_commutative(op->args[0], &op->args[1], &op->args[2]); |
73 | 68 | @@ -XXX,XX +XXX,XX @@ static bool fold_add(OptContext *ctx, TCGOp *op) | |
74 | @@ -XXX,XX +XXX,XX @@ def main(): | 69 | return false; |
75 | global insntype | 70 | } |
76 | global insnmask | 71 | |
77 | global decode_function | 72 | +/* We cannot as yet do_constant_folding with vectors. */ |
78 | + global bitop_width | 73 | +static bool fold_add_vec(OptContext *ctx, TCGOp *op) |
79 | global variablewidth | 74 | +{ |
80 | global anyextern | 75 | + if (fold_commutative(ctx, op) || |
81 | 76 | + fold_xi_to_x(ctx, op, 0)) { | |
82 | @@ -XXX,XX +XXX,XX @@ def main(): | 77 | + return true; |
83 | if insnwidth == 16: | 78 | + } |
84 | insntype = 'uint16_t' | 79 | + return false; |
85 | insnmask = 0xffff | 80 | +} |
86 | + elif insnwidth == 64: | 81 | + |
87 | + insntype = 'uint64_t' | 82 | static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) |
88 | + insnmask = 0xffffffffffffffff | 83 | { |
89 | + bitop_width = 64 | 84 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && |
90 | elif insnwidth != 32: | 85 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) |
91 | error(0, 'cannot handle insns of width', insnwidth) | 86 | return false; |
92 | else: | 87 | } |
88 | |||
89 | -static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
90 | +/* We cannot as yet do_constant_folding with vectors. */ | ||
91 | +static bool fold_sub_vec(OptContext *ctx, TCGOp *op) | ||
92 | { | ||
93 | - if (fold_const2(ctx, op) || | ||
94 | - fold_xx_to_i(ctx, op, 0) || | ||
95 | + if (fold_xx_to_i(ctx, op, 0) || | ||
96 | fold_xi_to_x(ctx, op, 0) || | ||
97 | fold_sub_to_neg(ctx, op)) { | ||
98 | return true; | ||
99 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | +static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
104 | +{ | ||
105 | + return fold_const2(ctx, op) || fold_sub_vec(ctx, op); | ||
106 | +} | ||
107 | + | ||
108 | static bool fold_sub2(OptContext *ctx, TCGOp *op) | ||
109 | { | ||
110 | return fold_addsub2(ctx, op, false); | ||
111 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
112 | * Sorted alphabetically by opcode as much as possible. | ||
113 | */ | ||
114 | switch (opc) { | ||
115 | - CASE_OP_32_64_VEC(add): | ||
116 | + CASE_OP_32_64(add): | ||
117 | done = fold_add(&ctx, op); | ||
118 | break; | ||
119 | + case INDEX_op_add_vec: | ||
120 | + done = fold_add_vec(&ctx, op); | ||
121 | + break; | ||
122 | CASE_OP_32_64(add2): | ||
123 | done = fold_add2(&ctx, op); | ||
124 | break; | ||
125 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
126 | CASE_OP_32_64(sextract): | ||
127 | done = fold_sextract(&ctx, op); | ||
128 | break; | ||
129 | - CASE_OP_32_64_VEC(sub): | ||
130 | + CASE_OP_32_64(sub): | ||
131 | done = fold_sub(&ctx, op); | ||
132 | break; | ||
133 | + case INDEX_op_sub_vec: | ||
134 | + done = fold_sub_vec(&ctx, op); | ||
135 | + break; | ||
136 | CASE_OP_32_64(sub2): | ||
137 | done = fold_sub2(&ctx, op); | ||
138 | break; | ||
93 | -- | 139 | -- |
94 | 2.25.1 | 140 | 2.25.1 |
95 | 141 | ||
96 | 142 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | When TCG is enabled, the accel/tcg/ include path is added to the | 3 | When building using GCC 8.3.0 on loongarch64 (Loongnix) we get: |
4 | project global include search list. This accel/tcg/ directory | ||
5 | contains a header named "internal.h" which, while intented to | ||
6 | be internal to accel/tcg/, is accessible by all files compiled | ||
7 | when TCG is enabled. This might lead to problem with other | ||
8 | directories using the same "internal.h" header name: | ||
9 | 4 | ||
10 | $ git ls-files | fgrep /internal.h | 5 | In file included from ../linux-user/signal.c:33: |
11 | accel/tcg/internal.h | 6 | ../linux-user/host/loongarch64/host-signal.h: In function ‘host_signal_write’: |
12 | include/hw/ide/internal.h | 7 | ../linux-user/host/loongarch64/host-signal.h:57:9: error: a label can only be part of a statement and a declaration is not a statement |
13 | target/hexagon/internal.h | 8 | uint32_t sel = (insn >> 15) & 0b11111111111; |
14 | target/mips/internal.h | 9 | ^~~~~~~~ |
15 | target/ppc/internal.h | ||
16 | target/s390x/internal.h | ||
17 | 10 | ||
18 | As we don't need to expose accel/tcg/ internals to the rest of | 11 | We don't use the 'sel' variable more than once, so drop it. |
19 | the code base, simplify by removing it from the include search | ||
20 | list, and include the accel/tcg/ public headers relative to the | ||
21 | project root search path (which is already in the generic include | ||
22 | search path). | ||
23 | 12 | ||
13 | Meson output for the record: | ||
14 | |||
15 | Host machine cpu family: loongarch64 | ||
16 | Host machine cpu: loongarch64 | ||
17 | C compiler for the host machine: cc (gcc 8.3.0 "cc (Loongnix 8.3.0-6.lnd.vec.27) 8.3.0") | ||
18 | C linker for the host machine: cc ld.bfd 2.31.1-system | ||
19 | |||
20 | Fixes: ad812c3bd65 ("linux-user: Implement CPU-specific signal handler for loongarch64 hosts") | ||
21 | Reported-by: Song Gao <gaosong@loongson.cn> | ||
22 | Suggested-by: Song Gao <gaosong@loongson.cn> | ||
24 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 23 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
25 | Reviewed-by: Claudio Fontana <cfontana@suse.de> | 24 | Reviewed-by: WANG Xuerui <git@xen0n.name> |
26 | Message-Id: <20210413081008.3409459-1-f4bug@amsat.org> | 25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
26 | Message-Id: <20220104215027.2180972-1-f4bug@amsat.org> | ||
27 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 27 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
28 | --- | 28 | --- |
29 | meson.build | 1 - | 29 | linux-user/host/loongarch64/host-signal.h | 4 +--- |
30 | include/exec/helper-gen.h | 4 ++-- | 30 | 1 file changed, 1 insertion(+), 3 deletions(-) |
31 | include/exec/helper-proto.h | 4 ++-- | ||
32 | include/exec/helper-tcg.h | 4 ++-- | ||
33 | 4 files changed, 6 insertions(+), 7 deletions(-) | ||
34 | 31 | ||
35 | diff --git a/meson.build b/meson.build | 32 | diff --git a/linux-user/host/loongarch64/host-signal.h b/linux-user/host/loongarch64/host-signal.h |
36 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/meson.build | 34 | --- a/linux-user/host/loongarch64/host-signal.h |
38 | +++ b/meson.build | 35 | +++ b/linux-user/host/loongarch64/host-signal.h |
39 | @@ -XXX,XX +XXX,XX @@ if not get_option('tcg').disabled() | 36 | @@ -XXX,XX +XXX,XX @@ static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc) |
40 | tcg_arch = 'riscv' | 37 | } |
41 | endif | 38 | break; |
42 | add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch, | 39 | case 0b001110: /* indexed, atomic, bounds-checking memory operations */ |
43 | - '-iquote', meson.current_source_dir() / 'accel/tcg', | 40 | - uint32_t sel = (insn >> 15) & 0b11111111111; |
44 | language: ['c', 'cpp', 'objc']) | 41 | - |
45 | 42 | - switch (sel) { | |
46 | accelerators += 'CONFIG_TCG' | 43 | + switch ((insn >> 15) & 0b11111111111) { |
47 | diff --git a/include/exec/helper-gen.h b/include/exec/helper-gen.h | 44 | case 0b00000100000: /* stx.b */ |
48 | index XXXXXXX..XXXXXXX 100644 | 45 | case 0b00000101000: /* stx.h */ |
49 | --- a/include/exec/helper-gen.h | 46 | case 0b00000110000: /* stx.w */ |
50 | +++ b/include/exec/helper-gen.h | ||
51 | @@ -XXX,XX +XXX,XX @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ | ||
52 | #include "helper.h" | ||
53 | #include "trace/generated-helpers.h" | ||
54 | #include "trace/generated-helpers-wrappers.h" | ||
55 | -#include "tcg-runtime.h" | ||
56 | -#include "plugin-helpers.h" | ||
57 | +#include "accel/tcg/tcg-runtime.h" | ||
58 | +#include "accel/tcg/plugin-helpers.h" | ||
59 | |||
60 | #undef DEF_HELPER_FLAGS_0 | ||
61 | #undef DEF_HELPER_FLAGS_1 | ||
62 | diff --git a/include/exec/helper-proto.h b/include/exec/helper-proto.h | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/include/exec/helper-proto.h | ||
65 | +++ b/include/exec/helper-proto.h | ||
66 | @@ -XXX,XX +XXX,XX @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ | ||
67 | |||
68 | #include "helper.h" | ||
69 | #include "trace/generated-helpers.h" | ||
70 | -#include "tcg-runtime.h" | ||
71 | -#include "plugin-helpers.h" | ||
72 | +#include "accel/tcg/tcg-runtime.h" | ||
73 | +#include "accel/tcg/plugin-helpers.h" | ||
74 | |||
75 | #undef IN_HELPER_PROTO | ||
76 | |||
77 | diff --git a/include/exec/helper-tcg.h b/include/exec/helper-tcg.h | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/include/exec/helper-tcg.h | ||
80 | +++ b/include/exec/helper-tcg.h | ||
81 | @@ -XXX,XX +XXX,XX @@ | ||
82 | |||
83 | #include "helper.h" | ||
84 | #include "trace/generated-helpers.h" | ||
85 | -#include "tcg-runtime.h" | ||
86 | -#include "plugin-helpers.h" | ||
87 | +#include "accel/tcg/tcg-runtime.h" | ||
88 | +#include "accel/tcg/plugin-helpers.h" | ||
89 | |||
90 | #undef str | ||
91 | #undef DEF_HELPER_FLAGS_0 | ||
92 | -- | 47 | -- |
93 | 2.25.1 | 48 | 2.25.1 |
94 | 49 | ||
95 | 50 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Form a hex constant of the appropriate insnwidth. | ||
2 | Begin using f-strings on changed lines. | ||
3 | 1 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | scripts/decodetree.py | 66 +++++++++++++++++++++++++------------------ | ||
8 | 1 file changed, 38 insertions(+), 28 deletions(-) | ||
9 | |||
10 | diff --git a/scripts/decodetree.py b/scripts/decodetree.py | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/scripts/decodetree.py | ||
13 | +++ b/scripts/decodetree.py | ||
14 | @@ -XXX,XX +XXX,XX @@ def str_fields(fields): | ||
15 | return r[1:] | ||
16 | |||
17 | |||
18 | +def whex(val): | ||
19 | + """Return a hex string for val padded for insnwidth""" | ||
20 | + global insnwidth | ||
21 | + return f'0x{val:0{insnwidth // 4}x}' | ||
22 | + | ||
23 | + | ||
24 | +def whexC(val): | ||
25 | + """Return a hex string for val padded for insnwidth, | ||
26 | + and with the proper suffix for a C constant.""" | ||
27 | + suffix = '' | ||
28 | + if val >= 0x80000000: | ||
29 | + suffix = 'u' | ||
30 | + return whex(val) + suffix | ||
31 | + | ||
32 | + | ||
33 | def str_match_bits(bits, mask): | ||
34 | """Return a string pretty-printing BITS/MASK""" | ||
35 | global insnwidth | ||
36 | @@ -XXX,XX +XXX,XX @@ def output_code(self, i, extracted, outerbits, outermask): | ||
37 | if outermask != p.fixedmask: | ||
38 | innermask = p.fixedmask & ~outermask | ||
39 | innerbits = p.fixedbits & ~outermask | ||
40 | - output(ind, 'if ((insn & ', | ||
41 | - '0x{0:08x}) == 0x{1:08x}'.format(innermask, innerbits), | ||
42 | - ') {\n') | ||
43 | - output(ind, ' /* ', | ||
44 | - str_match_bits(p.fixedbits, p.fixedmask), ' */\n') | ||
45 | + output(ind, f'if ((insn & {whexC(innermask)}) == {whexC(innerbits)}) {{\n') | ||
46 | + output(ind, f' /* {str_match_bits(p.fixedbits, p.fixedmask)} */\n') | ||
47 | p.output_code(i + 4, extracted, p.fixedbits, p.fixedmask) | ||
48 | output(ind, '}\n') | ||
49 | else: | ||
50 | @@ -XXX,XX +XXX,XX @@ def __init__(self, fm, tm): | ||
51 | |||
52 | def str1(self, i): | ||
53 | ind = str_indent(i) | ||
54 | - r = '{0}{1:08x}'.format(ind, self.fixedmask) | ||
55 | + r = ind + whex(self.fixedmask) | ||
56 | if self.format: | ||
57 | r += ' ' + self.format.name | ||
58 | r += ' [\n' | ||
59 | for (b, s) in self.subs: | ||
60 | - r += '{0} {1:08x}:\n'.format(ind, b) | ||
61 | + r += ind + f' {whex(b)}:\n' | ||
62 | r += s.str1(i + 4) + '\n' | ||
63 | r += ind + ']' | ||
64 | return r | ||
65 | @@ -XXX,XX +XXX,XX @@ def output_code(self, i, extracted, outerbits, outermask): | ||
66 | if sh > 0: | ||
67 | # Propagate SH down into the local functions. | ||
68 | def str_switch(b, sh=sh): | ||
69 | - return '(insn >> {0}) & 0x{1:x}'.format(sh, b >> sh) | ||
70 | + return f'(insn >> {sh}) & {b >> sh:#x}' | ||
71 | |||
72 | def str_case(b, sh=sh): | ||
73 | - return '0x{0:x}'.format(b >> sh) | ||
74 | + return hex(b >> sh) | ||
75 | else: | ||
76 | def str_switch(b): | ||
77 | - return 'insn & 0x{0:08x}'.format(b) | ||
78 | + return f'insn & {whexC(b)}' | ||
79 | |||
80 | def str_case(b): | ||
81 | - return '0x{0:08x}'.format(b) | ||
82 | + return whexC(b) | ||
83 | |||
84 | output(ind, 'switch (', str_switch(self.thismask), ') {\n') | ||
85 | for b, s in sorted(self.subs): | ||
86 | @@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks): | ||
87 | |||
88 | # Validate the masks that we have assembled. | ||
89 | if fieldmask & fixedmask: | ||
90 | - error(lineno, 'fieldmask overlaps fixedmask (0x{0:08x} & 0x{1:08x})' | ||
91 | - .format(fieldmask, fixedmask)) | ||
92 | + error(lineno, 'fieldmask overlaps fixedmask ', | ||
93 | + f'({whex(fieldmask)} & {whex(fixedmask)})') | ||
94 | if fieldmask & undefmask: | ||
95 | - error(lineno, 'fieldmask overlaps undefmask (0x{0:08x} & 0x{1:08x})' | ||
96 | - .format(fieldmask, undefmask)) | ||
97 | + error(lineno, 'fieldmask overlaps undefmask ', | ||
98 | + f'({whex(fieldmask)} & {whex(undefmask)})') | ||
99 | if fixedmask & undefmask: | ||
100 | - error(lineno, 'fixedmask overlaps undefmask (0x{0:08x} & 0x{1:08x})' | ||
101 | - .format(fixedmask, undefmask)) | ||
102 | + error(lineno, 'fixedmask overlaps undefmask ', | ||
103 | + f'({whex(fixedmask)} & {whex(undefmask)})') | ||
104 | if not is_format: | ||
105 | allbits = fieldmask | fixedmask | undefmask | ||
106 | if allbits != insnmask: | ||
107 | - error(lineno, 'bits left unspecified (0x{0:08x})' | ||
108 | - .format(allbits ^ insnmask)) | ||
109 | + error(lineno, 'bits left unspecified ', | ||
110 | + f'({whex(allbits ^ insnmask)})') | ||
111 | # end parse_general | ||
112 | |||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ def __init__(self, m, w): | ||
115 | |||
116 | def str1(self, i): | ||
117 | ind = str_indent(i) | ||
118 | - r = '{0}{1:08x}'.format(ind, self.mask) | ||
119 | - r += ' [\n' | ||
120 | + r = ind + whex(self.mask) + ' [\n' | ||
121 | for (b, s) in self.subs: | ||
122 | - r += '{0} {1:08x}:\n'.format(ind, b) | ||
123 | + r += ind + f' {whex(b)}:\n' | ||
124 | r += s.str1(i + 4) + '\n' | ||
125 | r += ind + ']' | ||
126 | return r | ||
127 | @@ -XXX,XX +XXX,XX @@ def output_code(self, i, extracted, outerbits, outermask): | ||
128 | if sh > 0: | ||
129 | # Propagate SH down into the local functions. | ||
130 | def str_switch(b, sh=sh): | ||
131 | - return '(insn >> {0}) & 0x{1:x}'.format(sh, b >> sh) | ||
132 | + return f'(insn >> {sh}) & {b >> sh:#x}' | ||
133 | |||
134 | def str_case(b, sh=sh): | ||
135 | - return '0x{0:x}'.format(b >> sh) | ||
136 | + return hex(b >> sh) | ||
137 | else: | ||
138 | def str_switch(b): | ||
139 | - return 'insn & 0x{0:08x}'.format(b) | ||
140 | + return f'insn & {whexC(b)}' | ||
141 | |||
142 | def str_case(b): | ||
143 | - return '0x{0:08x}'.format(b) | ||
144 | + return whexC(b) | ||
145 | |||
146 | output(ind, 'switch (', str_switch(self.mask), ') {\n') | ||
147 | for b, s in sorted(self.subs): | ||
148 | @@ -XXX,XX +XXX,XX @@ def __init__(self, m, w): | ||
149 | self.width = w | ||
150 | |||
151 | def str1(self, i): | ||
152 | - ind = str_indent(i) | ||
153 | - return '{0}{1:08x}'.format(ind, self.mask) | ||
154 | + return str_indent(i) + whex(self.mask) | ||
155 | |||
156 | def __str__(self): | ||
157 | return self.str1(0) | ||
158 | -- | ||
159 | 2.25.1 | ||
160 | |||
161 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Xiaoyao Li <xiaoyao.li@intel.com> |
---|---|---|---|
2 | |||
3 | Remove qemu_run_machine_init_done_notifiers() since no implementation | ||
4 | and user. | ||
5 | |||
6 | Fixes: f66dc8737c9 ("vl: move all generic initialization out of vl.c") | ||
7 | Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-Id: <20220104024136.1433545-1-xiaoyao.li@intel.com> | ||
2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
3 | --- | 11 | --- |
4 | scripts/decodetree.py | 50 ++++++++++++++++++++----------------------- | 12 | include/sysemu/sysemu.h | 1 - |
5 | 1 file changed, 23 insertions(+), 27 deletions(-) | 13 | 1 file changed, 1 deletion(-) |
6 | 14 | ||
7 | diff --git a/scripts/decodetree.py b/scripts/decodetree.py | 15 | diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h |
8 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
9 | --- a/scripts/decodetree.py | 17 | --- a/include/sysemu/sysemu.h |
10 | +++ b/scripts/decodetree.py | 18 | +++ b/include/sysemu/sysemu.h |
11 | @@ -XXX,XX +XXX,XX @@ def error_with_file(file, lineno, *args): | 19 | @@ -XXX,XX +XXX,XX @@ extern bool qemu_uuid_set; |
12 | 20 | void qemu_add_exit_notifier(Notifier *notify); | |
13 | prefix = '' | 21 | void qemu_remove_exit_notifier(Notifier *notify); |
14 | if file: | 22 | |
15 | - prefix += '{0}:'.format(file) | 23 | -void qemu_run_machine_init_done_notifiers(void); |
16 | + prefix += f'{file}:' | 24 | void qemu_add_machine_init_done_notifier(Notifier *notify); |
17 | if lineno: | 25 | void qemu_remove_machine_init_done_notifier(Notifier *notify); |
18 | - prefix += '{0}:'.format(lineno) | 26 | |
19 | + prefix += f'{lineno}:' | ||
20 | if prefix: | ||
21 | prefix += ' ' | ||
22 | print(prefix, end='error: ', file=sys.stderr) | ||
23 | @@ -XXX,XX +XXX,XX @@ def str_extract(self): | ||
24 | extr = 'sextract32' | ||
25 | else: | ||
26 | extr = 'extract32' | ||
27 | - return '{0}(insn, {1}, {2})'.format(extr, self.pos, self.len) | ||
28 | + return f'{extr}(insn, {self.pos}, {self.len})' | ||
29 | |||
30 | def __eq__(self, other): | ||
31 | return self.sign == other.sign and self.mask == other.mask | ||
32 | @@ -XXX,XX +XXX,XX @@ def str_extract(self): | ||
33 | ret = '0' | ||
34 | pos = 0 | ||
35 | for f in reversed(self.subs): | ||
36 | + ext = f.str_extract() | ||
37 | if pos == 0: | ||
38 | - ret = f.str_extract() | ||
39 | + ret = ext | ||
40 | else: | ||
41 | - ret = 'deposit32({0}, {1}, {2}, {3})' \ | ||
42 | - .format(ret, pos, 32 - pos, f.str_extract()) | ||
43 | + ret = f'deposit32({ret}, {pos}, {32 - pos}, {ext})' | ||
44 | pos += f.len | ||
45 | return ret | ||
46 | |||
47 | @@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks): | ||
48 | subtoks = t.split(':') | ||
49 | sign = False | ||
50 | else: | ||
51 | - error(lineno, 'invalid field token "{0}"'.format(t)) | ||
52 | + error(lineno, f'invalid field token "{t}"') | ||
53 | po = int(subtoks[0]) | ||
54 | le = int(subtoks[1]) | ||
55 | if po + le > insnwidth: | ||
56 | - error(lineno, 'field {0} too large'.format(t)) | ||
57 | + error(lineno, f'field {t} too large') | ||
58 | f = Field(sign, po, le) | ||
59 | subs.append(f) | ||
60 | width += le | ||
61 | @@ -XXX,XX +XXX,XX @@ def parse_arguments(lineno, name, toks): | ||
62 | anyextern = True | ||
63 | continue | ||
64 | if not re.fullmatch(re_C_ident, t): | ||
65 | - error(lineno, 'invalid argument set token "{0}"'.format(t)) | ||
66 | + error(lineno, f'invalid argument set token "{t}"') | ||
67 | if t in flds: | ||
68 | - error(lineno, 'duplicate argument "{0}"'.format(t)) | ||
69 | + error(lineno, f'duplicate argument "{t}"') | ||
70 | flds.append(t) | ||
71 | |||
72 | if name in arguments: | ||
73 | @@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks): | ||
74 | flen = flen[1:] | ||
75 | shift = int(flen, 10) | ||
76 | if shift + width > insnwidth: | ||
77 | - error(lineno, 'field {0} exceeds insnwidth'.format(fname)) | ||
78 | + error(lineno, f'field {fname} exceeds insnwidth') | ||
79 | f = Field(sign, insnwidth - width - shift, shift) | ||
80 | flds = add_field(lineno, flds, fname, f) | ||
81 | fixedbits <<= shift | ||
82 | fixedmask <<= shift | ||
83 | undefmask <<= shift | ||
84 | else: | ||
85 | - error(lineno, 'invalid token "{0}"'.format(t)) | ||
86 | + error(lineno, f'invalid token "{t}"') | ||
87 | width += shift | ||
88 | |||
89 | if variablewidth and width < insnwidth and width % 8 == 0: | ||
90 | @@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks): | ||
91 | |||
92 | # We should have filled in all of the bits of the instruction. | ||
93 | elif not (is_format and width == 0) and width != insnwidth: | ||
94 | - error(lineno, 'definition has {0} bits'.format(width)) | ||
95 | + error(lineno, f'definition has {width} bits') | ||
96 | |||
97 | # Do not check for fields overlapping fields; one valid usage | ||
98 | # is to be able to duplicate fields via import. | ||
99 | @@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks): | ||
100 | if arg: | ||
101 | for f in flds.keys(): | ||
102 | if f not in arg.fields: | ||
103 | - error(lineno, 'field {0} not in argument set {1}' | ||
104 | - .format(f, arg.name)) | ||
105 | + error(lineno, f'field {f} not in argument set {arg.name}') | ||
106 | else: | ||
107 | arg = infer_argument_set(flds) | ||
108 | if name in formats: | ||
109 | @@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks): | ||
110 | arg = fmt.base | ||
111 | for f in flds.keys(): | ||
112 | if f not in arg.fields: | ||
113 | - error(lineno, 'field {0} not in argument set {1}' | ||
114 | - .format(f, arg.name)) | ||
115 | + error(lineno, f'field {f} not in argument set {arg.name}') | ||
116 | if f in fmt.fields.keys(): | ||
117 | - error(lineno, 'field {0} set by format and pattern'.format(f)) | ||
118 | + error(lineno, f'field {f} set by format and pattern') | ||
119 | for f in arg.fields: | ||
120 | if f not in flds.keys() and f not in fmt.fields.keys(): | ||
121 | - error(lineno, 'field {0} not initialized'.format(f)) | ||
122 | + error(lineno, f'field {f} not initialized') | ||
123 | pat = Pattern(name, lineno, fmt, fixedbits, fixedmask, | ||
124 | undefmask, fieldmask, flds, width) | ||
125 | parent_pat.pats.append(pat) | ||
126 | @@ -XXX,XX +XXX,XX @@ def parse_file(f, parent_pat): | ||
127 | elif re.fullmatch(re_pat_ident, name): | ||
128 | parse_generic(start_lineno, parent_pat, name, toks) | ||
129 | else: | ||
130 | - error(lineno, 'invalid token "{0}"'.format(name)) | ||
131 | + error(lineno, f'invalid token "{name}"') | ||
132 | toks = [] | ||
133 | |||
134 | if nesting != 0: | ||
135 | @@ -XXX,XX +XXX,XX @@ def output_code(self, i, extracted, outerbits, outermask): | ||
136 | |||
137 | # If we need to load more bytes to test, do so now. | ||
138 | if extracted < self.width: | ||
139 | - output(ind, 'insn = ', decode_function, | ||
140 | - '_load_bytes(ctx, insn, {0}, {1});\n' | ||
141 | - .format(extracted // 8, self.width // 8)); | ||
142 | + output(ind, f'insn = {decode_function}_load_bytes', | ||
143 | + f'(ctx, insn, {extracted // 8}, {self.width // 8});\n') | ||
144 | extracted = self.width | ||
145 | |||
146 | # Attempt to aid the compiler in producing compact switch statements. | ||
147 | @@ -XXX,XX +XXX,XX @@ def output_code(self, i, extracted, outerbits, outermask): | ||
148 | |||
149 | # If we need to load more bytes, do so now. | ||
150 | if extracted < self.width: | ||
151 | - output(ind, 'insn = ', decode_function, | ||
152 | - '_load_bytes(ctx, insn, {0}, {1});\n' | ||
153 | - .format(extracted // 8, self.width // 8)); | ||
154 | + output(ind, f'insn = {decode_function}_load_bytes', | ||
155 | + f'(ctx, insn, {extracted // 8}, {self.width // 8});\n') | ||
156 | extracted = self.width | ||
157 | output(ind, 'return insn;\n') | ||
158 | # end SizeLeaf | ||
159 | @@ -XXX,XX +XXX,XX @@ def build_size_tree(pats, width, outerbits, outermask): | ||
160 | for p in pats: | ||
161 | pnames.append(p.name + ':' + p.file + ':' + str(p.lineno)) | ||
162 | error_with_file(pats[0].file, pats[0].lineno, | ||
163 | - 'overlapping patterns size {0}:'.format(width), pnames) | ||
164 | + f'overlapping patterns size {width}:', pnames) | ||
165 | |||
166 | bins = {} | ||
167 | for i in pats: | ||
168 | -- | 27 | -- |
169 | 2.25.1 | 28 | 2.25.1 |
170 | 29 | ||
171 | 30 | diff view generated by jsdifflib |
1 | Rather than force all structure members to be 'int', | 1 | For the ABIs in which the syscall return register is not |
---|---|---|---|
2 | allow the type of the member to be specified. | 2 | also the first function argument register, move the errno |
3 | value into the correct place. | ||
3 | 4 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 5 | Fixes: a3310c0397e2 ("linux-user: Move syscall error detection into safe_syscall_base") |
6 | Reported-by: Laurent Vivier <laurent@vivier.eu> | ||
7 | Tested-by: Laurent Vivier <laurent@vivier.eu> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Message-Id: <20220104190454.542225-1-richard.henderson@linaro.org> | ||
6 | --- | 11 | --- |
7 | docs/devel/decodetree.rst | 11 ++++--- | 12 | common-user/host/i386/safe-syscall.inc.S | 1 + |
8 | tests/decode/succ_argset_type1.decode | 1 + | 13 | common-user/host/mips/safe-syscall.inc.S | 1 + |
9 | scripts/decodetree.py | 45 +++++++++++++++++---------- | 14 | common-user/host/x86_64/safe-syscall.inc.S | 1 + |
10 | 3 files changed, 36 insertions(+), 21 deletions(-) | 15 | 3 files changed, 3 insertions(+) |
11 | create mode 100644 tests/decode/succ_argset_type1.decode | ||
12 | 16 | ||
13 | diff --git a/docs/devel/decodetree.rst b/docs/devel/decodetree.rst | 17 | diff --git a/common-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S |
14 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/docs/devel/decodetree.rst | 19 | --- a/common-user/host/i386/safe-syscall.inc.S |
16 | +++ b/docs/devel/decodetree.rst | 20 | +++ b/common-user/host/i386/safe-syscall.inc.S |
17 | @@ -XXX,XX +XXX,XX @@ and returns an integral value extracted from there. | 21 | @@ -XXX,XX +XXX,XX @@ safe_syscall_end: |
18 | 22 | pop %ebp | |
19 | A field with no ``unnamed_fields`` and no ``!function`` is in error. | 23 | .cfi_adjust_cfa_offset -4 |
20 | 24 | .cfi_restore ebp | |
21 | -FIXME: the fields of the structure into which this result will be stored | 25 | + mov %eax, (%esp) |
22 | -is restricted to ``int``. Which means that we cannot expand 64-bit items. | 26 | jmp safe_syscall_set_errno_tail |
23 | - | 27 | |
24 | Field examples: | 28 | .cfi_endproc |
25 | 29 | diff --git a/common-user/host/mips/safe-syscall.inc.S b/common-user/host/mips/safe-syscall.inc.S | |
26 | +---------------------------+---------------------------------------------+ | ||
27 | @@ -XXX,XX +XXX,XX @@ Argument Sets | ||
28 | Syntax:: | ||
29 | |||
30 | args_def := '&' identifier ( args_elt )+ ( !extern )? | ||
31 | - args_elt := identifier | ||
32 | + args_elt := identifier (':' identifier)? | ||
33 | |||
34 | Each *args_elt* defines an argument within the argument set. | ||
35 | +If the form of the *args_elt* contains a colon, the first | ||
36 | +identifier is the argument name and the second identifier is | ||
37 | +the argument type. If the colon is missing, the argument | ||
38 | +type will be ``int``. | ||
39 | + | ||
40 | Each argument set will be rendered as a C structure "arg_$name" | ||
41 | with each of the fields being one of the member arguments. | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ Argument set examples:: | ||
44 | |||
45 | ®3 ra rb rc | ||
46 | &loadstore reg base offset | ||
47 | + &longldst reg base offset:int64_t | ||
48 | |||
49 | |||
50 | Formats | ||
51 | diff --git a/tests/decode/succ_argset_type1.decode b/tests/decode/succ_argset_type1.decode | ||
52 | new file mode 100644 | ||
53 | index XXXXXXX..XXXXXXX | ||
54 | --- /dev/null | ||
55 | +++ b/tests/decode/succ_argset_type1.decode | ||
56 | @@ -0,0 +1 @@ | ||
57 | +&asdf b:bool c:uint64_t a | ||
58 | diff --git a/scripts/decodetree.py b/scripts/decodetree.py | ||
59 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
60 | --- a/scripts/decodetree.py | 31 | --- a/common-user/host/mips/safe-syscall.inc.S |
61 | +++ b/scripts/decodetree.py | 32 | +++ b/common-user/host/mips/safe-syscall.inc.S |
62 | @@ -XXX,XX +XXX,XX @@ def is_contiguous(bits): | 33 | @@ -XXX,XX +XXX,XX @@ safe_syscall_end: |
63 | return -1 | 34 | 1: USE_ALT_CP(t0) |
64 | 35 | SETUP_GPX(t1) | |
65 | 36 | SETUP_GPX64(t0, t1) | |
66 | -def eq_fields_for_args(flds_a, flds_b): | 37 | + move a0, v0 |
67 | - if len(flds_a) != len(flds_b): | 38 | PTR_LA t9, safe_syscall_set_errno_tail |
68 | +def eq_fields_for_args(flds_a, arg): | 39 | jr t9 |
69 | + if len(flds_a) != len(arg.fields): | 40 | |
70 | return False | 41 | diff --git a/common-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S |
71 | + # Only allow inference on default types | 42 | index XXXXXXX..XXXXXXX 100644 |
72 | + for t in arg.types: | 43 | --- a/common-user/host/x86_64/safe-syscall.inc.S |
73 | + if t != 'int': | 44 | +++ b/common-user/host/x86_64/safe-syscall.inc.S |
74 | + return False | 45 | @@ -XXX,XX +XXX,XX @@ safe_syscall_end: |
75 | for k, a in flds_a.items(): | 46 | 1: pop %rbp |
76 | - if k not in flds_b: | 47 | .cfi_def_cfa_offset 8 |
77 | + if k not in arg.fields: | 48 | .cfi_restore rbp |
78 | return False | 49 | + mov %eax, %edi |
79 | return True | 50 | jmp safe_syscall_set_errno_tail |
80 | 51 | .cfi_endproc | |
81 | @@ -XXX,XX +XXX,XX @@ def __ne__(self, other): | ||
82 | |||
83 | class Arguments: | ||
84 | """Class representing the extracted fields of a format""" | ||
85 | - def __init__(self, nm, flds, extern): | ||
86 | + def __init__(self, nm, flds, types, extern): | ||
87 | self.name = nm | ||
88 | self.extern = extern | ||
89 | - self.fields = sorted(flds) | ||
90 | + self.fields = flds | ||
91 | + self.types = types | ||
92 | |||
93 | def __str__(self): | ||
94 | return self.name + ' ' + str(self.fields) | ||
95 | @@ -XXX,XX +XXX,XX @@ def struct_name(self): | ||
96 | def output_def(self): | ||
97 | if not self.extern: | ||
98 | output('typedef struct {\n') | ||
99 | - for n in self.fields: | ||
100 | - output(' int ', n, ';\n') | ||
101 | + for (n, t) in zip(self.fields, self.types): | ||
102 | + output(f' {t} {n};\n') | ||
103 | output('} ', self.struct_name(), ';\n\n') | ||
104 | # end Arguments | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ def parse_arguments(lineno, name, toks): | ||
107 | global anyextern | ||
108 | |||
109 | flds = [] | ||
110 | + types = [] | ||
111 | extern = False | ||
112 | - for t in toks: | ||
113 | - if re.fullmatch('!extern', t): | ||
114 | + for n in toks: | ||
115 | + if re.fullmatch('!extern', n): | ||
116 | extern = True | ||
117 | anyextern = True | ||
118 | continue | ||
119 | - if not re.fullmatch(re_C_ident, t): | ||
120 | - error(lineno, f'invalid argument set token "{t}"') | ||
121 | - if t in flds: | ||
122 | - error(lineno, f'duplicate argument "{t}"') | ||
123 | - flds.append(t) | ||
124 | + if re.fullmatch(re_C_ident + ':' + re_C_ident, n): | ||
125 | + (n, t) = n.split(':') | ||
126 | + elif re.fullmatch(re_C_ident, n): | ||
127 | + t = 'int' | ||
128 | + else: | ||
129 | + error(lineno, f'invalid argument set token "{n}"') | ||
130 | + if n in flds: | ||
131 | + error(lineno, f'duplicate argument "{n}"') | ||
132 | + flds.append(n) | ||
133 | + types.append(t) | ||
134 | |||
135 | if name in arguments: | ||
136 | error(lineno, 'duplicate argument set', name) | ||
137 | - arguments[name] = Arguments(name, flds, extern) | ||
138 | + arguments[name] = Arguments(name, flds, types, extern) | ||
139 | # end parse_arguments | ||
140 | |||
141 | |||
142 | @@ -XXX,XX +XXX,XX @@ def infer_argument_set(flds): | ||
143 | global decode_function | ||
144 | |||
145 | for arg in arguments.values(): | ||
146 | - if eq_fields_for_args(flds, arg.fields): | ||
147 | + if eq_fields_for_args(flds, arg): | ||
148 | return arg | ||
149 | |||
150 | name = decode_function + str(len(arguments)) | ||
151 | - arg = Arguments(name, flds.keys(), False) | ||
152 | + arg = Arguments(name, flds.keys(), ['int'] * len(flds), False) | ||
153 | arguments[name] = arg | ||
154 | return arg | ||
155 | 52 | ||
156 | -- | 53 | -- |
157 | 2.25.1 | 54 | 2.25.1 |
158 | 55 | ||
159 | 56 | diff view generated by jsdifflib |