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

org.jetbrains.kotlin.wasm.ir.WasmIrExpressionBuilder.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.wasm.ir

class WasmIrExpressionBuilder(
    val expression: MutableList
) : WasmExpressionBuilder() {

    override fun buildInstr(op: WasmOp, vararg immediates: WasmImmediate) {
        val nextInstr = WasmInstr(op, immediates.toList())
        val foldedInstrs = foldWasmInstructions(expression.lastOrNull(), nextInstr)

        if (foldedInstrs == null) {
            expression += nextInstr
        } else {
            expression.removeLastOrNull()
            expression += foldedInstrs
        }
    }

    override var numberOfNestedBlocks: Int = 0
        set(value) {
            assert(value >= 0) { "end without matching block" }
            field = value
        }
}

inline fun buildWasmExpression(body: WasmExpressionBuilder.() -> Unit): MutableList {
    val res = mutableListOf()
    WasmIrExpressionBuilder(res).body()
    return res
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy