> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.1.69 #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 20 16:00:29 UTC 2023 x86_64 GNU/Linux
 09:25:24  up 1 day  9:41,  2 users,  load average: 0.21, 0.43, 0.48
This commit is contained in:
tracer-ysyx 2024-01-13 09:25:24 +08:00 committed by xinyangli
parent 6fe396f201
commit 74e272b7b5
3 changed files with 20 additions and 5 deletions

BIN
nemu/test Executable file

Binary file not shown.

8
nemu/test.c Normal file
View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdint.h>
int main() {
uint32_t result = (0xdU) * (31U / ((((0x45U)) - 75U)) * (0x41U) + 53U / (0xaU) - (0x50U));
printf("%u", result);
return 0;
}

View file

@ -9,10 +9,10 @@
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
char buf[65536] = {}; char buf[65536] = {}, ref_buf[65536] = {};
static char code_buf[65536 + 128] = {}; // a little larger than `buf` static char code_buf[65536 + 128] = {}; // a little larger than `buf`
const int buf_start_pos = 0; const int buf_start_pos = 0;
char *buf_ptr = buf + buf_start_pos; char *buf_ptr = buf + buf_start_pos, *ref_buf_ptr = ref_buf;
static char *code_format = static char *code_format =
"#include <stdio.h>\n" "#include <stdio.h>\n"
"#include <stdint.h>\n" "#include <stdint.h>\n"
@ -25,21 +25,25 @@ static char *code_format =
void gen(char c) { void gen(char c) {
*(buf_ptr++) = c; *(buf_ptr++) = c;
*(ref_buf_ptr) = c;
} }
void gen_num(void) { void gen_num(void) {
uint32_t num = rand() % 100; uint32_t num = rand() % 100;
int len = 0; int len = 0, ref_len = 0;
switch(rand() % 2) { switch(rand() % 2) {
case 0: case 0:
len = snprintf(buf_ptr, 100, "%u", num); len = snprintf(buf_ptr, 100, "%u", num);
ref_len = snprintf(buf_ptr, 100, "%uU", num);
break; break;
case 1: case 1:
len = snprintf(buf_ptr, 100, "0x%x", num); len = snprintf(buf_ptr, 100, "0x%x", num);
ref_len = snprintf(buf_ptr, 100, "%uU", num);
break; break;
default: assert(0); default: assert(0);
} }
buf_ptr += len; buf_ptr += len;
ref_buf_ptr += ref_len;
} }
void gen_rand_op(void) { void gen_rand_op(void) {
@ -71,7 +75,7 @@ START_TEST(test_expr_random_100) {
ck_assert(!yyparse(&addr)); ck_assert(!yyparse(&addr));
yylex_destroy(); yylex_destroy();
sprintf(code_buf, code_format, buf); sprintf(code_buf, code_format, ref_buf);
FILE *fp = fopen("/tmp/.code.c", "w"); FILE *fp = fopen("/tmp/.code.c", "w");
ck_assert(fp != NULL); ck_assert(fp != NULL);
@ -93,7 +97,10 @@ START_TEST(test_expr_random_100) {
ck_assert_msg(addr == reference, "\n\tbuf = %s\n\taddr = %u, reference = %u\n", buf, addr, reference); ck_assert_msg(addr == reference, "\n\tbuf = %s\n\taddr = %u, reference = %u\n", buf, addr, reference);
while(buf_ptr != buf + buf_start_pos) { while(buf_ptr != buf + buf_start_pos) {
*(--buf_ptr) = '\0'; *(--buf_ptr) = '\0';
}
while(ref_buf_ptr != ref_buf) {
*(--ref_buf_ptr) = '\0';
} }
} END_TEST } END_TEST