Commit c0a95531 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

util: Add and use is_digit().

parent f444ac10
......@@ -12,6 +12,7 @@
#ifndef FIRM_ADT_UTIL_H
#define FIRM_ADT_UTIL_H
#include <stdbool.h>
#include <string.h>
/**
......@@ -58,4 +59,9 @@ static inline void *safe_memcpy(void* const dst, void const* const src, size_t c
#define MEMCPY(dst, src, n) safe_memcpy((dst), (src), (n) * sizeof(*(1 ? (dst) : (src))))
static inline bool is_digit(char const c)
{
return '0' <= c && c <= '9';
}
#endif
......@@ -16,6 +16,7 @@
#include "gen_TEMPLATE_emitter.h"
#include "irgwalk.h"
#include "panic.h"
#include "util.h"
static void TEMPLATE_emit_immediate(const ir_node *node)
{
......@@ -75,7 +76,7 @@ void TEMPLATE_emitf(const ir_node *node, const char *format, ...)
break;
case 'S': {
if (*format < '0' || '9' <= *format)
if (!is_digit(*format))
goto unknown;
unsigned const pos = *format++ - '0';
TEMPLATE_emit_source_register(node, pos);
......@@ -83,7 +84,7 @@ void TEMPLATE_emitf(const ir_node *node, const char *format, ...)
}
case 'D': {
if (*format < '0' || '9' <= *format)
if (!is_digit(*format))
goto unknown;
unsigned const pos = *format++ - '0';
TEMPLATE_emit_dest_register(node, pos);
......
......@@ -465,7 +465,7 @@ end_of_mods:
}
case 'D':
if (*fmt < '0' || '9' <= *fmt)
if (!is_digit(*fmt))
goto unknown;
reg = arch_get_irn_register_out(node, *fmt++ - '0');
goto emit_R;
......@@ -504,12 +504,9 @@ end_of_mods:
emit_shiftop(node);
break;
}
int pos;
if ('0' <= *fmt && *fmt <= '9') {
pos = *fmt++ - '0';
} else {
if (!is_digit(*fmt))
goto unknown;
}
int const pos = *fmt++ - '0';
reg = arch_get_irn_register_in(node, pos);
emit_R:
if (mod & EMIT_IGNORE_MODE) {
......
......@@ -272,7 +272,7 @@ void arm_emitf(const ir_node *node, const char *format, ...)
break;
case 'S': {
if (*format < '0' || '9' <= *format)
if (!is_digit(*format))
goto unknown;
unsigned const pos = *format++ - '0';
arm_emit_source_register(node, pos);
......@@ -280,7 +280,7 @@ void arm_emitf(const ir_node *node, const char *format, ...)
}
case 'D': {
if (*format < '0' || '9' <= *format)
if (!is_digit(*format))
goto unknown;
unsigned const pos = *format++ - '0';
arm_emit_dest_register(node, pos);
......
......@@ -517,7 +517,7 @@ destination_operand:
}
case 'D':
if (*fmt < '0' || '9' < *fmt)
if (!is_digit(*fmt))
goto unknown;
reg = arch_get_irn_register_out(node, *fmt++ - '0');
goto emit_R;
......@@ -596,7 +596,7 @@ emit_I:
if (*fmt == 'X') {
++fmt;
cc = (x86_condition_code_t)va_arg(ap, int);
} else if ('0' <= *fmt && *fmt <= '9') {
} else if (is_digit(*fmt)) {
cc = determine_final_cc(node, *fmt - '0');
++fmt;
} else {
......@@ -632,7 +632,7 @@ emit_R:
emit_S:
case 'S': {
if (*fmt < '0' || '9' < *fmt)
if (!is_digit(*fmt))
goto unknown;
unsigned pos = *fmt++ - '0';
......
......@@ -579,7 +579,7 @@ void sparc_emitf(ir_node const *const node, char const *fmt, ...)
}
case 'D':
if (*fmt < '0' || '9' <= *fmt)
if (!is_digit(*fmt))
goto unknown;
sparc_emit_dest_register(node, *fmt++ - '0');
break;
......@@ -624,7 +624,7 @@ void sparc_emitf(ir_node const *const node, char const *fmt, ...)
break;
case 'O':
if (*fmt < '0' || '9' <= *fmt)
if (!is_digit(*fmt))
goto unknown;
sparc_emit_offset(node, *fmt++ - '0');
break;
......@@ -642,7 +642,7 @@ void sparc_emitf(ir_node const *const node, char const *fmt, ...)
imm = true;
++fmt;
}
if (*fmt < '0' || '9' <= *fmt)
if (!is_digit(*fmt))
goto unknown;
unsigned const pos = *fmt++ - '0';
if (imm && arch_get_irn_flags(node) & (arch_irn_flags_t)sparc_arch_irn_flag_immediate_form) {
......@@ -715,7 +715,7 @@ static const char *emit_asm_operand(const ir_node *node, const char *s)
} else if (c == '%') {
be_emit_char('%');
return s+1;
} else if (c < '0' || c > '9') {
} else if (!is_digit(c)) {
be_errorf(node, "asm contains unknown modifier '%c'", c);
return s+1;
}
......
......@@ -919,7 +919,7 @@ static unsigned get_token(void)
lexer.s = lexer.tok_start;
lexer.len = lexer.curr_pos - lexer.s;
return tok_identifier;
} else if (isdigit((unsigned char)c) || c == '-') {
} else if (is_digit(c) || c == '-') {
unsigned number = 0;
unsigned sign = 0;
......@@ -938,7 +938,7 @@ static unsigned get_token(void)
if (! isxdigit((unsigned char)c))
break;
if (isdigit((unsigned char)c))
if (is_digit(c))
number = (number << 4) | (c - '0');
else
number = (number << 4) | (toupper((unsigned char)c) - 'A' + 10);
......@@ -949,7 +949,7 @@ static unsigned get_token(void)
}
}
for (;;) {
if (! isdigit((unsigned char)c))
if (!is_digit(c))
break;
number = number * 10 + (c - '0');
c = next_char();
......
......@@ -19,6 +19,7 @@
#include "panic.h"
#include "bitfiddle.h"
#include "tv_t.h"
#include "util.h"
#define SC_MASK ((sc_word)0xFF)
#define SC_RESULT(x) ((x) & SC_MASK)
......@@ -342,7 +343,7 @@ bool sc_val_from_str(bool negative, unsigned base, const char *str, size_t len,
while (len > 0) {
char c = *str;
unsigned v;
if (c >= '0' && c <= '9')
if (is_digit(c))
v = c - '0';
else if (c >= 'A' && c <= 'F')
v = c - 'A' + 10;
......
......@@ -1178,7 +1178,7 @@ static char hexchar(unsigned val)
static unsigned hexval(char c)
{
if (c >= '0' && c <= '9')
if (is_digit(c))
return c - '0';
return (c - 'A')+10;
}
......
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