Commit 4075c542 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

adt: Add and use 'streq()'.

parent 31f3d128
......@@ -64,4 +64,9 @@ static inline bool is_digit(char const c)
return '0' <= c && c <= '9';
}
static inline bool streq(char const *const a, char const *const b)
{
return strcmp(a, b) == 0;
}
#endif
......@@ -111,7 +111,7 @@ arch_register_t const *arch_find_register(char const *const name)
arch_register_t const *const regs = isa_if->registers;
for (size_t i = 0, n = isa_if->n_registers; i < n; ++i) {
arch_register_t const *const reg = &regs[i];
if (strcmp(reg->name, name) == 0)
if (streq(reg->name, name))
return reg;
}
return NULL;
......
......@@ -545,7 +545,7 @@ static void emit_base_type(const ir_type *type)
ir_mode *mode = get_type_mode(type);
if (mode_is_int(mode)) {
/* bool hack */
if (strcmp(buf, "_Bool")==0 || strcmp(buf, "bool")==0) {
if (streq(buf, "_Bool") || streq(buf, "bool")) {
emit_int8(DW_ATE_boolean);
} else {
emit_int8(mode_is_signed(mode) ? DW_ATE_signed : DW_ATE_unsigned);
......
......@@ -188,10 +188,10 @@ int be_is_valid_clobber(const char *clobber)
/* memory is a valid clobber. (the frontend has to detect this case too,
* because it has to add memory edges to the asm) */
if (strcmp(clobber, "memory") == 0)
if (streq(clobber, "memory"))
return 1;
/* cc (condition code) is always valid */
if (strcmp(clobber, "cc") == 0)
if (streq(clobber, "cc"))
return 1;
return isa_if->is_valid_clobber(clobber);
......@@ -223,7 +223,7 @@ static void be_opt_register(void)
int be_parse_arg(const char *arg)
{
lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
if (strcmp(arg, "help") == 0 || (arg[0] == '?' && arg[1] == '\0')) {
if (streq(arg, "help") || streq(arg, "?")) {
lc_opt_print_help_for_entry(be_grp, '-', stdout);
return -1;
}
......
......@@ -13,6 +13,7 @@
#include <stdbool.h>
#include "bemodule.h"
#include "util.h"
#include "xmalloc.h"
/**
......@@ -149,7 +150,7 @@ static bool set_opt_module(void *const data, size_t const length, char const *co
bool res = false;
for (const be_module_list_entry_t *module = *(moddata->list_head);
module != NULL; module = module->next) {
if (strcmp(module->name, opt) == 0) {
if (streq(module->name, opt)) {
*(moddata->var) = module->data;
res = true;
break;
......
......@@ -18,6 +18,7 @@
#include "lc_opts_enum.h"
#include "irtools.h"
#include "tv.h"
#include "util.h"
#undef NATIVE_X86
......@@ -825,11 +826,11 @@ static void autodetect_arch(void)
cpu_info.ecx_features = regs.r.ecx;
cpu_info.add_features = regs.r.ebx;
if (0 == strcmp(vendorid, "GenuineIntel")) {
if (streq(vendorid, "GenuineIntel")) {
auto_arch = auto_detect_Intel(&cpu_info);
} else if (0 == strcmp(vendorid, "AuthenticAMD")) {
} else if (streq(vendorid, "AuthenticAMD")) {
auto_arch = auto_detect_AMD(&cpu_info);
} else if (0 == strcmp(vendorid, "Geode by NSC")) {
} else if (streq(vendorid, "Geode by NSC")) {
auto_arch = cpu_geode_generic;
}
......
......@@ -36,7 +36,7 @@ arch_register_t const *x86_parse_clobber(x86_clobber_name_t const *const additio
return reg;
arch_register_t const *const regs = isa_if->registers;
for (size_t i = 0; additional_clobber_names[i].name != NULL; ++i) {
if (strcmp(additional_clobber_names[i].name, clobber) == 0)
if (streq(additional_clobber_names[i].name, clobber))
return &regs[additional_clobber_names[i].index];
}
return NULL;
......
......@@ -229,7 +229,7 @@ static const arch_register_t *find_register(const char *name)
{
for (size_t i = 0; i < N_SPARC_REGISTERS; ++i) {
const arch_register_t *const reg = &sparc_registers[i];
if (strcmp(reg->name, name) == 0)
if (streq(reg->name, name))
return reg;
}
return NULL;
......@@ -296,9 +296,8 @@ static ir_node *gen_ASM(ir_node *node)
for (size_t c = 0; c < get_ASM_n_clobbers(node); ++c) {
const char *const clobber = get_id_str(clobbers[c]);
if (strcmp(clobber, "cc") == 0) {
if (streq(clobber, "cc"))
continue;
}
const arch_register_t *reg = find_register(clobber);
if (reg == NULL)
......@@ -377,7 +376,7 @@ static ir_node *gen_ASM(ir_node *node)
/* parse clobbers */
for (size_t c = 0; c < get_ASM_n_clobbers(node); ++c) {
const char *const clobber = get_id_str(clobbers[c]);
if (strcmp(clobber, "cc") == 0) {
if (streq(clobber, "cc")) {
ARR_APP1(arch_register_req_t const*, out_reqs, sparc_registers[REG_PSR].single_req);
ARR_APP1(arch_register_req_t const*, out_reqs, sparc_registers[REG_FSR].single_req);
continue;
......
......@@ -588,7 +588,7 @@ static ir_type *find_type_name(const char *name)
if (!is_compound_type(tp))
continue;
if (strcmp(get_compound_name(tp), name) == 0)
if (streq(get_compound_name(tp), name))
return tp;
}
return NULL;
......@@ -624,9 +624,8 @@ static void check_ent_name(ir_type *const type, ir_entity *const entity, void *c
(void)type;
find_env_t *env = (find_env_t*)ctx;
if (entity && strcmp(get_entity_name(entity), env->u.name) == 0) {
if (entity && streq(get_entity_name(entity), env->u.name))
env->res = entity;
}
}
/**
......@@ -1091,7 +1090,7 @@ void firm_debug(const char *cmd)
if (token == tok_number) {
dbg_printf("Setting initial node number to %u\n", lexer.number);
irp->max_node_nr = lexer.number;
} else if (token == tok_identifier && !strcmp(lexer.s, "rand")) {
} else if (token == tok_identifier && streq(lexer.s, "rand")) {
dbg_printf("Randomizing initial node number\n");
srand(time(0));
irp->max_node_nr += rand() % 6666;
......
......@@ -31,6 +31,7 @@
#include "obst.h"
#include "pmap.h"
#include "pdeq.h"
#include "util.h"
#define SYMERROR ((unsigned) ~0)
......@@ -1275,7 +1276,7 @@ static char *read_string_null(read_env_t *env)
skip_ws(env);
if (env->c == 'N') {
char *str = read_word(env);
if (strcmp(str, "NULL") == 0) {
if (streq(str, "NULL")) {
obstack_free(&env->obst, str);
return NULL;
}
......@@ -1407,11 +1408,10 @@ static ir_type *get_type(read_env_t *env, long typenr)
static ir_type *read_type_ref(read_env_t *env)
{
char *str = read_word(env);
if (strcmp(str, "unknown") == 0) {
if (streq(str, "unknown")) {
obstack_free(&env->obst, str);
return get_unknown_type();
}
if (strcmp(str, "code") == 0) {
} else if (streq(str, "code")) {
obstack_free(&env->obst, str);
return get_code_type();
}
......@@ -1455,7 +1455,7 @@ static ir_mode *read_mode_ref(read_env_t *env)
char *str = read_string(env);
for (size_t i = 0, n = ir_get_n_modes(); i < n; i++) {
ir_mode *mode = ir_get_mode(i);
if (strcmp(str, get_mode_name(mode)) == 0) {
if (streq(str, get_mode_name(mode))) {
obstack_free(&env->obst, str);
return mode;
}
......@@ -1652,7 +1652,7 @@ static void read_type(read_env_t *env)
ir_type *elemtype = read_type_ref(env);
type = new_type_array(elemtype);
char *str = read_word(env);
if (strcmp(str, "unknown") != 0) {
if (!streq(str, "unknown")) {
long size = atol(str);
set_array_size_int(type, size);
}
......@@ -1798,11 +1798,11 @@ static void read_entity(read_env_t *env, ir_entity_kind kind)
if (ld_name != NULL)
set_entity_ld_ident(entity, ld_name);
const char *str = read_word(env);
if (strcmp(str, "initializer") == 0) {
if (streq(str, "initializer")) {
ir_initializer_t *initializer = read_initializer(env);
if (initializer != NULL)
set_entity_initializer(entity, initializer);
} else if (strcmp(str, "none") == 0) {
} else if (streq(str, "none")) {
/* do nothing */
} else {
parse_error(env, "expected 'initializer' or 'none' got '%s'\n", str);
......@@ -1826,7 +1826,7 @@ static void read_entity(read_env_t *env, ir_entity_kind kind)
case IR_ENTITY_PARAMETER: {
char *str = read_word(env);
size_t parameter_number;
if (strcmp(str, "va_start") == 0) {
if (streq(str, "va_start")) {
parameter_number = IR_VA_START_PARAMETER_NUMBER;
} else {
parameter_number = atol(str);
......
......@@ -20,6 +20,7 @@
#include "array.h"
#include "panic.h"
#include "strcalc.h"
#include "util.h"
/** Obstack to hold all modes. */
static struct obstack modes;
......@@ -32,7 +33,7 @@ static bool modes_are_equal(const ir_mode *m, const ir_mode *n)
if (m->sort != n->sort)
return false;
if (m->sort == irms_auxiliary || m->sort == irms_data)
return strcmp(m->name, n->name) == 0;
return streq(m->name, n->name);
return m->arithmetic == n->arithmetic
&& m->size == n->size
&& m->sign == n->sign
......
......@@ -30,7 +30,7 @@ static void set_name(lc_opt_entry_t *ent, const char *name)
}
#define entry_matches(ent,hash_val,str) \
((ent)->hash == hash_val && strcmp((ent)->name, (str)) == 0)
((ent)->hash == hash_val && streq((ent)->name, (str)))
static lc_opt_entry_t *init_entry(lc_opt_entry_t *ent, lc_opt_entry_t *parent,
const char *name, const char *desc)
......
......@@ -8,6 +8,7 @@
#include "lc_opts_t.h"
#include "lc_opts_enum.h"
#include "util.h"
#include "xmalloc.h"
static const char *delim = " \t|,";
......@@ -39,7 +40,7 @@ bool lc_opt_enum_ ## N ## _cb(void *const data, size_t const len, char const *co
s[end - begin] = '\0'; \
\
for (i = 0; items[i].name != NULL; ++i) { \
if (strcmp(s, items[i].name) == 0) { \
if (streq(s, items[i].name)) { \
*var->value op items[i].value; \
res = true; \
} \
......
......@@ -10,6 +10,7 @@
#include "lpp_solvers.h"
#include "lpp_cplex.h"
#include "lpp_gurobi.h"
#include "util.h"
lpp_solver_t lpp_solvers[] = {
#ifdef WITH_CPLEX
......@@ -29,7 +30,7 @@ lpp_solver_func_t *lpp_find_solver(const char *name)
return lpp_solvers[0].solver;
for(i = 0; lpp_solvers[i].solver != NULL; i++)
if(strcmp(lpp_solvers[i].name, name) == 0)
if (streq(lpp_solvers[i].name, name))
return lpp_solvers[i].solver;
return NULL;
......
......@@ -1247,9 +1247,9 @@ ir_tarval *ir_tarval_from_ascii(const char *buf, ir_mode *mode)
}
case irms_data:
case irms_auxiliary:
if (strcmp(buf, "bad") == 0)
if (streq(buf, "bad"))
return tarval_bad;
else if (strcmp(buf, "unknown") == 0)
else if (streq(buf, "unknown"))
return tarval_unknown;
break;
}
......
......@@ -3,6 +3,7 @@
#include <stdio.h>
#include <inttypes.h>
#include "strcalc.h"
#include "util.h"
bool fine = true;
......@@ -18,7 +19,7 @@ static void test(const unsigned char *bytes, unsigned from, unsigned to,
char print_buf[32];
char *res = sc_print_buf(print_buf, sizeof(print_buf), val0, 32, SC_HEX, false);
if (strcmp(res, expected) != 0) {
if (!streq(res, expected)) {
printf("Failed: 0x%02X%02X%02X%02X [%u:%u) => %s (expected %s)\n",
bytes[3], bytes[2], bytes[1], bytes[0], from, to, res, expected);
fine = false;
......
......@@ -4,11 +4,7 @@
#include <stdbool.h>
#include "irprintf.h"
#include "firm.h"
static bool streq(const char *a, const char *b)
{
return strcmp(a, b) == 0;
}
#include "util.h"
int main(void)
{
......
......@@ -24,11 +24,6 @@ static bool equal(const sc_word *v0, const sc_word *v1)
return memcmp(v0, v1, len) == 0;
}
static bool streq(const char *str0, const char *str1)
{
return strcmp(str0, str1) == 0;
}
static void test_conv_print(unsigned long v, enum base_t base,
const char *expected)
{
......
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