UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

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 Created 02/01/2012
Last Updated 10/09/2013
Status Active
Type Solution Center
Tools
  • AutoESL - 2010.b
  • AutoESL - 2011.1
  • AutoESL - 2011.3
  • More
  • AutoESL - 2011.4
  • AutoESL
  • Vivado Design Suite - 2012.2
  • Less