refactor: redesign the type system | embrace the new bit_type concept

This commit is contained in:
DarkSharpness
2024-07-11 20:38:05 +08:00
parent f3d2074a79
commit 1693df2820
10 changed files with 171 additions and 255 deletions

View File

@ -1,39 +0,0 @@
#include "../include/tools"
signed main() {
[[maybe_unused]]
Bit <1> a; // Create a 1-bit object, default to 0
Bit <10> b(10); // Create a 10-bit object
auto ref = b.slice <4, 2> (); // A copy of [2, 3, 4] bit
std::cout << b << std::endl; // 10
b.set <3, 1> (ref); // Set [1, 2, 3] bit to [2, 3, 4] bit
std::cout << b << std::endl; // 4
b.set <0> (~a); // Set the 0-th bit to ~a (= 1 in this case)
std::cout << b << std::endl; // 5
auto sec = b.slice <2> (); // A copy of the 2-th bit (= 1 in this case)
auto d = sec.zero_extend(); // Zero extend (default to 32-bit)
std::cout << d << std::endl; // 1
auto c = sec.sign_extend <3> (); // Sign extend (default to 32-bit)
std::cout << c << std::endl; // 7
// c + d; // Error: different size
// a += 1; // Error: no assignment-operation operator
auto e = b - 1; // normal integer can be assumed as any size
std::cout << e << std::endl; // 4
return 0;
}

View File

@ -1,38 +0,0 @@
#include "../include/tools"
struct Input {
Wire a;
Wire b;
std::array <Wire, 2> c;
};
struct Output {
Register d;
Register e;
};
struct Content {
Register r;
};
struct MyModule : Input, Output, private Content {
using Tags = SyncTags <Input, Output, Content>;
friend class Visitor;
void demo() { this->d <= this->a + this->b; }
};
signed main() {
MyModule m;
m.a = []() { return 1; };
m.b.assign([&]() { return (target_size_t)m.d; });
for (int i = 0 ; i < 10 ; ++i) {
std::cout << m.d << std::endl;
m.demo();
std::cout << m.d << std::endl;
sync_member(m);
}
return 0;
}