From 8c08136c9a980ca446d9152b35c0fd9bef1d305e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 22 Jul 2016 19:27:23 +0300 Subject: [PATCH] Start developing WebAssembly model. Implement mostly all expressions --- .../org/teavm/wasm/model/WasmFunction.java | 101 ++++++++++++++++++ .../java/org/teavm/wasm/model/WasmLocal.java | 60 +++++++++++ .../java/org/teavm/wasm/model/WasmModule.java | 34 ++++++ .../java/org/teavm/wasm/model/WasmType.java | 23 ++++ .../wasm/model/expression/WasmAssignment.java | 49 +++++++++ .../wasm/model/expression/WasmBlock.java | 40 +++++++ .../wasm/model/expression/WasmBranch.java | 46 ++++++++ .../teavm/wasm/model/expression/WasmCall.java | 57 ++++++++++ .../model/expression/WasmConditional.java | 46 ++++++++ .../wasm/model/expression/WasmConversion.java | 71 ++++++++++++ .../teavm/wasm/model/expression/WasmDrop.java | 36 +++++++ .../wasm/model/expression/WasmExpression.java | 21 ++++ .../model/expression/WasmFloat32Constant.java | 32 ++++++ .../model/expression/WasmFloat64Constant.java | 32 ++++++ .../model/expression/WasmFloatBinary.java | 73 +++++++++++++ .../expression/WasmFloatBinaryOperation.java | 24 +++++ .../wasm/model/expression/WasmFloatType.java | 21 ++++ .../wasm/model/expression/WasmFloatUnary.java | 60 +++++++++++ .../expression/WasmFloatUnaryOperation.java | 35 ++++++ .../model/expression/WasmIndirectCall.java | 42 ++++++++ .../model/expression/WasmInt32Constant.java | 32 ++++++ .../model/expression/WasmInt32Subtype.java | 24 +++++ .../model/expression/WasmInt64Constant.java | 32 ++++++ .../model/expression/WasmInt64Subtype.java | 26 +++++ .../wasm/model/expression/WasmIntBinary.java | 73 +++++++++++++ .../expression/WasmIntBinaryOperation.java | 44 ++++++++ .../wasm/model/expression/WasmIntType.java | 21 ++++ .../wasm/model/expression/WasmIntUnary.java | 60 +++++++++++ .../expression/WasmIntUnaryOperation.java | 22 ++++ .../model/expression/WasmLoadFloat32.java | 46 ++++++++ .../model/expression/WasmLoadFloat64.java | 46 ++++++++ .../wasm/model/expression/WasmLoadInt32.java | 58 ++++++++++ .../wasm/model/expression/WasmLoadInt64.java | 58 ++++++++++ .../model/expression/WasmLocalReference.java | 37 +++++++ .../wasm/model/expression/WasmReturn.java | 36 +++++++ .../model/expression/WasmStoreFloat32.java | 58 ++++++++++ .../model/expression/WasmStoreFloat64.java | 58 ++++++++++ .../wasm/model/expression/WasmStoreInt32.java | 71 ++++++++++++ .../wasm/model/expression/WasmStoreInt64.java | 71 ++++++++++++ .../wasm/model/expression/WasmSwitch.java | 53 +++++++++ .../model/expression/WasmUnreachable.java | 23 ++++ 41 files changed, 1852 insertions(+) create mode 100644 core/src/main/java/org/teavm/wasm/model/WasmFunction.java create mode 100644 core/src/main/java/org/teavm/wasm/model/WasmLocal.java create mode 100644 core/src/main/java/org/teavm/wasm/model/WasmModule.java create mode 100644 core/src/main/java/org/teavm/wasm/model/WasmType.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmAssignment.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmBlock.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmBranch.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmCall.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmConditional.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmConversion.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmDrop.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmExpression.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloat32Constant.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloat64Constant.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinary.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinaryOperation.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloatType.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnary.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnaryOperation.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIndirectCall.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Constant.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Subtype.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Constant.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Subtype.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinary.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinaryOperation.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIntType.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnary.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnaryOperation.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat32.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat64.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt32.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt64.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmLocalReference.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmReturn.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat32.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat64.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt32.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt64.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmSwitch.java create mode 100644 core/src/main/java/org/teavm/wasm/model/expression/WasmUnreachable.java diff --git a/core/src/main/java/org/teavm/wasm/model/WasmFunction.java b/core/src/main/java/org/teavm/wasm/model/WasmFunction.java new file mode 100644 index 000000000..98de00e35 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/WasmFunction.java @@ -0,0 +1,101 @@ +/* + * Copyright 2016 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.wasm.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.teavm.wasm.model.expression.WasmExpression; + +public class WasmFunction { + WasmModule module; + private String name; + private boolean exported; + private String importName; + private String importModule; + private List parameters = new ArrayList<>(); + private WasmType result; + private List localVariables = new ArrayList<>(); + private List readonlyLocalVariables = Collections.unmodifiableList(localVariables); + private List body = new ArrayList<>(); + + public WasmFunction(String name) { + Objects.requireNonNull(name); + this.name = name; + } + + public WasmModule getModule() { + return module; + } + + public String getName() { + return name; + } + + public boolean isExported() { + return exported; + } + + public void setExported(boolean exported) { + this.exported = exported; + } + + public String getImportName() { + return importName; + } + + public void setImportName(String importName) { + this.importName = importName; + } + + public String getImportModule() { + return importModule; + } + + public void setImportModule(String importModule) { + this.importModule = importModule; + } + + public WasmType getResult() { + return result; + } + + public void setResult(WasmType result) { + this.result = result; + } + + public List getParameters() { + return parameters; + } + + public List getLocalVariables() { + return readonlyLocalVariables; + } + + public List getBody() { + return body; + } + + public void add(WasmLocal local) { + if (local.function != null) { + throw new IllegalArgumentException("This local is already registered in another function"); + } + local.function = this; + local.index = localVariables.size(); + localVariables.add(local); + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/WasmLocal.java b/core/src/main/java/org/teavm/wasm/model/WasmLocal.java new file mode 100644 index 000000000..2462eb481 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/WasmLocal.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 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.wasm.model; + +import java.util.Objects; + +public class WasmLocal { + WasmFunction function; + int index; + private String name; + private WasmType type; + + public WasmLocal(WasmType type, String name) { + Objects.requireNonNull(type); + this.type = type; + this.name = name; + } + + public WasmLocal(WasmType type) { + this(type, null); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public WasmType getType() { + return type; + } + + public void setType(WasmType type) { + Objects.requireNonNull(type); + this.type = type; + } + + public WasmFunction getFunction() { + return function; + } + + public int getIndex() { + return index; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/WasmModule.java b/core/src/main/java/org/teavm/wasm/model/WasmModule.java new file mode 100644 index 000000000..90eb52351 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/WasmModule.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016 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.wasm.model; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class WasmModule { + private Map functions = new LinkedHashMap<>(); + + public void add(WasmFunction function) { + if (functions.containsKey(function.getName())) { + throw new IllegalArgumentException("Function " + function.getName() + " already defined in this module"); + } + if (function.module != null) { + throw new IllegalArgumentException("Given function is already registered in another module"); + } + functions.put(function.getName(), function); + function.module = this; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/WasmType.java b/core/src/main/java/org/teavm/wasm/model/WasmType.java new file mode 100644 index 000000000..8902cd721 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/WasmType.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 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.wasm.model; + +public enum WasmType { + INT32, + INT64, + FLOAT32, + FLOAT64 +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmAssignment.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmAssignment.java new file mode 100644 index 000000000..b102623d6 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmAssignment.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; +import org.teavm.wasm.model.WasmLocal; + +public class WasmAssignment extends WasmExpression { + private WasmLocal local; + private WasmExpression value; + + public WasmAssignment(WasmLocal local, WasmExpression value) { + Objects.requireNonNull(local); + Objects.requireNonNull(value); + this.local = local; + this.value = value; + } + + public WasmLocal getLocal() { + return local; + } + + public void setLocal(WasmLocal local) { + Objects.requireNonNull(local); + this.local = local; + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + Objects.requireNonNull(value); + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmBlock.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmBlock.java new file mode 100644 index 000000000..2439017b7 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmBlock.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.ArrayList; +import java.util.List; + +public class WasmBlock extends WasmExpression { + private boolean loop; + private List body = new ArrayList<>(); + + public WasmBlock(boolean loop) { + this.loop = loop; + } + + public boolean isLoop() { + return loop; + } + + public void setLoop(boolean loop) { + this.loop = loop; + } + + public List getBody() { + return body; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmBranch.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmBranch.java new file mode 100644 index 000000000..598262477 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmBranch.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmBranch extends WasmExpression { + private WasmExpression condition; + private WasmBlock target; + + public WasmBranch(WasmExpression condition, WasmBlock target) { + this.condition = condition; + this.target = target; + } + + public WasmExpression getCondition() { + return condition; + } + + public void setCondition(WasmExpression condition) { + Objects.requireNonNull(condition); + this.condition = condition; + } + + public WasmBlock getTarget() { + return target; + } + + public void setTarget(WasmBlock target) { + Objects.requireNonNull(target); + this.target = target; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmCall.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmCall.java new file mode 100644 index 000000000..ce3213bae --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmCall.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class WasmCall extends WasmExpression { + private String functionName; + private boolean imported; + private List arguments = new ArrayList<>(); + + public WasmCall(String functionName, boolean imported) { + Objects.requireNonNull(functionName); + this.functionName = functionName; + this.imported = imported; + } + + public WasmCall(String functionName) { + this(functionName, false); + } + + public String getFunctionName() { + return functionName; + } + + public void setFunctionName(String functionName) { + Objects.requireNonNull(functionName); + this.functionName = functionName; + } + + public List getArguments() { + return arguments; + } + + public boolean isImported() { + return imported; + } + + public void setImported(boolean imported) { + this.imported = imported; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmConditional.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmConditional.java new file mode 100644 index 000000000..c53a08785 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmConditional.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmConditional extends WasmExpression { + private WasmExpression condition; + private WasmBlock thenBlock = new WasmBlock(false); + private WasmBlock elseBlock = new WasmBlock(false); + + public WasmConditional(WasmExpression condition) { + Objects.requireNonNull(condition); + this.condition = condition; + } + + public WasmExpression getCondition() { + return condition; + } + + public void setCondition(WasmExpression condition) { + Objects.requireNonNull(condition); + this.condition = condition; + } + + public WasmBlock getThenBlock() { + return thenBlock; + } + + public WasmBlock getElseBlock() { + return elseBlock; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmConversion.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmConversion.java new file mode 100644 index 000000000..11728ea45 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmConversion.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; +import org.teavm.wasm.model.WasmType; + +public class WasmConversion extends WasmExpression { + private WasmType sourceType; + private WasmType targetType; + private boolean signed; + private WasmExpression operand; + + public WasmConversion(WasmType sourceType, WasmType targetType, boolean signed, WasmExpression operand) { + Objects.requireNonNull(sourceType); + Objects.requireNonNull(targetType); + Objects.requireNonNull(operand); + this.sourceType = sourceType; + this.targetType = targetType; + this.signed = signed; + this.operand = operand; + } + + public WasmType getSourceType() { + return sourceType; + } + + public void setSourceType(WasmType sourceType) { + Objects.requireNonNull(sourceType); + this.sourceType = sourceType; + } + + public WasmType getTargetType() { + return targetType; + } + + public void setTargetType(WasmType targetType) { + Objects.requireNonNull(targetType); + this.targetType = targetType; + } + + public boolean isSigned() { + return signed; + } + + public void setSigned(boolean signed) { + this.signed = signed; + } + + public WasmExpression getOperand() { + return operand; + } + + public void setOperand(WasmExpression operand) { + Objects.requireNonNull(operand); + this.operand = operand; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmDrop.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmDrop.java new file mode 100644 index 000000000..2637e7d94 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmDrop.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmDrop extends WasmExpression { + private WasmExpression operand; + + public WasmDrop(WasmExpression operand) { + Objects.requireNonNull(operand); + this.operand = operand; + } + + public WasmExpression getOperand() { + return operand; + } + + public void setOperand(WasmExpression operand) { + Objects.requireNonNull(operand); + this.operand = operand; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmExpression.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmExpression.java new file mode 100644 index 000000000..b4de610f7 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmExpression.java @@ -0,0 +1,21 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public abstract class WasmExpression { + WasmExpression() { + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat32Constant.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat32Constant.java new file mode 100644 index 000000000..0bee8a487 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat32Constant.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmFloat32Constant extends WasmExpression { + private float value; + + public WasmFloat32Constant(float value) { + this.value = value; + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat64Constant.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat64Constant.java new file mode 100644 index 000000000..68c9e259c --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloat64Constant.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmFloat64Constant extends WasmExpression { + private double value; + + public WasmFloat64Constant(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinary.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinary.java new file mode 100644 index 000000000..2ae9e9f5f --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinary.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmFloatBinary extends WasmExpression { + private WasmFloatType type; + private WasmFloatBinaryOperation operation; + private WasmExpression first; + private WasmExpression second; + + public WasmFloatBinary(WasmFloatType type, WasmFloatBinaryOperation operation, WasmExpression first, + WasmExpression second) { + Objects.requireNonNull(type); + Objects.requireNonNull(operation); + Objects.requireNonNull(first); + Objects.requireNonNull(second); + this.type = type; + this.operation = operation; + this.first = first; + this.second = second; + } + + public WasmFloatType getType() { + return type; + } + + public void setType(WasmFloatType type) { + Objects.requireNonNull(type); + this.type = type; + } + + public WasmFloatBinaryOperation getOperation() { + return operation; + } + + public void setOperation(WasmFloatBinaryOperation operation) { + Objects.requireNonNull(operation); + this.operation = operation; + } + + public WasmExpression getFirst() { + return first; + } + + public void setFirst(WasmExpression first) { + Objects.requireNonNull(first); + this.first = first; + } + + public WasmExpression getSecond() { + return second; + } + + public void setSecond(WasmExpression second) { + Objects.requireNonNull(second); + this.second = second; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinaryOperation.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinaryOperation.java new file mode 100644 index 000000000..1566cbb71 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatBinaryOperation.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmFloatBinaryOperation { + ADD, + SUB, + MUL, + DIV, + +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatType.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatType.java new file mode 100644 index 000000000..3638acd17 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatType.java @@ -0,0 +1,21 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmFloatType { + FLOAT32, + FLOAT64 +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnary.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnary.java new file mode 100644 index 000000000..f6f7c34ae --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnary.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmFloatUnary extends WasmExpression { + private WasmFloatType type; + private WasmFloatUnaryOperation operation; + private WasmExpression operand; + + public WasmFloatUnary(WasmFloatType type, WasmFloatUnaryOperation operation, WasmExpression operand) { + Objects.requireNonNull(type); + Objects.requireNonNull(operation); + Objects.requireNonNull(operand); + this.type = type; + this.operation = operation; + this.operand = operand; + } + + public WasmFloatType getType() { + return type; + } + + public void setType(WasmFloatType type) { + Objects.requireNonNull(type); + this.type = type; + } + + public WasmFloatUnaryOperation getOperation() { + return operation; + } + + public void setOperation(WasmFloatUnaryOperation operation) { + Objects.requireNonNull(operation); + this.operation = operation; + } + + public WasmExpression getOperand() { + return operand; + } + + public void setOperand(WasmExpression operand) { + Objects.requireNonNull(operand); + this.operand = operand; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnaryOperation.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnaryOperation.java new file mode 100644 index 000000000..1c848f295 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmFloatUnaryOperation.java @@ -0,0 +1,35 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmFloatUnaryOperation { + ABS, + NEG, + COPYSIGN, + CEIL, + FLOOR, + TRUNC, + NEAREST, + MIN, + MAX, + SQRT, + EQ, + NE, + LT, + LE, + GT, + GE +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIndirectCall.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIndirectCall.java new file mode 100644 index 000000000..92661c7f2 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIndirectCall.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.List; +import java.util.Objects; + +public class WasmIndirectCall extends WasmExpression { + private WasmExpression selector; + private List arguments; + + public WasmIndirectCall(WasmExpression selector) { + Objects.requireNonNull(selector); + this.selector = selector; + } + + public WasmExpression getSelector() { + return selector; + } + + public void setSelector(WasmExpression selector) { + Objects.requireNonNull(selector); + this.selector = selector; + } + + public List getArguments() { + return arguments; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Constant.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Constant.java new file mode 100644 index 000000000..6a5324a53 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Constant.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmInt32Constant extends WasmExpression { + private int value; + + public WasmInt32Constant(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Subtype.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Subtype.java new file mode 100644 index 000000000..3954fcc93 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt32Subtype.java @@ -0,0 +1,24 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmInt32Subtype { + INT8, + UINT8, + INT16, + UINT16, + INT32 +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Constant.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Constant.java new file mode 100644 index 000000000..7c7825df1 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Constant.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmInt64Constant extends WasmExpression { + private long value; + + public WasmInt64Constant(long value) { + this.value = value; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Subtype.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Subtype.java new file mode 100644 index 000000000..ae42cf265 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmInt64Subtype.java @@ -0,0 +1,26 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmInt64Subtype { + INT8, + UINT8, + INT16, + UINT16, + INT32, + UINT32, + INT64 +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinary.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinary.java new file mode 100644 index 000000000..c45772e32 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinary.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmIntBinary extends WasmExpression { + private WasmIntType type; + private WasmIntBinaryOperation operation; + private WasmExpression first; + private WasmExpression second; + + public WasmIntBinary(WasmIntType type, WasmIntBinaryOperation operation, WasmExpression first, + WasmExpression second) { + Objects.requireNonNull(type); + Objects.requireNonNull(operation); + Objects.requireNonNull(first); + Objects.requireNonNull(second); + this.type = type; + this.operation = operation; + this.first = first; + this.second = second; + } + + public WasmIntType getType() { + return type; + } + + public void setType(WasmIntType type) { + Objects.requireNonNull(type); + this.type = type; + } + + public WasmIntBinaryOperation getOperation() { + return operation; + } + + public void setOperation(WasmIntBinaryOperation operation) { + Objects.requireNonNull(operation); + this.operation = operation; + } + + public WasmExpression getFirst() { + return first; + } + + public void setFirst(WasmExpression first) { + Objects.requireNonNull(first); + this.first = first; + } + + public WasmExpression getSecond() { + return second; + } + + public void setSecond(WasmExpression second) { + Objects.requireNonNull(second); + this.second = second; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinaryOperation.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinaryOperation.java new file mode 100644 index 000000000..340bd9fda --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntBinaryOperation.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmIntBinaryOperation { + ADD, + SUB, + MUL, + DIV_SIGNED, + DIV_UNSIGNED, + REM_SIGNED, + REM_UNSIGNED, + OR, + AND, + XOR, + SHL, + SHR_SIGNED, + SHR_UNSIGNED, + ROTL, + ROTR, + EQ, + NE, + LT_SIGNED, + LT_UNSIGNED, + LE_SIGNED, + LE_UNSIGNED, + GT_SIGNED, + GT_UNSIGNED, + GE_SIGNED, + GE_UNSIGNED +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIntType.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntType.java new file mode 100644 index 000000000..b36f6a475 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntType.java @@ -0,0 +1,21 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmIntType { + INT32, + INT64 +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnary.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnary.java new file mode 100644 index 000000000..c72631a90 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnary.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmIntUnary extends WasmExpression { + private WasmIntType type; + private WasmIntUnaryOperation operation; + private WasmExpression operand; + + public WasmIntUnary(WasmIntType type, WasmIntUnaryOperation operation, WasmExpression operand) { + Objects.requireNonNull(type); + Objects.requireNonNull(operation); + Objects.requireNonNull(operand); + this.type = type; + this.operation = operation; + this.operand = operand; + } + + public WasmIntType getType() { + return type; + } + + public void setType(WasmIntType type) { + Objects.requireNonNull(type); + this.type = type; + } + + public WasmIntUnaryOperation getOperation() { + return operation; + } + + public void setOperation(WasmIntUnaryOperation operation) { + Objects.requireNonNull(operation); + this.operation = operation; + } + + public WasmExpression getOperand() { + return operand; + } + + public void setOperand(WasmExpression operand) { + Objects.requireNonNull(operand); + this.operand = operand; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnaryOperation.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnaryOperation.java new file mode 100644 index 000000000..77a7d0666 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmIntUnaryOperation.java @@ -0,0 +1,22 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public enum WasmIntUnaryOperation { + CLZ, + CTZ, + POPCNT +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat32.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat32.java new file mode 100644 index 000000000..d3a84aec8 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat32.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmLoadFloat32 extends WasmExpression { + private int alignment; + private WasmExpression index; + + public WasmLoadFloat32(int alignment, WasmExpression index) { + Objects.requireNonNull(index); + this.alignment = alignment; + this.index = index; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat64.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat64.java new file mode 100644 index 000000000..dc997bc02 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadFloat64.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmLoadFloat64 extends WasmExpression { + private int alignment; + private WasmExpression index; + + public WasmLoadFloat64(int alignment, WasmExpression index) { + Objects.requireNonNull(index); + this.alignment = alignment; + this.index = index; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt32.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt32.java new file mode 100644 index 000000000..009f64c97 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt32.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmLoadInt32 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmInt32Subtype convertFrom; + + public WasmLoadInt32(int alignment, WasmExpression index, WasmInt32Subtype convertFrom) { + Objects.requireNonNull(index); + Objects.requireNonNull(convertFrom); + this.alignment = alignment; + this.index = index; + this.convertFrom = convertFrom; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmInt32Subtype getConvertFrom() { + return convertFrom; + } + + public void setConvertFrom(WasmInt32Subtype convertFrom) { + Objects.requireNonNull(convertFrom); + this.convertFrom = convertFrom; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt64.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt64.java new file mode 100644 index 000000000..12110ec66 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmLoadInt64.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmLoadInt64 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmInt64Subtype convertFrom; + + public WasmLoadInt64(int alignment, WasmExpression index, WasmInt64Subtype convertFrom) { + Objects.requireNonNull(index); + Objects.requireNonNull(convertFrom); + this.alignment = alignment; + this.index = index; + this.convertFrom = convertFrom; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmInt64Subtype getConvertFrom() { + return convertFrom; + } + + public void setConvertFrom(WasmInt64Subtype convertFrom) { + Objects.requireNonNull(convertFrom); + this.convertFrom = convertFrom; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmLocalReference.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmLocalReference.java new file mode 100644 index 000000000..1fbe730b7 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmLocalReference.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; +import org.teavm.wasm.model.WasmLocal; + +public class WasmLocalReference extends WasmExpression { + private WasmLocal local; + + public WasmLocalReference(WasmLocal local) { + Objects.requireNonNull(local); + this.local = local; + } + + public WasmLocal getLocal() { + return local; + } + + public void setLocal(WasmLocal local) { + Objects.requireNonNull(local); + this.local = local; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmReturn.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmReturn.java new file mode 100644 index 000000000..6bb92de7b --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmReturn.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmReturn extends WasmExpression { + private WasmExpression value; + + public WasmReturn(WasmExpression value) { + this.value = value; + } + + public WasmReturn() { + this(null); + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat32.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat32.java new file mode 100644 index 000000000..6f4c44636 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat32.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmStoreFloat32 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmExpression value; + + public WasmStoreFloat32(int alignment, WasmExpression index, WasmExpression value) { + Objects.requireNonNull(index); + Objects.requireNonNull(value); + this.alignment = alignment; + this.index = index; + this.value = value; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + Objects.requireNonNull(value); + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat64.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat64.java new file mode 100644 index 000000000..b35148bd7 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreFloat64.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmStoreFloat64 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmExpression value; + + public WasmStoreFloat64(int alignment, WasmExpression index, WasmExpression value) { + Objects.requireNonNull(index); + Objects.requireNonNull(value); + this.alignment = alignment; + this.index = index; + this.value = value; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + Objects.requireNonNull(value); + this.value = value; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt32.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt32.java new file mode 100644 index 000000000..add05ea36 --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt32.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmStoreInt32 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmExpression value; + private WasmInt32Subtype convertTo; + + public WasmStoreInt32(int alignment, WasmExpression index, WasmExpression value, + WasmInt32Subtype convertTo) { + Objects.requireNonNull(index); + Objects.requireNonNull(convertTo); + Objects.requireNonNull(value); + this.alignment = alignment; + this.index = index; + this.value = value; + this.convertTo = convertTo; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + Objects.requireNonNull(value); + this.value = value; + } + + public WasmInt32Subtype getConvertTo() { + return convertTo; + } + + public void setConvertTo(WasmInt32Subtype convertTo) { + Objects.requireNonNull(convertTo); + this.convertTo = convertTo; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt64.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt64.java new file mode 100644 index 000000000..dabf201fd --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmStoreInt64.java @@ -0,0 +1,71 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.Objects; + +public class WasmStoreInt64 extends WasmExpression { + private int alignment; + private WasmExpression index; + private WasmExpression value; + private WasmInt64Subtype convertTo; + + public WasmStoreInt64(int alignment, WasmExpression index, WasmExpression value, + WasmInt64Subtype convertTo) { + Objects.requireNonNull(index); + Objects.requireNonNull(convertTo); + Objects.requireNonNull(value); + this.alignment = alignment; + this.index = index; + this.value = value; + this.convertTo = convertTo; + } + + public int getAlignment() { + return alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public WasmExpression getIndex() { + return index; + } + + public void setIndex(WasmExpression index) { + Objects.requireNonNull(index); + this.index = index; + } + + public WasmExpression getValue() { + return value; + } + + public void setValue(WasmExpression value) { + Objects.requireNonNull(value); + this.value = value; + } + + public WasmInt64Subtype getConvertTo() { + return convertTo; + } + + public void setConvertTo(WasmInt64Subtype convertTo) { + Objects.requireNonNull(convertTo); + this.convertTo = convertTo; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmSwitch.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmSwitch.java new file mode 100644 index 000000000..9ea88e44e --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmSwitch.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class WasmSwitch extends WasmExpression { + private WasmExpression selector; + private List targets = new ArrayList<>(); + private WasmBlock defaultTarget; + + public WasmSwitch(WasmExpression selector, WasmBlock defaultTarget) { + this.selector = selector; + this.defaultTarget = defaultTarget; + } + + public WasmExpression getSelector() { + return selector; + } + + public void setSelector(WasmExpression selector) { + Objects.requireNonNull(selector); + this.selector = selector; + } + + public WasmBlock getDefaultTarget() { + return defaultTarget; + } + + public void setDefaultTarget(WasmBlock defaultTarget) { + Objects.requireNonNull(defaultTarget); + this.defaultTarget = defaultTarget; + } + + public List getTargets() { + return targets; + } +} diff --git a/core/src/main/java/org/teavm/wasm/model/expression/WasmUnreachable.java b/core/src/main/java/org/teavm/wasm/model/expression/WasmUnreachable.java new file mode 100644 index 000000000..e308c141a --- /dev/null +++ b/core/src/main/java/org/teavm/wasm/model/expression/WasmUnreachable.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 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.wasm.model.expression; + +public class WasmUnreachable extends WasmExpression { + public static final WasmUnreachable INSTANCE = new WasmUnreachable(); + + private WasmUnreachable() { + } +}