我已经将以下内容编写为文本冒险游戏的文本命令解析器的一部分.
我试图将用户输入的字符串与枚举类中的项相关联.以下是我的头文件:
#include <iostream>
#include <map>
#include <string>
using namespace std;
enum class Noun
{
// Interrogation subjects
name, // ask the subject his name
base, // where is the base?
attack, // when will the attack be?
invalid
};
map < string, Noun > knownNouns;
knownNouns["name"] = Noun::name;
knownNouns["base"] = Noun::base;
knownNouns["attack"] = Noun::attack;
Noun parseNoun(string &noun)
{
auto n = knownNouns.find(noun);
if ( n == knownNouns.end() ) {
return Noun::invalid;
}
return n->second;
Run Code Online (Sandbox Code Playgroud)
当我通过编译器,我得到以下内容:
nouns.h:46:1: error: 'knownNouns' does …Run Code Online (Sandbox Code Playgroud) 我想检测一个程序来访问硬件性能计数器。
我已经编译了一个基本的 Rocketchip ( freechips.rocketchip.system-DefaultConfig) 并riscv-pk用于运行二进制文件。我正在 Verilator 中运行内核的模拟,在 UCB Chipyard 项目中使用大部分默认值编译了它。
二进制文件的 C 如下:
#include <stdio.h>
#define CACHE_MISS 0x100
int loop(int n, int a) {
int b = 0;
for(int i=0; i<n; i++) {
b = a + b;
}
return b;
}
int main() {
int a = 1;
int n = 200;
int count = 0;
printf("Configuring event monitor ...\n");
/*
// initialize counters here
// should start tracking cache misses with 0x100
__asm__ volatile("csrw …Run Code Online (Sandbox Code Playgroud)