Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / arch / arm / annotate / instructions.c
blob2ff6cedeb9c53715f4c4f8280bed959fd2be3202
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include <linux/zalloc.h>
4 #include <sys/types.h>
5 #include <regex.h>
6 #include <stdlib.h>
8 struct arm_annotate {
9 regex_t call_insn,
10 jump_insn;
13 static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name)
15 struct arm_annotate *arm = arch->priv;
16 struct ins_ops *ops;
17 regmatch_t match[2];
19 if (!regexec(&arm->call_insn, name, 2, match, 0))
20 ops = &call_ops;
21 else if (!regexec(&arm->jump_insn, name, 2, match, 0))
22 ops = &jump_ops;
23 else
24 return NULL;
26 arch__associate_ins_ops(arch, name, ops);
27 return ops;
30 static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
32 struct arm_annotate *arm;
33 int err;
35 if (arch->initialized)
36 return 0;
38 arm = zalloc(sizeof(*arm));
39 if (!arm)
40 return ENOMEM;
42 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
43 err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
44 if (err)
45 goto out_free_arm;
46 err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED);
47 if (err)
48 goto out_free_call;
49 #undef ARM_CONDS
51 arch->initialized = true;
52 arch->priv = arm;
53 arch->associate_instruction_ops = arm__associate_instruction_ops;
54 arch->objdump.comment_char = ';';
55 arch->objdump.skip_functions_char = '+';
56 return 0;
58 out_free_call:
59 regfree(&arm->call_insn);
60 out_free_arm:
61 free(arm);
62 return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP;