Skip to content

Commit 7f328f3

Browse files
committed
Apply editorial changes
1 parent 0b306a5 commit 7f328f3

File tree

10 files changed

+163
-180
lines changed

10 files changed

+163
-180
lines changed

src/arm-codegen.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
1313
{
1414
switch (ph2_ir->op) {
1515
case OP_load_constant:
16-
/* ARMv7 uses 12 bits to encode immediate value, but the
17-
* higher 4 bits are for rotation. See A5.2.4 "Modified
18-
* immediate constants in ARM instructions" in ARMv7-A
19-
* manual.
16+
/* ARMv7 uses 12 bits to encode immediate value, but the higher 4 bits
17+
* are for rotation. See A5.2.4 "Modified immediate constants in ARM
18+
* instructions" in ARMv7-A manual.
2019
*/
2120
if (ph2_ir->src0 < 0)
2221
elf_offset += 12;
@@ -27,10 +26,9 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
2726
return;
2827
case OP_address_of:
2928
case OP_global_address_of:
30-
/* ARMv7 uses 12 bits to encode immediate value, but the
31-
* higher 4 bits are for rotation. See A5.2.4 "Modified
32-
* immediate constants in ARM instructions" in ARMv7-A
33-
* manual.
29+
/* ARMv7 uses 12 bits to encode immediate value, but the higher 4 bits
30+
* are for rotation. See A5.2.4 "Modified immediate constants in ARM
31+
* instructions" in ARMv7-A manual.
3432
*/
3533
if (ph2_ir->src0 > 255)
3634
elf_offset += 12;
@@ -45,8 +43,8 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
4543
return;
4644
case OP_load:
4745
case OP_global_load:
48-
/* ARMv7 straight uses 12 bits to encode the offset of
49-
* load instruction (no rotation).
46+
/* ARMv7 straight uses 12 bits to encode the offset of load instruction
47+
* (no rotation).
5048
*/
5149
if (ph2_ir->src0 > 4095)
5250
elf_offset += 16;
@@ -57,8 +55,8 @@ void update_elf_offset(ph2_ir_t *ph2_ir)
5755
return;
5856
case OP_store:
5957
case OP_global_store:
60-
/* ARMv7 straight uses 12 bits to encode the offset of
61-
* store instruction (no rotation).
58+
/* ARMv7 straight uses 12 bits to encode the offset of store instruction
59+
* (no rotation).
6260
*/
6361
if (ph2_ir->src1 > 4095)
6462
elf_offset += 16;
@@ -126,10 +124,11 @@ void cfg_flatten()
126124
GLOBAL_FUNC.fn->bbs->elf_offset = elf_offset;
127125

128126
for (ph2_ir_t *ph2_ir = GLOBAL_FUNC.fn->bbs->ph2_ir_list.head; ph2_ir;
129-
ph2_ir = ph2_ir->next)
127+
ph2_ir = ph2_ir->next) {
130128
update_elf_offset(ph2_ir);
129+
}
131130

132-
/* prepare `argc` and `argv`, then proceed to `main` function */
131+
/* prepare 'argc' and 'argv', then proceed to 'main' function */
133132
elf_offset += 24;
134133

135134
for (fn_t *fn = FUNC_LIST.head; fn; fn = fn->next) {
@@ -142,21 +141,23 @@ void cfg_flatten()
142141
for (basic_block_t *bb = fn->bbs; bb; bb = bb->rpo_next) {
143142
bb->elf_offset = elf_offset;
144143

145-
if (bb == fn->bbs)
144+
if (bb == fn->bbs) {
146145
/* save ra, sp */
147146
elf_offset += 16;
147+
}
148148

149149
for (ph2_ir_t *insn = bb->ph2_ir_list.head; insn;
150150
insn = insn->next) {
151151
flatten_ir = add_ph2_ir(OP_generic);
152152
memcpy(flatten_ir, insn, sizeof(ph2_ir_t));
153153

154-
if (insn->op == OP_return)
154+
if (insn->op == OP_return) {
155155
/* restore sp */
156156
flatten_ir->src1 = bb->belong_to->func->stack_size;
157+
}
157158

158159
if (insn->op == OP_branch) {
159-
/* In SSA, we index `else_bb` first, and then `then_bb` */
160+
/* In SSA, we index 'else_bb' first, and then 'then_bb' */
160161
if (insn->else_bb != bb->rpo_next)
161162
flatten_ir->is_branch_detached = 1;
162163
}
@@ -415,7 +416,7 @@ void code_generate()
415416
ph2_ir = ph2_ir->next)
416417
emit_ph2_ir(ph2_ir);
417418

418-
/* prepare `argc` and `argv`, then proceed to `main` function */
419+
/* prepare 'argc' and 'argv', then proceed to 'main' function */
419420
emit(__movw(__AL, __r8, GLOBAL_FUNC.stack_size));
420421
emit(__movt(__AL, __r8, GLOBAL_FUNC.stack_size));
421422
emit(__add_r(__AL, __r8, __r12, __r8));

src/defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#else
5757
/* suppress GCC/Clang warnings */
5858
#define UNUSED(x) (void) (x)
59-
/* configure host data model when using `memcpy()` */
59+
/* configure host data model when using 'memcpy'. */
6060
#define HOST_PTR_SIZE __SIZEOF_POINTER__
6161
#endif
6262

src/globals.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ char *elf_section;
7676
* insert_trie() - Inserts a new element into the trie structure.
7777
* @trie: A pointer to the trie where the name will be inserted.
7878
* @name: The name to be inserted into the trie.
79-
* @funcs_index: The index of the pointer to the func_t. The index is
80-
* recorded in a 1-indexed format. Because the first element of
81-
* `FUNCS` has been reserved, there's no need to shift it.
79+
* @funcs_index: The index of the pointer to the func_t. The index is recorded
80+
* in a 1-indexed format. Because the first element of 'FUNCS' has been
81+
* reserved, there is no need to shift it.
8282
* Return: The index of the pointer to the func_t.
8383
*
8484
* If the function has been inserted, the return value is the index of the
@@ -155,8 +155,7 @@ type_t *find_type(char *type_name, int flag)
155155
if (flag == 2)
156156
continue;
157157
if (!strcmp(TYPES[i].type_name, type_name)) {
158-
/*
159-
* If it is a forwardly declared alias of a structure, return
158+
/* If it is a forwardly declared alias of a structure, return
160159
* the base structure type.
161160
*/
162161
if (TYPES[i].base_type == TYPE_typedef && TYPES[i].size == 0)
@@ -305,7 +304,7 @@ func_t *add_func(char *name)
305304
strcpy(fn->return_def.var_name, name);
306305
}
307306
fn = &FUNCS[index];
308-
fn->stack_size = 4; /*starting point of stack */
307+
fn->stack_size = 4; /* starting point of stack */
309308
return fn;
310309
}
311310

@@ -347,8 +346,7 @@ func_t *find_func(char func_name[])
347346

348347
var_t *find_member(char token[], type_t *type)
349348
{
350-
/*
351-
* If it is a forwardly declared alias of a structure, switch to the base
349+
/* If it is a forwardly declared alias of a structure, switch to the base
352350
* structure type.
353351
*/
354352
if (type->size == 0)
@@ -419,7 +417,7 @@ int size_var(var_t *var)
419417
return size;
420418
}
421419

422-
/* TODO: Integrate with `func_t` */
420+
/* TODO: Integrate with 'func_t' */
423421
fn_t *add_fn()
424422
{
425423
fn_t *n = calloc(1, sizeof(fn_t));
@@ -434,7 +432,7 @@ fn_t *add_fn()
434432
return n;
435433
}
436434

437-
/* Create a basic block and set the scope of variables to `parent` block */
435+
/* Create a basic block and set the scope of variables to 'parent' block */
438436
basic_block_t *bb_create(block_t *parent)
439437
{
440438
basic_block_t *bb = calloc(1, sizeof(basic_block_t));
@@ -623,7 +621,8 @@ void global_release()
623621
void error(char *msg)
624622
{
625623
/* Construct error source diagnostics, enabling precise identification of
626-
* syntax and logic issues within the code. */
624+
* syntax and logic issues within the code.
625+
*/
627626
int offset, start_idx, i = 0;
628627
char diagnostic[512 /* MAX_LINE_LEN * 2 */];
629628

@@ -645,7 +644,8 @@ void error(char *msg)
645644
strcpy(diagnostic + i, "^ Error occurs here");
646645

647646
/* TODO: figure out the corresponding C source file path and report line
648-
* number */
647+
* number.
648+
*/
649649
printf("Error %s at source location %d\n%s\n", msg, source_idx, diagnostic);
650650
abort();
651651
}

src/lexer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ char peek_char(int offset)
174174
return SOURCE[source_idx + offset];
175175
}
176176

177-
/* Lex next token and returns its token type. Parameter `aliasing` is used for
177+
/* Lex next token and returns its token type. Parameter 'aliasing' is used for
178178
* disable preprocessor aliasing on identifier tokens.
179179
*/
180180
token_t lex_token_internal(int aliasing)
@@ -549,7 +549,8 @@ token_t lex_token_internal(int aliasing)
549549
}
550550

551551
/* Lex next token and returns its token type. To disable aliasing on next
552-
* token, use `lex_token_internal`. */
552+
* token, use 'lex_token_internal'.
553+
*/
553554
token_t lex_token()
554555
{
555556
return lex_token_internal(1);
@@ -576,16 +577,16 @@ int lex_accept_internal(token_t token, int aliasing)
576577
return 0;
577578
}
578579

579-
/* Accepts next token if token types are matched. To disable aliasing
580-
* on next token, use `lex_accept_internal`.
580+
/* Accepts next token if token types are matched. To disable aliasing on next
581+
* token, use 'lex_accept_internal'.
581582
*/
582583
int lex_accept(token_t token)
583584
{
584585
return lex_accept_internal(token, 1);
585586
}
586587

587-
/* Peeks next token and copy token's literal to value if token types
588-
* are matched.
588+
/* Peeks next token and copy token's literal to value if token types are
589+
* matched.
589590
*/
590591
int lex_peek(token_t token, char *value)
591592
{
@@ -598,8 +599,8 @@ int lex_peek(token_t token, char *value)
598599
return 0;
599600
}
600601

601-
/* Strictly match next token with given token type and copy token's
602-
* literal to value.
602+
/* Strictly match next token with given token type and copy token's literal to
603+
* value.
603604
*/
604605
void lex_ident_internal(token_t token, char *value, int aliasing)
605606
{
@@ -609,9 +610,8 @@ void lex_ident_internal(token_t token, char *value, int aliasing)
609610
next_token = lex_token_internal(aliasing);
610611
}
611612

612-
/* Strictly match next token with given token type and copy token's
613-
* literal to value. To disable aliasing on next token, use
614-
* `lex_ident_internal`.
613+
/* Strictly match next token with given token type and copy token's literal to
614+
* value. To disable aliasing on next token, use 'lex_ident_internal'.
615615
*/
616616
void lex_ident(token_t token, char *value)
617617
{
@@ -626,8 +626,8 @@ void lex_expect_internal(token_t token, int aliasing)
626626
next_token = lex_token_internal(aliasing);
627627
}
628628

629-
/* Strictly match next token with given token type. To disable aliasing
630-
* on next token, use `lex_expect_internal`.
629+
/* Strictly match next token with given token type. To disable aliasing on next
630+
* token, use 'lex_expect_internal'.
631631
*/
632632
void lex_expect(token_t token)
633633
{

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/* Peephole optimization */
3737
#include "peephole.c"
3838

39-
/* Machine code generation. support ARMv7-A and RISC-V32I */
39+
/* Machine code generation. support ARMv7-A and RV32I */
4040
#include "codegen.c"
4141

4242
/* inlined libc */

0 commit comments

Comments
 (0)