Roman Popov Posted November 24, 2017 Report Share Posted November 24, 2017 Hello, I need a data-structure to model RAMs and ROMs that are defined at elaboration time. For example when size and contents of memory are read from file during model construction. I thought that sc_vector can be a solution, but looks like it has no specialization for members that are not sc_objects. Any suggestions? Currently I'm thinking of creating a wrapper over std::vector with following api: template<typename T> class sc_elab_vector : public sc_object { std::vector<remove_const_t<T>> m_vec; //... }; sc_elab_vector<int> ram; sc_elab_vector<const int> rom; SC_CTOR(mod) { // ELABORATION ram.resize(42); // OK ram[0] = 42; // OK, for example models RAM on FPGA, initialized on reset for(int i = 0; i < 42; i++) rom.push_back(i); // OK rom[0] = 42; // OK } void test_thread() { // SIMULATION ram[0] = 42; // OK ram.push_back(1); // Runtime error rom[0] = 42; // Runtime error } Concept looks pretty generic for me, probably something like that should be standardized? Currently for SystemC synthesis we only have Compile-time sized arrays. But elaboration-time programming is more flexible than compile-time metaprogramming Quote Link to comment Share on other sites More sharing options...
maehne Posted November 25, 2017 Report Share Posted November 25, 2017 Hello Roman, instead of developing your own class, have you considered to use std::unique_ptr<T[]> (C++'11) and std::make_unique<T[]> to allocate your array of a fixed size during elaboration? For examples see, e.g.: http://en.cppreference.com/w/cpp/memory/unique_ptr http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique Regards, Torsten David Black 1 Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted November 27, 2017 Author Report Share Posted November 27, 2017 On 11/25/2017 at 7:23 AM, maehne said: Hello Roman, instead of developing your own class, have you considered to use std::unique_ptr<T[]> (C++'11) and std::make_unique<T[]> to allocate your array of a fixed size during elaboration? I thought about it. There are two issues: 1) Raw arrays do not store size. This is inconvenient: for debugging purposes I often want to visualize contents of RAM. But without knowing a size it is not possible to create a pretty printer. (Except for non-trivial constructible types, that actually store size, as specified by GCC/Clang ABI https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies ) 2) When modeling ROMs it will require to know memory contents at compile time: std::unique_ptr<const int[]> rom(new const int[3] {1,2,3}); As I understand I can't create initializer list {1,2,3} at runtime. So I can't initialize ROM contents from file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.