NJU-ProjectN/nemu ics2023 initialized
NJU-ProjectN/nemu eb63cf3568dbf4e0c3c6ef462e6ec685550fabbc Merge pull request #76 from rijuyuezhu/master
This commit is contained in:
parent
1efe03efb9
commit
2824efad33
141 changed files with 19573 additions and 0 deletions
1
nemu/tools/gen-expr/.gitignore
vendored
Normal file
1
nemu/tools/gen-expr/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.code.c
|
18
nemu/tools/gen-expr/Makefile
Normal file
18
nemu/tools/gen-expr/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
#***************************************************************************************
|
||||
# Copyright (c) 2014-2022 Zihao Yu, Nanjing University
|
||||
#
|
||||
# NEMU is licensed under Mulan PSL v2.
|
||||
# You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
# You may obtain a copy of Mulan PSL v2 at:
|
||||
# http://license.coscl.org.cn/MulanPSL2
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
# See the Mulan PSL v2 for more details.
|
||||
#**************************************************************************************/
|
||||
|
||||
NAME = gen-expr
|
||||
SRCS = gen-expr.c
|
||||
include $(NEMU_HOME)/scripts/build.mk
|
69
nemu/tools/gen-expr/gen-expr.c
Normal file
69
nemu/tools/gen-expr/gen-expr.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
/***************************************************************************************
|
||||
* Copyright (c) 2014-2022 Zihao Yu, Nanjing University
|
||||
*
|
||||
* NEMU is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the Mulan PSL v2 for more details.
|
||||
***************************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
// this should be enough
|
||||
static char buf[65536] = {};
|
||||
static char code_buf[65536 + 128] = {}; // a little larger than `buf`
|
||||
static char *code_format =
|
||||
"#include <stdio.h>\n"
|
||||
"int main() { "
|
||||
" unsigned result = %s; "
|
||||
" printf(\"%%u\", result); "
|
||||
" return 0; "
|
||||
"}";
|
||||
|
||||
static void gen_rand_expr() {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int seed = time(0);
|
||||
srand(seed);
|
||||
int loop = 1;
|
||||
if (argc > 1) {
|
||||
sscanf(argv[1], "%d", &loop);
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < loop; i ++) {
|
||||
gen_rand_expr();
|
||||
|
||||
sprintf(code_buf, code_format, buf);
|
||||
|
||||
FILE *fp = fopen("/tmp/.code.c", "w");
|
||||
assert(fp != NULL);
|
||||
fputs(code_buf, fp);
|
||||
fclose(fp);
|
||||
|
||||
int ret = system("gcc /tmp/.code.c -o /tmp/.expr");
|
||||
if (ret != 0) continue;
|
||||
|
||||
fp = popen("/tmp/.expr", "r");
|
||||
assert(fp != NULL);
|
||||
|
||||
int result;
|
||||
ret = fscanf(fp, "%d", &result);
|
||||
pclose(fp);
|
||||
|
||||
printf("%u %s\n", result, buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue