Skip to content

Commit

Permalink
wasm: move common part of wasm expression generator in order to later…
Browse files Browse the repository at this point in the history
… reuse it with Wasm GC BE
  • Loading branch information
konsoletyper committed Jul 9, 2024
1 parent 7efb3c9 commit b096977
Show file tree
Hide file tree
Showing 11 changed files with 4,140 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

import org.teavm.backend.wasm.model.expression.WasmExpression;

abstract class CachedExpression {
abstract WasmExpression expr();
public abstract class CachedExpression {
public abstract WasmExpression expr();

void release() {
public void release() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.teavm.backend.wasm.model.expression.WasmSetLocal;
import org.teavm.model.TextLocation;

class ExpressionCache {
public class ExpressionCache {
private TemporaryVariablePool tmpVars;

ExpressionCache(TemporaryVariablePool tmpVars) {
public ExpressionCache(TemporaryVariablePool tmpVars) {
this.tmpVars = tmpVars;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import org.teavm.backend.wasm.model.WasmLocal;
import org.teavm.backend.wasm.model.WasmType;

class TemporaryVariablePool {
public class TemporaryVariablePool {
private WasmFunction function;
private Map<WasmType, Deque<WasmLocal>> temporaryVariablesByType = new HashMap<>();

TemporaryVariablePool(WasmFunction function) {
public TemporaryVariablePool(WasmFunction function) {
this.function = function;
}

WasmLocal acquire(WasmType type) {
public WasmLocal acquire(WasmType type) {
var stack = temporaryVariablesByType.computeIfAbsent(type, k -> new ArrayDeque<>());
WasmLocal variable = stack.pollFirst();
if (variable == null) {
Expand All @@ -41,7 +41,7 @@ WasmLocal acquire(WasmType type) {
return variable;
}

void release(WasmLocal variable) {
public void release(WasmLocal variable) {
var stack = temporaryVariablesByType.get(variable.getType());
stack.push(variable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Alexey Andreev.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.backend.wasm.generate.common.methods;

import java.util.List;
import org.teavm.backend.wasm.WasmFunctionRepository;
import org.teavm.backend.wasm.WasmFunctionTypes;
import org.teavm.backend.wasm.model.WasmTag;
import org.teavm.model.ClassReaderSource;
import org.teavm.model.ValueType;
import org.teavm.model.lowlevel.CallSiteDescriptor;
import org.teavm.model.lowlevel.Characteristics;

public interface BaseWasmGenerationContext {
Characteristics characteristics();

WasmFunctionRepository functions();

WasmFunctionTypes functionTypes();

BaseWasmTypeMapper typeMapper();

WasmTag getExceptionTag();

ClassReaderSource classSource();

List<CallSiteDescriptor> callSites();
}
Loading

0 comments on commit b096977

Please sign in to comment.