CIRCT  19.0.0git
Public Types | Public Member Functions | Public Attributes | List of all members
circt::ImportVerilog::Context Struct Reference

A helper class to facilitate the conversion from a Slang AST to MLIR operations. More...

#include <ImportVerilogInternals.h>

Collaboration diagram for circt::ImportVerilog::Context:
Collaboration graph
[legend]

Public Types

using ValueSymbols = llvm::ScopedHashTable< const slang::ast::ValueSymbol *, Value >
 A table of defined values, such as variables, that may be referred to by name in expressions. More...
 
using ValueSymbolScope = ValueSymbols::ScopeTy
 

Public Member Functions

 Context (mlir::ModuleOp intoModuleOp, const slang::SourceManager &sourceManager, SmallDenseMap< slang::BufferID, StringRef > &bufferFilePaths)
 
 Context (const Context &)=delete
 
MLIRContext * getContext ()
 Return the MLIR context. More...
 
Location convertLocation (slang::SourceLocation loc)
 Convert a slang SourceLocation into an MLIR Location. More...
 
Location convertLocation (slang::SourceRange range)
 Convert a slang SourceRange into an MLIR Location. More...
 
Type convertType (const slang::ast::Type &type, LocationAttr loc={})
 Convert a slang type into an MLIR type. More...
 
Type convertType (const slang::ast::DeclaredType &type)
 
LogicalResult convertCompilation (slang::ast::Compilation &compilation)
 Convert hierarchy and structure AST nodes to MLIR ops. More...
 
moore::SVModuleOp convertModuleHeader (const slang::ast::InstanceBodySymbol *module)
 Convert a module and its ports to an empty module op in the IR. More...
 
LogicalResult convertModuleBody (const slang::ast::InstanceBodySymbol *module)
 Convert a module's body to the corresponding IR ops. More...
 
LogicalResult convertStatement (const slang::ast::Statement &stmt)
 
Value convertExpression (const slang::ast::Expression &expr)
 

Public Attributes

mlir::ModuleOp intoModuleOp
 
const slang::SourceManager & sourceManager
 
SmallDenseMap< slang::BufferID, StringRef > & bufferFilePaths
 
OpBuilder builder
 The builder used to create IR operations. More...
 
SymbolTable symbolTable
 A symbol table of the MLIR module we are emitting into. More...
 
std::map< slang::SourceLocation, Operation * > orderedRootOps
 The top-level operations ordered by their Slang source location. More...
 
DenseMap< const slang::ast::InstanceBodySymbol *, moore::SVModuleOp > moduleOps
 How we have lowered modules to MLIR. More...
 
std::queue< const slang::ast::InstanceBodySymbol * > moduleWorklist
 A list of modules for which the header has been created, but the body has not been converted yet. More...
 
ValueSymbols valueSymbols
 
SmallVector< Value > lvalueStack
 A stack of assignment left-hand side values. More...
 

Detailed Description

A helper class to facilitate the conversion from a Slang AST to MLIR operations.

Keeps track of the destination MLIR module, builders, and various worklists and utilities needed for conversion.

Definition at line 31 of file ImportVerilogInternals.h.

Member Typedef Documentation

◆ ValueSymbols

using circt::ImportVerilog::Context::ValueSymbols = llvm::ScopedHashTable<const slang::ast::ValueSymbol *, Value>

A table of defined values, such as variables, that may be referred to by name in expressions.

The expressions use this table to lookup the MLIR value that was created for a given declaration in the Slang AST node.

Definition at line 89 of file ImportVerilogInternals.h.

◆ ValueSymbolScope

using circt::ImportVerilog::Context::ValueSymbolScope = ValueSymbols::ScopeTy

Definition at line 91 of file ImportVerilogInternals.h.

Constructor & Destructor Documentation

◆ Context() [1/2]

circt::ImportVerilog::Context::Context ( mlir::ModuleOp  intoModuleOp,
const slang::SourceManager &  sourceManager,
SmallDenseMap< slang::BufferID, StringRef > &  bufferFilePaths 
)
inline

Definition at line 32 of file ImportVerilogInternals.h.

◆ Context() [2/2]

circt::ImportVerilog::Context::Context ( const Context )
delete

Member Function Documentation

◆ convertCompilation()

LogicalResult Context::convertCompilation ( slang::ast::Compilation &  compilation)

Convert hierarchy and structure AST nodes to MLIR ops.

Convert an entire Slang compilation to MLIR ops.

This is the main entry point for the conversion.

Definition at line 221 of file Structure.cpp.

References convertLocation(), convertModuleBody(), convertModuleHeader(), moduleWorklist, and toString().

◆ convertExpression()

Value Context::convertExpression ( const slang::ast::Expression &  expr)

Definition at line 446 of file Expressions.cpp.

References convertLocation().

◆ convertLocation() [1/2]

Location Context::convertLocation ( slang::SourceLocation  loc)

Convert a slang SourceLocation into an MLIR Location.

Definition at line 63 of file ImportVerilog.cpp.

References convertLocation().

Referenced by convertCompilation(), convertExpression(), convertModuleBody(), convertModuleHeader(), and convertType().

◆ convertLocation() [2/2]

Location Context::convertLocation ( slang::SourceRange  range)

Convert a slang SourceRange into an MLIR Location.

Definition at line 67 of file ImportVerilog.cpp.

References convertLocation().

◆ convertModuleBody()

LogicalResult Context::convertModuleBody ( const slang::ast::InstanceBodySymbol *  module)

Convert a module's body to the corresponding IR ops.

The module op must have already been created earlier through a convertModuleHeader call.

Definition at line 307 of file Structure.cpp.

References assert(), builder, convertLocation(), moduleOps, and valueSymbols.

Referenced by convertCompilation().

◆ convertModuleHeader()

moore::SVModuleOp Context::convertModuleHeader ( const slang::ast::InstanceBodySymbol *  module)

Convert a module and its ports to an empty module op in the IR.

Also adds the op to the worklist of module bodies to be lowered. This acts like a module "declaration", allowing instances to already refer to a module even before its body has been lowered.

Definition at line 257 of file Structure.cpp.

References builder, convertLocation(), intoModuleOp, moduleOps, moduleWorklist, orderedRootOps, symbolTable, and toString().

Referenced by convertCompilation().

◆ convertStatement()

LogicalResult Context::convertStatement ( const slang::ast::Statement &  stmt)

Definition at line 325 of file Statements.cpp.

References convertLocation().

◆ convertType() [1/2]

Type Context::convertType ( const slang::ast::DeclaredType &  type)

Definition at line 170 of file Types.cpp.

References convertLocation(), and convertType().

◆ convertType() [2/2]

Type Context::convertType ( const slang::ast::Type &  type,
LocationAttr  loc = {} 
)

Convert a slang type into an MLIR type.

Returns null on failure. Uses the provided location for error reporting, or tries to guess one from the given type. Types tend to have unreliable location information, so it's generally a good idea to pass in a location.

Definition at line 164 of file Types.cpp.

References convertLocation().

Referenced by convertType().

◆ getContext()

MLIRContext* circt::ImportVerilog::Context::getContext ( )
inline

Return the MLIR context.

Definition at line 42 of file ImportVerilogInternals.h.

References intoModuleOp.

Member Data Documentation

◆ bufferFilePaths

SmallDenseMap<slang::BufferID, StringRef>& circt::ImportVerilog::Context::bufferFilePaths

Definition at line 70 of file ImportVerilogInternals.h.

◆ builder

OpBuilder circt::ImportVerilog::Context::builder

The builder used to create IR operations.

Definition at line 73 of file ImportVerilogInternals.h.

Referenced by convertModuleBody(), and convertModuleHeader().

◆ intoModuleOp

mlir::ModuleOp circt::ImportVerilog::Context::intoModuleOp

Definition at line 68 of file ImportVerilogInternals.h.

Referenced by convertModuleHeader(), and getContext().

◆ lvalueStack

SmallVector<Value> circt::ImportVerilog::Context::lvalueStack

A stack of assignment left-hand side values.

Each assignment will push its lowered left-hand side onto this stack before lowering its right-hand side. This allows expressions to resolve the opaque LValueReferenceExpressions in the AST.

Definition at line 98 of file ImportVerilogInternals.h.

◆ moduleOps

DenseMap<const slang::ast::InstanceBodySymbol *, moore::SVModuleOp> circt::ImportVerilog::Context::moduleOps

How we have lowered modules to MLIR.

Definition at line 81 of file ImportVerilogInternals.h.

Referenced by convertModuleBody(), and convertModuleHeader().

◆ moduleWorklist

std::queue<const slang::ast::InstanceBodySymbol *> circt::ImportVerilog::Context::moduleWorklist

A list of modules for which the header has been created, but the body has not been converted yet.

Definition at line 84 of file ImportVerilogInternals.h.

Referenced by convertCompilation(), and convertModuleHeader().

◆ orderedRootOps

std::map<slang::SourceLocation, Operation *> circt::ImportVerilog::Context::orderedRootOps

The top-level operations ordered by their Slang source location.

This is used to produce IR that follows the source file order.

Definition at line 79 of file ImportVerilogInternals.h.

Referenced by convertModuleHeader().

◆ sourceManager

const slang::SourceManager& circt::ImportVerilog::Context::sourceManager

Definition at line 69 of file ImportVerilogInternals.h.

◆ symbolTable

SymbolTable circt::ImportVerilog::Context::symbolTable

A symbol table of the MLIR module we are emitting into.

Definition at line 75 of file ImportVerilogInternals.h.

Referenced by convertModuleHeader().

◆ valueSymbols

ValueSymbols circt::ImportVerilog::Context::valueSymbols

Definition at line 92 of file ImportVerilogInternals.h.

Referenced by convertModuleBody().


The documentation for this struct was generated from the following files: