Skip to content

Commit 4530829

Browse files
committed
Utilize bool when possible
1 parent a7b7fd0 commit 4530829

File tree

7 files changed

+108
-108
lines changed

7 files changed

+108
-108
lines changed

src/arm-codegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void cfg_flatten()
159159
if (insn->op == OP_branch) {
160160
/* In SSA, we index 'else_bb' first, and then 'then_bb' */
161161
if (insn->else_bb != bb->rpo_next)
162-
flatten_ir->is_branch_detached = 1;
162+
flatten_ir->is_branch_detached = true;
163163
}
164164

165165
update_elf_offset(flatten_ir);

src/defs.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ struct var {
160160
char type_name[MAX_TYPE_LEN];
161161
char var_name[MAX_VAR_LEN];
162162
int is_ptr;
163-
int is_func;
164-
int is_global;
163+
bool is_func;
164+
bool is_global;
165165
int array_size;
166166
int offset; /* offset from stack or frame, index 0 is reserved */
167167
int init_val; /* for global initialization */
@@ -174,21 +174,21 @@ struct var {
174174
rename_t rename;
175175
ref_block_list_t ref_block_list; /* blocks which kill variable */
176176
int consumed;
177-
int is_ternary_ret;
178-
int is_const; /* whether a constant representaion or not */
177+
bool is_ternary_ret;
178+
bool is_const; /* whether a constant representaion or not */
179179
};
180180

181181
typedef struct var var_t;
182182

183183
typedef struct {
184184
char name[MAX_VAR_LEN];
185-
int is_variadic;
185+
bool is_variadic;
186186
int start_source_idx;
187187
var_t param_defs[MAX_PARAMS];
188188
int num_param_defs;
189189
int params[MAX_PARAMS];
190190
int num_params;
191-
int disabled;
191+
bool disabled;
192192
} macro_t;
193193

194194
typedef struct fn fn_t;
@@ -246,7 +246,7 @@ struct ph2_ir {
246246
basic_block_t *then_bb;
247247
basic_block_t *else_bb;
248248
struct ph2_ir *next;
249-
int is_branch_detached;
249+
bool is_branch_detached;
250250
};
251251

252252
typedef struct ph2_ir ph2_ir_t;
@@ -267,16 +267,16 @@ typedef struct type type_t;
267267
typedef struct {
268268
int size;
269269
int is_ptr;
270-
int is_func;
271-
int is_reference;
270+
bool is_func;
271+
bool is_reference;
272272
type_t *type;
273273
} lvalue_t;
274274

275275
/* alias for #defines */
276276
typedef struct {
277277
char alias[MAX_VAR_LEN];
278278
char value[MAX_VAR_LEN];
279-
int disabled;
279+
bool disabled;
280280
} alias_t;
281281

282282
/* constants for enums */

src/globals.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void add_alias(char *alias, char *value)
227227
alias_t *al = &ALIASES[aliases_idx++];
228228
strcpy(al->alias, alias);
229229
strcpy(al->value, value);
230-
al->disabled = 0;
230+
al->disabled = false;
231231
}
232232

233233
char *find_alias(char alias[])
@@ -239,22 +239,22 @@ char *find_alias(char alias[])
239239
return NULL;
240240
}
241241

242-
int remove_alias(char *alias)
242+
bool remove_alias(char *alias)
243243
{
244244
for (int i = 0; i < aliases_idx; i++) {
245245
if (!ALIASES[i].disabled && !strcmp(alias, ALIASES[i].alias)) {
246-
ALIASES[i].disabled = 1;
247-
return 1;
246+
ALIASES[i].disabled = true;
247+
return true;
248248
}
249249
}
250-
return 0;
250+
return false;
251251
}
252252

253253
macro_t *add_macro(char *name)
254254
{
255255
macro_t *ma = &MACROS[macros_idx++];
256256
strcpy(ma->name, name);
257-
ma->disabled = 0;
257+
ma->disabled = false;
258258
return ma;
259259
}
260260

@@ -267,15 +267,15 @@ macro_t *find_macro(char *name)
267267
return NULL;
268268
}
269269

270-
int remove_macro(char *name)
270+
bool remove_macro(char *name)
271271
{
272272
for (int i = 0; i < macros_idx; i++) {
273273
if (!MACROS[i].disabled && !strcmp(name, MACROS[i].name)) {
274-
MACROS[i].disabled = 1;
275-
return 1;
274+
MACROS[i].disabled = true;
275+
return true;
276276
}
277277
}
278-
return 0;
278+
return false;
279279
}
280280

281281
void error(char *msg);
@@ -401,7 +401,7 @@ var_t *find_var(char *token, block_t *parent)
401401
int size_var(var_t *var)
402402
{
403403
int size;
404-
if (var->is_ptr > 0 || var->is_func > 0) {
404+
if (var->is_ptr > 0 || var->is_func) {
405405
size = 4;
406406
} else {
407407
type_t *type = find_type(var->type_name, 0);

src/parser.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ bool read_preproc_directive()
402402
lex_accept(T_comma);
403403
}
404404
if (lex_accept(T_elipsis))
405-
macro->is_variadic = 1;
405+
macro->is_variadic = true;
406406

407407
macro->start_source_idx = source_idx;
408408
skip_macro_body();
@@ -513,7 +513,7 @@ void read_inner_var_decl(var_t *vd, int anon, int is_param)
513513
lex_ident(T_identifier, vd->var_name);
514514
lex_expect(T_close_bracket);
515515
read_parameter_list_decl(&func, 1);
516-
vd->is_func = 1;
516+
vd->is_func = true;
517517
} else {
518518
if (anon == 0) {
519519
lex_ident(T_identifier, vd->var_name);
@@ -546,7 +546,7 @@ void read_inner_var_decl(var_t *vd, int anon, int is_param)
546546
} else {
547547
vd->array_size = 0;
548548
}
549-
vd->is_func = 0;
549+
vd->is_func = false;
550550
}
551551
}
552552

@@ -772,7 +772,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
772772
var_t *var = find_var(token, parent);
773773
read_lvalue(&lvalue, var, parent, bb, 0, OP_generic);
774774

775-
if (lvalue.is_reference == 0) {
775+
if (!lvalue.is_reference) {
776776
ph1_ir = add_ph1_ir(OP_address_of);
777777
ph1_ir->src0 = opstack_pop();
778778
vd = require_var(parent);
@@ -950,7 +950,7 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
950950
} else {
951951
/* indirective function pointer assignment */
952952
vd = require_var(parent);
953-
vd->is_func = 1;
953+
vd->is_func = true;
954954
strcpy(vd->var_name, token);
955955
opstack_push(vd);
956956
}
@@ -1054,13 +1054,13 @@ void read_lvalue(lvalue_t *lvalue,
10541054
lvalue->size = get_size(var, lvalue->type);
10551055
lvalue->is_ptr = var->is_ptr;
10561056
lvalue->is_func = var->is_func;
1057-
lvalue->is_reference = 0;
1057+
lvalue->is_reference = false;
10581058

10591059
opstack_push(var);
10601060

10611061
if (lex_peek(T_open_square, NULL) || lex_peek(T_arrow, NULL) ||
10621062
lex_peek(T_dot, NULL))
1063-
lvalue->is_reference = 1;
1063+
lvalue->is_reference = true;
10641064

10651065
while (lex_peek(T_open_square, NULL) || lex_peek(T_arrow, NULL) ||
10661066
lex_peek(T_dot, NULL)) {
@@ -1110,7 +1110,7 @@ void read_lvalue(lvalue_t *lvalue,
11101110
lex_expect(T_close_square);
11111111
is_address_got = 1;
11121112
is_member = 1;
1113-
lvalue->is_reference = 1;
1113+
lvalue->is_reference = true;
11141114
} else {
11151115
char token[MAX_ID_LEN];
11161116

@@ -1159,7 +1159,7 @@ void read_lvalue(lvalue_t *lvalue,
11591159
* its value.
11601160
*/
11611161
if (var->array_size > 0)
1162-
lvalue->is_reference = 0;
1162+
lvalue->is_reference = false;
11631163

11641164
/* move pointer to offset of structure */
11651165
ph1_ir = add_ph1_ir(OP_load_constant);
@@ -1421,7 +1421,7 @@ void read_ternary_operation(block_t *parent, basic_block_t **bb)
14211421
strcpy(vd->var_name, end_label);
14221422
ph1_ir->src0 = vd;
14231423

1424-
var->is_ternary_ret = 1;
1424+
var->is_ternary_ret = true;
14251425
opstack_push(var);
14261426
bb[0] = end_ternary;
14271427
}
@@ -2692,7 +2692,7 @@ void read_func_body(func_t *fdef, fn_t *fn)
26922692
void read_global_decl(block_t *block)
26932693
{
26942694
var_t *var = require_var(block);
2695-
var->is_global = 1;
2695+
var->is_global = true;
26962696

26972697
/* new function, or variables under parent */
26982698
read_full_var_decl(var, 0, 0);
@@ -2701,7 +2701,7 @@ void read_global_decl(block_t *block)
27012701
/* function */
27022702
func_t *fd = add_func(var->var_name);
27032703
memcpy(&fd->return_def, var, sizeof(var_t));
2704-
var->is_global = 0;
2704+
var->is_global = false;
27052705
block->next_local--;
27062706

27072707
read_parameter_list_decl(fd, 0);

src/peephole.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file "LICENSE" for information on usage and redistribution of this file.
66
*/
77

8-
int is_fusible_insn(ph2_ir_t *ph2_ir)
8+
bool is_fusible_insn(ph2_ir_t *ph2_ir)
99
{
1010
switch (ph2_ir->op) {
1111
case OP_add:
@@ -25,9 +25,9 @@ int is_fusible_insn(ph2_ir_t *ph2_ir)
2525
case OP_load:
2626
case OP_global_load:
2727
case OP_load_data_address:
28-
return 1;
28+
return true;
2929
default:
30-
return 0;
30+
return false;
3131
}
3232
}
3333

src/reg-alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
* dead variable and does NOT wrtie it back to the stack.
1313
*/
1414

15-
int check_live_out(basic_block_t *bb, var_t *var)
15+
bool check_live_out(basic_block_t *bb, var_t *var)
1616
{
1717
for (int i = 0; i < bb->live_out_idx; i++) {
1818
if (bb->live_out[i] == var)
19-
return 1;
19+
return true;
2020
}
21-
return 0;
21+
return false;
2222
}
2323

2424
void refresh(basic_block_t *bb, insn_t *insn)

0 commit comments

Comments
 (0)