All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.backend.asm2.AsmToAst2.kt Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.backend.asm2

import com.jtransc.ast.*
import com.jtransc.ast.optimize.optimize
import com.jtransc.backend.BaseAsmToAst
import com.jtransc.backend.asm1.disasm
import com.jtransc.backend.isStatic
import com.jtransc.ds.cast
import com.jtransc.ds.hasFlag
import com.jtransc.injector.Singleton
import com.jtransc.org.objectweb.asm.Label
import com.jtransc.org.objectweb.asm.Opcodes
import com.jtransc.org.objectweb.asm.tree.*
import java.util.*
import kotlin.collections.set

@Singleton
class AsmToAst2(types: AstTypes) : BaseAsmToAst(types) {
	override val expandFrames = true

	override fun genBody(classRef: AstType.REF, methodNode: MethodNode, types: AstTypes, source: String): AstBody {
		return AsmToAstMethodBody2(classRef, methodNode, types, source)
	}
}

data class PHIOption(val branch: AbstractInsnNode, val op: Operand)

class LocalBox(var local: Local)

interface Operand {
	val type: AstType
}

data class Local(override val type: AstType, val index: Int) : Operand {
	override fun toString(): String = "\$$index:$type"

	class Box(var local: Local)
}

fun Local.box() = Local.Box(this)

data class Constant(override val type: AstType, val v: Any?) : Operand {
	override fun toString(): String = "$v"
}

data class Param(override val type: AstType, val index: Int) : Operand {
	override fun toString(): String = "p$index"
}

data class This(val clazz: AstType.REF) : Operand {
	override val type = clazz
	override fun toString(): String = "this"
}

data class CatchException(override val type: AstType) : Operand {
	override fun toString(): String = "exception"
}

class Definition {
}

// http://compilers.cs.uni-saarland.de/papers/bbhlmz13cc.pdf
// Simple and Efficient Construction of Static Single Assignment Form
// ----------------------------------------------------------------
// PASS1: Build untyped Basic Blocks with simple constant clean ups
// PASS2: SSA-Form
// PASS3: Type locals
// PASS4: Construct AstStm + AstExpr
// ----------------------------------------------------------------
fun AsmToAstMethodBody2(clazz: AstType.REF, method: MethodNode, types: AstTypes, source: String = "unknown.java"): AstBody {
	//val body = BasicBlockBuilder(types)
	val methodType = types.demangleMethod(method.desc)
	val methodInstructions = method.instructions

	val referencedLabels = hashSetOf




© 2015 - 2024 Weber Informatics LLC | Privacy Policy