Annotation used
This commit is contained in:
committed by
alexander-gorshenev
parent
90b6a12a5c
commit
bd5b4b2f52
+4
@@ -43,6 +43,10 @@ internal class CodeGenerator(override val context: Context) : ContextUtils {
|
||||
|
||||
currentFunction!!.registerVariable(name, v)
|
||||
}
|
||||
|
||||
if (descriptor.usedAnnotation) {
|
||||
context.usedFunctions.add(fn!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
@@ -29,4 +29,6 @@ internal class Context(val irModule: IrModuleFragment, val runtime: Runtime, val
|
||||
val isInstanceFunction = importRtFunction("IsInstance")
|
||||
val checkInstanceFunction = importRtFunction("CheckInstance")
|
||||
val throwExceptionFunction = importRtFunction("ThrowException")
|
||||
|
||||
val usedFunctions = mutableListOf<LLVMValueRef>()
|
||||
}
|
||||
|
||||
+19
@@ -165,6 +165,9 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
override fun visitModuleFragment(module: IrModuleFragment) {
|
||||
logger.log("visitModule : ${ir2string(module)}")
|
||||
module.acceptChildrenVoid(this)
|
||||
|
||||
appendLlvmUsed(context.usedFunctions)
|
||||
|
||||
metadator.endModule(module)
|
||||
}
|
||||
|
||||
@@ -1436,4 +1439,20 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
})
|
||||
return skipBody
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
fun appendLlvmUsed(args: List<LLVMValueRef>) {
|
||||
if (args.isEmpty()) return
|
||||
|
||||
memScoped {
|
||||
val arrayLength = args.size
|
||||
val argsCasted = args.map{it -> constPointer(LLVMConstBitCast(it, int8TypePtr)) }
|
||||
val llvmUsedGlobal =
|
||||
context.staticData.placeGlobalArray("llvm.used", int8TypePtr, argsCasted)
|
||||
|
||||
LLVMSetLinkage(llvmUsedGlobal.llvmGlobal, LLVMLinkage.LLVMAppendingLinkage);
|
||||
LLVMSetSection(llvmUsedGlobal.llvmGlobal, "llvm.metadata");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
private val annotationName = FqName("kotlin.Used")
|
||||
|
||||
internal val FunctionDescriptor.usedAnnotation: Boolean
|
||||
get() {
|
||||
return (this.annotations.findAnnotation(annotationName) != null)
|
||||
}
|
||||
@@ -12,10 +12,16 @@
|
||||
extern int run_test();
|
||||
|
||||
void * resolve_symbol(char *name) {
|
||||
/* here we can add here some magic to resolve symbols in kotlin native*/
|
||||
return dlsym(RTLD_DEFAULT, name);
|
||||
/* here we can add here some magic to resolve symbols in kotlin native*/
|
||||
void* symbol = dlsym(RTLD_DEFAULT, name);
|
||||
|
||||
if (!symbol) {
|
||||
printf("Could not find kotlin symbol '%s': %s\n", name, dlerror());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
kotlinNativeMain() {
|
||||
@@ -28,20 +34,3 @@ kotlinNativeMain() {
|
||||
#endif
|
||||
}
|
||||
|
||||
int ktype_kotlin_any asm("_ktype:kotlin.Any");
|
||||
|
||||
#define DEFINE(name, symbol) int name() asm(#symbol);
|
||||
#define DECLARE(name) \
|
||||
int \
|
||||
name() { \
|
||||
abort(); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define DEFINE_AND_DECLARE(name, sym) \
|
||||
DEFINE(name, sym) \
|
||||
DECLARE(name)
|
||||
|
||||
DEFINE_AND_DECLARE(kfun_kotlin_any_to_string,_kfun:kotlin.Any.toString)
|
||||
DEFINE_AND_DECLARE(kfun_kotlin_any_hash_code,_kfun:kotlin.Any.hashCode)
|
||||
DEFINE_AND_DECLARE(kfun_kotlin_any_equals,_kfun:kotlin.Any.equals)
|
||||
|
||||
@@ -34,4 +34,10 @@ public annotation class Suppress(vararg val names: String)
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
//@Retention(SOURCE)
|
||||
//@MustBeDocumented
|
||||
public annotation class UnsafeVariance
|
||||
public annotation class UnsafeVariance
|
||||
|
||||
/**
|
||||
* Preserve the function entry point during global optimizations
|
||||
*/
|
||||
public annotation class Used
|
||||
|
||||
|
||||
Reference in New Issue
Block a user