aindump: show function prototype in dasm output

Show full function prototypes in disassembled output.
Also, fix a bug with enum types.
This commit is contained in:
Nunuhara Cabbage
2020-01-16 19:51:50 -08:00
parent 3fa214a22a
commit 41c39baaba
4 changed files with 39 additions and 12 deletions
+3 -3
View File
@@ -203,7 +203,7 @@ char *ain_strtype_d(struct ain *ain, struct ain_type *v)
if (!v->array_type || v->array_type->struc == -1 || !ain)
return strdup("enum");
//return strdup(ain->enums[v->array_type->struc]);
return type_sprintf("%s#86", ain->enums[v->array_type->struc]);
return type_sprintf("%s#86", ain->enums[v->array_type->struc].name);
case AIN_IFACE:
if (v->struc == -1 || !ain)
return strdup("interface");
@@ -213,11 +213,11 @@ char *ain_strtype_d(struct ain *ain, struct ain_type *v)
if (v->struc == -1 || !ain)
return strdup("enum");
//return strdup(ain->enums[v->struc]);
return type_sprintf("%s#%d", ain->enums[v->struc], v->data);
return type_sprintf("%s#%d", ain->enums[v->struc].name, v->data);
case AIN_REF_ENUM:
if (v->struc == -1 || !ain)
return strdup("enum");
return type_sprintf("ref %s", ain->enums[v->struc]);
return type_sprintf("ref %s", ain->enums[v->struc].name);
case AIN_UNKNOWN_TYPE_95: return strdup("type_95");
default:
WARNING("Unknown type: %d", v->data);
+3 -9
View File
@@ -89,35 +89,29 @@ static void print_arglist(FILE *f, struct ain *ain, struct ain_variable *args, i
static void print_varlist(FILE *f, struct ain *ain, struct ain_variable *vars, int nr_vars)
{
if (!nr_vars) {
fputc(';', f);
return;
}
for (int i = 0; i < nr_vars; i++) {
if (i > 0)
fputc(',', f);
fputc(' ', f);
print_sjis(f, ain_variable_to_string(ain, &vars[i]));
}
fputc(';', f);
}
static void print_function(FILE *out, struct ain *ain, struct ain_function *f)
void ain_dump_function(FILE *out, struct ain *ain, struct ain_function *f)
{
print_type(out, ain, &f->return_type);
fputc(' ', out);
print_sjis(out, f->name);
print_arglist(out, ain, f->vars, f->nr_args);
print_varlist(out, ain, f->vars+f->nr_args, f->nr_vars - f->nr_args);
fputc('\n', out);
}
static void ain_dump_functions(FILE *f, struct ain *ain)
{
for (int i = 0; i < ain->nr_functions; i++) {
fprintf(f, "/* 0x%08x */\t", i);
print_function(f, ain, &ain->functions[i]);
ain_dump_function(f, ain, &ain->functions[i]);
fprintf(f, ";\n");
}
}
+27
View File
@@ -0,0 +1,27 @@
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://gnu.org/licenses/>.
*/
#ifndef AINDUMP_H
#define AINDUMP_H
#include <stdio.h>
struct ain;
struct ain_function;
void ain_dump_function(FILE *out, struct ain *ain, struct ain_function *f);
#endif /* AINDUMP_H */
+6
View File
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <string.h>
#include "aindump.h"
#include "khash.h"
#include "little_endian.h"
#include "system4/ain.h"
@@ -248,6 +249,11 @@ static void print_arguments(struct dasm_state *dasm, const struct instruction *i
fprintf(dasm->out, " %s.%s", dasm->ain->libraries[lib].name, dasm->ain->libraries[lib].functions[fun].name);
return;
}
if (instr->opcode == FUNC) {
fputc(' ', dasm->out);
ain_dump_function(dasm->out, dasm->ain, &dasm->ain->functions[dasm->func]);
return;
}
for (int i = 0; i < instr->nr_args; i++) {
fputc(' ', dasm->out);