> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.1.71 #1-NixOS SMP PREEMPT_DYNAMIC Fri Jan  5 14:18:41 UTC 2024 x86_64 GNU/Linux
 11:18:05  up   0:12,  2 users,  load average: 0.53, 0.27, 0.14
This commit is contained in:
tracer-ysyx 2024-01-13 11:18:05 +08:00 committed by xinyangli
parent f5a7ed17f6
commit c70ced4738
7 changed files with 5 additions and 214 deletions

View file

@ -1,74 +0,0 @@
#
# Automatically generated file; DO NOT EDIT.
# NEMU Configuration Menu
#
# CONFIG_ISA_x86 is not set
# CONFIG_ISA_mips32 is not set
CONFIG_ISA_riscv=y
# CONFIG_ISA_loongarch32r is not set
CONFIG_ISA="riscv32"
#
# ISA-dependent Options for riscv
#
# CONFIG_RV64 is not set
# CONFIG_RVE is not set
# end of ISA-dependent Options for riscv
CONFIG_ENGINE_INTERPRETER=y
CONFIG_ENGINE="interpreter"
CONFIG_MODE_SYSTEM=y
CONFIG_TARGET_NATIVE_ELF=y
# CONFIG_TARGET_SHARE is not set
# CONFIG_TARGET_AM is not set
#
# Build Options
#
CONFIG_CC_GCC=y
# CONFIG_CC_GPP is not set
# CONFIG_CC_CLANG is not set
CONFIG_CC="gcc"
# CONFIG_CC_O0 is not set
# CONFIG_CC_O1 is not set
CONFIG_CC_O2=y
# CONFIG_CC_O3 is not set
CONFIG_CC_OPT="-O2"
# CONFIG_CC_LTO is not set
# CONFIG_CC_DEBUG is not set
# CONFIG_CC_ASAN is not set
# end of Build Options
#
# Testing and Debugging
#
CONFIG_TRACE=y
CONFIG_TRACE_START=0
CONFIG_TRACE_END=10000
CONFIG_ITRACE=y
CONFIG_ITRACE_COND="true"
# CONFIG_DIFFTEST is not set
CONFIG_DIFFTEST_REF_PATH="none"
CONFIG_DIFFTEST_REF_NAME="none"
# end of Testing and Debugging
#
# Memory Configuration
#
CONFIG_MBASE=0x80000000
CONFIG_MSIZE=0x8000000
CONFIG_PC_RESET_OFFSET=0
# CONFIG_PMEM_MALLOC is not set
CONFIG_PMEM_GARRAY=y
CONFIG_MEM_RANDOM=y
# end of Memory Configuration
# CONFIG_DEVICE is not set
#
# Miscellaneous
#
CONFIG_TIMER_GETTIMEOFDAY=y
# CONFIG_TIMER_CLOCK_GETTIME is not set
CONFIG_RT_CHECK=y
# end of Miscellaneous

1
nemu/.gitignore vendored
View file

@ -5,6 +5,7 @@ build/
.cache/
.direnv/
.config
.config.old
.envrc
compile_commands.json

View file

@ -1,3 +1,6 @@
%code requires {
#include <common.h>
}
%{
#include <stdio.h>
#include <stdlib.h>
@ -10,7 +13,7 @@
%token NUMBER HEX_NUMBER
%start input
%define api.value.type { uint32_t }
%define api.value.type { word_t }
%parse-param { uint32_t *result }
%left '-' '+'
%left '*' '/'

View file

@ -1,129 +0,0 @@
/***************************************************************************************
* 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 <isa.h>
/* We use the POSIX regex functions to process regular expressions.
* Type 'man regex' for more information about POSIX regex functions.
*/
#include <regex.h>
enum {
TK_NOTYPE = 256, TK_EQ, TK_NUMBER,
LEX_GROUP_OPERATOR, LEX_GROUP_DIGIT
};
static struct rule {
const char *regex;
int token_type;
} rules[] = {
{"[ \t]+", TK_NOTYPE},
{"==", TK_EQ},
{"[0-9]+", LEX_GROUP_DIGIT},
{"[\\+-*/()", LEX_GROUP_OPERATOR},
};
#define NR_REGEX ARRLEN(rules)
static regex_t re[NR_REGEX] = {};
/* Rules are used for many times.
* Therefore we compile them only once before any usage.
*/
void init_regex() {
int i;
char error_msg[128];
int ret;
for (i = 0; i < NR_REGEX; i ++) {
ret = regcomp(&re[i], rules[i].regex, REG_EXTENDED);
if (ret != 0) {
regerror(ret, &re[i], error_msg, 128);
panic("regex compilation failed: %s\n%s", error_msg, rules[i].regex);
}
}
}
typedef struct token {
int type;
char str[32];
} Token;
static Token tokens[32] __attribute__((used)) = {};
static int nr_token __attribute__((used)) = 0;
static bool make_token(char *e) {
int position = 0;
int i;
regmatch_t pmatch;
nr_token = 0;
while (e[position] != '\0') {
/* Try all rules one by one. */
for (i = 0; i < NR_REGEX; i ++) {
if (regexec(&re[i], e + position, 1, &pmatch, 0) == 0 && pmatch.rm_so == 0) {
char *substr_start = e + position;
int substr_len = pmatch.rm_eo;
Log("match rules[%d] = \"%s\" at position %d with len %d: %.*s",
i, rules[i].regex, position, substr_len, substr_len, substr_start);
position += substr_len;
/* TODO: Now a new token is recognized with rules[i]. Add codes
* to record the token in the array `tokens'. For certain types
* of tokens, some extra actions should be performed.
*/
switch (rules[i].token_type) {
case LEX_GROUP_OPERATOR:
tokens[nr_token].type = *substr_start;
tokens[nr_token].str[0] = '\0';
nr_token++;
break;
case LEX_GROUP_DIGIT:
tokens[nr_token].type = TK_NUMBER;
nr_token++;
break;
case TK_NOTYPE: break;
default: TODO();
}
break;
}
}
if (i == NR_REGEX) {
printf("no match at position %d\n%s\n%*.s^\n", position, e, position, "");
return false;
}
}
return true;
}
word_t expr(char *e, bool *success) {
if (!make_token(e)) {
*success = false;
return 0;
}
/* TODO: Insert codes to evaluate the expression. */
TODO();
return 0;
}

View file

@ -18,6 +18,4 @@
#include <common.h>
word_t expr(char *e, bool *success);
#endif

BIN
nemu/test

Binary file not shown.

View file

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