Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.history/
example/
# Prerequisites
*.d
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ build:
cmake . -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_PARALLEL=`nproc` $(ARGS)
cd build && make -j`nproc`

clean_build:
rm -rf build

rebuild: clean_build build

install: build
cd build && make install

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Currently supported RTL simulators by picker:

1. Verilator
1. Synopsys VCS
1. [GSIM](https://github.com/OpenXiangShan/gsim)

## How to Use

Expand Down Expand Up @@ -134,7 +135,7 @@ Options:
-h,--help Print this help message and exit
--fs,--filelist TEXT ... DUT .v/.sv source files, contain the top module, split by comma.
Or use '*.txt' file with one RTL file path per line to specify the file list
--sim TEXT [verilator] vcs or verilator as simulator, default is verilator
--sim TEXT [verilator] vcs, gsim or verilator as simulator, default is verilator
--lang,--language TEXT:{python,cpp,java,scala,golang,lua} [python]
Build target project with assigned language, default python
--sdir,--source_dir TEXT [/home/yaozhicheng/workspace/picker/template]
Expand Down
3 changes: 2 additions & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Picker 目前支持的 RTL 仿真器:

1. Verilator
1. Synopsys VCS
1. [GSIM](https://github.com/OpenXiangShan/gsim)

# 使用方法

Expand Down Expand Up @@ -132,7 +133,7 @@ Options:
-h,--help Print this help message and exit
--fs,--filelist TEXT ... DUT .v/.sv source files, contain the top module, split by comma.
Or use '*.txt' file with one RTL file path per line to specify the file list
--sim TEXT [verilator] vcs or verilator as simulator, default is verilator
--sim TEXT [verilator] vcs, gsim or verilator as simulator, default is verilator
--lang,--language TEXT:{python,cpp,java,scala,golang,lua} [python]
Build target project with assigned language, default python
--sdir,--source_dir TEXT Template Files Dir, default is ${picker_install_path}/../picker/template
Expand Down
Binary file added example/GSim/NutShell/SimTop-nutshell.tar.bz2
Binary file not shown.
64 changes: 64 additions & 0 deletions example/GSim/NutShell/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
try:
from UT_SimTop import *
except:
try:
from SimTop import *
except:
from __init__ import *

from xspcomm import ComUseDataArray

def load_bin(dut: DUTSimTop, bin_file: str):
try:
with open(bin_file, 'rb') as f:
data = f.read()
except FileNotFoundError:
print(f"Error: File {bin_file} not found.")
return False
address = dut.xcfg.Address("mem$rdata_mem$mem")
bin_array = ComUseDataArray(address, len(data))
bin_array.FromBytes(data)
print(f"Loading {bin_file} ({len(data)} bytes) to address {hex(address)}")
return True

def init(dut: DUTSimTop):
dut.difftest_logCtrl_begin.value = 0
dut.difftest_logCtrl_end.value = 0
dut.difftest_uart_in_ch.value = -1
print("Initialization complete.")

def reset(dut: DUTSimTop):
dut.reset.value = 1
dut.Step(10)
dut.reset.value = 0
print("Reset complete.")

def uart(dut: DUTSimTop):
if dut.difftest_uart_out_valid.value:
print(chr(dut.difftest_uart_out_ch.value), end='', flush=True)

def main():
import sys
dut = DUTSimTop()
print("DUTSimTop initialized")
if len(sys.argv) < 2:
bin_file = "microbench-NutShell.bin"
else:
bin_file = sys.argv[1]
if len(sys.argv) < 3:
step_count = 1000000
else:
step_count = int(sys.argv[2])
if not load_bin(dut, bin_file):
print(f"Failed to load binary file: {bin_file}.")
print("Usage: python example.py <binary_file> [<step_count>]")
dut.StepRis(lambda c: uart(dut))
init(dut)
reset(dut)
print("Starting simulation with step count:", step_count)
dut.Step(step_count)
dut.Finish()
print("Simulation finished.")

if __name__ == "__main__":
main()
41 changes: 41 additions & 0 deletions example/GSim/NutShell/release-gsim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash


if ! command -v gsim &> /dev/null
then
echo "gsim could not be found"
echo "please add gsim into path first"
exit
fi

rm -rf picker_out_GSIM/
if [ ! -f example/GSim/NutShell/SimTop-nutshell.fir ]; then
tar -xf example/GSim/NutShell/SimTop-nutshell.tar.bz2 -C example/GSim/NutShell/
fi
./build/bin/picker export example/GSim/NutShell/SimTop-nutshell.fir --rw mem_direct --autobuild false --sim gsim --tdir picker_out_GSIM/NutShell $@
# if python in $@, then it will generate python binding
if [[ $@ == *"python"* ]]; then
cp example/GSim/NutShell/example.py picker_out_GSIM/NutShell/python/
cp example/GSim/NutShell/microbench-NutShell.bin picker_out_GSIM/NutShell/
elif [[ $@ == *"java"* ]]; then
cp example/GSim/NutShell/example.java picker_out_GSIM/NutShell/java/
elif [[ $@ == *"scala"* ]]; then
cp example/GSim/NutShell/example.scala picker_out_GSIM/NutShell/scala/
elif [[ $@ == *"golang"* ]]; then
cp example/GSim/NutShell/example.go picker_out_GSIM/NutShell/golang/
elif [[ $@ == *"lua"* ]]; then
cp example/GSim/NutShell/example.lua picker_out_GSIM/NutShell/lua/
elif [[ $@ == *"cpp"* ]]; then
cp example/GSim/NutShell/example.cpp picker_out_GSIM/NutShell/cpp/
else
echo "No example file copied, use default config."
fi

if [ -z $CC ] && [ -z $CXX ]; then
echo "CC and CXX not set, using default clang and clang++."
export CC=clang
export CXX=clang++
else
echo "Using CC=$CC and CXX=$CXX"
fi
cd picker_out_GSIM/NutShell && make EXAMPLE=ON
13 changes: 13 additions & 0 deletions include/codegen/firrtl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <bits/stdc++.h>
#include "picker.hpp"
#include "parser/firrtl.hpp"

namespace picker { namespace codegen {
std::vector<picker::sv_signal_define> gen_firrtl_param(nlohmann::json &global_render_data,
const std::vector<picker::sv_module_define> &sv_module_result,
const std::vector<picker::sv_signal_define> &internal_signal,
nlohmann::json &signal_tree_json,
const std::string &wave_file_name, const std::string &simulator, SignalAccessType rw_type);
}} // namespace picker::codegen
1 change: 1 addition & 0 deletions include/codegen/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <bits/stdc++.h>
#include "picker.hpp"
#include "parser/sv.hpp"
#include "parser/firrtl.hpp"

namespace picker { namespace codegen {

Expand Down
2 changes: 1 addition & 1 deletion include/codegen/mem_direct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace picker { namespace codegen {

void render_md_addr_generator(const std::vector<VariableInfo> &varibles, picker::export_opts &opts);
void render_md_addr_generator(const std::vector<cpp_variableInfo> &varibles, picker::export_opts &opts);

}}; // namespace picker::codegen
8 changes: 8 additions & 0 deletions include/parser/firrtl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <bits/stdc++.h>
#include "picker.hpp"

namespace picker { namespace parser {
int firrtl(picker::export_opts &opts, std::vector<picker::sv_module_define> &external_pin);
}; } // namespace picker::parser
12 changes: 12 additions & 0 deletions include/parser/gsim_root.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "picker.hpp"
#include "parser/verilator_root.hpp"

namespace picker {
namespace parser {
namespace gsim {
std::vector<std::string> readVarDeclarations(const std::string &filename);
std::vector<cpp_variableInfo> processDeclarations(const std::vector<std::string> &declarations);
} // namespace gsim
} // namespace parser
} // namespace picker
15 changes: 15 additions & 0 deletions include/parser/parser_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <map>
#include <string>
#include <functional>

#include "parser/gsim_root.hpp"
#include "parser/verilator_root.hpp"

namespace picker{namespace parser {

std::function<std::vector<std::string>(const std::string &)> GetReadVarDeclarations(const std::string &sim);
std::function<std::vector<picker::cpp_variableInfo>(const std::vector<std::string> &)> GetProcessDeclarations(const std::string &sim);
std::function<int(picker::export_opts &, std::vector<picker::sv_module_define> &)> GetInputParser(const std::string &sim);

}} // namespace parser
13 changes: 4 additions & 9 deletions include/parser/verilator_root.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
#include "picker.hpp"

namespace picker {
struct VariableInfo {
std::string name;
std::string type;
int width = 0;
int array_size = 0;
int64_t offset = 0;
};
namespace parser {
void outputYAML(const std::vector<cpp_variableInfo> &vars, const std::string &fileName = "");
namespace verilator {
std::vector<std::string> readVarDeclarations(const std::string &filename);
std::vector<VariableInfo> processDeclarations(const std::vector<std::string> &declarations);
void outputYAML(const std::vector<VariableInfo> &vars, const std::string &fileName = "");
std::vector<cpp_variableInfo> processDeclarations(const std::vector<std::string> &declarations);
} // namespace verilator
} // namespace parser
} // namespace picker
4 changes: 4 additions & 0 deletions include/picker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
#include "codegen/scala.hpp"
#include "codegen/golang.hpp"
#include "codegen/sv.hpp"
#include "codegen/firrtl.hpp"
#include "codegen/lib.hpp"
#include "codegen/lua.hpp"
#include "parser/sv.hpp"
#include "parser/firrtl.hpp"
#include "parser/internalcfg.hpp"
#include "parser/verilator_root.hpp"
#include "parser/gsim_root.hpp"
#include "parser/parser_map.hpp"

extern std::map<std::string, std::string> lang_lib_map;
extern std::map<std::string, std::string> display_names;
Expand Down
9 changes: 9 additions & 0 deletions include/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ typedef struct uvm_transaction_define {
std::vector<uvm_parameter> parameters;

} uvm_transaction_define;

typedef struct cpp_variableInfo {
std::string name;
std::string type;
int width = 0;
int array_size = 0;
int64_t offset = 0;
} cpp_variableInfo;

} // namespace picker
1 change: 1 addition & 0 deletions src/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(source_file
lua.cpp
uvm.cpp
mem_direct.cpp
firrtl.cpp
)

add_library(codegen_ STATIC ${source_file})
1 change: 1 addition & 0 deletions src/codegen/cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ namespace codegen {

data["__COMMENTS__"] = comments;
data["__COPY_XSPCOMM_LIB__"] = opts.cp_lib;
data["__SIMULATOR__"] = opts.sim;

// Render
inja::Environment env;
Expand Down
29 changes: 29 additions & 0 deletions src/codegen/firrtl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>
#include "codegen/firrtl.hpp"


namespace picker { namespace codegen {
std::vector<picker::sv_signal_define> gen_firrtl_param(nlohmann::json &global_render_data,
const std::vector<picker::sv_module_define> &sv_module_result,
const std::vector<picker::sv_signal_define> &internal_signal,
nlohmann::json &signal_tree_json,
const std::string &wave_file_name, const std::string &simulator, SignalAccessType rw_type){

global_render_data["__WAVE_FILE_NAME__"] = "__GISM_NOT_SUPPORT___WAVE_FILE_NAME__";
global_render_data["__DUMP_VAR_OPTIONS__"] = "__GISM_NOT_SUPPORT___DUMP_VAR_OPTIONS__";
global_render_data["__TRACE__"] = "__GISM_NOT_SUPPORT___TRACE__";
global_render_data["__LOGIC_PIN_DECLARATION__"] = "__GISM_NOT_SUPPORT___LOGIC_PIN_DECLARATION__";
global_render_data["__SV_DUMP_WAVE__"] = "__GISM_NOT_SUPPORT___SV_DUMP_WAVE__";
global_render_data["__WIRE_PIN_DECLARATION__"] = "__GISM_NOT_SUPPORT___WIRE_PIN_DECLARATION__";
global_render_data["__INNER_MODULES__"] = "__GISM_NOT_SUPPORT___INNER_MODULES__";
global_render_data["__DPI_FUNCTION_EXPORT__"] = "__GISM_NOT_SUPPORT___DPI_FUNCTION_EXPORT__";
global_render_data["__DPI_FUNCTION_IMPLEMENT__"] = "__GISM_NOT_SUPPORT___DPI_FUNCTION_IMPLEMENT__";
global_render_data["__EXTEND_SV__"] = "__GISM_NOT_SUPPORT___EXTEND_SV__";
global_render_data["__LIB_DPI_FUNC_NAME_HASH__"] = "__GISM_NOT_SUPPORT___LIB_DPI_FUNC_NAME_HASH__";
global_render_data["__SIGNAL_TREE__"] = "__GISM_NOT_SUPPORT___SIGNAL_TREE__";
assert(sv_module_result.size() == 1);
return sv_module_result[0].pins;
}

// end of namespace picker::codegen
};}
1 change: 1 addition & 0 deletions src/codegen/golang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ namespace picker { namespace codegen {
data["__SWIG_CONSTANT__"] = swig_constant;
data["__USE_SIMULATOR__"] = "USE_" + simulator;
data["__COPY_XSPCOMM_LIB__"] = opts.cp_lib;
data["__SIMULATOR__"] = opts.sim;

// Render
inja::Environment env;
Expand Down
1 change: 1 addition & 0 deletions src/codegen/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ namespace picker { namespace codegen {
data["__SWIG_CONSTANT__"] = swig_constant;
data["__USE_SIMULATOR__"] = "USE_" + simulator;
data["__COPY_XSPCOMM_LIB__"] = opts.cp_lib;
data["__SIMULATOR__"] = opts.sim;

// Render
inja::Environment env;
Expand Down
Loading