CIRCT  19.0.0git
Classes | Namespaces | Macros | Typedefs | Functions
EmitHGLDD.cpp File Reference
#include "circt/Analysis/DebugInfo.h"
#include "circt/Dialect/Comb/CombOps.h"
#include "circt/Dialect/Debug/DebugOps.h"
#include "circt/Dialect/HW/HWOps.h"
#include "circt/Dialect/HW/HWSymCache.h"
#include "circt/Dialect/SV/SVOps.h"
#include "circt/Support/Namespace.h"
#include "circt/Target/DebugInfo.h"
#include "mlir/IR/Threading.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/IndentedOstream.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ToolOutputFile.h"
Include dependency graph for EmitHGLDD.cpp:

Go to the source code of this file.

Classes

struct  llvm::DenseMapInfo< JValue >
 

Namespaces

 llvm
 

Macros

#define DEBUG_TYPE   "di"
 

Typedefs

using JValue = llvm::json::Value
 
using JArray = llvm::json::Array
 
using JObject = llvm::json::Object
 
using JOStream = llvm::json::OStream
 

Functions

static void findLocations (Location loc, unsigned level, SmallVectorImpl< FileLineColLoc > &locs)
 Walk the given loc and collect file-line-column locations that we want to report as source ("HGL") locations or as emitted Verilog ("HDL") locations. More...
 
static FileLineColLoc findBestLocation (Location loc, bool emitted, bool fileMustExist)
 Find the best location to report as source location ("HGL", emitted = false) or as emitted location ("HDL", emitted = true). More...
 
static bool makePathRelative (StringRef path, StringRef relativeTo, SmallVectorImpl< char > &relativePath)
 Make the given path relative to the relativeTo path and store the result in relativePath. More...
 
static StringRef legalizeName (StringRef name, llvm::StringMap< size_t > &nextGeneratedNameIDs)
 Legalize the given name such that it only consists of valid identifier characters in Verilog and does not collide with any Verilog keyword, and uniquify the resulting name such that it does not collide with any of the names stored in the nextGeneratedNameIDs map. More...
 
StringAttr getVerilogModuleName (DIModule &module)
 
StringAttr getVerilogInstanceName (DIInstance &inst)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "di"

Definition at line 26 of file EmitHGLDD.cpp.

Typedef Documentation

◆ JArray

using JArray = llvm::json::Array

Definition at line 36 of file EmitHGLDD.cpp.

◆ JObject

using JObject = llvm::json::Object

Definition at line 37 of file EmitHGLDD.cpp.

◆ JOStream

using JOStream = llvm::json::OStream

Definition at line 38 of file EmitHGLDD.cpp.

◆ JValue

using JValue = llvm::json::Value

Definition at line 35 of file EmitHGLDD.cpp.

Function Documentation

◆ findBestLocation()

static FileLineColLoc findBestLocation ( Location  loc,
bool  emitted,
bool  fileMustExist 
)
static

Find the best location to report as source location ("HGL", emitted = false) or as emitted location ("HDL", emitted = true).

Returns any non-FIR file it finds, and only falls back to FIR files if nothing else is found.

Definition at line 81 of file EmitHGLDD.cpp.

References findLocations().

◆ findLocations()

static void findLocations ( Location  loc,
unsigned  level,
SmallVectorImpl< FileLineColLoc > &  locs 
)
static

Walk the given loc and collect file-line-column locations that we want to report as source ("HGL") locations or as emitted Verilog ("HDL") locations.

This function treats locations inside a NameLoc called "emitted" or a FusedLoc with the metadata attribute string "verilogLocations" as emitted Verilog locations. All other locations are considered to be source locations.

The level parameter is used to track into how many "emitted" or "verilogLocations" we have already descended. For every one of those we look through the level gets decreased by one. File-line-column locations are only collected at level 0. We don't descend into "emitted" or "verilogLocations" once we've reached level 0. This effectively makes the level parameter decide behind how many layers of "emitted" or "verilogLocations" we want to collect file-line-column locations. Setting this to 0 effectively collects source locations, i.e., everything not marked as emitted. Setting this to 1 effectively collects emitted locations, i.e., nothing that isn't behind exactly one layer of "emitted" or "verilogLocations".

Definition at line 58 of file EmitHGLDD.cpp.

Referenced by findBestLocation().

◆ getVerilogInstanceName()

StringAttr getVerilogInstanceName ( DIInstance inst)

Definition at line 562 of file EmitHGLDD.cpp.

References circt::DIInstance::name, and circt::DIInstance::op.

◆ getVerilogModuleName()

StringAttr getVerilogModuleName ( DIModule module)

◆ legalizeName()

static StringRef legalizeName ( StringRef  name,
llvm::StringMap< size_t > &  nextGeneratedNameIDs 
)
static

Legalize the given name such that it only consists of valid identifier characters in Verilog and does not collide with any Verilog keyword, and uniquify the resulting name such that it does not collide with any of the names stored in the nextGeneratedNameIDs map.

The HGLDD output is likely to be ingested by tools that have been developed to debug Verilog code. These have the limitation of only supporting valid Verilog identifiers for signals and other names. HGLDD therefore requires these names to be valid Verilog identifiers.

Definition at line 172 of file EmitHGLDD.cpp.

◆ makePathRelative()

static bool makePathRelative ( StringRef  path,
StringRef  relativeTo,
SmallVectorImpl< char > &  relativePath 
)
static

Make the given path relative to the relativeTo path and store the result in relativePath.

Returns whether the conversion was successful. Fails if the relativeTo path has a longer prefix of ../ than path, or if it contains any non-prefix ../ components. Does not clear relativePath before appending to it.

Definition at line 123 of file EmitHGLDD.cpp.

References append().