10 #ifndef CONVERSION_IMPORTVERILOG_IMPORTVERILOGINTERNALS_H
11 #define CONVERSION_IMPORTVERILOG_IMPORTVERILOGINTERNALS_H
17 #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
18 #include "mlir/Dialect/Func/IR/FuncOps.h"
19 #include "slang/ast/ASTVisitor.h"
20 #include "llvm/ADT/ScopedHashTable.h"
21 #include "llvm/Support/Debug.h"
25 #define DEBUG_TYPE "import-verilog"
28 namespace ImportVerilog {
34 const slang::ast::PortSymbol &
ast;
42 SmallVector<PortLowering>
ports;
43 DenseMap<const slang::syntax::SyntaxNode *, const slang::ast::PortSymbol *>
49 mlir::func::FuncOp
op;
87 Type
convertType(
const slang::ast::Type &type, LocationAttr loc = {});
88 Type
convertType(
const slang::ast::DeclaredType &type);
95 LogicalResult
convertPackage(
const slang::ast::PackageSymbol &package);
98 LogicalResult
convertFunction(
const slang::ast::SubroutineSymbol &subroutine);
105 Type requiredType = {});
110 const slang::ast::Statement &stmt);
131 const slang::ast::Type &type, Location loc);
136 const slang::ast::Type &type, Location loc);
143 slang::span<const slang::ast::Expression *const> arguments, Location loc,
144 moore::IntFormat defaultFormat = moore::IntFormat::Decimal,
145 bool appendNewline =
false);
166 DenseMap<
const slang::ast::InstanceBodySymbol *,
167 std::unique_ptr<ModuleLowering>>
174 DenseMap<
const slang::ast::SubroutineSymbol *,
175 std::unique_ptr<FunctionLowering>>
182 llvm::ScopedHashTable<const slang::ast::ValueSymbol *, Value>;
Domain
The number of values each bit of a type can assume.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Options that control how Verilog input files are parsed and processed.
A helper class to facilitate the conversion from a Slang AST to MLIR operations.
LogicalResult convertFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function.
Value materializeConversion(Type type, Value value, bool isSigned, Location loc)
Helper function to insert the necessary operations to cast a value from one type to another.
ModuleLowering * convertModuleHeader(const slang::ast::InstanceBodySymbol *module)
Convert a module and its ports to an empty module op in the IR.
Value convertLvalueExpression(const slang::ast::Expression &expr)
Value materializeConstant(const slang::ConstantValue &constant, const slang::ast::Type &type, Location loc)
Helper function to materialize a ConstantValue as an SSA value.
SmallVector< LoopFrame > loopStack
A stack of loop continuation and exit blocks.
LogicalResult convertModuleBody(const slang::ast::InstanceBodySymbol *module)
Convert a module's body to the corresponding IR ops.
slang::ConstantValue evaluateConstant(const slang::ast::Expression &expr)
Evaluate the constant value of an expression.
slang::ast::Compilation & compilation
LogicalResult convertTimingControl(const slang::ast::TimingControl &ctrl, const slang::ast::Statement &stmt)
OpBuilder builder
The builder used to create IR operations.
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.
std::function< void(moore::ReadOp)> rvalueReadCallback
A listener called for every variable or net being read.
Context(const Context &)=delete
std::map< slang::SourceLocation, Operation * > orderedRootOps
The top-level operations ordered by their Slang source location.
Type convertType(const slang::ast::Type &type, LocationAttr loc={})
Convert a slang type into an MLIR type.
DenseMap< const slang::ast::SubroutineSymbol *, std::unique_ptr< FunctionLowering > > functions
Functions that have already been converted.
Value materializeSVInt(const slang::SVInt &svint, const slang::ast::Type &type, Location loc)
Helper function to materialize an SVInt as an SSA value.
SmallDenseMap< slang::BufferID, StringRef > & bufferFilePaths
Value convertToBool(Value value)
Helper function to convert a value to its "truthy" boolean value.
FailureOr< Value > convertFormatString(slang::span< const slang::ast::Expression *const > arguments, Location loc, moore::IntFormat defaultFormat=moore::IntFormat::Decimal, bool appendNewline=false)
Convert a list of string literal arguments with formatting specifiers and arguments to be interpolate...
ValueSymbols valueSymbols
ValueSymbols::ScopeTy ValueSymbolScope
const ImportVerilogOptions & options
Value convertRvalueExpression(const slang::ast::Expression &expr, Type requiredType={})
llvm::ScopedHashTable< const slang::ast::ValueSymbol *, Value > ValueSymbols
A table of defined values, such as variables, that may be referred to by name in expressions.
Value convertToSimpleBitVector(Value value)
Helper function to convert a value to its simple bit vector representation, if it has one.
const slang::SourceManager & sourceManager
mlir::ModuleOp intoModuleOp
SymbolTable symbolTable
A symbol table of the MLIR module we are emitting into.
FunctionLowering * declareFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function and its arguments to a function declaration in the IR.
Context(const ImportVerilogOptions &options, slang::ast::Compilation &compilation, mlir::ModuleOp intoModuleOp, const slang::SourceManager &sourceManager, SmallDenseMap< slang::BufferID, StringRef > &bufferFilePaths)
LogicalResult convertPackage(const slang::ast::PackageSymbol &package)
Convert a package and its contents.
LogicalResult convertCompilation()
Convert hierarchy and structure AST nodes to MLIR ops.
MLIRContext * getContext()
Return the MLIR context.
LogicalResult convertStatement(const slang::ast::Statement &stmt)
SmallVector< Value > lvalueStack
A stack of assignment left-hand side values.
DenseMap< const slang::ast::InstanceBodySymbol *, std::unique_ptr< ModuleLowering > > modules
How we have lowered modules to MLIR.
Location convertLocation(slang::SourceLocation loc)
Convert a slang SourceLocation into an MLIR Location.
Function lowering information.
Information about a loops continuation and exit blocks relevant while lowering the loop's body statem...
Block * breakBlock
The block to jump to from a break statement.
Block * continueBlock
The block to jump to from a continue statement.
Module lowering information.
DenseMap< const slang::syntax::SyntaxNode *, const slang::ast::PortSymbol * > portsBySyntaxNode
SmallVector< PortLowering > ports
Port lowering information.
const slang::ast::PortSymbol & ast