10#include "slang/ast/Compilation.h"
13using namespace ImportVerilog;
20 SmallString<64> &prefix) {
21 if (symbol.kind != slang::ast::SymbolKind::Package)
24 if (!symbol.name.empty()) {
25 prefix += symbol.name;
42 BaseVisitor(
Context &context, Location loc)
43 : context(context), loc(loc), builder(context.builder) {}
46 LogicalResult visit(
const slang::ast::EmptyMemberSymbol &) {
52 LogicalResult visit(
const slang::ast::TransparentMemberSymbol &) {
57 LogicalResult visit(
const slang::ast::TypeAliasType &) {
return success(); }
60 LogicalResult visit(
const slang::ast::ExplicitImportSymbol &) {
63 LogicalResult visit(
const slang::ast::WildcardImportSymbol &) {
68 LogicalResult visit(
const slang::ast::TypeParameterSymbol &) {
73 LogicalResult visit(
const slang::ast::ElabSystemTaskSymbol &) {
78 LogicalResult visit(
const slang::ast::ParameterSymbol ¶m) {
79 visitParameter(param);
83 LogicalResult visit(
const slang::ast::SpecparamSymbol ¶m) {
84 visitParameter(param);
89 void visitParameter(
const Node ¶m) {
99 if (builder.getInsertionBlock()->getParentOp() == context.
intoModuleOp)
100 context.
orderedRootOps.insert({param.location, value.getDefiningOp()});
104 SmallString<64> paramName;
106 paramName += param.name;
108 builder.create<debug::VariableOp>(loc, builder.getStringAttr(paramName),
119struct RootVisitor :
public BaseVisitor {
120 using BaseVisitor::BaseVisitor;
121 using BaseVisitor::visit;
124 LogicalResult visit(
const slang::ast::PackageSymbol &package) {
129 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
134 template <
typename T>
135 LogicalResult visit(T &&node) {
136 mlir::emitError(loc,
"unsupported construct: ")
137 << slang::ast::toString(node.kind);
148struct PackageVisitor :
public BaseVisitor {
149 using BaseVisitor::BaseVisitor;
150 using BaseVisitor::visit;
153 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
158 template <
typename T>
159 LogicalResult visit(T &&node) {
160 mlir::emitError(loc,
"unsupported package member: ")
161 << slang::ast::toString(node.kind);
171static moore::ProcedureKind
174 case slang::ast::ProceduralBlockKind::Always:
175 return moore::ProcedureKind::Always;
176 case slang::ast::ProceduralBlockKind::AlwaysComb:
177 return moore::ProcedureKind::AlwaysComb;
178 case slang::ast::ProceduralBlockKind::AlwaysLatch:
179 return moore::ProcedureKind::AlwaysLatch;
180 case slang::ast::ProceduralBlockKind::AlwaysFF:
181 return moore::ProcedureKind::AlwaysFF;
182 case slang::ast::ProceduralBlockKind::Initial:
183 return moore::ProcedureKind::Initial;
184 case slang::ast::ProceduralBlockKind::Final:
185 return moore::ProcedureKind::Final;
187 llvm_unreachable(
"all procedure kinds handled");
192 case slang::ast::NetType::Supply0:
193 return moore::NetKind::Supply0;
194 case slang::ast::NetType::Supply1:
195 return moore::NetKind::Supply1;
196 case slang::ast::NetType::Tri:
197 return moore::NetKind::Tri;
198 case slang::ast::NetType::TriAnd:
199 return moore::NetKind::TriAnd;
200 case slang::ast::NetType::TriOr:
201 return moore::NetKind::TriOr;
202 case slang::ast::NetType::TriReg:
203 return moore::NetKind::TriReg;
204 case slang::ast::NetType::Tri0:
205 return moore::NetKind::Tri0;
206 case slang::ast::NetType::Tri1:
207 return moore::NetKind::Tri1;
208 case slang::ast::NetType::UWire:
209 return moore::NetKind::UWire;
210 case slang::ast::NetType::Wire:
211 return moore::NetKind::Wire;
212 case slang::ast::NetType::WAnd:
213 return moore::NetKind::WAnd;
214 case slang::ast::NetType::WOr:
215 return moore::NetKind::WOr;
216 case slang::ast::NetType::Interconnect:
217 return moore::NetKind::Interconnect;
218 case slang::ast::NetType::UserDefined:
219 return moore::NetKind::UserDefined;
220 case slang::ast::NetType::Unknown:
221 return moore::NetKind::Unknown;
223 llvm_unreachable(
"all net kinds handled");
227struct ModuleVisitor :
public BaseVisitor {
228 using BaseVisitor::BaseVisitor;
229 using BaseVisitor::visit;
232 LogicalResult visit(
const slang::ast::PortSymbol &) {
return success(); }
233 LogicalResult visit(
const slang::ast::MultiPortSymbol &) {
return success(); }
236 LogicalResult visit(
const slang::ast::GenvarSymbol &genvarNode) {
241 LogicalResult visit(
const slang::ast::DefParamSymbol &) {
return success(); }
245 LogicalResult visit(
const slang::ast::TypeParameterSymbol &) {
250 LogicalResult visit(
const slang::ast::InstanceSymbol &instNode) {
251 using slang::ast::ArgumentDirection;
252 using slang::ast::AssignmentExpression;
253 using slang::ast::MultiPortSymbol;
254 using slang::ast::PortSymbol;
259 auto module = moduleLowering->op;
260 auto moduleType =
module.getModuleType();
263 SymbolTable::setSymbolVisibility(module, SymbolTable::Visibility::Private);
270 portValues.reserve(moduleType.getNumPorts());
272 for (
const auto *con : instNode.getPortConnections()) {
273 const auto *expr = con->getExpression();
278 auto *port = con->port.as_if<PortSymbol>();
279 if (
auto *existingPort =
280 moduleLowering->portsBySyntaxNode.lookup(port->getSyntax()))
283 switch (port->direction) {
284 case ArgumentDirection::In: {
285 auto refType = moore::RefType::get(
286 cast<moore::UnpackedType>(context.
convertType(port->getType())));
288 if (
const auto *net =
289 port->internalSymbol->as_if<slang::ast::NetSymbol>()) {
290 auto netOp = builder.create<moore::NetOp>(
291 loc, refType, StringAttr::get(builder.getContext(), net->name),
293 auto readOp = builder.create<moore::ReadOp>(loc, netOp);
294 portValues.insert({port, readOp});
295 }
else if (
const auto *var =
297 ->as_if<slang::ast::VariableSymbol>()) {
298 auto varOp = builder.create<moore::VariableOp>(
299 loc, refType, StringAttr::get(builder.getContext(), var->name),
301 auto readOp = builder.create<moore::ReadOp>(loc, varOp);
302 portValues.insert({port, readOp});
304 return mlir::emitError(loc)
305 <<
"unsupported internal symbol for unconnected port `"
306 << port->name <<
"`";
313 case ArgumentDirection::Out:
318 return mlir::emitError(loc)
319 <<
"unsupported port `" << port->name <<
"` ("
320 << slang::ast::toString(port->kind) <<
")";
326 if (
const auto *assign = expr->as_if<AssignmentExpression>())
327 expr = &assign->left();
332 if (
auto *port = con->port.as_if<PortSymbol>()) {
334 auto value = (port->direction == ArgumentDirection::In)
339 if (
auto *existingPort =
340 moduleLowering->portsBySyntaxNode.lookup(con->port.getSyntax()))
342 portValues.insert({port, value});
349 if (
const auto *multiPort = con->port.as_if<MultiPortSymbol>()) {
355 for (
const auto *port :
llvm::reverse(multiPort->ports)) {
356 if (
auto *existingPort = moduleLowering->portsBySyntaxNode.lookup(
357 con->port.getSyntax()))
359 unsigned width = port->getType().getBitWidth();
360 auto sliceType = context.
convertType(port->getType());
363 Value slice = builder.create<moore::ExtractRefOp>(
364 loc, moore::RefType::get(cast<moore::UnpackedType>(sliceType)),
367 if (port->direction == ArgumentDirection::In)
368 slice = builder.create<moore::ReadOp>(loc, slice);
369 portValues.insert({port, slice});
375 mlir::emitError(loc) <<
"unsupported instance port `" << con->port.name
376 <<
"` (" << slang::ast::toString(con->port.kind)
382 SmallVector<Value> inputValues;
383 SmallVector<Value> outputValues;
384 inputValues.reserve(moduleType.getNumInputs());
385 outputValues.reserve(moduleType.getNumOutputs());
387 for (
auto &port : moduleLowering->ports) {
388 auto value = portValues.lookup(&port.ast);
389 if (port.ast.direction == ArgumentDirection::Out)
390 outputValues.push_back(value);
392 inputValues.push_back(value);
396 for (
auto [value, type] :
397 llvm::zip(inputValues, moduleType.getInputTypes()))
398 if (value.getType() != type)
400 builder.create<moore::ConversionOp>(value.
getLoc(), type, value);
404 for (
const auto &hierPath : context.hierPaths[&instNode.body])
405 if (auto hierValue = context.valueSymbols.lookup(hierPath.valueSym);
406 hierPath.hierName && hierPath.direction == ArgumentDirection::In)
407 inputValues.push_back(hierValue);
410 auto inputNames = builder.getArrayAttr(moduleType.getInputNames());
411 auto outputNames = builder.getArrayAttr(moduleType.getOutputNames());
412 auto inst = builder.create<moore::InstanceOp>(
413 loc, moduleType.getOutputTypes(), builder.getStringAttr(instNode.name),
414 FlatSymbolRefAttr::get(module.getSymNameAttr()), inputValues,
415 inputNames, outputNames);
418 for (
const auto &hierPath : context.hierPaths[&instNode.body])
419 if (hierPath.idx && hierPath.direction == ArgumentDirection::
Out)
420 context.valueSymbols.insert(hierPath.valueSym,
421 inst->getResult(*hierPath.idx));
424 for (
auto [lvalue, output] :
llvm::zip(outputValues, inst.getOutputs())) {
427 Value rvalue = output;
428 auto dstType = cast<moore::RefType>(lvalue.getType()).getNestedType();
429 if (dstType != rvalue.getType())
430 rvalue = builder.create<moore::ConversionOp>(loc, dstType, rvalue);
431 builder.create<moore::ContinuousAssignOp>(loc, lvalue, rvalue);
438 LogicalResult visit(
const slang::ast::VariableSymbol &varNode) {
439 auto loweredType = context.
convertType(*varNode.getDeclaredType());
444 if (
const auto *init = varNode.getInitializer()) {
450 auto varOp = builder.create<moore::VariableOp>(
451 loc, moore::RefType::get(cast<moore::UnpackedType>(loweredType)),
452 builder.getStringAttr(varNode.name), initial);
458 LogicalResult visit(
const slang::ast::NetSymbol &netNode) {
459 auto loweredType = context.
convertType(*netNode.getDeclaredType());
464 if (
const auto *init = netNode.getInitializer()) {
471 if (netkind == moore::NetKind::Interconnect ||
472 netkind == moore::NetKind::UserDefined ||
473 netkind == moore::NetKind::Unknown)
474 return mlir::emitError(loc,
"unsupported net kind `")
475 << netNode.netType.name <<
"`";
477 auto netOp = builder.create<moore::NetOp>(
478 loc, moore::RefType::get(cast<moore::UnpackedType>(loweredType)),
479 builder.getStringAttr(netNode.name), netkind, assignment);
485 LogicalResult visit(
const slang::ast::ContinuousAssignSymbol &assignNode) {
486 if (
const auto *delay = assignNode.getDelay()) {
488 return mlir::emitError(loc,
489 "delayed continuous assignments not supported");
493 assignNode.getAssignment().as<slang::ast::AssignmentExpression>();
499 expr.right(), cast<moore::RefType>(lhs.getType()).getNestedType());
503 builder.create<moore::ContinuousAssignOp>(loc, lhs, rhs);
508 LogicalResult convertProcedure(moore::ProcedureKind kind,
509 const slang::ast::Statement &body) {
510 auto procOp = builder.create<moore::ProcedureOp>(loc, kind);
511 OpBuilder::InsertionGuard guard(builder);
512 builder.setInsertionPointToEnd(&procOp.getBody().emplaceBlock());
516 if (builder.getBlock())
517 builder.create<moore::ReturnOp>(loc);
521 LogicalResult visit(
const slang::ast::ProceduralBlockSymbol &procNode) {
525 auto *stmt = procNode.getBody().as_if<slang::ast::TimedStatement>();
526 if (procNode.procedureKind == slang::ast::ProceduralBlockKind::Always &&
528 stmt->timing.kind == slang::ast::TimingControlKind::ImplicitEvent)
529 return convertProcedure(moore::ProcedureKind::AlwaysComb, stmt->stmt);
537 LogicalResult visit(
const slang::ast::GenerateBlockSymbol &genNode) {
538 if (!genNode.isUninstantiated) {
539 for (
auto &member : genNode.members()) {
540 if (failed(member.visit(ModuleVisitor(context, loc))))
548 LogicalResult visit(
const slang::ast::GenerateBlockArraySymbol &genArrNode) {
549 for (
const auto *member : genArrNode.entries) {
550 if (failed(member->asSymbol().visit(ModuleVisitor(context, loc))))
562 LogicalResult visit(
const slang::ast::StatementBlockSymbol &) {
567 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
572 template <
typename T>
573 LogicalResult visit(T &&node) {
574 mlir::emitError(loc,
"unsupported module member: ")
575 << slang::ast::toString(node.kind);
592 for (
auto *inst : root.topInstances)
599 for (
auto *unit : root.compilationUnits) {
600 for (
const auto &member : unit->members()) {
602 if (failed(member.visit(RootVisitor(*
this, loc))))
608 SmallVector<const slang::ast::InstanceSymbol *> topInstances;
609 for (
auto *inst : root.topInstances)
615 auto *
module = moduleWorklist.front();
630 using slang::ast::ArgumentDirection;
631 using slang::ast::MultiPortSymbol;
632 using slang::ast::ParameterSymbol;
633 using slang::ast::PortSymbol;
634 using slang::ast::TypeParameterSymbol;
636 auto parameters =
module->parameters;
637 bool hasModuleSame =
false;
641 for (
auto const &existingModule :
modules) {
642 if (module->getDeclaringDefinition() ==
643 existingModule.getFirst()->getDeclaringDefinition()) {
644 auto moduleParameters = existingModule.getFirst()->parameters;
645 hasModuleSame =
true;
646 for (
auto it1 = parameters.begin(), it2 = moduleParameters.begin();
647 it1 != parameters.end() && it2 != moduleParameters.end();
650 if (it1 == parameters.end() || it2 == moduleParameters.end()) {
651 hasModuleSame =
false;
654 const auto *para1 = (*it1)->symbol.as_if<ParameterSymbol>();
655 const auto *para2 = (*it2)->symbol.as_if<ParameterSymbol>();
657 if ((para1 ==
nullptr) ^ (para2 ==
nullptr)) {
658 hasModuleSame =
false;
662 if (para1 !=
nullptr) {
663 hasModuleSame = para1->getValue() == para2->getValue();
666 if (para1 ==
nullptr) {
668 (*it1)->symbol.as<TypeParameterSymbol>().getTypeAlias());
670 (*it2)->symbol.as<TypeParameterSymbol>().getTypeAlias());
671 hasModuleSame = para1Type == para2Type;
677 module = existingModule.first;
686 slot = std::make_unique<ModuleLowering>();
687 auto &lowering = *slot;
690 OpBuilder::InsertionGuard g(
builder);
695 if (module->getDefinition().definitionKind !=
696 slang::ast::DefinitionKind::Module) {
697 mlir::emitError(loc) <<
"unsupported definition: "
698 <<
module->getDefinition().getKindString();
703 auto block = std::make_unique<Block>();
704 SmallVector<hw::ModulePort> modulePorts;
707 unsigned int outputIdx = 0, inputIdx = 0;
708 for (
auto *symbol :
module->getPortList()) {
709 auto handlePort = [&](const PortSymbol &port) {
710 auto portLoc = convertLocation(port.location);
714 auto portName =
builder.getStringAttr(port.name);
716 if (port.direction == ArgumentDirection::Out) {
722 if (port.direction != ArgumentDirection::In)
723 type = moore::RefType::get(cast<moore::UnpackedType>(type));
725 arg = block->addArgument(type, portLoc);
728 lowering.ports.push_back({port, portLoc, arg});
732 if (
const auto *port = symbol->as_if<PortSymbol>()) {
733 if (failed(handlePort(*port)))
735 }
else if (
const auto *multiPort = symbol->as_if<MultiPortSymbol>()) {
736 for (
auto *port : multiPort->ports)
737 if (failed(handlePort(*port)))
741 <<
"unsupported module port `" << symbol->name <<
"` ("
742 << slang::ast::toString(symbol->kind) <<
")";
748 for (
auto &hierPath : hierPaths[module]) {
749 auto hierType =
convertType(hierPath.valueSym->getType());
753 if (
auto hierName = hierPath.hierName) {
755 hierType = moore::RefType::get(cast<moore::UnpackedType>(hierType));
756 if (hierPath.direction == ArgumentDirection::Out) {
757 hierPath.idx = outputIdx++;
760 hierPath.idx = inputIdx++;
763 block->addArgument(hierType, hierLoc);
767 auto moduleType = hw::ModuleType::get(getContext(), modulePorts);
771 auto it = orderedRootOps.upper_bound(module->location);
772 if (it == orderedRootOps.end())
773 builder.setInsertionPointToEnd(intoModuleOp.getBody());
775 builder.setInsertionPoint(it->second);
779 builder.create<moore::SVModuleOp>(loc,
module->name, moduleType);
780 orderedRootOps.insert(it, {
module->location, moduleOp});
781 moduleOp.getBodyRegion().push_back(block.release());
782 lowering.op = moduleOp;
786 symbolTable.insert(moduleOp);
789 moduleWorklist.push(module);
792 for (
const auto &port : lowering.ports)
793 lowering.portsBySyntaxNode.insert({port.ast.getSyntax(), &port.ast});
802 auto &lowering = *
modules[module];
803 OpBuilder::InsertionGuard g(
builder);
804 builder.setInsertionPointToEnd(lowering.op.getBody());
812 if (hierPath.direction == slang::ast::ArgumentDirection::In && hierPath.idx)
814 lowering.op.getBody()->getArgument(*hierPath.idx));
817 for (
auto &member :
module->members()) {
818 auto loc = convertLocation(member.location);
819 if (failed(member.visit(ModuleVisitor(*
this, loc))))
826 SmallVector<Value> outputs;
827 for (
auto &port : lowering.ports) {
829 if (
auto *expr = port.ast.getInternalExpr()) {
830 value = convertLvalueExpression(*expr);
831 }
else if (port.ast.internalSymbol) {
832 if (
const auto *sym =
833 port.ast.internalSymbol->as_if<slang::ast::ValueSymbol>())
834 value = valueSymbols.lookup(sym);
837 return mlir::emitError(port.loc,
"unsupported port: `")
839 <<
"` does not map to an internal symbol or expression";
842 if (port.ast.direction == slang::ast::ArgumentDirection::Out) {
843 if (isa<moore::RefType>(value.getType()))
844 value = builder.create<moore::ReadOp>(value.getLoc(), value);
845 outputs.push_back(value);
851 Value portArg = port.arg;
852 if (port.ast.direction != slang::ast::ArgumentDirection::In)
853 portArg = builder.create<moore::ReadOp>(port.loc, port.arg);
854 builder.create<moore::ContinuousAssignOp>(port.loc, value, portArg);
859 for (
auto &hierPath : hierPaths[module])
860 if (auto hierValue = valueSymbols.lookup(hierPath.valueSym))
861 if (hierPath.direction == slang::ast::ArgumentDirection::
Out)
862 outputs.push_back(hierValue);
864 builder.create<moore::OutputOp>(lowering.op.getLoc(), outputs);
871 OpBuilder::InsertionGuard g(
builder);
874 for (
auto &member : package.members()) {
876 if (failed(member.visit(PackageVisitor(*
this, loc))))
886 using slang::ast::ArgumentDirection;
893 return lowering.get();
895 lowering = std::make_unique<FunctionLowering>();
900 OpBuilder::InsertionGuard g(
builder);
905 builder.setInsertionPoint(it->second);
908 if (subroutine.thisVar) {
909 mlir::emitError(loc) <<
"unsupported class method";
914 SmallVector<Type> inputTypes;
915 SmallVector<Type, 1> outputTypes;
917 for (
const auto *arg : subroutine.getArguments()) {
918 auto type = cast<moore::UnpackedType>(
convertType(arg->getType()));
921 if (arg->direction == ArgumentDirection::In) {
922 inputTypes.push_back(type);
924 inputTypes.push_back(moore::RefType::get(type));
928 if (!subroutine.getReturnType().isVoid()) {
929 auto type =
convertType(subroutine.getReturnType());
932 outputTypes.push_back(type);
935 auto funcType = FunctionType::get(
getContext(), inputTypes, outputTypes);
939 SmallString<64> funcName;
941 funcName += subroutine.name;
944 auto funcOp =
builder.create<mlir::func::FuncOp>(loc, funcName, funcType);
945 SymbolTable::setSymbolVisibility(funcOp, SymbolTable::Visibility::Private);
947 lowering->op = funcOp;
953 return lowering.get();
966 SmallVector<moore::VariableOp> argVariables;
967 auto &block = lowering->op.getBody().emplaceBlock();
968 for (
auto [astArg, type] :
969 llvm::zip(subroutine.getArguments(),
970 lowering->op.getFunctionType().getInputs())) {
972 auto blockArg = block.addArgument(type, loc);
974 if (isa<moore::RefType>(type)) {
978 OpBuilder::InsertionGuard g(
builder);
979 builder.setInsertionPointToEnd(&block);
981 auto shadowArg =
builder.create<moore::VariableOp>(
982 loc, moore::RefType::get(cast<moore::UnpackedType>(type)),
983 StringAttr{}, blockArg);
985 argVariables.push_back(shadowArg);
990 OpBuilder::InsertionGuard g(
builder);
991 builder.setInsertionPointToEnd(&block);
994 if (subroutine.returnValVar) {
995 auto type =
convertType(*subroutine.returnValVar->getDeclaredType());
998 returnVar =
builder.create<moore::VariableOp>(
999 lowering->op.getLoc(),
1000 moore::RefType::get(cast<moore::UnpackedType>(type)), StringAttr{},
1002 valueSymbols.insert(subroutine.returnValVar, returnVar);
1011 if (returnVar && !subroutine.getReturnType().isVoid()) {
1012 Value read =
builder.create<moore::ReadOp>(returnVar.getLoc(), returnVar);
1013 builder.create<mlir::func::ReturnOp>(lowering->op.getLoc(), read);
1015 builder.create<mlir::func::ReturnOp>(lowering->op.getLoc(), ValueRange{});
1018 if (returnVar && returnVar.use_empty())
1019 returnVar.getDefiningOp()->erase();
1021 for (
auto var : argVariables) {
1022 if (llvm::all_of(var->getUsers(),
1023 [](
auto *user) { return isa<moore::ReadOp>(user); })) {
1024 for (
auto *user : llvm::make_early_inc_range(var->getUsers())) {
1025 user->getResult(0).replaceAllUsesWith(var.getInitial());
static FIRRTLBaseType convertType(FIRRTLBaseType type)
Returns null type if no conversion is needed.
static Location convertLocation(MLIRContext *context, const slang::SourceManager &sourceManager, SmallDenseMap< slang::BufferID, StringRef > &bufferFilePaths, slang::SourceLocation loc)
Convert a slang SourceLocation to an MLIR Location.
static Location getLoc(DefSlot slot)
static moore::ProcedureKind convertProcedureKind(slang::ast::ProceduralBlockKind kind)
static void guessNamespacePrefix(const slang::ast::Symbol &symbol, SmallString< 64 > &prefix)
static moore::NetKind convertNetKind(slang::ast::NetType::NetKind kind)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
bool lowerAlwaysAtStarAsComb
Interpret always @(*) as always_comb.
bool debugInfo
Generate debug information in the form of debug dialect ops in the IR.
A helper class to facilitate the conversion from a Slang AST to MLIR operations.
LogicalResult convertFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function.
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.
LogicalResult convertModuleBody(const slang::ast::InstanceBodySymbol *module)
Convert a module's body to the corresponding IR ops.
slang::ast::Compilation & compilation
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::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.
ValueSymbols valueSymbols
ValueSymbols::ScopeTy ValueSymbolScope
const ImportVerilogOptions & options
Value convertRvalueExpression(const slang::ast::Expression &expr, Type requiredType={})
LogicalResult traverseInstanceBody(const slang::ast::Symbol &symbol)
mlir::ModuleOp intoModuleOp
SymbolTable symbolTable
A symbol table of the MLIR module we are emitting into.
DenseMap< const slang::ast::InstanceBodySymbol *, SmallVector< HierPathInfo > > hierPaths
Collect all hierarchical names used for the per module/instance.
FunctionLowering * declareFunction(const slang::ast::SubroutineSymbol &subroutine)
Convert a function and its arguments to a function declaration in the IR.
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)
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.
Module lowering information.