@@ -229,9 +229,18 @@ namespace mlir::rlc
229229 mlir::TypeRange types,
230230 llvm::ArrayRef<llvm::StringRef> args,
231231 mlir::Type returnType,
232- mlir::rlc::StreamWriter& writer)
232+ mlir::rlc::StreamWriter& writer,
233+ bool isMac,
234+ bool isWindows)
233235 {
234- writer.writenl (" [DllImport(\" Lib.so\" )]" );
236+ writer.write (" [DllImport(\" Lib." );
237+ if (isMac)
238+ writer.write (" dylib" );
239+ else if (isWindows)
240+ writer.write (" dll" );
241+ else
242+ writer.write (" so" );
243+ writer.writenl (" \" )]" );
235244 writer.write (" public static extern void " , mangledName);
236245 writeFunctionArgs (types, args, returnType, writer, true );
237246 writer.writenl (" ;" );
@@ -405,7 +414,15 @@ namespace mlir::rlc
405414 */
406415 class CSharpFunctionDeclarationMatcher
407416 {
417+ private:
418+ bool isMac;
419+ bool isWindows;
420+
408421 public:
422+ CSharpFunctionDeclarationMatcher (bool isMac, bool isWindows)
423+ : isMac(isMac), isWindows(isWindows)
424+ {
425+ }
409426 void apply (mlir::rlc::FunctionOp op, mlir::rlc::StreamWriter& writer)
410427 {
411428 auto _ = writer.indent ();
@@ -416,26 +433,33 @@ namespace mlir::rlc
416433 op.getFunctionType ().getInputs (),
417434 op.getInfo ().getArgNames (),
418435 getResultType (op.getFunctionType ()),
419- writer);
436+ writer,
437+ isMac,
438+ isWindows);
420439
421440 if (not op.getPrecondition ().empty ())
422441 declareFunction (
423442 op.getCanFunctionMangledName (),
424443 op.getFunctionType ().getInputs (),
425444 op.getInfo ().getArgNames (),
426445 mlir::rlc::BoolType::get (op.getContext ()),
427- writer);
446+ writer,
447+ isMac,
448+ isWindows);
428449 }
429450 };
430451
431452 class CSharpActionDeclarationMatcher
432453 {
433454 private:
434455 mlir::rlc::ModuleBuilder& builder;
456+ bool isMac;
457+ bool isWindows;
435458
436459 public:
437- CSharpActionDeclarationMatcher (mlir::rlc::ModuleBuilder& builder)
438- : builder(builder)
460+ CSharpActionDeclarationMatcher (
461+ mlir::rlc::ModuleBuilder& builder, bool isMac, bool isWindows)
462+ : builder(builder), isMac(isMac), isWindows(isWindows)
439463 {
440464 }
441465 void apply (mlir::rlc::ActionFunction op, mlir::rlc::StreamWriter& writer)
@@ -449,15 +473,19 @@ namespace mlir::rlc
449473 op.getFunctionType ().getInputs (),
450474 op.getArgNames (),
451475 getResultType (op.getFunctionType ()),
452- writer);
476+ writer,
477+ isMac,
478+ isWindows);
453479 if (not op.getPrecondition ().empty ())
454480 {
455481 declareFunction (
456482 op.getCanFunctionMangledName (),
457483 op.getFunctionType ().getInputs (),
458484 op.getArgNames (),
459485 mlir::rlc::BoolType::get (op.getContext ()),
460- writer);
486+ writer,
487+ isMac,
488+ isWindows);
461489 }
462490
463491 for (auto value : op.getActions ())
@@ -474,7 +502,13 @@ namespace mlir::rlc
474502 auto mangled = mangledName (actionStatement.getName (), true , fType );
475503
476504 declareFunction (
477- mangled, fType .getInputs (), argNames, getResultType (fType ), writer);
505+ mangled,
506+ fType .getInputs (),
507+ argNames,
508+ getResultType (fType ),
509+ writer,
510+ isMac,
511+ isWindows);
478512
479513 auto canDoType = mlir::FunctionType::get (
480514 fType .getContext (),
@@ -487,7 +521,9 @@ namespace mlir::rlc
487521 canDoType.getInputs (),
488522 argNames,
489523 getResultType (canDoType),
490- writer);
524+ writer,
525+ isMac,
526+ isWindows);
491527 }
492528
493529 auto canFType = mlir::FunctionType::get (
@@ -500,7 +536,9 @@ namespace mlir::rlc
500536 canFType.getInputs (),
501537 { " self" },
502538 getResultType (canFType),
503- writer);
539+ writer,
540+ isMac,
541+ isWindows);
504542 }
505543 };
506544
@@ -989,8 +1027,8 @@ namespace mlir::rlc
9891027 registerTypeConversion (matcher.getWriter ().getTypeSerializer ());
9901028 registerTypeConversionRaw (matcher.getWriter ().getTypeSerializer (1 ));
9911029 matcher.getWriter ().writenl (" unsafe class RLCNative {" );
992- matcher.add <CSharpFunctionDeclarationMatcher>();
993- matcher.add <CSharpActionDeclarationMatcher>(builder);
1030+ matcher.add <CSharpFunctionDeclarationMatcher>(isMac, isWindows );
1031+ matcher.add <CSharpActionDeclarationMatcher>(builder, isMac, isWindows );
9941032 matcher.apply (getOperation ());
9951033 matcher.getWriter ().writenl (" }" ).endLine ();
9961034
0 commit comments