I'm trying to add a top level function which I can...
# compiler
s
I'm trying to add a top level function which I can then invoke from native using
-entry
I can see the function looks ok using dump, but I get an error saying it cannot be found. If I create the function manually, then it looks identical to my generated output. Is there something special that needs to be done for the native task to pick up the entry point ?
I create the function like this:
Copy code
val main = pluginContext.irFactory.buildFun {
               name = Name.identifier("mymain")
               returnType = pluginContext.irBuiltIns.unitType
               visibility = DescriptorVisibilities.PUBLIC
               modality = Modality.FINAL
            }.also { func: IrSimpleFunction ->
               func.body = DeclarationIrBuilder(pluginContext, func.symbol).irBlockBody {
                  val callPrintln = irCall(funPrintln)
                  callPrintln.putValueArgument(0, irString("Hello, World!"))
                  +callPrintln
               }
            }
I am adding the function to an arbitrary file, by using
Copy code
fragment.files.first().addChild(main)
inside
Copy code
visitModuleFragment
Dump from the generated function:
Copy code
FUN name:mymain visibility:public modality:FINAL <> () returnType:kotlin.Unit
  BLOCK_BODY
    CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in <http://kotlin.io|kotlin.io>' type=kotlin.Unit origin=null
      message: CONST String type=kotlin.String value="Hello, World!"
y
Maybe it needs a
IrDeclarationOrigin.DEFINED
?
s
like this?
Copy code
val main = pluginContext.irFactory.buildFun {
               name = Name.identifier("mymain")
               returnType = pluginContext.irBuiltIns.unitType
               visibility = DescriptorVisibilities.PUBLIC
               modality = Modality.FINAL
               origin = IrDeclarationOrigin.DEFINED
            }
(That didn't work)