package com.jaytux.simd.data

import org.jetbrains.exposed.dao.id.UUIDTable
import org.jetbrains.exposed.dao.id.CompositeIdTable

object Techs : UUIDTable() {
    val name = varchar("name", 255).uniqueIndex()
}

object CppTypes : UUIDTable() {
    val name = varchar("name", 255).uniqueIndex()
}

object Categories : UUIDTable() {
    val name = varchar("name", 255).uniqueIndex()
}

object CPUIDs : UUIDTable() {
    val name = varchar("name", 255).uniqueIndex()
}

object Intrinsics : UUIDTable() {
    val mnemonic = varchar("mnemonic", 255)
    val returnType = reference("return_type", CppTypes)
    val returnVar = varchar("return_var", 255).nullable()
    val description = text("description")
    val operations = text("operations").nullable()
    val category = reference("category", Categories)
    val cpuid = reference("cpuid", CPUIDs).nullable()
    val tech = reference("tech", Techs)
}

object IntrinsicArguments : UUIDTable() {
    val intrinsic = reference("intrinsic", Intrinsics)
    val name = varchar("name", 255)
    val type = reference("type", CppTypes)
    val index = integer("index")

    init {
        uniqueIndex(intrinsic, name)
        uniqueIndex(intrinsic, index)
    }
}

object IntrinsicInstructions : UUIDTable() {
    val intrinsic = reference("intrinsic", Intrinsics)
    val mnemonic = varchar("mnemonic", 255)
    val xed = varchar("xed", 255)
    val form = text("form").nullable()
}

object Platforms : UUIDTable() {
    val name = varchar("name", 255).uniqueIndex()
}

object Performances : CompositeIdTable() {
    val instruction = reference("instruction", IntrinsicInstructions)
    val platform = reference("platform", Platforms)
    val latency = float("latency").nullable()
    val throughput = float("throughput").nullable()

    override val primaryKey: PrimaryKey = PrimaryKey(instruction, platform)
}