Commit 01c7899a authored by Matthias Braun's avatar Matthias Braun
Browse files

use int32_t instead of int/long for ia32 offsets

This should fix strange overly long immediate values emitted in the
assembler sometimes.
parent b88b4cf8
......@@ -27,6 +27,7 @@
* pnc_Ne => P || NE
*/
#include <limits.h>
#include <inttypes.h>
#include "../../adt/util.h"
#include "xmalloc.h"
......@@ -211,10 +212,10 @@ static void emit_ia32_Immediate_no_prefix(const ir_node *node)
if (entity != NULL) {
ia32_emit_entity(entity, attr->no_pic_adjust);
if (attr->offset != 0) {
be_emit_irprintf("%+d", attr->offset);
be_emit_irprintf("%+"PRId32, attr->offset);
}
} else {
be_emit_irprintf("0x%lX", attr->offset);
be_emit_irprintf("0x%"PRIX32, (uint32_t)attr->offset);
}
}
......@@ -361,7 +362,7 @@ ENUM_BITSET(ia32_emit_mod_t)
static void ia32_emit_am(ir_node const *const node)
{
ir_entity *ent = get_ia32_am_ent(node);
int offs = get_ia32_am_offs_int(node);
int32_t offs = get_ia32_am_offs_int(node);
ir_node *base = get_irn_n(node, n_ia32_base);
int has_base = !is_ia32_NoReg_GP(base);
ir_node *idx = get_irn_n(node, n_ia32_index);
......@@ -382,9 +383,9 @@ static void ia32_emit_am(ir_node const *const node)
/* also handle special case if nothing is set */
if (offs != 0 || (ent == NULL && !has_base && !has_index)) {
if (ent != NULL) {
be_emit_irprintf("%+d", offs);
be_emit_irprintf("%+"PRId32, offs);
} else {
be_emit_irprintf("%d", offs);
be_emit_irprintf("%"PRId32, offs);
}
}
......@@ -1810,19 +1811,19 @@ enum Mod {
We will change this when enough infrastructure is there to create complete
machine code in memory/object files */
static void bemit8(const unsigned char byte)
static void bemit8(const uint8_t byte)
{
be_emit_irprintf("\t.byte 0x%x\n", byte);
be_emit_write_line();
}
static void bemit16(const unsigned short u16)
static void bemit16(const uint16_t u16)
{
be_emit_irprintf("\t.word 0x%x\n", u16);
be_emit_write_line();
}
static void bemit32(const unsigned u32)
static void bemit32(const uint32_t u32)
{
be_emit_irprintf("\t.long 0x%x\n", u32);
be_emit_write_line();
......@@ -1832,7 +1833,7 @@ static void bemit32(const unsigned u32)
* Emit address of an entity. If @p is_relative is true then a relative
* offset from behind the address to the entity is created.
*/
static void bemit_entity(ir_entity *entity, int offset, bool is_relative)
static void bemit_entity(ir_entity *entity, int32_t offset, bool is_relative)
{
if (entity == NULL) {
bemit32(offset);
......@@ -1858,7 +1859,7 @@ static void bemit_entity(ir_entity *entity, int offset, bool is_relative)
}
if (offset != 0) {
be_emit_irprintf("%+d", offset);
be_emit_irprintf("%+"PRId32, offset);
}
be_emit_char('\n');
be_emit_write_line();
......@@ -1934,7 +1935,7 @@ static bool ia32_is_8bit_imm(ia32_immediate_attr_t const *const imm)
static void bemit_mod_am(unsigned reg, const ir_node *node)
{
ir_entity *ent = get_ia32_am_ent(node);
int offs = get_ia32_am_offs_int(node);
int32_t offs = get_ia32_am_offs_int(node);
ir_node *base = get_irn_n(node, n_ia32_base);
int has_base = !is_ia32_NoReg_GP(base);
ir_node *idx = get_irn_n(node, n_ia32_index);
......@@ -2716,7 +2717,7 @@ static void bemit_load(const ir_node *node)
int has_index = !is_ia32_NoReg_GP(idx);
if (!has_base && !has_index) {
ir_entity *ent = get_ia32_am_ent(node);
int offs = get_ia32_am_offs_int(node);
int32_t offs = get_ia32_am_offs_int(node);
/* load from constant address to EAX can be encoded
as 0xA1 [offset] */
bemit8(0xA1);
......
......@@ -13,6 +13,7 @@
*/
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
#include "irargs_t.h"
#include "irprog_t.h"
......@@ -66,7 +67,7 @@ static void ia32_dump_node(FILE *F, const ir_node *n, dump_reason_t reason)
if (attr->offset > 0 && attr->entity != NULL) {
fputc('+', F);
}
fprintf(F, "%ld", attr->offset);
fprintf(F, "%"PRId32, attr->offset);
if (attr->no_pic_adjust) {
fputs("(no_pic_adjust)", F);
}
......@@ -368,7 +369,7 @@ void set_ia32_am_support(ir_node *node, ia32_am_type_t arity)
/**
* Gets the address mode offset as int.
*/
int get_ia32_am_offs_int(const ir_node *node)
int32_t get_ia32_am_offs_int(const ir_node *node)
{
const ia32_attr_t *attr = get_ia32_attr_const(node);
return attr->am_offs;
......@@ -377,13 +378,13 @@ int get_ia32_am_offs_int(const ir_node *node)
/**
* Sets the address mode offset from an int.
*/
void set_ia32_am_offs_int(ir_node *node, int offset)
void set_ia32_am_offs_int(ir_node *node, int32_t offset)
{
ia32_attr_t *attr = get_ia32_attr(node);
attr->am_offs = offset;
}
void add_ia32_am_offs_int(ir_node *node, int offset)
void add_ia32_am_offs_int(ir_node *node, int32_t offset)
{
ia32_attr_t *attr = get_ia32_attr(node);
attr->am_offs += offset;
......@@ -754,7 +755,7 @@ static void init_ia32_asm_attributes(ir_node *res)
}
static void init_ia32_immediate_attributes(ir_node *res, ir_entity *entity,
int no_pic_adjust, long offset)
bool no_pic_adjust, int32_t offset)
{
ia32_immediate_attr_t *attr = (ia32_immediate_attr_t*)get_irn_generic_attr(res);
......@@ -948,7 +949,7 @@ static unsigned ia32_hash_Immediate(const ir_node *irn)
{
const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
return hash_ptr(a->entity) + a->offset;
return hash_ptr(a->entity) + (unsigned)a->offset;
}
/** Compare node attributes for Immediates. */
......
......@@ -100,14 +100,14 @@ void set_ia32_am_support(ir_node *node, ia32_am_type_t am_arity);
/**
* Gets the addressmode offset as long.
*/
int get_ia32_am_offs_int(const ir_node *node);
int32_t get_ia32_am_offs_int(const ir_node *node);
/**
* Sets the addressmode offset
*/
void set_ia32_am_offs_int(ir_node *node, int offset);
void set_ia32_am_offs_int(ir_node *node, int32_t offset);
void add_ia32_am_offs_int(ir_node *node, int offset);
void add_ia32_am_offs_int(ir_node *node, int32_t offset);
/**
* Returns the entity associated to addrmode.
......
......@@ -105,7 +105,7 @@ struct ia32_attr_t {
unsigned is_remat : 1;
} data;
int am_offs; /**< offsets for AddrMode */
int32_t am_offs; /**< offsets for AddrMode */
ir_entity *am_ent; /**< entity for AddrMode */
ir_mode *ls_mode; /**< Load/Store mode: This is the mode of the
......@@ -166,7 +166,7 @@ typedef struct ia32_immediate_attr_t ia32_immediate_attr_t;
struct ia32_immediate_attr_t {
ia32_attr_t attr; /**< generic attribute */
ir_entity *entity; /**< An entity if any. */
long offset; /**< An offset if any. */
int32_t offset; /**< An offset if any. */
unsigned no_pic_adjust : 1; /**< constant can be relative to EIP */
};
......
......@@ -170,7 +170,7 @@ Immediate => {
op_flags => [ "constlike" ],
irn_flags => [ "not_scheduled" ],
reg_req => { out => [ "gp_NOREG:I" ] },
attr => "ir_entity *entity, int no_pic_adjust, long offset",
attr => "ir_entity *entity, bool no_pic_adjust, int32_t offset",
attr_type => "ia32_immediate_attr_t",
hash_func => "ia32_hash_Immediate",
latency => 0,
......@@ -882,7 +882,7 @@ Const => {
irn_flags => [ "rematerializable" ],
reg_req => { out => [ "gp" ] },
emit => "movl %I, %D0",
attr => "ir_entity *entity, int no_pic_adjust, long offset",
attr => "ir_entity *entity, bool no_pic_adjust, int32_t offset",
attr_type => "ia32_immediate_attr_t",
latency => 1,
mode => $mode_gp,
......
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