title: How to create a string from a pre-processor macro
body: <p>I have a preprocessor macro that represents a hierarchical path into my design.</p>
  
  <p>Example:</p>
  
  <pre><code>`define HPATH top.chip.block
  </code></pre>
  
  <p>I need to construct a string which holds the value of <code>`HPATH</code>, so in my example the string should equal <code>top.chip.block</code>.</p>
  
  <p>Is there a way to construct such a string? </p>
  
  <p>None of the following attempts worked:</p>
  
  <pre><code>string hpath;
  hpath = "`HPATH";     // Results in hpath = "`HPATH"
  hpath = \"``HPATH\";  // Doesn't compile
  hpath = `HPATH;       // Doesn't compile
  </code></pre>
  
  <p>I want <code>hpath</code> to be equivalent to doing this assignment <code>hpath = "top.chip.block"</code>, but by using <code>`HPATH</code> instead of specifying the path again.</p>
  
  <p>I cannot use <code>%m</code> because I need the string within my top-level UVM environment, not within a module.</p>
  
  <p>A little more background: the reason I want to do this is because I am using backdoor register access in the UVM class library. The backdoor API requires setting the hdl_path to the blocks within the design, as a string. I already have `defines for the hierarchical paths and am trying to reuse those when specifying the hdl_paths so I don't have the same path defined twice. My testbench will use both the hierarchical path and the string path.</p>