Created
August 17, 2020 12:38
-
-
Save totegamma/782f25b7db3bbc4c57b75295d3a40f83 to your computer and use it in GitHub Desktop.
vivadoHLSのstreamを検証用に簡易的に実装したものです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <queue> | |
namespace hls { | |
template <typename T> | |
class stream { | |
const char* name; | |
std::queue<T> queue; | |
public: | |
stream() {} | |
stream(const char* s): name(s) {} | |
~stream() { | |
if (!queue.empty()) { | |
printf("%s contains leftover data.\n", name); | |
} | |
} | |
T read() { | |
if (queue.empty()) { | |
printf("stream %s is read while empty.\n", name); | |
exit(-1); | |
} | |
T tmp = queue.front(); | |
queue.pop(); | |
return tmp; | |
} | |
int size() { | |
return queue.size(); | |
} | |
void printname() { | |
printf("%s", name); | |
} | |
void printlnname() { | |
printf("%s\n", name); | |
} | |
void operator << (T input) { | |
queue.push(input); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "hls_stream.h" | |
int main() { | |
hls::stream<int> mystream = hls::stream<int>("myname"); | |
mystream.printlnname(); | |
mystream << 10; | |
mystream << 50; | |
printf("size: %d\n", mystream.size()); | |
printf("val: %d\n", mystream.read()); | |
printf("size: %d\n", mystream.size()); | |
printf("val: %d\n", mystream.read()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment