Skip to content

Commit d80c68f

Browse files
committed
Apply editorial changes
1 parent 84b2fde commit d80c68f

File tree

12 files changed

+47
-50
lines changed

12 files changed

+47
-50
lines changed

src/elf.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ bool elf_open(elf_t *e, const char *input)
299299

300300
#if HAVE_MMAP
301301
int fd = open(path, O_RDONLY);
302-
if (fd < 0) {
302+
if (fd < 0)
303303
goto free_path;
304-
}
305304

306305
/* get file size */
307306
struct stat st;
@@ -312,24 +311,21 @@ bool elf_open(elf_t *e, const char *input)
312311
* The beginning of the file is ELF header.
313312
*/
314313
e->raw_data = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
315-
if (e->raw_data == MAP_FAILED) {
314+
if (e->raw_data == MAP_FAILED)
316315
goto free_fd;
317-
}
318316
close(fd);
319317

320318
#else /* fallback to standard I/O text stream */
321319
FILE *f = fopen(path, "rb");
322-
if (!f) {
320+
if (!f)
323321
goto free_path;
324-
}
325322

326323
/* get file size */
327324
fseek(f, 0, SEEK_END);
328325
e->raw_size = ftell(f);
329326
fseek(f, 0, SEEK_SET);
330-
if (e->raw_size == 0) {
327+
if (!e->raw_size)
331328
goto free_fd;
332-
}
333329

334330
/* allocate memory */
335331
free(e->raw_data);
@@ -339,18 +335,16 @@ bool elf_open(elf_t *e, const char *input)
339335
/* read data into memory */
340336
const size_t r = fread(e->raw_data, 1, e->raw_size, f);
341337
fclose(f);
342-
if (r != e->raw_size) {
338+
if (r != e->raw_size)
343339
goto free_path;
344-
}
345340
#endif /* HAVE_MMAP */
346341

347342
/* point to the header */
348343
e->hdr = (const struct Elf32_Ehdr *) e->raw_data;
349344

350345
/* check it is a valid ELF file */
351-
if (!is_valid(e)) {
346+
if (!is_valid(e))
352347
goto free_path;
353-
}
354348

355349
free(path);
356350
return true;

src/elf.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ enum {
3232
EI_NIDENT = 16,
3333
};
3434

35-
/*
36-
* Section Types
37-
*/
35+
/* Section Types */
3836
enum {
3937
SHT_NULL = 0, /* Section header table entry unused */
4038
SHT_PROGBITS = 1, /* Program data */
@@ -55,9 +53,7 @@ enum {
5553
SHT_HIUSER = 0xffffffff, /* End of application-specific */
5654
};
5755

58-
/*
59-
* Section Attribute Flags
60-
*/
56+
/* Section Attribute Flags */
6157
enum {
6258
SHF_WRITE = 0x1,
6359
SHF_ALLOC = 0x2,

src/gdbstub.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ static int rv_read_mem(void *args, size_t addr, size_t len, void *val)
5353
for (size_t i = 0; i < len; i++) {
5454
/* FIXME: This is implemented as a simple workaround for reading
5555
* an invalid address. We may have to do error handling in the
56-
* mem_read_* function directly. */
56+
* mem_read_* function directly.
57+
*/
5758
*((uint8_t *) val + i) = rv->io.mem_read_b(addr + i);
5859
}
5960

src/jit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ static void divmod(struct jit_state *state,
758758
* instruction already returns 0 when dividing by zero.
759759
*/
760760
emit_dataproc_2source(state, is64, DP2_UDIV, div_dest, rn, rm);
761-
if (mod) {
761+
if (mod)
762762
emit_dataproc_3source(state, is64, DP3_MSUB, rd, rm, div_dest, rn);
763-
}
764763
}
765764
#endif
766765

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static bool parse_args(int argc, char **args)
150150
assert(getcwd(cwd_path, PATH_MAX));
151151

152152
char rel_path[PATH_MAX] = {0};
153-
memcpy(rel_path, args[0], strlen(args[0]) - 7 /* strlen("rv32emu")*/);
153+
memcpy(rel_path, args[0], strlen(args[0]) - 7 /* strlen("rv32emu") */);
154154

155155
char *prog_basename = basename(opt_prog_name);
156156
prof_out_file = malloc(strlen(cwd_path) + 1 + strlen(rel_path) +

src/map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ static void rb_remove(map_t rb, map_node_t *node)
290290
rb_node_set_right(pathp[-1].node, left);
291291
}
292292
return;
293-
} else if (pathp == path) {
293+
}
294+
if (pathp == path) {
294295
/* the tree only contained one node */
295296
rb->root = NULL;
296297
return;

src/mpool.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ typedef struct mpool {
3030

3131
static void *mem_arena(size_t sz)
3232
{
33+
void *p;
3334
#if HAVE_MMAP
34-
void *p =
35-
mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
35+
p = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
3636
if (p == MAP_FAILED)
3737
return NULL;
3838
#else
39-
void *p = malloc(sz);
39+
p = malloc(sz);
4040
if (!p)
4141
return NULL;
4242
#endif
@@ -81,9 +81,11 @@ static void *mpool_extend(mpool_t *mp)
8181
char *p = mem_arena(pool_size);
8282
if (!p)
8383
return NULL;
84+
8485
area_t *new_area = malloc(sizeof(area_t));
8586
if (!new_area)
8687
return NULL;
88+
8789
new_area->mapped = p;
8890
new_area->next = NULL;
8991
size_t chunk_count = pool_size / (sizeof(memchunk_t) + mp->chunk_size);
@@ -95,19 +97,21 @@ static void *mpool_extend(mpool_t *mp)
9597
cur = cur->next;
9698
}
9799
mp->chunk_count += chunk_count;
100+
98101
/* insert new mapped */
99102
area_t *cur_area = &mp->area;
100-
while (cur_area->next) {
103+
while (cur_area->next)
101104
cur_area = cur_area->next;
102-
}
103105
cur_area->next = new_area;
106+
104107
return p;
105108
}
106109

107110
void *mpool_alloc(mpool_t *mp)
108111
{
109112
if (!mp->chunk_count && !(mpool_extend(mp)))
110113
return NULL;
114+
111115
char *ptr = (char *) mp->free_chunk_head + sizeof(memchunk_t);
112116
mp->free_chunk_head = mp->free_chunk_head->next;
113117
mp->chunk_count--;
@@ -118,6 +122,7 @@ void *mpool_calloc(mpool_t *mp)
118122
{
119123
if (!mp->chunk_count && !(mpool_extend(mp)))
120124
return NULL;
125+
121126
char *ptr = (char *) mp->free_chunk_head + sizeof(memchunk_t);
122127
mp->free_chunk_head = mp->free_chunk_head->next;
123128
mp->chunk_count--;

src/riscv.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void block_map_clear(riscv_t *rv)
4949
block_t *block = map->map[i];
5050
if (!block)
5151
continue;
52+
5253
uint32_t idx;
5354
rv_insn_t *ir, *next;
5455
for (idx = 0, ir = block->ir_head; idx < block->n_insn;
@@ -110,15 +111,13 @@ riscv_word_t rv_get_reg(riscv_t *rv, uint32_t reg)
110111
return ~0U;
111112
}
112113

113-
/*
114-
* Remap standard stream
114+
/* Remap standard stream
115115
*
116116
* @rv: riscv
117117
* @fsp: a list of pair of mapping from fd to FILE *
118118
* @fsp_size: list size
119119
*
120120
* Note: fd inside fsp should be 0 or 1 or 2 only
121-
*
122121
*/
123122
void rv_remap_stdstream(riscv_t *rv, fd_stream_pair_t *fsp, uint32_t fsp_size)
124123
{
@@ -195,9 +194,7 @@ riscv_t *rv_create(const riscv_io_t *io, riscv_user_t rv_attr)
195194
/* TODO: system emulator */
196195
}
197196

198-
/*
199-
* default standard stream
200-
*
197+
/* default standard stream.
201198
* rv_remap_stdstream can be called to overwrite them
202199
*/
203200
attr->fd_map = map_init(int, FILE *, map_cmp_int);
@@ -274,7 +271,8 @@ void rv_run(riscv_t *rv)
274271
else if (attr->run_flag & RV_RUN_GDBSTUB)
275272
rv_debug(rv);
276273
#endif
277-
else { /* default main loop */
274+
else {
275+
/* default main loop */
278276
for (; !rv_has_halted(rv);) /* run until the flag is done */
279277
rv_step(rv, attr->cycle_per_step); /* step instructions */
280278
}

src/syscall.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "utils.h"
1515

1616
#define PREALLOC_SIZE 4096
17+
1718
/* newlib is a portable (not RISC-V specific) C library, which implements
1819
* printf(3) and other functions described in C standards. Some system calls
1920
* should be provided in conjunction with newlib.
@@ -106,6 +107,7 @@ static void syscall_write(riscv_t *rv)
106107
} else
107108
goto error_handler;
108109
}
110+
109111
memory_read(attr->mem, tmp, buffer + total_write, count);
110112
if (!map_at_end(attr->fd_map, &it)) {
111113
/* write out the data */
@@ -117,9 +119,11 @@ static void syscall_write(riscv_t *rv)
117119
} else
118120
goto error_handler;
119121
assert(total_write == rv_get_reg(rv, rv_reg_a2));
122+
120123
/* return number of bytes written */
121124
rv_set_reg(rv, rv_reg_a0, total_write);
122125
return;
126+
123127
/* read the string being printed */
124128
error_handler:
125129
/* error */
@@ -129,9 +133,7 @@ static void syscall_write(riscv_t *rv)
129133

130134
static void syscall_exit(riscv_t *rv)
131135
{
132-
/*
133-
* simply halt cpu and save exit code
134-
*
136+
/* simply halt cpu and save exit code.
135137
* the application decides the usage of exit code
136138
*/
137139
rv_halt(rv);

src/syscall_sdl.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,15 @@ static void *sfx_handler(void *arg)
630630
if (chan == -1)
631631
return NULL;
632632

633-
if (*ptr & 0x3) /* Doom, multiplied by 8 because sfx->volume's max is 15 */
633+
if (*ptr & 0x3) {
634+
/* Doom, multiplied by 8 because sfx->volume's max is 15 */
634635
Mix_Volume(chan, sfx->volume * 8);
635-
else /* Quake, + 1 mod by 128 because sfx->volume's max is 255 and
636-
Mix_Volume's max is 128 */
636+
} else {
637+
/* Quake, + 1 mod by 128 because sfx->volume's max is 255 and
638+
* Mix_Volume's max is 128.
639+
*/
637640
Mix_Volume(chan, (sfx->volume + 1) % 128);
641+
}
638642

639643
return NULL;
640644
}

0 commit comments

Comments
 (0)