15
15
#include <string.h>
17
17
#include "dwarves.h"
19
20
static const char *prefix = "sys_";
20
21
static size_t prefix_len = 4;
22
static struct tag *filter(struct tag *self, struct cu *cu,
23
void *cookie __unused)
23
static bool filter(struct function *f, struct cu *cu)
25
if (self->tag == DW_TAG_subprogram) {
26
struct function *f = tag__function(self);
28
if (f->proto.nr_parms != 0) {
29
const char *name = function__name(f, cu);
31
if (strlen(name) > prefix_len &&
32
memcmp(name, prefix, prefix_len) == 0)
25
if (f->proto.nr_parms != 0) {
26
const char *name = function__name(f, cu);
28
if (strlen(name) > prefix_len &&
29
memcmp(name, prefix, prefix_len) == 0)
39
35
static void zero_extend(const int regparm, const struct base_type *bt,
36
struct cu *cu, const char *parm)
42
38
const char *instr = "INVALID";
40
switch (bt->bit_size) {
56
53
printf("\t%s\t$a%d, $a%d, 0"
57
"\t/* zero extend $a%d(%s %s) from %zd to 64-bit */\n",
58
instr, regparm, regparm, regparm, bt->name, parm, bt->size * 8);
54
"\t/* zero extend $a%d(%s %s) from %d to 64-bit */\n",
55
instr, regparm, regparm, regparm,
56
base_type__name(bt, cu, bf, sizeof(bf)),
61
static int emit_wrapper(struct tag *self, struct cu *cu, void *cookie __unused)
60
static void emit_wrapper(struct function *f, struct cu *cu)
63
62
struct parameter *parm;
64
struct function *f = tag__function(self);
65
63
const char *name = function__name(f, cu);
66
64
int regparm = 0, needs_wrapper = 0;
68
66
function__for_each_parameter(f, parm) {
69
const Dwarf_Off type_id = parameter__type(parm, cu);
70
struct tag *type = cu__find_tag_by_id(cu, type_id);
67
const uint16_t type_id = parm->tag.type;
68
struct tag *type = cu__type(cu, type_id);
70
tag__assert_search_result(type);
73
71
if (type->tag == DW_TAG_base_type) {
74
72
struct base_type *bt = tag__base_type(type);
77
strncmp(bt->name, "unsigned", 8) == 0) {
75
if (bt->bit_size < 64 &&
76
strncmp(base_type__name(bt, cu, bf, sizeof(bf)),
77
"unsigned", 8) == 0) {
78
78
if (!needs_wrapper) {
79
79
printf("wrap_%s:\n", name);
82
zero_extend(regparm, bt,
82
zero_extend(regparm, bt, cu,
83
83
parameter__name(parm, cu));
142
149
int main(int argc, char *argv[])
145
struct cus *cus = cus__new(NULL, NULL);
152
struct cus *cus = cus__new();
147
154
if (cus == NULL) {
148
155
fprintf(stderr, "%s: insufficient memory\n", argv[0]);
149
156
return EXIT_FAILURE;
152
err = cus__loadfl(cus, &argp, argc, argv);
159
if (argp_parse(&argp, argc, argv, 0, &remaining, NULL) ||
161
argp_help(&argp, stderr, ARGP_HELP_SEE, argv[0]);
164
err = cus__load_files(cus, NULL, argv + remaining);
154
166
return EXIT_FAILURE;