Commit 157db987 authored by Christian Würdig's avatar Christian Würdig
Browse files

removed old unused files

parent 664936b8
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "obst.h"
#include "beasm_asm_gnu.h"
#include "tv.h"
static struct obstack *get_obstack_for_segment ( gnuasm_privdata_t *privdata, asm_segment_t segment ) {
switch (segment) {
case ASM_SEGMENT_CONST:
return &privdata->rdata_obst;
break;
case ASM_SEGMENT_DATA_INIT:
return &privdata->data_obst;
break;
case ASM_SEGMENT_CODE:
return &privdata->code_obst;
break;
case ASM_SEGMENT_DATA_UNINIT:
return &privdata->common_obst;
break;
default:
assert(0 && "unknown segment type");
break;
}
return NULL;
}
/**
* the dumper callbacks
*/
/*
static void gnuasm_dump_align(void *data, asm_segment_t segment, int align) {
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment( privdata, segment );
obstack_printf(obst, "\t.align %d\n", align);
}
*/
static void gnuasm_dump_arith_tarval(void *data, asm_segment_t segment, tarval *tv, int bytes)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
switch (bytes) {
case 1:
obstack_printf(obst, "0x%02x", get_tarval_sub_bits(tv, 0));
break;
case 2:
obstack_printf(obst, "0x%02x%02x", get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
break;
case 4:
obstack_printf(obst, "0x%02x%02x%02x%02x",
get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2), get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
break;
case 8:
obstack_printf(obst, "0x%02x%02x%02x%02x%02x%02x%02x%02x",
get_tarval_sub_bits(tv, 7), get_tarval_sub_bits(tv, 6), get_tarval_sub_bits(tv, 5), get_tarval_sub_bits(tv, 4), get_tarval_sub_bits(tv, 3), get_tarval_sub_bits(tv, 2), get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
break;
default:
fprintf(stderr, "Try to dump an tarval with %d bytes\n", bytes);
assert(0);
}
}
static void gnuasm_dump_atomic_decl(void *data, asm_segment_t segment, int bytes)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment( privdata, segment );
switch (bytes) {
case 1:
obstack_printf(obst, "\t.byte\t");
break;
case 2:
obstack_printf(obst, "\t.value\t");
break;
case 4:
obstack_printf(obst, "\t.long\t");
break;
case 8:
obstack_printf(obst, "\t.quad\t");
break;
default:
fprintf(stderr, "Try to dump an tarval with %d bytes\n", bytes);
assert(0);
}
// obstack_printf(obst, "\n");
}
static void gnuasm_dump_string(void *data, asm_segment_t segment, entity *ent)
{
gnuasm_privdata_t *privdata = data;
int i, n;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
obstack_printf(obst, "\t.string \"");
n = get_compound_ent_n_values(ent);
for (i = 0; i < n-1; ++i) {
ir_node *irn;
int c;
irn = get_compound_ent_value(ent, i);
c = (int) get_tarval_long(get_Const_tarval(irn));
switch (c) {
case '"' : obstack_printf(obst, "\\\""); break;
case '\n': obstack_printf(obst, "\\n"); break;
case '\r': obstack_printf(obst, "\\r"); break;
case '\t': obstack_printf(obst, "\\t"); break;
default:
if (isprint(c))
obstack_printf(obst, "%c", c);
else
obstack_printf(obst, "%O", c);
break;
}
}
obstack_printf(obst, "\"\n");
}
static void gnuasm_dump_declare_initialized_symbol(void *data, asm_segment_t segment, const char* ld_name, int bytes, int align, visibility visibility)
{
gnuasm_privdata_t* priv_data = data;
/* get the obstack for the given segment (const, data) */
struct obstack* obst = get_obstack_for_segment ( priv_data, segment );
/* if the symbol is externally visible, declare it so. */
if (visibility == visibility_external_visible)
obstack_printf(obst, ".globl\t%s\n", ld_name);
obstack_printf(obst, "\t.type\t%s,@object\n", ld_name);
obstack_printf(obst, "\t.size\t%s,%d\n", ld_name, bytes);
obstack_printf(obst, "\t.align\t%d\n", align);
obstack_printf(obst, "\t%s:\n", ld_name);
}
static void gnuasm_dump_declare_uninitialized_symbol(void *data, asm_segment_t segment, const char* ld_name, int bytes, int align, visibility visibility)
{
gnuasm_privdata_t *priv_data = data;
/* external symbols are not required to be declared in gnuasm. */
if(visibility == visibility_external_allocated) return;
/* declare local, uninitialized symbol to the uninit-obst */
obstack_printf(&priv_data->common_obst, "\t.comm\t%s,%d,%d\n", ld_name, bytes, align);
}
static void gnuasm_dump_zero_padding(void *data, asm_segment_t segment, int size)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
obstack_printf(obst, "\t.zero\t%d\n", size);
}
////////////////////////////////////////////////////////////////////////////
static void gnuasm_dump_arith_op(void *data, asm_segment_t segment, asm_arith_operation_t op)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
switch (op) {
case ASM_ARITH_OPERATION_ADD:
obstack_printf(obst, "+");
break;
case ASM_ARITH_OPERATION_SUB:
obstack_printf(obst, "-");
break;
case ASM_ARITH_OPERATION_MUL:
obstack_printf(obst, "*");
break;
}
//obstack_printf(obst, "+");
}
static void gnuasm_dump_symconst(void *data, asm_segment_t segment, ir_node *init)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
switch (get_SymConst_kind(init)) {
case symconst_addr_name:
obstack_printf(obst, "%s", get_id_str(get_SymConst_name(init)));
break;
case symconst_addr_ent:
obstack_printf(obst, "%s", get_entity_ld_name(get_SymConst_entity(init)));
break;
case symconst_size:
obstack_printf(obst, "%d", get_type_size_bytes(get_SymConst_type(init)));
break;
default:
assert(0 && "dump_atomic_init(): don't know how to init from this SymConst");
}
}
static void gnuasm_dump_newline(void *data, asm_segment_t segment)
{
gnuasm_privdata_t *privdata = data;
struct obstack* obst = get_obstack_for_segment ( privdata, segment );
obstack_printf(obst, "\n");
}
//////////////////////////////////////////////////////////////////////////////
static void gnuasm_dump_header(void *data) {
/*gnuasm_privdata_t *privdata = data;*/
}
static void gnuasm_dump_footer(void *data) {
/*gnuasm_privdata_t *privdata = data;*/
}
static void gnuasm_dump_segment_header(void *data) {
/*gnuasm_privdata_t *privdata = data;*/
}
//////////////////////////////////////////////////////////////////////////////
assembler_t *gnuasm_create_assembler ( void ) {
gnuasm_privdata_t *priv_data = xmalloc ( sizeof(gnuasm_privdata_t ));
assembler_t *assembler = xmalloc ( sizeof( assembler_t ));
memset(assembler, 0, sizeof( assembler_t ));
assembler->private_data = priv_data;
obstack_init (&priv_data->common_obst);
obstack_init (&priv_data->data_obst);
obstack_init (&priv_data->rdata_obst);
obstack_init (&priv_data->code_obst);
assembler->dump_declare_uninitialized_symbol = gnuasm_dump_declare_uninitialized_symbol;
assembler->dump_declare_initialized_symbol = gnuasm_dump_declare_initialized_symbol;
// assembler->dump_align = (dump_align_proc) &gnuasm_dump_align;
assembler->dump_arith_tarval = gnuasm_dump_arith_tarval;
assembler->dump_atomic_decl = gnuasm_dump_atomic_decl;
assembler->dump_string = gnuasm_dump_string;
assembler->dump_zero_padding = gnuasm_dump_zero_padding;
assembler->dump_arith_op = gnuasm_dump_arith_op;
assembler->dump_symconst = gnuasm_dump_symconst;
assembler->dump_newline = gnuasm_dump_newline;
assembler->dump_header = gnuasm_dump_header;
assembler->dump_footer = gnuasm_dump_footer;
assembler->dump_segment_header = gnuasm_dump_segment_header;
return assembler;
}
static void gnuasm_dump_obst(struct obstack *obst, FILE *out) {
obstack_grow0 (obst, NULL, 0);
fprintf(out, "%s", (char *)obstack_finish(obst));
}
void gnuasm_dump( assembler_t *assembler, FILE *out ) {
gnuasm_privdata_t *privdata = assembler->private_data;
// fprintf(out, "<COMMON>\n");
gnuasm_dump_obst ( &privdata->common_obst, out);
fprintf(out, ".data\n");
gnuasm_dump_obst ( &privdata->data_obst, out);
fprintf(out, ".section .rodata\n");
gnuasm_dump_obst ( &privdata->rdata_obst, out);
fprintf(out, ".text\n");
gnuasm_dump_obst ( &privdata->code_obst, out);
//////
}
void gnuasm_delete_assembler( assembler_t *assembler ) {
free( assembler->private_data );
free( assembler );
}
#ifndef BEASM_ASM_GNU_H
#define BEASM_ASM_GNU H
#include "beasm_dump_globals.h"
#include "obst.h"
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
typedef struct _gnuasm_privdata_t {
struct obstack common_obst;
struct obstack data_obst;
struct obstack rdata_obst;
struct obstack code_obst;
} gnuasm_privdata_t;
assembler_t *gnuasm_create_assembler ( void );
void gnuasm_dump ( assembler_t *assembler, FILE* out );
void gnuasm_delete_assembler ( assembler_t *assembler );
#endif
/**
* dumper for initialized and uninitialized global data. based on cggg's implementation.
* @author Hannes Jakschitsch
* @date 19.01.2005
*/
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "irprog_t.h"
#include "type.h"
#include "xmalloc.h"
#include "tv.h"
#include "beasm_dump_globals.h"
/*
* returns the highest bit value
*/
static unsigned highest_bit(unsigned v)
{
int res = -1;
if (v >= (1U << 16U)) {
res += 16;
v >>= 16;
}
if (v >= (1U << 8U)) {
res += 8;
v >>= 8;
}
if (v >= (1U << 4U)) {
res += 4;
v >>= 4;
}
if (v >= (1U << 2U)) {
res += 2;
v >>= 2;
}
if (v >= (1U << 1U)) {
res += 1;
v >>= 1;
}
if (v >= 1)
res += 1;
return res;
}
/**
* Determine if an entity is a string constant
* @param ent The entity
* @return 1 if it is a string constant, 0 otherwise
*/
static int ent_is_string_const(entity *ent)
{
int res = 0;
ir_type *ty;
ty = get_entity_type(ent);
/* if it's an array */
if (is_Array_type(ty)) {
ir_type *elm_ty = get_array_element_type(ty);
/* and the array's alement type is primitive */
if (is_Primitive_type(elm_ty)) {
ir_mode *mode = get_type_mode(elm_ty);
/*
* and the mode of the element type is an int of
* the same size as the byte mode
*/
if (mode_is_int(mode)
&& get_mode_size_bits(mode) == get_mode_size_bits(mode_Bs))
{
int i, c, n;
n = get_compound_ent_n_values(ent);
for (i = 0; i < n; ++i) {
ir_node *irn = get_compound_ent_value(ent, i);
if(get_irn_opcode(irn) != iro_Const)
return 0;
c = (int) get_tarval_long(get_Const_tarval(irn));
if((i < n - 1 && !(isgraph(c) || isspace(c)))
|| (i == n - 1 && c != '\0'))
return 0;
}
res = 1;
}
}
}
return res;
}
/*
* dump an atomic value
*/
static void dump_atomic_value( assembler_t *assembler,
asm_segment_t target_segment, ir_node *init)
{
ir_mode *mode = get_irn_mode(init);
int bytes = get_mode_size_bytes(mode);
tarval *tv;
switch (get_irn_opcode(init)) {
case iro_Cast:
dump_atomic_value(assembler, target_segment, get_Cast_op(init));
return;
case iro_Conv:
dump_atomic_value(assembler, target_segment, get_Conv_op(init));
return;
case iro_Const:
tv = get_Const_tarval(init);
/* beware of old stuff */
assert(! mode_is_reference(mode));
/* it's a arithmetic value */
assembler->dump_arith_tarval(assembler->private_data, target_segment, tv, bytes);
return;
case iro_SymConst:
assembler->dump_symconst(assembler->private_data, target_segment, init);
/*
switch (get_SymConst_kind(init)) {
case symconst_addr_name:
assembler->dump_addr_name(assembler->private_data, target_segment, get_id_str(get_SymConst_name(init)));
break;
case symconst_addr_ent:
assembler->dump_addr_ent(assembler->private_data, target_segment, get_entity_ld_name(get_SymConst_entity(init)));
break;
case symconst_size:
assembler->dump_size(assembler->private_data, target_segment, get_type_size_bytes(get_SymConst_type(init)));
break;
default:
assert(0 && "dump_atomic_init(): don't know how to init from this SymConst");
} */
return;
case iro_Add:
dump_atomic_value(assembler, target_segment, get_Add_left(init));
assembler->dump_arith_op(assembler->private_data, target_segment, ASM_ARITH_OPERATION_ADD);
dump_atomic_value(assembler, target_segment, get_Add_right(init));
return;
case iro_Sub:
dump_atomic_value(assembler, target_segment, get_Sub_left(init));
assembler->dump_arith_op(assembler, target_segment, ASM_ARITH_OPERATION_SUB);
dump_atomic_value(assembler, target_segment, get_Sub_right(init));
return;
case iro_Mul:
dump_atomic_value(assembler, target_segment, get_Mul_left(init));
assembler->dump_arith_op(assembler, target_segment, ASM_ARITH_OPERATION_MUL);
dump_atomic_value(assembler, target_segment, get_Mul_right(init));
return;
default:
assert(0 && "dump_atomic_init(): unknown IR-node");
}
}
/*
* dump an atomic value
*/
static void dump_atomic_init(assembler_t* assembler,
asm_segment_t target_segment, ir_node *init)
{
ir_mode *mode = get_irn_mode(init);
int bytes = get_mode_size_bytes(mode);
assembler->dump_atomic_decl(assembler->private_data, target_segment, bytes);
dump_atomic_value(assembler, target_segment, init);
assembler->dump_newline(assembler->private_data, target_segment);
}
struct arr_info {
int n_elems;
int visit_cnt;
int size;
};
/*
* Dumps the initialization of global variables that are not
* "uninitialized".
*/
static void asm_dump_global ( assembler_t *assembler, entity *ent)
{
ir_type *ty = get_entity_type(ent);
const char *ld_name = get_entity_ld_name(ent);
int align, /*is_constant,*/ h;
int i, /*j,*/ size = 0;
ent_variability variability;
visibility visibility;
asm_segment_t target_segment = ASM_SEGMENT_DATA_INIT;
/*
* FIXME: did NOT work for partly constant values
*/
/* ignore methods, they are emitted later */
if (is_Method_type(ty))
return;
/* get the properties of the entity */
variability = get_entity_variability(ent);
visibility = get_entity_visibility(ent);
if (variability == variability_constant) {
/* a constant entity, put it into the const segment */
target_segment = ASM_SEGMENT_CONST;
}
/* check, whether it is initialized, if yes create data */
if (variability != variability_uninitialized ) {
/* if (visibility == visibility_external_visible) {
assembler->dump_external_declaration(assembler->private_data, target_segment, ld_name);
// obstack_printf(obst, ".globl\t%s\n", ld_name);
}
align = get_type_alignment_bytes(ty);
// obstack_printf(obst, "\t.type\t%s,@object\n", ld_name);
// obstack_printf(obst, "\t.size\t%s,%d\n", ld_name, (get_type_size_bits(ty) + 7) >> 3);
assembler->dump_declare_object_symbol(assembler->private_data, target_segment, ld_name, (get_type_size_bits(ty) + 7) >> 3);
align = get_type_alignment_bytes(ty);
assembler->dump_align(assembler->private_data, target_segment, align );
assembler->dump_object_symbol_init_decl(assembler->private_data, target_segment, ld_name);
*/
align = get_type_alignment_bytes(ty);
assembler->dump_declare_initialized_symbol ( assembler->private_data, target_segment, ld_name, (get_type_size_bits(ty)+7)>>3, align, visibility );
/* dumps of the different entity type initializiations */
/* atomic types */
if (is_atomic_type(ty)) {
if (get_entity_visibility(ent) != visibility_external_allocated)
dump_atomic_init(assembler, target_segment, get_atomic_ent_value(ent));
}
else if(ent_is_string_const(ent)) {
assembler->dump_string(assembler->private_data, target_segment, ent);
}
else if(is_Array_type(ty)) {
int filler;
/* potential spare values should be already included! */
for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
entity *step = get_compound_ent_value_member(ent, i);
ir_type *stype = get_entity_type(step);
if (get_type_mode(stype)) {
int align = (get_type_alignment_bits(stype) + 7) >> 3;
int n = size % align;
if (n > 0) {
assembler->dump_zero_padding(assembler->private_data, target_segment, align-n);
size += align - n;
}
}
dump_atomic_init(assembler, target_segment, get_compound_ent_value(ent, i));
size += get_type_size_bytes(stype);
}
filler = get_type_size_bytes(ty) - size;
if (filler > 0)