@@ -984,17 +984,29 @@ struct RvalueExprVisitor : public ExprVisitor {
984984 const auto &subroutine = *info.subroutine ;
985985 auto args = expr.arguments ();
986986
987- if (args.size () == 1 ) {
988- auto value = context.convertRvalueExpression (*args[0 ]);
987+ FailureOr<Value> result;
988+ Value value;
989+
990+ switch (args.size ()) {
991+ case (0 ):
992+ result = context.convertSystemCallArity0 (subroutine, loc);
993+ break ;
994+
995+ case (1 ):
996+ value = context.convertRvalueExpression (*args[0 ]);
989997 if (!value)
990998 return {};
991- auto result = context.convertSystemCallArity1 (subroutine, loc, value);
992- if ( failed (result))
993- return {};
994- if (*result)
995- return *result ;
999+ result = context.convertSystemCallArity1 (subroutine, loc, value);
1000+ break ;
1001+
1002+ default :
1003+ break ;
9961004 }
9971005
1006+ if (failed (result))
1007+ return {};
1008+ if (*result)
1009+ return *result;
9981010 mlir::emitError (loc) << " unsupported system call `" << subroutine.name
9991011 << " `" ;
10001012 return {};
@@ -1572,6 +1584,20 @@ Value Context::materializeConversion(Type type, Value value, bool isSigned,
15721584 return value;
15731585}
15741586
1587+ FailureOr<Value>
1588+ Context::convertSystemCallArity0 (const slang::ast::SystemSubroutine &subroutine,
1589+ Location loc) {
1590+
1591+ auto systemCallRes =
1592+ llvm::StringSwitch<std::function<FailureOr<Value>()>>(subroutine.name )
1593+ .Case (" $urandom" ,
1594+ [&]() -> Value {
1595+ return moore::UrandomBIOp::create (builder, loc, nullptr );
1596+ })
1597+ .Default ([&]() -> Value { return {}; });
1598+ return systemCallRes ();
1599+ }
1600+
15751601FailureOr<Value>
15761602Context::convertSystemCallArity1 (const slang::ast::SystemSubroutine &subroutine,
15771603 Location loc, Value value) {
@@ -1661,6 +1687,10 @@ Context::convertSystemCallArity1(const slang::ast::SystemSubroutine &subroutine,
16611687 [&]() -> Value {
16621688 return moore::AtanhBIOp::create (builder, loc, value);
16631689 })
1690+ .Case (" $urandom" ,
1691+ [&]() -> Value {
1692+ return moore::UrandomBIOp::create (builder, loc, value);
1693+ })
16641694 .Default ([&]() -> Value { return {}; });
16651695 return systemCallRes ();
16661696}
0 commit comments