编译指示指令支持使用 #define
语句指定的值。
例如,以下代码会尝试使用 #define
语句指定串流深度:
#include <hls_stream.h>
using namespace hls;
#define STREAM_IN_DEPTH 8
void foo (stream<int> &InStream, stream<int> &OutStream) {
// pragma using #DEFINE
#pragma HLS stream depth=STREAM_IN_DEPTH variable=InStream
// pragma using value
#pragma HLS stream depth=8 variable=OutStream
}
您可使用 const int
或 constexpr
等常量。例如:
const int MY_DEPTH=1024;
#pragma HLS stream variable=my_var depth=MY_DEPTH
在 C 语言代码中也可使用宏来实现此功能。使用宏的关键在于使用宏中的层级。这样即可正确执行扩展。代码将按如下方式进行编译:
#include <hls_stream.h>
using namespace hls;
#define PRAGMA_SUB(x) _Pragma (#x)
#define PRAGMA_HLS(x) PRAGMA_SUB(x)
#define STREAM_IN_DEPTH 8
void foo (stream<int> &InStream, stream<int> &OutStream) {
// Legal pragmas
PRAGMA_HLS(HLS stream depth=STREAM_IN_DEPTH variable=InStream)
#pragma HLS stream depth=8 variable=OutStream
}