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(); }
58 LogicalResult visit(
const slang::ast::ForwardingTypedefSymbol &) {
63 LogicalResult visit(
const slang::ast::ExplicitImportSymbol &) {
66 LogicalResult visit(
const slang::ast::WildcardImportSymbol &) {
71 LogicalResult visit(
const slang::ast::TypeParameterSymbol &) {
76 LogicalResult visit(
const slang::ast::ElabSystemTaskSymbol &) {
81 LogicalResult visit(
const slang::ast::ParameterSymbol ¶m) {
82 visitParameter(param);
86 LogicalResult visit(
const slang::ast::SpecparamSymbol ¶m) {
87 visitParameter(param);
92 void visitParameter(
const Node ¶m) {
102 if (builder.getInsertionBlock()->getParentOp() == context.
intoModuleOp)
103 context.
orderedRootOps.insert({param.location, value.getDefiningOp()});
107 SmallString<64> paramName;
109 paramName += param.name;
111 builder.create<debug::VariableOp>(loc, builder.getStringAttr(paramName),
122struct RootVisitor :
public BaseVisitor {
123 using BaseVisitor::BaseVisitor;
124 using BaseVisitor::visit;
127 LogicalResult visit(
const slang::ast::PackageSymbol &package) {
132 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
137 template <
typename T>
138 LogicalResult visit(T &&node) {
139 mlir::emitError(loc,
"unsupported construct: ")
140 << slang::ast::toString(node.kind);
151struct PackageVisitor :
public BaseVisitor {
152 using BaseVisitor::BaseVisitor;
153 using BaseVisitor::visit;
156 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
161 template <
typename T>
162 LogicalResult visit(T &&node) {
163 mlir::emitError(loc,
"unsupported package member: ")
164 << slang::ast::toString(node.kind);
174static moore::ProcedureKind
177 case slang::ast::ProceduralBlockKind::Always:
178 return moore::ProcedureKind::Always;
179 case slang::ast::ProceduralBlockKind::AlwaysComb:
180 return moore::ProcedureKind::AlwaysComb;
181 case slang::ast::ProceduralBlockKind::AlwaysLatch:
182 return moore::ProcedureKind::AlwaysLatch;
183 case slang::ast::ProceduralBlockKind::AlwaysFF:
184 return moore::ProcedureKind::AlwaysFF;
185 case slang::ast::ProceduralBlockKind::Initial:
186 return moore::ProcedureKind::Initial;
187 case slang::ast::ProceduralBlockKind::Final:
188 return moore::ProcedureKind::Final;
190 llvm_unreachable(
"all procedure kinds handled");
195 case slang::ast::NetType::Supply0:
196 return moore::NetKind::Supply0;
197 case slang::ast::NetType::Supply1:
198 return moore::NetKind::Supply1;
199 case slang::ast::NetType::Tri:
200 return moore::NetKind::Tri;
201 case slang::ast::NetType::TriAnd:
202 return moore::NetKind::TriAnd;
203 case slang::ast::NetType::TriOr:
204 return moore::NetKind::TriOr;
205 case slang::ast::NetType::TriReg:
206 return moore::NetKind::TriReg;
207 case slang::ast::NetType::Tri0:
208 return moore::NetKind::Tri0;
209 case slang::ast::NetType::Tri1:
210 return moore::NetKind::Tri1;
211 case slang::ast::NetType::UWire:
212 return moore::NetKind::UWire;
213 case slang::ast::NetType::Wire:
214 return moore::NetKind::Wire;
215 case slang::ast::NetType::WAnd:
216 return moore::NetKind::WAnd;
217 case slang::ast::NetType::WOr:
218 return moore::NetKind::WOr;
219 case slang::ast::NetType::Interconnect:
220 return moore::NetKind::Interconnect;
221 case slang::ast::NetType::UserDefined:
222 return moore::NetKind::UserDefined;
223 case slang::ast::NetType::Unknown:
224 return moore::NetKind::Unknown;
226 llvm_unreachable(
"all net kinds handled");
230struct ModuleVisitor :
public BaseVisitor {
231 using BaseVisitor::BaseVisitor;
232 using BaseVisitor::visit;
235 LogicalResult visit(
const slang::ast::PortSymbol &) {
return success(); }
236 LogicalResult visit(
const slang::ast::MultiPortSymbol &) {
return success(); }
239 LogicalResult visit(
const slang::ast::GenvarSymbol &genvarNode) {
244 LogicalResult visit(
const slang::ast::DefParamSymbol &) {
return success(); }
248 LogicalResult visit(
const slang::ast::TypeParameterSymbol &) {
253 LogicalResult visit(
const slang::ast::InstanceSymbol &instNode) {
254 using slang::ast::ArgumentDirection;
255 using slang::ast::AssignmentExpression;
256 using slang::ast::MultiPortSymbol;
257 using slang::ast::PortSymbol;
262 auto module = moduleLowering->op;
263 auto moduleType =
module.getModuleType();
266 SymbolTable::setSymbolVisibility(module, SymbolTable::Visibility::Private);
273 portValues.reserve(moduleType.getNumPorts());
275 for (
const auto *con : instNode.getPortConnections()) {
276 const auto *expr = con->getExpression();
281 auto *port = con->port.as_if<PortSymbol>();
282 if (
auto *existingPort =
283 moduleLowering->portsBySyntaxNode.lookup(port->getSyntax()))
286 switch (port->direction) {
287 case ArgumentDirection::In: {
288 auto refType = moore::RefType::get(
289 cast<moore::UnpackedType>(context.
convertType(port->getType())));
291 if (
const auto *net =
292 port->internalSymbol->as_if<slang::ast::NetSymbol>()) {
293 auto netOp = builder.create<moore::NetOp>(
294 loc, refType, StringAttr::get(builder.getContext(), net->name),
296 auto readOp = builder.create<moore::ReadOp>(loc, netOp);
297 portValues.insert({port, readOp});
298 }
else if (
const auto *var =
300 ->as_if<slang::ast::VariableSymbol>()) {
301 auto varOp = builder.create<moore::VariableOp>(
302 loc, refType, StringAttr::get(builder.getContext(), var->name),
304 auto readOp = builder.create<moore::ReadOp>(loc, varOp);
305 portValues.insert({port, readOp});
307 return mlir::emitError(loc)
308 <<
"unsupported internal symbol for unconnected port `"
309 << port->name <<
"`";
316 case ArgumentDirection::Out:
321 return mlir::emitError(loc)
322 <<
"unsupported port `" << port->name <<
"` ("
323 << slang::ast::toString(port->kind) <<
")";
329 if (
const auto *assign = expr->as_if<AssignmentExpression>())
330 expr = &assign->left();
335 if (
auto *port = con->port.as_if<PortSymbol>()) {
337 auto value = (port->direction == ArgumentDirection::In)
342 if (
auto *existingPort =
343 moduleLowering->portsBySyntaxNode.lookup(con->port.getSyntax()))
345 portValues.insert({port, value});
352 if (
const auto *multiPort = con->port.as_if<MultiPortSymbol>()) {
358 for (
const auto *port :
llvm::reverse(multiPort->ports)) {
359 if (
auto *existingPort = moduleLowering->portsBySyntaxNode.lookup(
360 con->port.getSyntax()))
362 unsigned width = port->getType().getBitWidth();
363 auto sliceType = context.
convertType(port->getType());
366 Value slice = builder.create<moore::ExtractRefOp>(
367 loc, moore::RefType::get(cast<moore::UnpackedType>(sliceType)),
370 if (port->direction == ArgumentDirection::In)
371 slice = builder.create<moore::ReadOp>(loc, slice);
372 portValues.insert({port, slice});
378 mlir::emitError(loc) <<
"unsupported instance port `" << con->port.name
379 <<
"` (" << slang::ast::toString(con->port.kind)
385 SmallVector<Value> inputValues;
386 SmallVector<Value> outputValues;
387 inputValues.reserve(moduleType.getNumInputs());
388 outputValues.reserve(moduleType.getNumOutputs());
390 for (
auto &port : moduleLowering->ports) {
391 auto value = portValues.lookup(&port.ast);
392 if (port.ast.direction == ArgumentDirection::Out)
393 outputValues.push_back(value);
395 inputValues.push_back(value);
399 for (
auto [value, type] :
400 llvm::zip(inputValues, moduleType.getInputTypes()))
401 if (value.getType() != type)
403 builder.create<moore::ConversionOp>(value.
getLoc(), type, value);
407 for (
const auto &hierPath : context.hierPaths[&instNode.body])
408 if (auto hierValue = context.valueSymbols.lookup(hierPath.valueSym);
409 hierPath.hierName && hierPath.direction == ArgumentDirection::In)
410 inputValues.push_back(hierValue);
413 auto inputNames = builder.getArrayAttr(moduleType.getInputNames());
414 auto outputNames = builder.getArrayAttr(moduleType.getOutputNames());
415 auto inst = builder.create<moore::InstanceOp>(
416 loc, moduleType.getOutputTypes(), builder.getStringAttr(instNode.name),
417 FlatSymbolRefAttr::get(module.getSymNameAttr()), inputValues,
418 inputNames, outputNames);
421 for (
const auto &hierPath : context.hierPaths[&instNode.body])
422 if (hierPath.idx && hierPath.direction == ArgumentDirection::
Out)
423 context.valueSymbols.insert(hierPath.valueSym,
424 inst->getResult(*hierPath.idx));
427 for (
auto [lvalue, output] :
llvm::zip(outputValues, inst.getOutputs())) {
430 Value rvalue = output;
431 auto dstType = cast<moore::RefType>(lvalue.getType()).getNestedType();
432 if (dstType != rvalue.getType())
433 rvalue = builder.create<moore::ConversionOp>(loc, dstType, rvalue);
434 builder.create<moore::ContinuousAssignOp>(loc, lvalue, rvalue);
441 LogicalResult visit(
const slang::ast::VariableSymbol &varNode) {
442 auto loweredType = context.
convertType(*varNode.getDeclaredType());
447 if (
const auto *init = varNode.getInitializer()) {
453 auto varOp = builder.create<moore::VariableOp>(
454 loc, moore::RefType::get(cast<moore::UnpackedType>(loweredType)),
455 builder.getStringAttr(varNode.name), initial);
461 LogicalResult visit(
const slang::ast::NetSymbol &netNode) {
462 auto loweredType = context.
convertType(*netNode.getDeclaredType());
467 if (
const auto *init = netNode.getInitializer()) {
474 if (netkind == moore::NetKind::Interconnect ||
475 netkind == moore::NetKind::UserDefined ||
476 netkind == moore::NetKind::Unknown)
477 return mlir::emitError(loc,
"unsupported net kind `")
478 << netNode.netType.name <<
"`";
480 auto netOp = builder.create<moore::NetOp>(
481 loc, moore::RefType::get(cast<moore::UnpackedType>(loweredType)),
482 builder.getStringAttr(netNode.name), netkind, assignment);
488 LogicalResult visit(
const slang::ast::ContinuousAssignSymbol &assignNode) {
489 if (
const auto *delay = assignNode.getDelay()) {
491 return mlir::emitError(loc,
492 "delayed continuous assignments not supported");
496 assignNode.getAssignment().as<slang::ast::AssignmentExpression>();
502 expr.right(), cast<moore::RefType>(lhs.getType()).getNestedType());
506 builder.create<moore::ContinuousAssignOp>(loc, lhs, rhs);
511 LogicalResult convertProcedure(moore::ProcedureKind kind,
512 const slang::ast::Statement &body) {
513 auto procOp = builder.create<moore::ProcedureOp>(loc, kind);
514 OpBuilder::InsertionGuard guard(builder);
515 builder.setInsertionPointToEnd(&procOp.getBody().emplaceBlock());
519 if (builder.getBlock())
520 builder.create<moore::ReturnOp>(loc);
524 LogicalResult visit(
const slang::ast::ProceduralBlockSymbol &procNode) {
528 auto *stmt = procNode.getBody().as_if<slang::ast::TimedStatement>();
529 if (procNode.procedureKind == slang::ast::ProceduralBlockKind::Always &&
531 stmt->timing.kind == slang::ast::TimingControlKind::ImplicitEvent)
532 return convertProcedure(moore::ProcedureKind::AlwaysComb, stmt->stmt);
540 LogicalResult visit(
const slang::ast::GenerateBlockSymbol &genNode) {
541 if (!genNode.isUninstantiated) {
542 for (
auto &member : genNode.members()) {
543 if (failed(member.visit(ModuleVisitor(context, loc))))
551 LogicalResult visit(
const slang::ast::GenerateBlockArraySymbol &genArrNode) {
552 for (
const auto *member : genArrNode.entries) {
553 if (failed(member->asSymbol().visit(ModuleVisitor(context, loc))))
565 LogicalResult visit(
const slang::ast::StatementBlockSymbol &) {
570 LogicalResult visit(
const slang::ast::SubroutineSymbol &subroutine) {
575 template <
typename T>
576 LogicalResult visit(T &&node) {
577 mlir::emitError(loc,
"unsupported module member: ")
578 << slang::ast::toString(node.kind);
595 for (
auto *inst : root.topInstances)
602 for (
auto *unit : root.compilationUnits) {
603 for (
const auto &member : unit->members()) {
605 if (failed(member.visit(RootVisitor(*
this, loc))))
611 SmallVector<const slang::ast::InstanceSymbol *> topInstances;
612 for (
auto *inst : root.topInstances)
618 auto *
module = moduleWorklist.front();
633 using slang::ast::ArgumentDirection;
634 using slang::ast::MultiPortSymbol;
635 using slang::ast::ParameterSymbol;
636 using slang::ast::PortSymbol;
637 using slang::ast::TypeParameterSymbol;
639 auto parameters =
module->parameters;
640 bool hasModuleSame =
false;
644 for (
auto const &existingModule :
modules) {
645 if (module->getDeclaringDefinition() ==
646 existingModule.getFirst()->getDeclaringDefinition()) {
647 auto moduleParameters = existingModule.getFirst()->parameters;
648 hasModuleSame =
true;
649 for (
auto it1 = parameters.begin(), it2 = moduleParameters.begin();
650 it1 != parameters.end() && it2 != moduleParameters.end();
653 if (it1 == parameters.end() || it2 == moduleParameters.end()) {
654 hasModuleSame =
false;
657 const auto *para1 = (*it1)->symbol.as_if<ParameterSymbol>();
658 const auto *para2 = (*it2)->symbol.as_if<ParameterSymbol>();
660 if ((para1 ==
nullptr) ^ (para2 ==
nullptr)) {
661 hasModuleSame =
false;
665 if (para1 !=
nullptr) {
666 hasModuleSame = para1->getValue() == para2->getValue();
669 if (para1 ==
nullptr) {
671 (*it1)->symbol.as<TypeParameterSymbol>().getTypeAlias());
673 (*it2)->symbol.as<TypeParameterSymbol>().getTypeAlias());
674 hasModuleSame = para1Type == para2Type;
680 module = existingModule.first;
689 slot = std::make_unique<ModuleLowering>();
690 auto &lowering = *slot;
693 OpBuilder::InsertionGuard g(
builder);
698 if (module->getDefinition().definitionKind !=
699 slang::ast::DefinitionKind::Module) {
700 mlir::emitError(loc) <<
"unsupported definition: "
701 <<
module->getDefinition().getKindString();
706 auto block = std::make_unique<Block>();
707 SmallVector<hw::ModulePort> modulePorts;
710 unsigned int outputIdx = 0, inputIdx = 0;
711 for (
auto *symbol :
module->getPortList()) {
712 auto handlePort = [&](const PortSymbol &port) {
713 auto portLoc = convertLocation(port.location);
717 auto portName =
builder.getStringAttr(port.name);
719 if (port.direction == ArgumentDirection::Out) {
725 if (port.direction != ArgumentDirection::In)
726 type = moore::RefType::get(cast<moore::UnpackedType>(type));
728 arg = block->addArgument(type, portLoc);
731 lowering.ports.push_back({port, portLoc, arg});
735 if (
const auto *port = symbol->as_if<PortSymbol>()) {
736 if (failed(handlePort(*port)))
738 }
else if (
const auto *multiPort = symbol->as_if<MultiPortSymbol>()) {
739 for (
auto *port : multiPort->ports)
740 if (failed(handlePort(*port)))
744 <<
"unsupported module port `" << symbol->name <<
"` ("
745 << slang::ast::toString(symbol->kind) <<
")";
751 for (
auto &hierPath : hierPaths[module]) {
752 auto hierType =
convertType(hierPath.valueSym->getType());
756 if (
auto hierName = hierPath.hierName) {
758 hierType = moore::RefType::get(cast<moore::UnpackedType>(hierType));
759 if (hierPath.direction == ArgumentDirection::Out) {
760 hierPath.idx = outputIdx++;
763 hierPath.idx = inputIdx++;
766 block->addArgument(hierType, hierLoc);
770 auto moduleType = hw::ModuleType::get(getContext(), modulePorts);
774 auto it = orderedRootOps.upper_bound(module->location);
775 if (it == orderedRootOps.end())
776 builder.setInsertionPointToEnd(intoModuleOp.getBody());
778 builder.setInsertionPoint(it->second);
782 builder.create<moore::SVModuleOp>(loc,
module->name, moduleType);
783 orderedRootOps.insert(it, {
module->location, moduleOp});
784 moduleOp.getBodyRegion().push_back(block.release());
785 lowering.op = moduleOp;
789 symbolTable.insert(moduleOp);
792 moduleWorklist.push(module);
795 for (
const auto &port : lowering.ports)
796 lowering.portsBySyntaxNode.insert({port.ast.getSyntax(), &port.ast});
805 auto &lowering = *
modules[module];
806 OpBuilder::InsertionGuard g(
builder);
807 builder.setInsertionPointToEnd(lowering.op.getBody());
815 if (hierPath.direction == slang::ast::ArgumentDirection::In && hierPath.idx)
817 lowering.op.getBody()->getArgument(*hierPath.idx));
820 for (
auto &member :
module->members()) {
821 auto loc = convertLocation(member.location);
822 if (failed(member.visit(ModuleVisitor(*
this, loc))))
829 SmallVector<Value> outputs;
830 for (
auto &port : lowering.ports) {
832 if (
auto *expr = port.ast.getInternalExpr()) {
833 value = convertLvalueExpression(*expr);
834 }
else if (port.ast.internalSymbol) {
835 if (
const auto *sym =
836 port.ast.internalSymbol->as_if<slang::ast::ValueSymbol>())
837 value = valueSymbols.lookup(sym);
840 return mlir::emitError(port.loc,
"unsupported port: `")
842 <<
"` does not map to an internal symbol or expression";
845 if (port.ast.direction == slang::ast::ArgumentDirection::Out) {
846 if (isa<moore::RefType>(value.getType()))
847 value = builder.create<moore::ReadOp>(value.getLoc(), value);
848 outputs.push_back(value);
854 Value portArg = port.arg;
855 if (port.ast.direction != slang::ast::ArgumentDirection::In)
856 portArg = builder.create<moore::ReadOp>(port.loc, port.arg);
857 builder.create<moore::ContinuousAssignOp>(port.loc, value, portArg);
862 for (
auto &hierPath : hierPaths[module])
863 if (auto hierValue = valueSymbols.lookup(hierPath.valueSym))
864 if (hierPath.direction == slang::ast::ArgumentDirection::
Out)
865 outputs.push_back(hierValue);
867 builder.create<moore::OutputOp>(lowering.op.getLoc(), outputs);
874 OpBuilder::InsertionGuard g(
builder);
877 for (
auto &member : package.members()) {
879 if (failed(member.visit(PackageVisitor(*
this, loc))))
889 using slang::ast::ArgumentDirection;
896 return lowering.get();
898 lowering = std::make_unique<FunctionLowering>();
903 OpBuilder::InsertionGuard g(
builder);
908 builder.setInsertionPoint(it->second);
911 if (subroutine.thisVar) {
912 mlir::emitError(loc) <<
"unsupported class method";
917 SmallVector<Type> inputTypes;
918 SmallVector<Type, 1> outputTypes;
920 for (
const auto *arg : subroutine.getArguments()) {
921 auto type = cast<moore::UnpackedType>(
convertType(arg->getType()));
924 if (arg->direction == ArgumentDirection::In) {
925 inputTypes.push_back(type);
927 inputTypes.push_back(moore::RefType::get(type));
931 if (!subroutine.getReturnType().isVoid()) {
932 auto type =
convertType(subroutine.getReturnType());
935 outputTypes.push_back(type);
938 auto funcType = FunctionType::get(
getContext(), inputTypes, outputTypes);
942 SmallString<64> funcName;
944 funcName += subroutine.name;
947 auto funcOp =
builder.create<mlir::func::FuncOp>(loc, funcName, funcType);
948 SymbolTable::setSymbolVisibility(funcOp, SymbolTable::Visibility::Private);
950 lowering->op = funcOp;
956 return lowering.get();
969 SmallVector<moore::VariableOp> argVariables;
970 auto &block = lowering->op.getBody().emplaceBlock();
971 for (
auto [astArg, type] :
972 llvm::zip(subroutine.getArguments(),
973 lowering->op.getFunctionType().getInputs())) {
975 auto blockArg = block.addArgument(type, loc);
977 if (isa<moore::RefType>(type)) {
981 OpBuilder::InsertionGuard g(
builder);
982 builder.setInsertionPointToEnd(&block);
984 auto shadowArg =
builder.create<moore::VariableOp>(
985 loc, moore::RefType::get(cast<moore::UnpackedType>(type)),
986 StringAttr{}, blockArg);
988 argVariables.push_back(shadowArg);
993 OpBuilder::InsertionGuard g(
builder);
994 builder.setInsertionPointToEnd(&block);
997 if (subroutine.returnValVar) {
998 auto type =
convertType(*subroutine.returnValVar->getDeclaredType());
1001 returnVar =
builder.create<moore::VariableOp>(
1002 lowering->op.getLoc(),
1003 moore::RefType::get(cast<moore::UnpackedType>(type)), StringAttr{},
1005 valueSymbols.insert(subroutine.returnValVar, returnVar);
1014 if (returnVar && !subroutine.getReturnType().isVoid()) {
1015 Value read =
builder.create<moore::ReadOp>(returnVar.getLoc(), returnVar);
1016 builder.create<mlir::func::ReturnOp>(lowering->op.getLoc(), read);
1018 builder.create<mlir::func::ReturnOp>(lowering->op.getLoc(), ValueRange{});
1021 if (returnVar && returnVar.use_empty())
1022 returnVar.getDefiningOp()->erase();
1024 for (
auto var : argVariables) {
1025 if (llvm::all_of(var->getUsers(),
1026 [](
auto *user) { return isa<moore::ReadOp>(user); })) {
1027 for (
auto *user : llvm::make_early_inc_range(var->getUsers())) {
1028 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.