AR# 46111

Vivado HLS - How do I use the #define in pragmas?

Description

I am attempting to use a harcorded value in the source, but it does not function as intended:

/*Code begins*/
#include <hls_stream.h>
using namespace hls;
define STREAM_IN_DEPTH 8
void foo (stream<int> &InStream, stream<int> &OutStream) {

// Illegal pragma
#pragma HLS stream depth=STREAM_IN_DEPTH variable=InStream
// Legal pragma
#pragma HLS stream depth=8 variable=OutStream
/* Source Code */
}
/*Code ends*/

Solution

The solution is given by the standards: C99 introduces the Pragma operator. This feature addresses a major problem with '#pragma': being a directive, it cannot be produced as the result of macro expansion. _Pragma is an operator, much like sizeof or defined, and can be embedded in a macro.

In order to use the #define in the #pragma, a possible work-around could be:

/*Code begins*/
#include <hls_stream.h>
using namespace hls;
#define PRAGMA_SUB(x) _Pragma (#x)
#define DO_PRAGMA(x) PRAGMA_SUB(x)
#define STREAM_IN_DEPTH 8
void foo (stream<int> &InStream, stream<int> &OutStream) {

// Legal pragmas
DO_PRAGMA(HLS stream depth=STREAM_IN_DEPTH variable=InStream)
#pragma HLS stream depth=8 variable=OutStream

/* Source Code */
}
/*Code ends*/
AR# 46111
Date 10/09/2013
Status Active
Type Solution Center
Tools More Less