}
void
-operand_print(FILE *f, const insn_operand *op)
+operand_print(FILE *f, int indent_level, const insn_operand *op)
{
switch (op->type) {
case INSN_OPERAND_REG:
break;
case INSN_OPERAND_MEMORY:
fprintf(f, "%*sMemory=\n", indent_level, "");
- indent_level++;
- ea_print(f, op->data.ea);
- indent_level--;
+ ea_print(f, indent_level, op->data.ea);
break;
case INSN_OPERAND_IMM:
fprintf(f, "%*sImm=", indent_level, "");
}
void
-ops_print(FILE *f, const insn_operandhead *headp)
+ops_print(FILE *f, int indent_level, const insn_operandhead *headp)
{
insn_operand *cur;
STAILQ_FOREACH (cur, headp, link)
- operand_print(f, cur);
+ operand_print(f, indent_level, cur);
}
const int type_max;
void (*bc_delete) (bytecode *bc);
- void (*bc_print) (FILE *f, const bytecode *bc);
+ void (*bc_print) (FILE *f, int indent_level, const bytecode *bc);
/* See bytecode.h comments on bc_resolve() */
bc_resolve_flags (*bc_resolve) (bytecode *bc, int save,
*/
void (*ea_data_delete) (effaddr *ea);
- void (*ea_data_print) (FILE *f, const effaddr *ea);
+ void (*ea_data_print) (FILE *f, int indent_level, const effaddr *ea);
};
struct insn_operand {
insn_operand *operand_new_mem(/*@only@*/ effaddr *ea);
insn_operand *operand_new_imm(/*@only@*/ expr *val);
-void operand_print(FILE *f, const insn_operand *op);
+void operand_print(FILE *f, int indent_level, const insn_operand *op);
#define ops_initialize(headp) STAILQ_INIT(headp)
#define ops_first(headp) STAILQ_FIRST(headp)
/*@null@*/ insn_operand *ops_append(insn_operandhead *headp,
/*@returned@*/ /*@null@*/ insn_operand *op);
-void ops_print(FILE *f, const insn_operandhead *headp);
+void ops_print(FILE *f, int indent_level, const insn_operandhead *headp);
#endif
/*@-nullstate@*/
void
-ea_print(FILE *f, const effaddr *ea)
+ea_print(FILE *f, int indent_level, const effaddr *ea)
{
fprintf(f, "%*sDisp=", indent_level, "");
expr_print(f, ea->disp);
fprintf(f, "\n%*sLen=%u\n", indent_level, "", (unsigned int)ea->len);
fprintf(f, "%*sNoSplit=%u\n", indent_level, "", (unsigned int)ea->nosplit);
if (cur_arch->ea_data_print)
- cur_arch->ea_data_print(f, ea);
+ cur_arch->ea_data_print(f, indent_level, ea);
}
/*@=nullstate@*/
}
void
-bc_print(FILE *f, const bytecode *bc)
+bc_print(FILE *f, int indent_level, const bytecode *bc)
{
const bytecode_data *data;
const bytecode_reserve *reserve;
case BC_DATA:
data = (const bytecode_data *)bc;
fprintf(f, "%*s_Data_\n", indent_level, "");
- indent_level++;
- fprintf(f, "%*sFinal Element Size=%u\n", indent_level, "",
+ fprintf(f, "%*sFinal Element Size=%u\n", indent_level+1, "",
(unsigned int)data->size);
- fprintf(f, "%*sElements:\n", indent_level, "");
- indent_level++;
- dvs_print(f, &data->datahead);
- indent_level-=2;
+ fprintf(f, "%*sElements:\n", indent_level+1, "");
+ dvs_print(f, indent_level+2, &data->datahead);
break;
case BC_RESERVE:
reserve = (const bytecode_reserve *)bc;
objfmt_data = (const bytecode_objfmt_data *)bc;
fprintf(f, "%*s_ObjFmt_Data_\n", indent_level, "");
if (objfmt_data->of->bc_objfmt_data_print)
- objfmt_data->of->bc_objfmt_data_print(f, objfmt_data->type,
+ objfmt_data->of->bc_objfmt_data_print(f, indent_level,
+ objfmt_data->type,
objfmt_data->data);
else
fprintf(f, "%*sUNKNOWN\n", indent_level, "");
break;
default:
if (bc->type < cur_arch->bc.type_max)
- cur_arch->bc.bc_print(f, bc);
+ cur_arch->bc.bc_print(f, indent_level, bc);
else
fprintf(f, "%*s_Unknown_\n", indent_level, "");
break;
}
void
-bcs_print(FILE *f, const bytecodehead *headp)
+bcs_print(FILE *f, int indent_level, const bytecodehead *headp)
{
bytecode *cur;
STAILQ_FOREACH(cur, headp, link) {
fprintf(f, "%*sNext Bytecode:\n", indent_level, "");
- indent_level++;
- bc_print(f, cur);
- indent_level--;
+ bc_print(f, indent_level+1, cur);
}
}
}
void
-dvs_print(FILE *f, const datavalhead *head)
+dvs_print(FILE *f, int indent_level, const datavalhead *head)
{
dataval *cur;
void ea_set_len(effaddr *ea, unsigned char len);
void ea_set_nosplit(effaddr *ea, unsigned char nosplit);
void ea_delete(/*@only@*/ effaddr *ea);
-void ea_print(FILE *f, const effaddr *ea);
+void ea_print(FILE *f, int indent_level, const effaddr *ea);
void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e);
void bc_delete(/*@only@*/ /*@null@*/ bytecode *bc);
-void bc_print(FILE *f, const bytecode *bc);
+void bc_print(FILE *f, int indent_level, const bytecode *bc);
/* A common version of a calc_bc_dist function that should work for the final
* stages of optimizers as well as in objfmt expr output functions. It takes
/*@returned@*/ /*@only@*/ /*@null@*/
bytecode *bc);
-void bcs_print(FILE *f, const bytecodehead *headp);
+void bcs_print(FILE *f, int indent_level, const bytecodehead *headp);
/* Calls func for each bytecode in the linked list of bytecodes pointed to by
* headp. The data pointer d is passed to each func call.
/*@null@*/ dataval *dvs_append(datavalhead *headp,
/*@returned@*/ /*@null@*/ dataval *dv);
-void dvs_print(FILE *f, const datavalhead *head);
+void dvs_print(FILE *f, int indent_level, const datavalhead *head);
#endif
/* Global assembler options. */
unsigned int asm_options = 0;
-/* Indentation level for assembler *_print() routines */
-int indent_level = 0;
-
static void
filename_delete_one(/*@only@*/ void *d)
{
/* Global assembler options. */
extern unsigned int asm_options;
-/* Indentation level for assembler *_print() routines */
-extern int indent_level;
-
void line_set(const char *filename, unsigned long line,
unsigned long line_inc);
void line_shutdown(void);
* May be NULL if no data is ever allocated in sections_switch().
*/
void (*section_data_delete)(/*@only@*/ void *data);
- void (*section_data_print)(FILE *f, void *data);
+ void (*section_data_print)(FILE *f, int indent_level, void *data);
/* These functions should call symrec_set_of_data() to store data.
* May be NULL if objfmt doesn't care about such declarations.
/* May be NULL if symrec_set_of_data() is never called. */
void (*symrec_data_delete)(/*@only@*/ void *data);
- void (*symrec_data_print)(FILE *f, void *data);
+ void (*symrec_data_print)(FILE *f, int indent_level, void *data);
/* Object format-specific directive support. Returns 1 if directive was
* not recognized. Returns 0 if directive was recognized, even if it
* May be NULL if no BC_OBJFMT_DATA is ever allocated by the object format.
*/
void (*bc_objfmt_data_delete)(unsigned int type, /*@only@*/ void *data);
- void (*bc_objfmt_data_print)(FILE *f, unsigned int type, const void *data);
+ void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type,
+ const void *data);
};
/* Generic functions for all object formats - implemented in src/objfmt.c */
}
void
-sections_print(FILE *f, const sectionhead *headp)
+sections_print(FILE *f, int indent_level, const sectionhead *headp)
{
section *cur;
STAILQ_FOREACH(cur, headp, link) {
fprintf(f, "%*sSection:\n", indent_level, "");
- indent_level++;
- section_print(f, cur, 1);
- indent_level--;
+ section_print(f, indent_level+1, cur, 1);
}
}
}
void
-section_print(FILE *f, const section *sect, int print_bcs)
+section_print(FILE *f, int indent_level, const section *sect, int print_bcs)
{
if (!sect) {
fprintf(f, "%*s(none)\n", indent_level, "");
if (sect->data.general.of_data && sect->data.general.of) {
objfmt *of = sect->data.general.of;
if (of->section_data_print)
- of->section_data_print(f, sect->data.general.of_data);
+ of->section_data_print(f, indent_level,
+ sect->data.general.of_data);
else
fprintf(f, "%*sUNKNOWN\n", indent_level, "");
} else
if (print_bcs) {
fprintf(f, "%*sBytecodes:\n", indent_level, "");
- indent_level++;
- bcs_print(f, §->bc);
- indent_level--;
+ bcs_print(f, indent_level+1, §->bc);
}
}
void sections_delete(sectionhead *headp);
-void sections_print(FILE *f, const sectionhead *headp);
+void sections_print(FILE *f, int indent_level, const sectionhead *headp);
/* Calls func for each section in the linked list of sections pointed to by
* headp. The data pointer d is passed to each func call.
void section_delete(/*@only@*/ section *sect);
-void section_print(FILE *f, /*@null@*/ const section *sect, int print_bcs);
+void section_print(FILE *f, int indent_level, /*@null@*/ const section *sect,
+ int print_bcs);
#endif
}
}
+typedef struct symrec_print_data {
+ FILE *f;
+ int indent_level;
+} symrec_print_data;
+
/*@+voidabstract@*/
static int
symrec_print_wrapper(symrec *sym, /*@null@*/ void *d)
{
- FILE *f;
- assert(d != NULL);
- f = (FILE *)d;
- fprintf(f, "%*sSymbol `%s'\n", indent_level, "", sym->name);
- indent_level++;
- symrec_print(f, sym);
- indent_level--;
+ symrec_print_data *data = (symrec_print_data *)d;
+ assert(data != NULL);
+ fprintf(data->f, "%*sSymbol `%s'\n", data->indent_level, "", sym->name);
+ symrec_print(data->f, data->indent_level+1, sym);
return 1;
}
void
-symrec_print_all(FILE *f)
+symrec_print_all(FILE *f, int indent_level)
{
- symrec_traverse(f, symrec_print_wrapper);
+ symrec_print_data data;
+ data.f = f;
+ data.indent_level = indent_level;
+ symrec_traverse(&data, symrec_print_wrapper);
}
/*@=voidabstract@*/
void
-symrec_print(FILE *f, const symrec *sym)
+symrec_print(FILE *f, int indent_level, const symrec *sym)
{
const char *filename;
unsigned long line;
case SYM_LABEL:
fprintf(f, "%*s_Label_\n%*sSection:\n", indent_level, "",
indent_level, "");
- indent_level++;
- section_print(f, sym->value.label.sect, 0);
- indent_level--;
+ section_print(f, indent_level+1, sym->value.label.sect, 0);
if (!sym->value.label.bc)
fprintf(f, "%*sFirst bytecode\n", indent_level, "");
else {
fprintf(f, "%*sPreceding bytecode:\n", indent_level, "");
- indent_level++;
- bc_print(f, sym->value.label.bc);
- indent_level--;
+ bc_print(f, indent_level+1, sym->value.label.bc);
}
break;
}
if (sym->of_data && sym->of) {
fprintf(f, "%*sObject format-specific data:\n", indent_level, "");
- indent_level++;
if (sym->of->symrec_data_print)
- sym->of->symrec_data_print(f, sym->of_data);
+ sym->of->symrec_data_print(f, indent_level+1, sym->of_data);
else
- fprintf(f, "%*sUNKNOWN\n", indent_level, "");
- indent_level--;
+ fprintf(f, "%*sUNKNOWN\n", indent_level+1, "");
}
line_lookup(sym->line, &filename, &line);
void symrec_delete_all(void);
-void symrec_print_all(FILE *f);
+void symrec_print_all(FILE *f, int indent_level);
-void symrec_print(FILE *f, const symrec *sym);
+void symrec_print(FILE *f, int indent_level, const symrec *sym);
#endif
extern unsigned char yasm_x86_LTX_mode_bits;
void x86_bc_delete(bytecode *bc);
-void x86_bc_print(FILE *f, const bytecode *bc);
+void x86_bc_print(FILE *f, int indent_level, const bytecode *bc);
bc_resolve_flags x86_bc_resolve(bytecode *bc, int save, const section *sect,
calc_bc_dist_func calc_bc_dist);
int x86_bc_tobytes(bytecode *bc, unsigned char **bufp, const section *sect,
void x86_segreg_print(FILE *f, unsigned long segreg);
-void x86_ea_data_print(FILE *f, const effaddr *ea);
+void x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea);
#endif
}
void
-x86_ea_data_print(FILE *f, const effaddr *ea)
+x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea)
{
const x86_effaddr *x86_ea = (const x86_effaddr *)ea;
fprintf(f, "%*sSegmentOv=%02x\n", indent_level, "",
}
void
-x86_bc_print(FILE *f, const bytecode *bc)
+x86_bc_print(FILE *f, int indent_level, const bytecode *bc)
{
const x86_insn *insn;
const x86_jmprel *jmprel;
fprintf(f, "%*sEffective Address:", indent_level, "");
if (insn->ea) {
fprintf(f, "\n");
- indent_level++;
- ea_print(f, (effaddr *)insn->ea);
- indent_level--;
+ ea_print(f, indent_level+1, (effaddr *)insn->ea);
} else
fprintf(f, " (nil)\n");
fprintf(f, "%*sImmediate Value:", indent_level, "");
fprintf(f, "%*sTarget=", indent_level, "");
expr_print(f, jmprel->target);
fprintf(f, "\n%*sShort Form:\n", indent_level, "");
- indent_level++;
if (jmprel->shortop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
+ fprintf(f, "%*sNone\n", indent_level+1, "");
else
fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
+ indent_level+1, "",
(unsigned int)jmprel->shortop.opcode[0],
(unsigned int)jmprel->shortop.opcode[1],
(unsigned int)jmprel->shortop.opcode[2],
(unsigned int)jmprel->shortop.opcode_len);
- indent_level--;
fprintf(f, "%*sNear Form:\n", indent_level, "");
- indent_level++;
if (jmprel->nearop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
+ fprintf(f, "%*sNone\n", indent_level+1, "");
else
fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
+ indent_level+1, "",
(unsigned int)jmprel->nearop.opcode[0],
(unsigned int)jmprel->nearop.opcode[1],
(unsigned int)jmprel->nearop.opcode[2],
(unsigned int)jmprel->nearop.opcode_len);
- indent_level--;
fprintf(f, "%*sOpSel=", indent_level, "");
switch (jmprel->op_sel) {
case JR_NONE:
}
static void
-bin_objfmt_section_data_print(FILE *f, void *data)
+bin_objfmt_section_data_print(FILE *f, int indent_level, void *data)
{
fprintf(f, "%*salign=%ld\n", indent_level, "", *((unsigned long *)data));
}
}
static void
-coff_objfmt_section_data_print(FILE *f, void *data)
+coff_objfmt_section_data_print(FILE *f, int indent_level, void *data)
{
coff_section_data *csd = (coff_section_data *)data;
coff_reloc *reloc;
unsigned long relocnum = 0;
fprintf(f, "%*ssym=\n", indent_level, "");
- indent_level++;
- symrec_print(f, csd->sym);
- indent_level--;
+ symrec_print(f, indent_level+1, csd->sym);
fprintf(f, "%*sscnum=%d\n", indent_level, "", csd->scnum);
fprintf(f, "%*sflags=", indent_level, "");
switch (csd->flags) {
fprintf(f, "%*srelptr=0x%lx\n", indent_level, "", csd->relptr);
fprintf(f, "%*snreloc=%ld\n", indent_level, "", csd->nreloc);
fprintf(f, "%*srelocs:\n", indent_level, "");
- indent_level++;
STAILQ_FOREACH(reloc, &csd->relocs, link) {
- fprintf(f, "%*sReloc %lu:\n", indent_level, "", relocnum++);
- indent_level++;
- fprintf(f, "%*ssym=\n", indent_level, "");
- indent_level++;
- symrec_print(f, reloc->sym);
- indent_level--;
- fprintf(f, "%*stype=", indent_level, "");
+ fprintf(f, "%*sReloc %lu:\n", indent_level+1, "", relocnum++);
+ fprintf(f, "%*ssym=\n", indent_level+2, "");
+ symrec_print(f, indent_level+3, reloc->sym);
+ fprintf(f, "%*stype=", indent_level+2, "");
switch (reloc->type) {
case COFF_RELOC_ADDR32:
printf("Addr32\n");
printf("Rel32\n");
break;
}
- indent_level--;
}
- indent_level--;
}
static void
}
static void
-coff_objfmt_symrec_data_print(FILE *f, void *data)
+coff_objfmt_symrec_data_print(FILE *f, int indent_level, void *data)
{
coff_symrec_data *csd = (coff_symrec_data *)data;
dbgfmt *df, arch *a)
{
dbg_objfmt_file = fopen(obj_filename, "wt");
- if (!dbg_objfmt_file)
+ if (!dbg_objfmt_file) {
ErrorNow(_("could not open file `%s'"), obj_filename);
+ return;
+ }
fprintf(dbg_objfmt_file,
- "%*sinitialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", indent_level,
- "", in_filename, obj_filename, df->keyword, a->keyword);
+ "initialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n",
+ in_filename, obj_filename, df->keyword, a->keyword);
}
static void
dbg_objfmt_output(/*@unused@*/ FILE *f, sectionhead *sections)
{
- fprintf(dbg_objfmt_file, "%*soutput(f, sections->\n", indent_level, "");
- indent_level++;
- sections_print(dbg_objfmt_file, sections);
- indent_level--;
- fprintf(dbg_objfmt_file, "%*s)\n", indent_level, "");
- indent_level++;
- fprintf(dbg_objfmt_file, "%*sSymbol Table:\n", indent_level, "");
- symrec_print_all(dbg_objfmt_file);
- indent_level--;
+ fprintf(dbg_objfmt_file, "output(f, sections->\n");
+ sections_print(dbg_objfmt_file, 1, sections);
+ fprintf(dbg_objfmt_file, ")\n");
+ fprintf(dbg_objfmt_file, " Symbol Table:\n");
+ symrec_print_all(dbg_objfmt_file, 1);
}
static void
dbg_objfmt_cleanup(void)
{
- fprintf(dbg_objfmt_file, "%*scleanup()\n", indent_level, "");
+ fprintf(dbg_objfmt_file, "cleanup()\n");
}
static /*@observer@*/ /*@null@*/ section *
section *retval;
int isnew;
- fprintf(dbg_objfmt_file, "%*ssections_switch(headp, ", indent_level, "");
+ fprintf(dbg_objfmt_file, "sections_switch(headp, ");
vps_print(dbg_objfmt_file, valparams);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_section_data_delete(/*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssection_data_delete(%p)\n", indent_level, "",
- data);
+ fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data);
xfree(data);
}
static void
-dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data)
+dbg_objfmt_section_data_print(FILE *f, int indent_level, /*@null@*/ void *data)
{
if (data)
fprintf(f, "%*s%p\n", indent_level, "", data);
dbg_objfmt_extern_declare(symrec *sym, /*@unused@*/ /*@null@*/
valparamhead *objext_valparams)
{
- fprintf(dbg_objfmt_file, "%*sextern_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "extern_declare(\"%s\", ", symrec_get_name(sym));
vps_print(dbg_objfmt_file, objext_valparams);
fprintf(dbg_objfmt_file, "), setting of_data=NULL\n");
symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL);
dbg_objfmt_global_declare(symrec *sym, /*@unused@*/ /*@null@*/
valparamhead *objext_valparams)
{
- fprintf(dbg_objfmt_file, "%*sglobal_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "global_declare(\"%s\", ", symrec_get_name(sym));
vps_print(dbg_objfmt_file, objext_valparams);
fprintf(dbg_objfmt_file, "), setting of_data=NULL\n");
symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL);
/*@null@*/ valparamhead *objext_valparams)
{
assert(dbg_objfmt_file != NULL);
- fprintf(dbg_objfmt_file, "%*scommon_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "common_declare(\"%s\", ", symrec_get_name(sym));
expr_print(dbg_objfmt_file, size);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_symrec_data_delete(/*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(", indent_level, "");
+ fprintf(dbg_objfmt_file, "symrec_data_delete(");
if (data) {
expr_print(dbg_objfmt_file, data);
expr_delete(data);
}
static void
-dbg_objfmt_symrec_data_print(FILE *f, /*@null@*/ void *data)
+dbg_objfmt_symrec_data_print(FILE *f, int indent_level, /*@null@*/ void *data)
{
if (data) {
fprintf(f, "%*sSize=", indent_level, "");
/*@null@*/ valparamhead *objext_valparams,
/*@unused@*/ sectionhead *headp)
{
- fprintf(dbg_objfmt_file, "%*sdirective(\"%s\", ", indent_level, "", name);
+ fprintf(dbg_objfmt_file, "directive(\"%s\", ", name);
vps_print(dbg_objfmt_file, valparams);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(%u, %p)\n", indent_level,
- "", type, data);
+ fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data);
xfree(data);
}
static void
-dbg_objfmt_bc_objfmt_data_print(FILE *f, unsigned int type, const void *data)
+dbg_objfmt_bc_objfmt_data_print(FILE *f, int indent_level, unsigned int type,
+ const void *data)
{
fprintf(f, "%*sType=%u\n", indent_level, "", type);
fprintf(f, "%*sData=%p\n", indent_level, "", data);
}
void
-operand_print(FILE *f, const insn_operand *op)
+operand_print(FILE *f, int indent_level, const insn_operand *op)
{
switch (op->type) {
case INSN_OPERAND_REG:
break;
case INSN_OPERAND_MEMORY:
fprintf(f, "%*sMemory=\n", indent_level, "");
- indent_level++;
- ea_print(f, op->data.ea);
- indent_level--;
+ ea_print(f, indent_level, op->data.ea);
break;
case INSN_OPERAND_IMM:
fprintf(f, "%*sImm=", indent_level, "");
}
void
-ops_print(FILE *f, const insn_operandhead *headp)
+ops_print(FILE *f, int indent_level, const insn_operandhead *headp)
{
insn_operand *cur;
STAILQ_FOREACH (cur, headp, link)
- operand_print(f, cur);
+ operand_print(f, indent_level, cur);
}
const int type_max;
void (*bc_delete) (bytecode *bc);
- void (*bc_print) (FILE *f, const bytecode *bc);
+ void (*bc_print) (FILE *f, int indent_level, const bytecode *bc);
/* See bytecode.h comments on bc_resolve() */
bc_resolve_flags (*bc_resolve) (bytecode *bc, int save,
*/
void (*ea_data_delete) (effaddr *ea);
- void (*ea_data_print) (FILE *f, const effaddr *ea);
+ void (*ea_data_print) (FILE *f, int indent_level, const effaddr *ea);
};
struct insn_operand {
insn_operand *operand_new_mem(/*@only@*/ effaddr *ea);
insn_operand *operand_new_imm(/*@only@*/ expr *val);
-void operand_print(FILE *f, const insn_operand *op);
+void operand_print(FILE *f, int indent_level, const insn_operand *op);
#define ops_initialize(headp) STAILQ_INIT(headp)
#define ops_first(headp) STAILQ_FIRST(headp)
/*@null@*/ insn_operand *ops_append(insn_operandhead *headp,
/*@returned@*/ /*@null@*/ insn_operand *op);
-void ops_print(FILE *f, const insn_operandhead *headp);
+void ops_print(FILE *f, int indent_level, const insn_operandhead *headp);
#endif
extern unsigned char yasm_x86_LTX_mode_bits;
void x86_bc_delete(bytecode *bc);
-void x86_bc_print(FILE *f, const bytecode *bc);
+void x86_bc_print(FILE *f, int indent_level, const bytecode *bc);
bc_resolve_flags x86_bc_resolve(bytecode *bc, int save, const section *sect,
calc_bc_dist_func calc_bc_dist);
int x86_bc_tobytes(bytecode *bc, unsigned char **bufp, const section *sect,
void x86_segreg_print(FILE *f, unsigned long segreg);
-void x86_ea_data_print(FILE *f, const effaddr *ea);
+void x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea);
#endif
}
void
-x86_ea_data_print(FILE *f, const effaddr *ea)
+x86_ea_data_print(FILE *f, int indent_level, const effaddr *ea)
{
const x86_effaddr *x86_ea = (const x86_effaddr *)ea;
fprintf(f, "%*sSegmentOv=%02x\n", indent_level, "",
}
void
-x86_bc_print(FILE *f, const bytecode *bc)
+x86_bc_print(FILE *f, int indent_level, const bytecode *bc)
{
const x86_insn *insn;
const x86_jmprel *jmprel;
fprintf(f, "%*sEffective Address:", indent_level, "");
if (insn->ea) {
fprintf(f, "\n");
- indent_level++;
- ea_print(f, (effaddr *)insn->ea);
- indent_level--;
+ ea_print(f, indent_level+1, (effaddr *)insn->ea);
} else
fprintf(f, " (nil)\n");
fprintf(f, "%*sImmediate Value:", indent_level, "");
fprintf(f, "%*sTarget=", indent_level, "");
expr_print(f, jmprel->target);
fprintf(f, "\n%*sShort Form:\n", indent_level, "");
- indent_level++;
if (jmprel->shortop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
+ fprintf(f, "%*sNone\n", indent_level+1, "");
else
fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
+ indent_level+1, "",
(unsigned int)jmprel->shortop.opcode[0],
(unsigned int)jmprel->shortop.opcode[1],
(unsigned int)jmprel->shortop.opcode[2],
(unsigned int)jmprel->shortop.opcode_len);
- indent_level--;
fprintf(f, "%*sNear Form:\n", indent_level, "");
- indent_level++;
if (jmprel->nearop.opcode_len == 0)
- fprintf(f, "%*sNone\n", indent_level, "");
+ fprintf(f, "%*sNone\n", indent_level+1, "");
else
fprintf(f, "%*sOpcode: %02x %02x %02x OpLen=%u\n",
- indent_level, "",
+ indent_level+1, "",
(unsigned int)jmprel->nearop.opcode[0],
(unsigned int)jmprel->nearop.opcode[1],
(unsigned int)jmprel->nearop.opcode[2],
(unsigned int)jmprel->nearop.opcode_len);
- indent_level--;
fprintf(f, "%*sOpSel=", indent_level, "");
switch (jmprel->op_sel) {
case JR_NONE:
/*@-nullstate@*/
void
-ea_print(FILE *f, const effaddr *ea)
+ea_print(FILE *f, int indent_level, const effaddr *ea)
{
fprintf(f, "%*sDisp=", indent_level, "");
expr_print(f, ea->disp);
fprintf(f, "\n%*sLen=%u\n", indent_level, "", (unsigned int)ea->len);
fprintf(f, "%*sNoSplit=%u\n", indent_level, "", (unsigned int)ea->nosplit);
if (cur_arch->ea_data_print)
- cur_arch->ea_data_print(f, ea);
+ cur_arch->ea_data_print(f, indent_level, ea);
}
/*@=nullstate@*/
}
void
-bc_print(FILE *f, const bytecode *bc)
+bc_print(FILE *f, int indent_level, const bytecode *bc)
{
const bytecode_data *data;
const bytecode_reserve *reserve;
case BC_DATA:
data = (const bytecode_data *)bc;
fprintf(f, "%*s_Data_\n", indent_level, "");
- indent_level++;
- fprintf(f, "%*sFinal Element Size=%u\n", indent_level, "",
+ fprintf(f, "%*sFinal Element Size=%u\n", indent_level+1, "",
(unsigned int)data->size);
- fprintf(f, "%*sElements:\n", indent_level, "");
- indent_level++;
- dvs_print(f, &data->datahead);
- indent_level-=2;
+ fprintf(f, "%*sElements:\n", indent_level+1, "");
+ dvs_print(f, indent_level+2, &data->datahead);
break;
case BC_RESERVE:
reserve = (const bytecode_reserve *)bc;
objfmt_data = (const bytecode_objfmt_data *)bc;
fprintf(f, "%*s_ObjFmt_Data_\n", indent_level, "");
if (objfmt_data->of->bc_objfmt_data_print)
- objfmt_data->of->bc_objfmt_data_print(f, objfmt_data->type,
+ objfmt_data->of->bc_objfmt_data_print(f, indent_level,
+ objfmt_data->type,
objfmt_data->data);
else
fprintf(f, "%*sUNKNOWN\n", indent_level, "");
break;
default:
if (bc->type < cur_arch->bc.type_max)
- cur_arch->bc.bc_print(f, bc);
+ cur_arch->bc.bc_print(f, indent_level, bc);
else
fprintf(f, "%*s_Unknown_\n", indent_level, "");
break;
}
void
-bcs_print(FILE *f, const bytecodehead *headp)
+bcs_print(FILE *f, int indent_level, const bytecodehead *headp)
{
bytecode *cur;
STAILQ_FOREACH(cur, headp, link) {
fprintf(f, "%*sNext Bytecode:\n", indent_level, "");
- indent_level++;
- bc_print(f, cur);
- indent_level--;
+ bc_print(f, indent_level+1, cur);
}
}
}
void
-dvs_print(FILE *f, const datavalhead *head)
+dvs_print(FILE *f, int indent_level, const datavalhead *head)
{
dataval *cur;
void ea_set_len(effaddr *ea, unsigned char len);
void ea_set_nosplit(effaddr *ea, unsigned char nosplit);
void ea_delete(/*@only@*/ effaddr *ea);
-void ea_print(FILE *f, const effaddr *ea);
+void ea_print(FILE *f, int indent_level, const effaddr *ea);
void bc_set_multiple(bytecode *bc, /*@keep@*/ expr *e);
void bc_delete(/*@only@*/ /*@null@*/ bytecode *bc);
-void bc_print(FILE *f, const bytecode *bc);
+void bc_print(FILE *f, int indent_level, const bytecode *bc);
/* A common version of a calc_bc_dist function that should work for the final
* stages of optimizers as well as in objfmt expr output functions. It takes
/*@returned@*/ /*@only@*/ /*@null@*/
bytecode *bc);
-void bcs_print(FILE *f, const bytecodehead *headp);
+void bcs_print(FILE *f, int indent_level, const bytecodehead *headp);
/* Calls func for each bytecode in the linked list of bytecodes pointed to by
* headp. The data pointer d is passed to each func call.
/*@null@*/ dataval *dvs_append(datavalhead *headp,
/*@returned@*/ /*@null@*/ dataval *dv);
-void dvs_print(FILE *f, const datavalhead *head);
+void dvs_print(FILE *f, int indent_level, const datavalhead *head);
#endif
/* Global assembler options. */
unsigned int asm_options = 0;
-/* Indentation level for assembler *_print() routines */
-int indent_level = 0;
-
static void
filename_delete_one(/*@only@*/ void *d)
{
/* Global assembler options. */
extern unsigned int asm_options;
-/* Indentation level for assembler *_print() routines */
-extern int indent_level;
-
void line_set(const char *filename, unsigned long line,
unsigned long line_inc);
void line_shutdown(void);
/* Global assembler options. */
unsigned int asm_options = 0;
-/* Indentation level for assembler *_print() routines */
-int indent_level = 0;
-
static void
filename_delete_one(/*@only@*/ void *d)
{
/* Global assembler options. */
extern unsigned int asm_options;
-/* Indentation level for assembler *_print() routines */
-extern int indent_level;
-
void line_set(const char *filename, unsigned long line,
unsigned long line_inc);
void line_shutdown(void);
* May be NULL if no data is ever allocated in sections_switch().
*/
void (*section_data_delete)(/*@only@*/ void *data);
- void (*section_data_print)(FILE *f, void *data);
+ void (*section_data_print)(FILE *f, int indent_level, void *data);
/* These functions should call symrec_set_of_data() to store data.
* May be NULL if objfmt doesn't care about such declarations.
/* May be NULL if symrec_set_of_data() is never called. */
void (*symrec_data_delete)(/*@only@*/ void *data);
- void (*symrec_data_print)(FILE *f, void *data);
+ void (*symrec_data_print)(FILE *f, int indent_level, void *data);
/* Object format-specific directive support. Returns 1 if directive was
* not recognized. Returns 0 if directive was recognized, even if it
* May be NULL if no BC_OBJFMT_DATA is ever allocated by the object format.
*/
void (*bc_objfmt_data_delete)(unsigned int type, /*@only@*/ void *data);
- void (*bc_objfmt_data_print)(FILE *f, unsigned int type, const void *data);
+ void (*bc_objfmt_data_print)(FILE *f, int indent_level, unsigned int type,
+ const void *data);
};
/* Generic functions for all object formats - implemented in src/objfmt.c */
}
static void
-bin_objfmt_section_data_print(FILE *f, void *data)
+bin_objfmt_section_data_print(FILE *f, int indent_level, void *data)
{
fprintf(f, "%*salign=%ld\n", indent_level, "", *((unsigned long *)data));
}
}
static void
-coff_objfmt_section_data_print(FILE *f, void *data)
+coff_objfmt_section_data_print(FILE *f, int indent_level, void *data)
{
coff_section_data *csd = (coff_section_data *)data;
coff_reloc *reloc;
unsigned long relocnum = 0;
fprintf(f, "%*ssym=\n", indent_level, "");
- indent_level++;
- symrec_print(f, csd->sym);
- indent_level--;
+ symrec_print(f, indent_level+1, csd->sym);
fprintf(f, "%*sscnum=%d\n", indent_level, "", csd->scnum);
fprintf(f, "%*sflags=", indent_level, "");
switch (csd->flags) {
fprintf(f, "%*srelptr=0x%lx\n", indent_level, "", csd->relptr);
fprintf(f, "%*snreloc=%ld\n", indent_level, "", csd->nreloc);
fprintf(f, "%*srelocs:\n", indent_level, "");
- indent_level++;
STAILQ_FOREACH(reloc, &csd->relocs, link) {
- fprintf(f, "%*sReloc %lu:\n", indent_level, "", relocnum++);
- indent_level++;
- fprintf(f, "%*ssym=\n", indent_level, "");
- indent_level++;
- symrec_print(f, reloc->sym);
- indent_level--;
- fprintf(f, "%*stype=", indent_level, "");
+ fprintf(f, "%*sReloc %lu:\n", indent_level+1, "", relocnum++);
+ fprintf(f, "%*ssym=\n", indent_level+2, "");
+ symrec_print(f, indent_level+3, reloc->sym);
+ fprintf(f, "%*stype=", indent_level+2, "");
switch (reloc->type) {
case COFF_RELOC_ADDR32:
printf("Addr32\n");
printf("Rel32\n");
break;
}
- indent_level--;
}
- indent_level--;
}
static void
}
static void
-coff_objfmt_symrec_data_print(FILE *f, void *data)
+coff_objfmt_symrec_data_print(FILE *f, int indent_level, void *data)
{
coff_symrec_data *csd = (coff_symrec_data *)data;
dbgfmt *df, arch *a)
{
dbg_objfmt_file = fopen(obj_filename, "wt");
- if (!dbg_objfmt_file)
+ if (!dbg_objfmt_file) {
ErrorNow(_("could not open file `%s'"), obj_filename);
+ return;
+ }
fprintf(dbg_objfmt_file,
- "%*sinitialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n", indent_level,
- "", in_filename, obj_filename, df->keyword, a->keyword);
+ "initialize(\"%s\", \"%s\", %s dbgfmt, %s arch)\n",
+ in_filename, obj_filename, df->keyword, a->keyword);
}
static void
dbg_objfmt_output(/*@unused@*/ FILE *f, sectionhead *sections)
{
- fprintf(dbg_objfmt_file, "%*soutput(f, sections->\n", indent_level, "");
- indent_level++;
- sections_print(dbg_objfmt_file, sections);
- indent_level--;
- fprintf(dbg_objfmt_file, "%*s)\n", indent_level, "");
- indent_level++;
- fprintf(dbg_objfmt_file, "%*sSymbol Table:\n", indent_level, "");
- symrec_print_all(dbg_objfmt_file);
- indent_level--;
+ fprintf(dbg_objfmt_file, "output(f, sections->\n");
+ sections_print(dbg_objfmt_file, 1, sections);
+ fprintf(dbg_objfmt_file, ")\n");
+ fprintf(dbg_objfmt_file, " Symbol Table:\n");
+ symrec_print_all(dbg_objfmt_file, 1);
}
static void
dbg_objfmt_cleanup(void)
{
- fprintf(dbg_objfmt_file, "%*scleanup()\n", indent_level, "");
+ fprintf(dbg_objfmt_file, "cleanup()\n");
}
static /*@observer@*/ /*@null@*/ section *
section *retval;
int isnew;
- fprintf(dbg_objfmt_file, "%*ssections_switch(headp, ", indent_level, "");
+ fprintf(dbg_objfmt_file, "sections_switch(headp, ");
vps_print(dbg_objfmt_file, valparams);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_section_data_delete(/*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssection_data_delete(%p)\n", indent_level, "",
- data);
+ fprintf(dbg_objfmt_file, "section_data_delete(%p)\n", data);
xfree(data);
}
static void
-dbg_objfmt_section_data_print(FILE *f, /*@null@*/ void *data)
+dbg_objfmt_section_data_print(FILE *f, int indent_level, /*@null@*/ void *data)
{
if (data)
fprintf(f, "%*s%p\n", indent_level, "", data);
dbg_objfmt_extern_declare(symrec *sym, /*@unused@*/ /*@null@*/
valparamhead *objext_valparams)
{
- fprintf(dbg_objfmt_file, "%*sextern_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "extern_declare(\"%s\", ", symrec_get_name(sym));
vps_print(dbg_objfmt_file, objext_valparams);
fprintf(dbg_objfmt_file, "), setting of_data=NULL\n");
symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL);
dbg_objfmt_global_declare(symrec *sym, /*@unused@*/ /*@null@*/
valparamhead *objext_valparams)
{
- fprintf(dbg_objfmt_file, "%*sglobal_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "global_declare(\"%s\", ", symrec_get_name(sym));
vps_print(dbg_objfmt_file, objext_valparams);
fprintf(dbg_objfmt_file, "), setting of_data=NULL\n");
symrec_set_of_data(sym, &yasm_dbg_LTX_objfmt, NULL);
/*@null@*/ valparamhead *objext_valparams)
{
assert(dbg_objfmt_file != NULL);
- fprintf(dbg_objfmt_file, "%*scommon_declare(\"%s\", ", indent_level, "",
- symrec_get_name(sym));
+ fprintf(dbg_objfmt_file, "common_declare(\"%s\", ", symrec_get_name(sym));
expr_print(dbg_objfmt_file, size);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_symrec_data_delete(/*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(", indent_level, "");
+ fprintf(dbg_objfmt_file, "symrec_data_delete(");
if (data) {
expr_print(dbg_objfmt_file, data);
expr_delete(data);
}
static void
-dbg_objfmt_symrec_data_print(FILE *f, /*@null@*/ void *data)
+dbg_objfmt_symrec_data_print(FILE *f, int indent_level, /*@null@*/ void *data)
{
if (data) {
fprintf(f, "%*sSize=", indent_level, "");
/*@null@*/ valparamhead *objext_valparams,
/*@unused@*/ sectionhead *headp)
{
- fprintf(dbg_objfmt_file, "%*sdirective(\"%s\", ", indent_level, "", name);
+ fprintf(dbg_objfmt_file, "directive(\"%s\", ", name);
vps_print(dbg_objfmt_file, valparams);
fprintf(dbg_objfmt_file, ", ");
vps_print(dbg_objfmt_file, objext_valparams);
static void
dbg_objfmt_bc_objfmt_data_delete(unsigned int type, /*@only@*/ void *data)
{
- fprintf(dbg_objfmt_file, "%*ssymrec_data_delete(%u, %p)\n", indent_level,
- "", type, data);
+ fprintf(dbg_objfmt_file, "symrec_data_delete(%u, %p)\n", type, data);
xfree(data);
}
static void
-dbg_objfmt_bc_objfmt_data_print(FILE *f, unsigned int type, const void *data)
+dbg_objfmt_bc_objfmt_data_print(FILE *f, int indent_level, unsigned int type,
+ const void *data)
{
fprintf(f, "%*sType=%u\n", indent_level, "", type);
fprintf(f, "%*sData=%p\n", indent_level, "", data);
}
void
-sections_print(FILE *f, const sectionhead *headp)
+sections_print(FILE *f, int indent_level, const sectionhead *headp)
{
section *cur;
STAILQ_FOREACH(cur, headp, link) {
fprintf(f, "%*sSection:\n", indent_level, "");
- indent_level++;
- section_print(f, cur, 1);
- indent_level--;
+ section_print(f, indent_level+1, cur, 1);
}
}
}
void
-section_print(FILE *f, const section *sect, int print_bcs)
+section_print(FILE *f, int indent_level, const section *sect, int print_bcs)
{
if (!sect) {
fprintf(f, "%*s(none)\n", indent_level, "");
if (sect->data.general.of_data && sect->data.general.of) {
objfmt *of = sect->data.general.of;
if (of->section_data_print)
- of->section_data_print(f, sect->data.general.of_data);
+ of->section_data_print(f, indent_level,
+ sect->data.general.of_data);
else
fprintf(f, "%*sUNKNOWN\n", indent_level, "");
} else
if (print_bcs) {
fprintf(f, "%*sBytecodes:\n", indent_level, "");
- indent_level++;
- bcs_print(f, §->bc);
- indent_level--;
+ bcs_print(f, indent_level+1, §->bc);
}
}
void sections_delete(sectionhead *headp);
-void sections_print(FILE *f, const sectionhead *headp);
+void sections_print(FILE *f, int indent_level, const sectionhead *headp);
/* Calls func for each section in the linked list of sections pointed to by
* headp. The data pointer d is passed to each func call.
void section_delete(/*@only@*/ section *sect);
-void section_print(FILE *f, /*@null@*/ const section *sect, int print_bcs);
+void section_print(FILE *f, int indent_level, /*@null@*/ const section *sect,
+ int print_bcs);
#endif
}
}
+typedef struct symrec_print_data {
+ FILE *f;
+ int indent_level;
+} symrec_print_data;
+
/*@+voidabstract@*/
static int
symrec_print_wrapper(symrec *sym, /*@null@*/ void *d)
{
- FILE *f;
- assert(d != NULL);
- f = (FILE *)d;
- fprintf(f, "%*sSymbol `%s'\n", indent_level, "", sym->name);
- indent_level++;
- symrec_print(f, sym);
- indent_level--;
+ symrec_print_data *data = (symrec_print_data *)d;
+ assert(data != NULL);
+ fprintf(data->f, "%*sSymbol `%s'\n", data->indent_level, "", sym->name);
+ symrec_print(data->f, data->indent_level+1, sym);
return 1;
}
void
-symrec_print_all(FILE *f)
+symrec_print_all(FILE *f, int indent_level)
{
- symrec_traverse(f, symrec_print_wrapper);
+ symrec_print_data data;
+ data.f = f;
+ data.indent_level = indent_level;
+ symrec_traverse(&data, symrec_print_wrapper);
}
/*@=voidabstract@*/
void
-symrec_print(FILE *f, const symrec *sym)
+symrec_print(FILE *f, int indent_level, const symrec *sym)
{
const char *filename;
unsigned long line;
case SYM_LABEL:
fprintf(f, "%*s_Label_\n%*sSection:\n", indent_level, "",
indent_level, "");
- indent_level++;
- section_print(f, sym->value.label.sect, 0);
- indent_level--;
+ section_print(f, indent_level+1, sym->value.label.sect, 0);
if (!sym->value.label.bc)
fprintf(f, "%*sFirst bytecode\n", indent_level, "");
else {
fprintf(f, "%*sPreceding bytecode:\n", indent_level, "");
- indent_level++;
- bc_print(f, sym->value.label.bc);
- indent_level--;
+ bc_print(f, indent_level+1, sym->value.label.bc);
}
break;
}
if (sym->of_data && sym->of) {
fprintf(f, "%*sObject format-specific data:\n", indent_level, "");
- indent_level++;
if (sym->of->symrec_data_print)
- sym->of->symrec_data_print(f, sym->of_data);
+ sym->of->symrec_data_print(f, indent_level+1, sym->of_data);
else
- fprintf(f, "%*sUNKNOWN\n", indent_level, "");
- indent_level--;
+ fprintf(f, "%*sUNKNOWN\n", indent_level+1, "");
}
line_lookup(sym->line, &filename, &line);
void symrec_delete_all(void);
-void symrec_print_all(FILE *f);
+void symrec_print_all(FILE *f, int indent_level);
-void symrec_print(FILE *f, const symrec *sym);
+void symrec_print(FILE *f, int indent_level, const symrec *sym);
#endif