diff options
| -rw-r--r-- | src/main/resources/vpi.cpp | 130 | ||||
| -rw-r--r-- | src/main/resources/vpi.h | 212 | ||||
| -rw-r--r-- | src/main/resources/vpi_user.cc | 562 |
3 files changed, 0 insertions, 904 deletions
diff --git a/src/main/resources/vpi.cpp b/src/main/resources/vpi.cpp deleted file mode 100644 index 7850f3b0..00000000 --- a/src/main/resources/vpi.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "vpi.h" - -vpi_api_t vpi_api; - -/*========================================================================== - User Functions -=============================================================================*/ - -PLI_INT32 init_clks_calltf(PLI_BYTE8 *user_data) { - vpi_api.init_clks(); - return 0; -} - -PLI_INT32 init_rsts_calltf(PLI_BYTE8 *user_data) { - vpi_api.init_rsts(); - return 0; -} - -PLI_INT32 init_ins_calltf(PLI_BYTE8 *user_data) { - vpi_api.init_ins(); - return 0; -} - -PLI_INT32 init_outs_calltf(PLI_BYTE8 *user_data) { - vpi_api.init_outs(); - return 0; -} - -PLI_INT32 init_sigs_calltf(PLI_BYTE8 *user_data) { - vpi_api.init_sigs(); - return 0; -} - -PLI_INT32 tick_calltf(PLI_BYTE8 *user_data) { - vpi_api.tick(); - return 0; -} - -PLI_INT32 tick_cb(p_cb_data cb_data) { - vpi_api.tick(); - return 0; -} - -/*========================================================================== - Registration Functions -=============================================================================*/ -void init_clks_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$init_clks"; - tf_data.sizetf = NULL; - tf_data.calltf = init_clks_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -void init_rsts_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$init_rsts"; - tf_data.sizetf = NULL; - tf_data.calltf = init_rsts_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -void init_ins_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$init_ins"; - tf_data.sizetf = NULL; - tf_data.calltf = init_ins_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -void init_outs_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$init_outs"; - tf_data.sizetf = NULL; - tf_data.calltf = init_outs_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -void init_sigs_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$init_sigs"; - tf_data.sizetf = NULL; - tf_data.calltf = init_sigs_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -void tick_registration() { - s_vpi_systf_data tf_data; - tf_data.type = vpiSysTask; - tf_data.tfname = (PLI_BYTE8*) "$tick"; - tf_data.sizetf = NULL; - tf_data.calltf = tick_calltf; - tf_data.compiletf = NULL; - tf_data.user_data = NULL; - vpi_register_systf(&tf_data); - return; -} - -/*========================================================================== - Start-up Array -=============================================================================*/ -void (*vlog_startup_routines[]) () = { - init_clks_registration, - init_rsts_registration, - init_ins_registration, - init_outs_registration, - init_sigs_registration, - tick_registration, - 0 -}; diff --git a/src/main/resources/vpi.h b/src/main/resources/vpi.h deleted file mode 100644 index 09c2dc75..00000000 --- a/src/main/resources/vpi.h +++ /dev/null @@ -1,212 +0,0 @@ -#ifndef __VPI_H -#define __VPI_h - -#include "vpi_user.h" -#include "sim_api.h" -#include <queue> - -PLI_INT32 tick_cb(p_cb_data cb_data); - -class vpi_api_t: public sim_api_t<vpiHandle> { -public: - void init_clks() { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // Cache clocks - while (vpiHandle arg_handle = vpi_scan(arg_iter)) { - std::string name = vpi_get_str(vpiName, arg_handle); - sim_data.clk_map[name.substr(0, name.rfind("_len"))] = arg_handle; - } - } - - void init_rsts() { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // Cache Resets - while (vpiHandle arg_handle = vpi_scan(arg_iter)) { - sim_data.resets.push_back(arg_handle); - } - } - - void init_ins() { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // Cache Inputs - while (vpiHandle arg_handle = vpi_scan(arg_iter)) { - sim_data.inputs.push_back(arg_handle); - } - } - - void init_outs() { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // Cache Outputs - while (vpiHandle arg_handle = vpi_scan(arg_iter)) { - sim_data.outputs.push_back(arg_handle); - } - } - - void init_sigs() { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - top_handle = vpi_scan(vpi_iterate(vpiArgument, syscall_handle)); - search_signals(); - } - -private: - vpiHandle top_handle; - - void put_value(vpiHandle& sig) { - std::string value; - for (size_t k = 0 ; k < ((vpi_get(vpiSize, sig) - 1) >> 6) + 1 ; k++) { - // 64 bit chunks are given - std::string v; - std::cin >> v; - value += v; - } - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - value_s.value.str = (PLI_BYTE8*) value.c_str(); - vpi_put_value(sig, &value_s, NULL, vpiNoDelay); - } - - void get_value(vpiHandle& sig) { - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - vpi_get_value(sig, &value_s); - std::cerr << value_s.value.str << std::endl; - } - - virtual void reset() { - for (size_t i = 0 ; i < sim_data.resets.size() ; i++) { - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - value_s.value.str = (PLI_BYTE8*) "1"; - vpi_put_value(sim_data.resets[i], &value_s, NULL, vpiNoDelay); - } - } - - virtual void start() { - for (size_t i = 0 ; i < sim_data.resets.size() ; i++) { - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - value_s.value.str = (PLI_BYTE8*) "0"; - vpi_put_value(sim_data.resets[i], &value_s, NULL, vpiNoDelay); - } - } - - virtual void finish() { vpi_control(vpiFinish, 0); } - - virtual void step() { } - - virtual void update() { - s_cb_data data_s; - s_vpi_time time_s; - time_s.type = vpiSimTime; - time_s.low = 0; - time_s.high = 0; - data_s.reason = cbReadWriteSynch; - data_s.cb_rtn = tick_cb; - data_s.obj = NULL; - data_s.time = &time_s; - data_s.value = NULL; - data_s.user_data = NULL; - vpi_free_object(vpi_register_cb(&data_s)); - } - - virtual size_t add_signal(vpiHandle& sig_handle, std::string& wire) { - size_t id = sim_data.signals.size(); - sim_data.signals.push_back(sig_handle); - sim_data.signal_map[wire] = id; - return id; - } - - int search_signals(const char *wire = NULL) { - int id = -1; - std::string wirepath = wire ? wire : ""; - int dotpos = wirepath.rfind("."); - std::string modpath = dotpos > 0 ? wirepath.substr(0, dotpos) : ""; - std::string wirename = dotpos > 0 ? wirepath.substr(dotpos+1) : ""; - int sbrpos = wirename.rfind("["); - std::string arrname = sbrpos > 0 ? wirename.substr(0, sbrpos) : ""; - std::queue<vpiHandle> modules; - size_t offset = std::string(vpi_get_str(vpiFullName, top_handle)).find(".") + 1; - - // Start from the top module - modules.push(top_handle); - - while (!modules.empty()) { - vpiHandle mod_handle = modules.front(); - modules.pop(); - - std::string modname = std::string(vpi_get_str(vpiFullName, mod_handle)).substr(offset); - // If the module is found - if (!wire || modpath == modname) { - // Iterate its nets - vpiHandle net_iter = vpi_iterate(vpiNet, mod_handle); - while (vpiHandle net_handle = vpi_scan(net_iter)) { - std::string netname = vpi_get_str(vpiName, net_handle); - std::string netpath = modname + "." + netname; - size_t netid = (!wire && netname[0] != 'T') || wirename == netname ? - add_signal(net_handle, netpath) : 0; - id = netid ? netid : id; - if (id > 0) break; - } - if (id > 0) break; - - // Iterate its regs - vpiHandle reg_iter = vpi_iterate(vpiReg, mod_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - std::string regname = vpi_get_str(vpiName, reg_handle); - std::string regpath = modname + "." + regname; - size_t regid = !wire || wirename == regname ? - add_signal(reg_handle, regpath) : 0; - id = regid ? regid : id; - if (id > 0) break; - } - if (id > 0) break; - - // Iterate its mems - vpiHandle mem_iter = vpi_iterate(vpiRegArray, mod_handle); - while (vpiHandle mem_handle = vpi_scan(mem_iter)) { - std::string memname = vpi_get_str(vpiName, mem_handle); - if (!wire || arrname == memname) { - vpiHandle elm_iter = vpi_iterate(vpiReg, mem_handle); - size_t idx = vpi_get(vpiSize, mem_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - std::string elmname = vpi_get_str(vpiName, elm_handle); - std::string elmpath = modname + "." + elmname; - size_t elmid = add_signal(elm_handle, elmpath); - id = wirename == elmname ? elmid : id; - } - } - if (id > 0) break; - } - } - - // Find DFF - if (!wire || wirepath == modname) { - vpiHandle udp_iter = vpi_iterate(vpiPrimitive, mod_handle); - while (vpiHandle udp_handle = vpi_scan(udp_iter)) { - if (vpi_get(vpiPrimType, udp_handle) == vpiSeqPrim) { - id = add_signal(udp_handle, modname); - break; - } - } - } - if (id > 0) break; - - vpiHandle sub_iter = vpi_iterate(vpiModule, mod_handle); - while (vpiHandle sub_handle = vpi_scan(sub_iter)) { - modules.push(sub_handle); - } - } - - return id; - } - - virtual int search(std::string& wire) { - return search_signals(wire.c_str()); - } -}; - -#endif // __VPI_H diff --git a/src/main/resources/vpi_user.cc b/src/main/resources/vpi_user.cc deleted file mode 100644 index f24d8e39..00000000 --- a/src/main/resources/vpi_user.cc +++ /dev/null @@ -1,562 +0,0 @@ -#include <fstream> -#include <sstream> -#include <string> -#include <set> -#include <map> -#include <queue> -#include <ctime> -#include <vpi_user.h> - -using namespace std; - -/*========================================================================== - User Functions -=============================================================================*/ -int32_t wire_poke_calltf(char *user_data) { - queue<vpiHandle> modules; - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // First argument: <node_name> - s_vpi_value node_s; - node_s.format = vpiStringVal; - vpi_get_value(vpi_scan(arg_iter), &node_s); - // Second argument: <value> - s_vpi_value value_s; - value_s.format = vpiIntVal; - vpi_get_value(vpi_scan(arg_iter), &value_s); - vpi_free_object(arg_iter); - - vpiHandle test_handle = vpi_scan(vpi_iterate(vpiModule, NULL)); - vpiHandle top_handle = vpi_scan(vpi_iterate(vpiModule, test_handle)); - // Construct node paths - string testname = vpi_get_str(vpiDefName, test_handle); - istringstream iss(node_s.value.str); - string nodename; - iss >> nodename; - ostringstream oss; - oss << testname << "." << nodename; - string nodepath = oss.str(); - - // Examine the regs in the testbench - // in order to give the correct input values - string modulepath = vpi_get_str(vpiFullName, top_handle); - string testpath = testname + nodepath.substr(modulepath.length(), nodepath.length() - modulepath.length()); - vpiHandle reg_iter = vpi_iterate(vpiReg, test_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (testpath == vpi_get_str(vpiFullName, reg_handle)) { - vpi_put_value(reg_handle, &value_s, NULL, vpiNoDelay); - vpi_printf("ok\n"); - return 0; - } - } - - // Start from the top module - modules.push(top_handle); - - bool found = false; - while (!modules.empty()) { - vpiHandle mod_handle = modules.front(); - modules.pop(); - - // Iterate its net - vpiHandle net_iter = vpi_iterate(vpiNet, mod_handle); - while (vpiHandle net_handle = vpi_scan(net_iter)) { - if (nodepath == vpi_get_str(vpiFullName, net_handle)) { - vpi_put_value(net_handle, &value_s, NULL, vpiNoDelay); - found = true; - } - if (found) break; - } - if (found) break; - - // Iterate its reg - vpiHandle reg_iter = vpi_iterate(vpiReg, mod_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (nodepath == vpi_get_str(vpiFullName, reg_handle)) { - vpi_put_value(reg_handle, &value_s, NULL, vpiNoDelay); - found = true; - } - if (found) break; - } - if (found) break; - - vpiHandle sub_iter = vpi_iterate(vpiModule, mod_handle); - while (vpiHandle sub_handle = vpi_scan(sub_iter)) { - modules.push(sub_handle); - } - } - - if (found) - vpi_printf("ok\n"); - else - vpi_printf("error\n"); - - return 0; -} - -int32_t wire_peek_calltf(char *user_data) { - queue<vpiHandle> modules; - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // First argument: <node_name> - s_vpi_value node_s; - node_s.format = vpiStringVal; - vpi_get_value(vpi_scan(arg_iter), &node_s); - vpi_free_object(arg_iter); - - vpiHandle test_handle = vpi_scan(vpi_iterate(vpiModule, NULL)); - vpiHandle top_handle = vpi_scan(vpi_iterate(vpiModule, test_handle)); - // Construct node paths - string testname = vpi_get_str(vpiDefName, test_handle); - istringstream iss(node_s.value.str); - string nodename; - iss >> nodename; - ostringstream oss; - oss << testname << "." << nodename; - string nodepath = oss.str(); - // Start from the top module - modules.push(top_handle); - - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - bool found = false; - while (!modules.empty()) { - vpiHandle mod_handle = modules.front(); - modules.pop(); - - // Iterate its net - vpiHandle net_iter = vpi_iterate(vpiNet, mod_handle); - while (vpiHandle net_handle = vpi_scan(net_iter)) { - if (nodepath == vpi_get_str(vpiFullName, net_handle)) { - vpi_get_value(net_handle, &value_s); - found = true; - } - } - if (found) break; - - // Iterate its reg - vpiHandle reg_iter = vpi_iterate(vpiReg, mod_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (nodepath == vpi_get_str(vpiFullName, reg_handle)) { - vpi_get_value(reg_handle, &value_s); - found = true; - } - } - if (found) break; - - vpiHandle sub_iter = vpi_iterate(vpiModule, mod_handle); - while (vpiHandle sub_handle = vpi_scan(sub_iter)) { - modules.push(sub_handle); - } - } - - if (found) - vpi_printf("0x%s\n", value_s.value.str); - else - vpi_printf("error\n"); - - return 0; -} - -int32_t mem_poke_calltf(char *user_data) { - queue<vpiHandle> modules; - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // First argument: <mem_name> - s_vpi_value node_s; - node_s.format = vpiStringVal; - vpi_get_value(vpi_scan(arg_iter), &node_s); - // Second argument: <mem_index> - s_vpi_value index_s; - index_s.format = vpiIntVal; - vpi_get_value(vpi_scan(arg_iter), &index_s); - // Third argument: <value> - s_vpi_value value_s; - value_s.format = vpiIntVal; - vpi_get_value(vpi_scan(arg_iter), &value_s); - - vpiHandle test_handle = vpi_scan(vpi_iterate(vpiModule, NULL)); - vpiHandle top_handle = vpi_scan(vpi_iterate(vpiModule, test_handle)); - // Construct node paths - string testname = vpi_get_str(vpiDefName, test_handle); - istringstream iss(node_s.value.str); - string nodename; - iss >> nodename; - ostringstream oss; - oss << testname << "." << nodename; - string nodepath = oss.str(); - oss << "[" << index_s.value.integer << "]"; - string elmpath = oss.str(); - - // Examine the reg arrays in the testbench - // in order to give the correct input values - string modulepath = vpi_get_str(vpiFullName, top_handle); - string testpath = testname + nodepath.substr(modulepath.length(), nodepath.length() - modulepath.length()); - vpiHandle reg_iter = vpi_iterate(vpiRegArray, test_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (testpath == vpi_get_str(vpiFullName, reg_handle)) { - vpiHandle elm_iter = vpi_iterate(vpiReg, reg_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - if (elmpath == vpi_get_str(vpiFullName, elm_handle)) { - vpi_put_value(elm_handle, &value_s, NULL, vpiNoDelay); - vpi_printf("ok\n"); - return 0; - } - } - } - } - - // Start from the top module - modules.push(top_handle); - - bool found = false; - while (!modules.empty()) { - vpiHandle mod_handle = modules.front(); - modules.pop(); - - // Iterate its net arrays - vpiHandle net_iter = vpi_iterate(vpiNetArray, mod_handle); - while (vpiHandle net_handle = vpi_scan(net_iter)) { - if (nodepath == vpi_get_str(vpiFullName, net_handle)) { - vpiHandle elm_iter = vpi_iterate(vpiNet, net_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - if (elmpath == vpi_get_str(vpiFullName, elm_handle)){ - vpi_put_value(elm_handle, &value_s, NULL, vpiNoDelay); - found = true; - } - if (found) break; - } - } - if (found) break; - } - if (found) break; - - // Iterate its reg arrays - vpiHandle reg_iter = vpi_iterate(vpiRegArray, mod_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (nodepath == vpi_get_str(vpiFullName, reg_handle)) { - vpiHandle elm_iter = vpi_iterate(vpiReg, reg_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - if (elmpath == vpi_get_str(vpiFullName, elm_handle)){ - vpi_put_value(elm_handle, &value_s, NULL, vpiNoDelay); - found = true; - } - if (found) break; - } - } - if (found) break; - } - if (found) break; - - vpiHandle sub_iter = vpi_iterate(vpiModule, mod_handle); - while (vpiHandle sub_handle = vpi_scan(sub_iter)) { - modules.push(sub_handle); - } - } - - if (found) - vpi_printf("ok\n"); - else - vpi_printf("error\n"); -} - -int32_t mem_peek_calltf(char *user_data) { - queue<vpiHandle> modules; - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle); - // First argument: <node_name> - s_vpi_value node_s; - node_s.format = vpiStringVal; - vpi_get_value(vpi_scan(arg_iter), &node_s); - // Second argument: <mem_index> - s_vpi_value index_s; - index_s.format = vpiIntVal; - vpi_get_value(vpi_scan(arg_iter), &index_s); - - vpiHandle test_handle = vpi_scan(vpi_iterate(vpiModule, NULL)); - vpiHandle top_handle = vpi_scan(vpi_iterate(vpiModule, test_handle)); - // Construct node paths - string testname = vpi_get_str(vpiDefName, test_handle); - istringstream iss(node_s.value.str); - string nodename; - iss >> nodename; - ostringstream oss; - oss << testname << "." << nodename; - string nodepath = oss.str(); - oss << "[" << index_s.value.integer << "]"; - string elmpath = oss.str(); - // Start from the top module - modules.push(top_handle); - - s_vpi_value value_s; - value_s.format = vpiHexStrVal; - bool found = false; - while (!modules.empty()) { - vpiHandle mod_handle = modules.front(); - modules.pop(); - - // Iterate its net arrays - vpiHandle net_iter = vpi_iterate(vpiNetArray, mod_handle); - while (vpiHandle net_handle = vpi_scan(net_iter)) { - if (nodepath == vpi_get_str(vpiFullName, net_handle)) { - vpiHandle elm_iter = vpi_iterate(vpiNet, net_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - if (elmpath == vpi_get_str(vpiFullName, elm_handle)){ - vpi_get_value(elm_handle, &value_s); - found = true; - } - if (found) break; - } - } - if (found) break; - } - if (found) break; - - // Iterate its reg arrays - vpiHandle reg_iter = vpi_iterate(vpiRegArray, mod_handle); - while (vpiHandle reg_handle = vpi_scan(reg_iter)) { - if (nodepath == vpi_get_str(vpiFullName, reg_handle)) { - vpiHandle elm_iter = vpi_iterate(vpiReg, reg_handle); - while (vpiHandle elm_handle = vpi_scan(elm_iter)) { - if (elmpath == vpi_get_str(vpiFullName, elm_handle)){ - vpi_get_value(elm_handle, &value_s); - found = true; - } - if (found) break; - } - } - if (found) break; - } - if (found) break; - - vpiHandle sub_iter = vpi_iterate(vpiModule, mod_handle); - while (vpiHandle sub_handle = vpi_scan(sub_iter)) { - modules.push(sub_handle); - } - } - - if (found) - vpi_printf("0x%s\n", value_s.value.str); - else - vpi_printf("error\n"); -} - -/*========================================================================== - Compile Time Functions -=============================================================================*/ - -int32_t wire_poke_compiletf (char *user_data) { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle), arg_handle; - bool error = false; - - if (arg_iter == NULL) { - vpi_printf("ERROR: $wire_poke requires at least two argument(nodename, hex_value)\n"); - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiStringConst) { - vpi_printf("ERROR: $wire_poke requires the first argument as a string(nodename)\n"); - error = true; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiHexConst) { - vpi_printf("ERROR: $wire_poke requires the second argument as a hex number(value)\n"); - error = true; - } - - if (vpi_scan(arg_iter) != NULL) { - vpi_printf("ERROR: $wire_poke requires only two arguments(nodename, hex_value))\n"); - error = true; - } - - if (error) { - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - return 0; -} - -int32_t wire_peek_compiletf (char *user_data) { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle), arg_handle; - bool error = false; - - if (arg_iter == NULL) { - vpi_printf("ERROR: $wire_peek requires at least one argument(nodename)\n"); - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiStringConst) { - vpi_printf("ERROR: $wire_peek requires the first argument as a string(nodename)\n"); - error = true; - } - - if (vpi_scan(arg_iter) != NULL) { - vpi_printf("ERROR: $wire_peek requires only one arguments(nodename))\n"); - error = true; - } - - if (error) { - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - return 0; -} - -int32_t mem_poke_compiletf (char *user_data) { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle), arg_handle; - bool error = false; - - if (arg_iter == NULL) { - vpi_printf("ERROR: $mem_poke requires at least three argument(nodename, offset, hex_value)\n"); - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiStringConst) { - vpi_printf("ERROR: $mem_poke requires the first argument as a string(nodename)\n"); - error = true; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiIntegerVar && vpi_get(vpiType, arg_handle) != vpiDecConst) { - vpi_printf("ERROR: $mem_poke requires the second argument as a integer(offset)\n"); - error = true; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiHexConst) { - vpi_printf("ERROR: $mem_poke requires the third argument as a hex string(value)\n"); - error = true; - } - - if (vpi_scan(arg_iter) != NULL) { - vpi_printf("ERROR: $mem_poke requires only three arguments(nodename, offset, hex_value))\n"); - error = true; - } - - if (error) { - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - return 0; -} - -int32_t mem_peek_compiletf (char *user_data) { - vpiHandle syscall_handle = vpi_handle(vpiSysTfCall, NULL); - vpiHandle arg_iter = vpi_iterate(vpiArgument, syscall_handle), arg_handle; - bool error = false; - - if (arg_iter == NULL) { - vpi_printf("ERROR: $mem_peek requires at least two argument(nodename, offset, hex_value)\n"); - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiReg && vpi_get(vpiType, arg_handle) != vpiStringConst) { - vpi_printf("ERROR: $mem_peek requires the first argument as a string(nodename)\n"); - error = true; - } - - arg_handle = vpi_scan(arg_iter); - if (vpi_get(vpiType, arg_handle) != vpiIntegerVar && vpi_get(vpiType, arg_handle) != vpiDecConst) { - vpi_printf("ERROR: $mem_peek requires the second argument as a integer(offset)\n"); - error = true; - } - - if (vpi_scan(arg_iter) != NULL) { - vpi_printf("ERROR: $mem_peek requires only two arguments(nodename, offset))\n"); - error = true; - } - - if (error) { - vpi_control(vpiFinish, 1); /* abort simulation */ - return 0; - } - return 0; -} - - -/*========================================================================== - Registration Functions -=============================================================================*/ - -void wire_poke_registration() { - s_vpi_systf_data tf_data; - - tf_data.type = vpiSysTask; - tf_data.tfname = "$wire_poke"; - tf_data.sizetf = NULL; - tf_data.calltf = wire_poke_calltf; - tf_data.compiletf = wire_poke_compiletf; - tf_data.user_data = NULL; - - vpi_register_systf(&tf_data); - - return; -} - -void wire_peek_registration() { - s_vpi_systf_data tf_data; - - tf_data.type = vpiSysTask; - tf_data.tfname = "$wire_peek"; - tf_data.sizetf = NULL; - tf_data.calltf = wire_peek_calltf; - tf_data.compiletf = wire_peek_compiletf; - tf_data.user_data = NULL; - - vpi_register_systf(&tf_data); - - return; -} - -void mem_poke_registration() { - s_vpi_systf_data tf_data; - - tf_data.type = vpiSysTask; - tf_data.tfname = "$mem_poke"; - tf_data.sizetf = NULL; - tf_data.calltf = mem_poke_calltf; - tf_data.compiletf = mem_poke_compiletf; - tf_data.user_data = NULL; - - vpi_register_systf(&tf_data); - - return; -} - -void mem_peek_registration() { - s_vpi_systf_data tf_data; - - tf_data.type = vpiSysTask; - tf_data.tfname = "$mem_peek"; - tf_data.sizetf = NULL; - tf_data.calltf = mem_peek_calltf; - tf_data.compiletf = mem_peek_compiletf; - tf_data.user_data = NULL; - - vpi_register_systf(&tf_data); - - return; -} - -/*========================================================================== - Start-up Array -=============================================================================*/ -void (*vlog_startup_routines[]) () = { - wire_poke_registration, - wire_peek_registration, - mem_poke_registration, - mem_peek_registration, - 0 -}; |
