Commit a6aacda3 authored by Matthias Braun's avatar Matthias Braun
Browse files

beemitter: Move helper function to beemithlp

Only keep the basics necessary to emit text lines in beemitter.[ch] and
move all the other convenience stuff to beemithlp.[ch].
parent feb0f2ad
......@@ -11,6 +11,8 @@
#include "TEMPLATE_new_nodes.h"
#include "bearch.h"
#include "beblocksched.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "begnuas.h"
#include "benode.h"
#include "besched.h"
......
......@@ -16,6 +16,8 @@
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "begnuas.h"
#include "beirg.h"
#include "benode.h"
......
......@@ -17,6 +17,8 @@
#include "bearch_arm_t.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "begnuas.h"
#include "benode.h"
#include "besched.h"
......
......@@ -10,6 +10,7 @@
#include "beasm.h"
#include "bediagnostic.h"
#include "beemitter.h"
#include "begnuas.h"
#include "benode.h"
#include "betranshlp.h"
#include "ident_t.h"
......
/*
* This file is part of libFirm.
* Copyright (C) 2016 University of Karlsruhe.
*/
/**
* @file
* @brief Helper functions for emitting assembly from a firm graph.
* @author Matthias Braun
*/
#include "beemithlp.h"
#include "bedwarf.h"
#include "beemitter.h"
#include "be_t.h"
#include "benode.h"
#include "dbginfo.h"
#include "debug.h"
#include "firm_types.h"
#include "irnode_t.h"
#include "irop_t.h"
#include "util.h"
void be_init_emitters(void)
{
ir_clear_opcodes_generic_func();
be_set_emitter(op_Phi, be_emit_nothing);
be_set_emitter(op_be_Keep, be_emit_nothing);
be_set_emitter(op_be_Start, be_emit_nothing);
}
void be_emit_nothing(ir_node const *const node)
{
(void)node;
}
void be_emit_node(ir_node const *const node)
{
be_dwarf_location(get_irn_dbg_info(node));
ir_op *const op = get_irn_op(node);
emit_func *const emit = get_generic_function_ptr(emit_func, op);
DEBUG_ONLY(if (!emit) panic("no emit handler for node %+F (%+G, graph %+F)", node, node, get_irn_irg(node));)
emit(node);
}
void be_emit_pad_comment(void)
{
size_t col = be_emit_get_column();
col = MIN(col, 30);
/* 34 spaces */
be_emit_string_len(" ", 34 - col);
}
/*
* This file is part of libFirm.
* Copyright (C) 2016 University of Karlsruhe.
*/
/**
* @file
* @brief Helper functions for emitting assembly from a firm graph.
* @author Matthias Braun
*
* You typically register an emission function for each node type of your
* backend with be_set_emitter().
*/
#ifndef FIRM_BE_BEEMITHLP_H
#define FIRM_BE_BEEMITHLP_H
#include "be.h"
#include "irop_t.h"
/**
* Emit spaces until the comment position is reached.
*/
void be_emit_pad_comment(void);
/**
* The type of a emitter function.
*/
typedef void emit_func(ir_node const *node);
static inline void be_set_emitter(ir_op *const op, emit_func *const func)
{
set_generic_function_ptr(op, func);
}
void be_init_emitters(void);
void be_emit_nothing(ir_node const *node);
/**
* Emit code for a node by calling a handler registeres with be_set_emitter().
*/
void be_emit_node(ir_node const *node);
#endif
......@@ -9,17 +9,10 @@
* @author Matthias Braun
* @date 12.03.2007
*/
#include "bedwarf.h"
#include "beemitter.h"
#include "benode.h"
#include "be_t.h"
#include "debug.h"
#include "panic.h"
#include "irnode_t.h"
#include "irprintf.h"
#include "tv.h"
#include "dbginfo.h"
#include "util.h"
static FILE *emit_file;
struct obstack emit_obst;
......@@ -55,51 +48,3 @@ void be_emit_write_line(void)
fwrite(line, 1, len, emit_file);
obstack_free(&emit_obst, line);
}
void be_emit_pad_comment(void)
{
size_t len = obstack_object_size(&emit_obst);
len = MIN(len, 30);
/* 34 spaces */
be_emit_string_len(" ", 34 - len);
}
void be_emit_finish_line_gas(const ir_node *node)
{
if (node && be_options.verbose_asm) {
be_emit_pad_comment();
dbg_info *const dbg = get_irn_dbg_info(node);
src_loc_t const loc = ir_retrieve_dbg_info(dbg);
char const *const fmt =
!loc.file ? "/* %+F */\n" :
loc.line == 0 ? "/* %+F %s */\n" :
loc.column == 0 ? "/* %+F %s:%u */\n" :
/* */ "/* %+F %s:%u:%u */\n";
be_emit_irprintf(fmt, node, loc.file, loc.line, loc.column);
} else {
be_emit_char('\n');
}
be_emit_write_line();
}
void be_init_emitters(void)
{
ir_clear_opcodes_generic_func();
be_set_emitter(op_Phi, be_emit_nothing);
be_set_emitter(op_be_Keep, be_emit_nothing);
be_set_emitter(op_be_Start, be_emit_nothing);
}
void be_emit_nothing(ir_node const *const node)
{
(void)node;
}
void be_emit_node(ir_node const *const node)
{
be_dwarf_location(get_irn_dbg_info(node));
ir_op *const op = get_irn_op(node);
emit_func *const emit = get_generic_function_ptr(emit_func, op);
DEBUG_ONLY(if (!emit) panic("no emit handler for node %+F (%+G, graph %+F)", node, node, get_irn_irg(node));)
emit(node);
}
......@@ -5,20 +5,18 @@
/**
* @file
* @brief Interface for assembler output.
* @brief Interface for text output.
* @author Matthias Braun
* @date 12.03.2007
*
* This is a framework for emitting data (usually the final assembly code)
* This is a framework for emitting line base text used by most backends to
* emit assembly code.
*/
#ifndef FIRM_BE_BEEMITTER_H
#define FIRM_BE_BEEMITTER_H
#include <stdio.h>
#include "firm_types.h"
#include "obst.h"
#include "be.h"
#include "irop_t.h"
/* don't use the following vars directly, they're only here for the inlines */
extern struct obstack emit_obst;
......@@ -92,36 +90,10 @@ void be_emit_irvprintf(const char *fmt, va_list args);
*/
void be_emit_write_line(void);
/**
* Flush the line in the current line buffer to the emitter file and
* appends a gas-style comment with the node number and writes the line
*
* @param node the node to get the debug info from
*/
void be_emit_finish_line_gas(const ir_node *node);
/**
* Emit spaces until the comment position is reached.
*/
void be_emit_pad_comment(void);
/**
* The type of a emitter function.
*/
typedef void emit_func(ir_node const *node);
static inline void be_set_emitter(ir_op *const op, emit_func *const func)
/** Return column in current line. Counting starts at 0. */
static inline size_t be_emit_get_column(void)
{
set_generic_function_ptr(op, func);
return obstack_object_size(&emit_obst);
}
void be_init_emitters(void);
void be_emit_nothing(ir_node const *node);
/**
* Emit code for a node.
*/
void be_emit_node(ir_node const *node);
#endif
......@@ -19,8 +19,10 @@
#include "be_t.h"
#include "bearch.h"
#include "bedwarf.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "bemodule.h"
#include "dbginfo.h"
#include "entity_t.h"
#include "execfreq.h"
#include "iredges_t.h"
......@@ -1705,6 +1707,24 @@ void be_gas_end_compilation_unit(const be_main_env_t *env)
be_dwarf_close();
}
void be_emit_finish_line_gas(const ir_node *node)
{
if (node && be_options.verbose_asm) {
be_emit_pad_comment();
dbg_info *const dbg = get_irn_dbg_info(node);
src_loc_t const loc = ir_retrieve_dbg_info(dbg);
char const *const fmt =
!loc.file ? "/* %+F */\n" :
loc.line == 0 ? "/* %+F %s */\n" :
loc.column == 0 ? "/* %+F %s:%u */\n" :
/* */ "/* %+F %s:%u:%u */\n";
be_emit_irprintf(fmt, node, loc.file, loc.line, loc.column);
} else {
be_emit_char('\n');
}
be_emit_write_line();
}
BE_REGISTER_MODULE_CONSTRUCTOR(be_init_gas)
void be_init_gas(void)
{
......
......@@ -14,7 +14,6 @@
#include <stdbool.h>
#include "be_types.h"
#include "beemitter.h"
#include "bedwarf.h"
typedef enum {
......@@ -132,4 +131,12 @@ void be_emit_jump_table(const ir_node *node, const ir_switch_table *table,
bool be_gas_produces_dwarf_line_info(void);
/**
* Flush the line in the current line buffer to the emitter file and
* appends a gas-style comment with the node number and writes the line
*
* @param node the node to get the debug info from
*/
void be_emit_finish_line_gas(const ir_node *node);
#endif
......@@ -34,6 +34,8 @@
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "begnuas.h"
#include "bejit.h"
#include "besched.h"
......
......@@ -89,6 +89,7 @@ close($out_h);
my $out_c = create_with_header("$target_dir/gen_${arch}_emitter.c", "Generated functions to emit code for assembler ir nodes.");
print $out_c <<EOF;
#include "beemithlp.h"
#include "beemitter.h"
#include "gen_${arch}_emitter.h"
#include "${arch}_new_nodes.h"
......
......@@ -14,6 +14,8 @@
#include "beasm.h"
#include "beblocksched.h"
#include "bediagnostic.h"
#include "beemithlp.h"
#include "beemitter.h"
#include "begnuas.h"
#include "beirg.h"
#include "benode.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment