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

ia32: Move x86_imm structure to an own file

parent 3fa0d594
......@@ -90,60 +90,6 @@ static void parse_asm_constraints(be_asm_constraint_t *const constraint, x86_asm
be_parse_asm_constraints_internal(constraint, constraint_text, is_output, &x86_parse_constraint_letter, constraints);
}
static bool check_immediate_constraint(long val, char immediate_constraint_type)
{
switch (immediate_constraint_type) {
case 'g':
case 'i':
case 'n': return true;
case 'I': return 0 <= val && val <= 31;
case 'J': return 0 <= val && val <= 63;
case 'K': return -128 <= val && val < 128;
case 'L': return val == 0xff || val == 0xffff;
case 'M': return 0 <= val && val <= 3;
case 'N': return 0 <= val && val <= 255;
case 'O': return 0 <= val && val <= 127;
}
panic("invalid immediate constraint found");
}
bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
char const constraint)
{
ir_mode *const mode = get_irn_mode(node);
if (get_mode_arithmetic(mode) != irma_twos_complement)
return false;
ir_tarval *offset;
ir_entity *entity;
if (!be_match_immediate(node, &offset, &entity))
return false;
long val = 0;
if (offset) {
if (!tarval_is_long(offset)) {
be_warningf(node, "tarval is not long");
return false;
}
val = get_tarval_long(offset);
if (!check_immediate_constraint(val, constraint))
return false;
}
if (entity != NULL) {
/* we need full 32bits for entities */
if (constraint != 'i' && constraint != 'g')
return false;
}
/* we are fine */
immediate->entity = entity;
immediate->offset = (int32_t)val;
return true;
}
static void set_operand_if_invalid(x86_asm_operand_t *const op, x86_asm_operand_kind_t const kind, unsigned const pos, ir_asm_constraint const *const constraint)
{
/* Multiple constraints for same pos. This can happen for example when
......
......@@ -18,11 +18,7 @@
#include "compiler.h"
#include "firm_types.h"
#include "util.h"
typedef struct x86_imm32_t {
ir_entity *entity;
int32_t offset;
} x86_imm32_t;
#include "x86_imm.h"
typedef enum x86_asm_operand_kind_t {
ASM_OP_INVALID,
......@@ -69,9 +65,6 @@ arch_register_t const *x86_parse_clobber(x86_clobber_name_t const *additional_cl
ir_node *x86_match_ASM(ir_node const *node, x86_clobber_name_t const *names, x86_asm_constraint_list_t const *constraints);
bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
char constraint);
void x86_set_be_asm_constraint_support(const x86_asm_constraint_list_t *constraints);
#endif
/*
* This file is part of libFirm.
* Copyright (C) 2014 University of Karlsruhe.
*/
/**
* @file
* @brief Helper functions for immediates / relocations.
* @author Matthias Braun
*/
#include "x86_imm.h"
#include "bediagnostic.h"
#include "betranshlp.h"
#include "irmode_t.h"
#include "irnode_t.h"
#include "panic.h"
#include "tv_t.h"
static bool check_immediate_constraint(long val, char immediate_constraint_type)
{
switch (immediate_constraint_type) {
case 'g':
case 'i':
case 'n': return true;
case 'I': return 0 <= val && val <= 31;
case 'J': return 0 <= val && val <= 63;
case 'K': return -128 <= val && val < 128;
case 'L': return val == 0xff || val == 0xffff;
case 'M': return 0 <= val && val <= 3;
case 'N': return 0 <= val && val <= 255;
case 'O': return 0 <= val && val <= 127;
}
panic("invalid immediate constraint found");
}
bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
char const constraint)
{
ir_mode *const mode = get_irn_mode(node);
if (get_mode_arithmetic(mode) != irma_twos_complement)
return false;
ir_tarval *offset;
ir_entity *entity;
if (!be_match_immediate(node, &offset, &entity))
return false;
long val = 0;
if (offset) {
if (!tarval_is_long(offset)) {
be_warningf(node, "tarval is not long");
return false;
}
val = get_tarval_long(offset);
if (!check_immediate_constraint(val, constraint))
return false;
}
if (entity != NULL) {
/* we need full 32bits for entities */
if (constraint != 'i' && constraint != 'g')
return false;
}
/* we are fine */
immediate->entity = entity;
immediate->offset = (int32_t)val;
return true;
}
/*
* This file is part of libFirm.
* Copyright (C) 2015 University of Karlsruhe.
*/
/**
* @file
* @brief Data structures for immediate values and relocations.
* @author Matthias Braun
*/
#ifndef FIRM_BE_IA32_IMM_H
#define FIRM_BE_IA32_IMM_H
#include <stdbool.h>
#include <stdint.h>
#include "compiler.h"
#include "firm_types.h"
typedef struct x86_imm32_t {
ir_entity *entity;
int32_t offset;
} x86_imm32_t;
bool x86_match_immediate(x86_imm32_t *immediate, const ir_node *node,
char constraint);
static inline bool x86_imm32_equal(x86_imm32_t const *const imm0,
x86_imm32_t const *const imm1)
{
return imm0->entity == imm1->entity && imm0->offset == imm1->offset;
}
#endif
Supports Markdown
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