mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
WASM: add support of offset field in memory operations
This commit is contained in:
parent
25c9b03dff
commit
8a012178ed
|
@ -96,6 +96,7 @@ import org.teavm.backend.wasm.model.expression.WasmLoadFloat32;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmLoadFloat64;
|
import org.teavm.backend.wasm.model.expression.WasmLoadFloat64;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmLoadInt32;
|
import org.teavm.backend.wasm.model.expression.WasmLoadInt32;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmLoadInt64;
|
import org.teavm.backend.wasm.model.expression.WasmLoadInt64;
|
||||||
|
import org.teavm.backend.wasm.model.expression.WasmMemoryAccess;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmReturn;
|
import org.teavm.backend.wasm.model.expression.WasmReturn;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmSetLocal;
|
import org.teavm.backend.wasm.model.expression.WasmSetLocal;
|
||||||
import org.teavm.backend.wasm.model.expression.WasmStoreFloat32;
|
import org.teavm.backend.wasm.model.expression.WasmStoreFloat32;
|
||||||
|
@ -472,34 +473,41 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
WasmExpression address = getAddress(qualified, field, location);
|
WasmExpression address = getAddress(qualified, field, location);
|
||||||
ValueType type = context.getFieldType(field);
|
ValueType type = context.getFieldType(field);
|
||||||
accept(value);
|
accept(value);
|
||||||
|
|
||||||
|
WasmMemoryAccess resultExpr;
|
||||||
if (type instanceof ValueType.Primitive) {
|
if (type instanceof ValueType.Primitive) {
|
||||||
switch (((ValueType.Primitive) type).getKind()) {
|
switch (((ValueType.Primitive) type).getKind()) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
case BYTE:
|
case BYTE:
|
||||||
result = new WasmStoreInt32(1, address, result, WasmInt32Subtype.INT8);
|
resultExpr = new WasmStoreInt32(1, address, result, WasmInt32Subtype.INT8);
|
||||||
break;
|
break;
|
||||||
case SHORT:
|
case SHORT:
|
||||||
result = new WasmStoreInt32(2, address, result, WasmInt32Subtype.INT16);
|
resultExpr = new WasmStoreInt32(2, address, result, WasmInt32Subtype.INT16);
|
||||||
break;
|
break;
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
result = new WasmStoreInt32(2, address, result, WasmInt32Subtype.UINT16);
|
resultExpr = new WasmStoreInt32(2, address, result, WasmInt32Subtype.UINT16);
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
result = new WasmStoreInt32(4, address, result, WasmInt32Subtype.INT32);
|
resultExpr = new WasmStoreInt32(4, address, result, WasmInt32Subtype.INT32);
|
||||||
break;
|
break;
|
||||||
case LONG:
|
case LONG:
|
||||||
result = new WasmStoreInt64(8, address, result, WasmInt64Subtype.INT64);
|
resultExpr = new WasmStoreInt64(8, address, result, WasmInt64Subtype.INT64);
|
||||||
break;
|
break;
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
result = new WasmStoreFloat32(4, address, result);
|
resultExpr = new WasmStoreFloat32(4, address, result);
|
||||||
break;
|
break;
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
result = new WasmStoreFloat64(8, address, result);
|
resultExpr = new WasmStoreFloat64(8, address, result);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError(type.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = new WasmStoreInt32(4, address, result, WasmInt32Subtype.INT32);
|
resultExpr = new WasmStoreInt32(4, address, result, WasmInt32Subtype.INT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultExpr.setOffset(getOffset(qualified, field));
|
||||||
|
result = (WasmExpression) resultExpr;
|
||||||
result.setLocation(location);
|
result.setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -948,12 +956,18 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
slotExpr.acceptVisitor(this);
|
slotExpr.acceptVisitor(this);
|
||||||
WasmExpression slotOffset = getSlotOffset(result);
|
WasmExpression slotOffset = getSlotOffset(result);
|
||||||
WasmExpression address = new WasmGetLocal(stackVariable);
|
WasmExpression address = new WasmGetLocal(stackVariable);
|
||||||
|
if (!(slotOffset instanceof WasmInt32Constant)) {
|
||||||
address = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, address, slotOffset);
|
address = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, address, slotOffset);
|
||||||
|
}
|
||||||
|
|
||||||
gcRootExpr.acceptVisitor(this);
|
gcRootExpr.acceptVisitor(this);
|
||||||
WasmExpression gcRoot = result;
|
WasmExpression gcRoot = result;
|
||||||
|
|
||||||
result = new WasmStoreInt32(4, address, gcRoot, WasmInt32Subtype.INT32);
|
WasmStoreInt32 store = new WasmStoreInt32(4, address, gcRoot, WasmInt32Subtype.INT32);
|
||||||
|
if (slotOffset instanceof WasmInt32Constant) {
|
||||||
|
store.setOffset(((WasmInt32Constant) slotOffset).getValue());
|
||||||
|
}
|
||||||
|
result = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRemoveGcRoot(Expr slotExpr) {
|
private void generateRemoveGcRoot(Expr slotExpr) {
|
||||||
|
@ -965,9 +979,15 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
slotExpr.acceptVisitor(this);
|
slotExpr.acceptVisitor(this);
|
||||||
WasmExpression slotOffset = getSlotOffset(result);
|
WasmExpression slotOffset = getSlotOffset(result);
|
||||||
WasmExpression address = new WasmGetLocal(stackVariable);
|
WasmExpression address = new WasmGetLocal(stackVariable);
|
||||||
|
if (!(slotOffset instanceof WasmInt32Constant)) {
|
||||||
address = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, address, slotOffset);
|
address = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD, address, slotOffset);
|
||||||
|
}
|
||||||
|
|
||||||
result = new WasmStoreInt32(4, address, new WasmInt32Constant(0), WasmInt32Subtype.INT32);
|
WasmStoreInt32 store = new WasmStoreInt32(4, address, new WasmInt32Constant(0), WasmInt32Subtype.INT32);
|
||||||
|
if (slotOffset instanceof WasmInt32Constant) {
|
||||||
|
store.setOffset(((WasmInt32Constant) slotOffset).getValue());
|
||||||
|
}
|
||||||
|
result = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmExpression getSlotOffset(WasmExpression slot) {
|
private WasmExpression getSlotOffset(WasmExpression slot) {
|
||||||
|
@ -1008,56 +1028,59 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
WasmExpression address = getAddress(expr.getQualified(), expr.getField(), expr.getLocation());
|
WasmExpression address = getAddress(expr.getQualified(), expr.getField(), expr.getLocation());
|
||||||
|
|
||||||
ValueType type = context.getFieldType(expr.getField());
|
ValueType type = context.getFieldType(expr.getField());
|
||||||
|
WasmMemoryAccess resultExpr;
|
||||||
if (type instanceof ValueType.Primitive) {
|
if (type instanceof ValueType.Primitive) {
|
||||||
switch (((ValueType.Primitive) type).getKind()) {
|
switch (((ValueType.Primitive) type).getKind()) {
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
case BYTE:
|
case BYTE:
|
||||||
result = new WasmLoadInt32(1, address, WasmInt32Subtype.INT8);
|
resultExpr = new WasmLoadInt32(1, address, WasmInt32Subtype.INT8);
|
||||||
break;
|
break;
|
||||||
case SHORT:
|
case SHORT:
|
||||||
result = new WasmLoadInt32(2, address, WasmInt32Subtype.INT16);
|
resultExpr = new WasmLoadInt32(2, address, WasmInt32Subtype.INT16);
|
||||||
break;
|
break;
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
result = new WasmLoadInt32(2, address, WasmInt32Subtype.UINT16);
|
resultExpr = new WasmLoadInt32(2, address, WasmInt32Subtype.UINT16);
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
result = new WasmLoadInt32(4, address, WasmInt32Subtype.INT32);
|
resultExpr = new WasmLoadInt32(4, address, WasmInt32Subtype.INT32);
|
||||||
break;
|
break;
|
||||||
case LONG:
|
case LONG:
|
||||||
result = new WasmLoadInt64(8, address, WasmInt64Subtype.INT64);
|
resultExpr = new WasmLoadInt64(8, address, WasmInt64Subtype.INT64);
|
||||||
break;
|
break;
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
result = new WasmLoadFloat32(4, address);
|
resultExpr = new WasmLoadFloat32(4, address);
|
||||||
break;
|
break;
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
result = new WasmLoadFloat64(8, address);
|
resultExpr = new WasmLoadFloat64(8, address);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError(type.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = new WasmLoadInt32(4, address, WasmInt32Subtype.INT32);
|
resultExpr = new WasmLoadInt32(4, address, WasmInt32Subtype.INT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultExpr.setOffset(getOffset(expr.getQualified(), expr.getField()));
|
||||||
|
result = (WasmExpression) resultExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmExpression getAddress(Expr qualified, FieldReference field, TextLocation location) {
|
private WasmExpression getAddress(Expr qualified, FieldReference field, TextLocation location) {
|
||||||
int offset = classGenerator.getFieldOffset(field);
|
|
||||||
if (qualified == null) {
|
if (qualified == null) {
|
||||||
|
int offset = classGenerator.getFieldOffset(field);
|
||||||
WasmExpression result = new WasmInt32Constant(offset);
|
WasmExpression result = new WasmInt32Constant(offset);
|
||||||
result.setLocation(location);
|
result.setLocation(location);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
accept(qualified);
|
accept(qualified);
|
||||||
if (offset != 0) {
|
|
||||||
WasmExpression offsetExpr = new WasmInt32Constant(offset);
|
|
||||||
offsetExpr.setLocation(qualified.getLocation());
|
|
||||||
|
|
||||||
WasmExpression address = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.ADD,
|
|
||||||
result, offsetExpr);
|
|
||||||
address.setLocation(location);
|
|
||||||
return address;
|
|
||||||
} else {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getOffset(Expr qualified, FieldReference field) {
|
||||||
|
if (qualified == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return classGenerator.getFieldOffset(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Objects;
|
||||||
public class WasmLoadFloat32 extends WasmExpression implements WasmMemoryAccess {
|
public class WasmLoadFloat32 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmLoadFloat32(int alignment, WasmExpression index) {
|
public WasmLoadFloat32(int alignment, WasmExpression index) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -35,6 +36,16 @@ public class WasmLoadFloat32 extends WasmExpression implements WasmMemoryAccess
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Objects;
|
||||||
public class WasmLoadFloat64 extends WasmExpression implements WasmMemoryAccess {
|
public class WasmLoadFloat64 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmLoadFloat64(int alignment, WasmExpression index) {
|
public WasmLoadFloat64(int alignment, WasmExpression index) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -35,6 +36,16 @@ public class WasmLoadFloat64 extends WasmExpression implements WasmMemoryAccess
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class WasmLoadInt32 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmInt32Subtype convertFrom;
|
private WasmInt32Subtype convertFrom;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmLoadInt32(int alignment, WasmExpression index, WasmInt32Subtype convertFrom) {
|
public WasmLoadInt32(int alignment, WasmExpression index, WasmInt32Subtype convertFrom) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -38,6 +39,16 @@ public class WasmLoadInt32 extends WasmExpression implements WasmMemoryAccess {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class WasmLoadInt64 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmInt64Subtype convertFrom;
|
private WasmInt64Subtype convertFrom;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmLoadInt64(int alignment, WasmExpression index, WasmInt64Subtype convertFrom) {
|
public WasmLoadInt64(int alignment, WasmExpression index, WasmInt64Subtype convertFrom) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -38,6 +39,16 @@ public class WasmLoadInt64 extends WasmExpression implements WasmMemoryAccess {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -19,4 +19,8 @@ public interface WasmMemoryAccess {
|
||||||
WasmExpression getIndex();
|
WasmExpression getIndex();
|
||||||
|
|
||||||
void setIndex(WasmExpression index);
|
void setIndex(WasmExpression index);
|
||||||
|
|
||||||
|
int getOffset();
|
||||||
|
|
||||||
|
void setOffset(int offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class WasmStoreFloat32 extends WasmExpression implements WasmMemoryAccess
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmExpression value;
|
private WasmExpression value;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmStoreFloat32(int alignment, WasmExpression index, WasmExpression value) {
|
public WasmStoreFloat32(int alignment, WasmExpression index, WasmExpression value) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -38,6 +39,16 @@ public class WasmStoreFloat32 extends WasmExpression implements WasmMemoryAccess
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class WasmStoreFloat64 extends WasmExpression implements WasmMemoryAccess
|
||||||
private int alignment;
|
private int alignment;
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmExpression value;
|
private WasmExpression value;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmStoreFloat64(int alignment, WasmExpression index, WasmExpression value) {
|
public WasmStoreFloat64(int alignment, WasmExpression index, WasmExpression value) {
|
||||||
Objects.requireNonNull(index);
|
Objects.requireNonNull(index);
|
||||||
|
@ -38,6 +39,16 @@ public class WasmStoreFloat64 extends WasmExpression implements WasmMemoryAccess
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class WasmStoreInt32 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmExpression value;
|
private WasmExpression value;
|
||||||
private WasmInt32Subtype convertTo;
|
private WasmInt32Subtype convertTo;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmStoreInt32(int alignment, WasmExpression index, WasmExpression value,
|
public WasmStoreInt32(int alignment, WasmExpression index, WasmExpression value,
|
||||||
WasmInt32Subtype convertTo) {
|
WasmInt32Subtype convertTo) {
|
||||||
|
@ -42,6 +43,16 @@ public class WasmStoreInt32 extends WasmExpression implements WasmMemoryAccess {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class WasmStoreInt64 extends WasmExpression implements WasmMemoryAccess {
|
||||||
private WasmExpression index;
|
private WasmExpression index;
|
||||||
private WasmExpression value;
|
private WasmExpression value;
|
||||||
private WasmInt64Subtype convertTo;
|
private WasmInt64Subtype convertTo;
|
||||||
|
private int offset;
|
||||||
|
|
||||||
public WasmStoreInt64(int alignment, WasmExpression index, WasmExpression value,
|
public WasmStoreInt64(int alignment, WasmExpression index, WasmExpression value,
|
||||||
WasmInt64Subtype convertTo) {
|
WasmInt64Subtype convertTo) {
|
||||||
|
@ -42,6 +43,16 @@ public class WasmStoreInt64 extends WasmExpression implements WasmMemoryAccess {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOffset(int offset) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WasmExpression getIndex() {
|
public WasmExpression getIndex() {
|
||||||
return index;
|
return index;
|
||||||
|
|
|
@ -669,7 +669,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -699,7 +699,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -707,7 +707,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
expression.getIndex().acceptVisitor(this);
|
expression.getIndex().acceptVisitor(this);
|
||||||
writer.writeByte(0x2C);
|
writer.writeByte(0x2C);
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -715,7 +715,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
expression.getIndex().acceptVisitor(this);
|
expression.getIndex().acceptVisitor(this);
|
||||||
writer.writeByte(0x2D);
|
writer.writeByte(0x2D);
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -736,7 +736,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -761,7 +761,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -770,7 +770,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
expression.getValue().acceptVisitor(this);
|
expression.getValue().acceptVisitor(this);
|
||||||
writer.writeByte(0x35);
|
writer.writeByte(0x35);
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -779,7 +779,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||||
expression.getValue().acceptVisitor(this);
|
expression.getValue().acceptVisitor(this);
|
||||||
writer.writeByte(0x36);
|
writer.writeByte(0x36);
|
||||||
writer.writeByte(alignment(expression.getAlignment()));
|
writer.writeByte(alignment(expression.getAlignment()));
|
||||||
writer.writeByte(0);
|
writer.writeLEB(expression.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int alignment(int value) {
|
private int alignment(int value) {
|
||||||
|
|
|
@ -777,21 +777,22 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
|
String base = "&wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]";
|
||||||
switch (expression.getConvertFrom()) {
|
switch (expression.getConvertFrom()) {
|
||||||
case INT8:
|
case INT8:
|
||||||
result.setText("(int32_t) (int8_t) wasm_heap[" + index.getText() + "]");
|
result.setText("(int32_t) (int8_t) " + base.substring(1));
|
||||||
break;
|
break;
|
||||||
case UINT8:
|
case UINT8:
|
||||||
result.setText("(int32_t) (uint8_t) wasm_heap[" + index.getText() + "]");
|
result.setText("(int32_t) (uint8_t) " + base.substring(1));
|
||||||
break;
|
break;
|
||||||
case INT16:
|
case INT16:
|
||||||
result.setText("(int32_t) *((int16_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int32_t) *((int16_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
result.setText("(int32_t) *((uint16_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int32_t) *((uint16_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case INT32:
|
case INT32:
|
||||||
result.setText("*((int32_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("*((int32_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -812,27 +813,28 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
|
String base = "&wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]";
|
||||||
switch (expression.getConvertFrom()) {
|
switch (expression.getConvertFrom()) {
|
||||||
case INT8:
|
case INT8:
|
||||||
result.setText("(int64_t) (int8_t) wasm_heap[" + index.getText() + "]");
|
result.setText("(int64_t) (int8_t) " + base.substring(1));
|
||||||
break;
|
break;
|
||||||
case UINT8:
|
case UINT8:
|
||||||
result.setText("(int64_t) (uint8_t) wasm_heap[" + index.getText() + "]");
|
result.setText("(int64_t) (uint8_t) " + base.substring(1));
|
||||||
break;
|
break;
|
||||||
case INT16:
|
case INT16:
|
||||||
result.setText("(int64_t) *((int16_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int64_t) *((int16_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
result.setText("(int64_t) *((uint16_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int64_t) *((uint16_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case INT32:
|
case INT32:
|
||||||
result.setText("(int64_t) *((int32_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int64_t) *((int32_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case UINT32:
|
case UINT32:
|
||||||
result.setText("(int64_t) *((uint32_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("(int64_t) *((uint32_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
case INT64:
|
case INT64:
|
||||||
result.setText("*((int64_t *) &wasm_heap[" + index.getText() + "])");
|
result.setText("*((int64_t *) " + base + ")");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,7 +855,7 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
result.setText("*((float *) &wasm_heap[" + index.getText() + "])");
|
result.setText("*((float *) &wasm_heap[" + index.getText() + " + " + expression.getOffset() + "])");
|
||||||
|
|
||||||
value = result;
|
value = result;
|
||||||
}
|
}
|
||||||
|
@ -872,7 +874,7 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
result.setText("*((double *) &wasm_heap[" + index.getText() + "])");
|
result.setText("*((double *) &wasm_heap[" + index.getText() + " + " + expression.getOffset() + "])");
|
||||||
|
|
||||||
value = result;
|
value = result;
|
||||||
}
|
}
|
||||||
|
@ -893,21 +895,22 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
result.getLines().addAll(valueToStore.getLines());
|
result.getLines().addAll(valueToStore.getLines());
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
String base = "&wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]";
|
||||||
switch (expression.getConvertTo()) {
|
switch (expression.getConvertTo()) {
|
||||||
case INT8:
|
case INT8:
|
||||||
line = "wasm_heap[" + index.getText() + "] = " + valueToStore.getText() + ";";
|
line = base.substring(1) + " = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case UINT8:
|
case UINT8:
|
||||||
line = "*((uint8_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((uint8_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case INT16:
|
case INT16:
|
||||||
line = "*((int16_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((int16_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
line = "*((uint16_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((uint16_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case INT32:
|
case INT32:
|
||||||
line = "*((int32_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((int32_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError(expression.getConvertTo().toString());
|
throw new AssertionError(expression.getConvertTo().toString());
|
||||||
|
@ -933,27 +936,28 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
result.getLines().addAll(valueToStore.getLines());
|
result.getLines().addAll(valueToStore.getLines());
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
String base = "&wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]";
|
||||||
switch (expression.getConvertTo()) {
|
switch (expression.getConvertTo()) {
|
||||||
case INT8:
|
case INT8:
|
||||||
line = "wasm_heap[" + index.getText() + "] = " + valueToStore.getText();
|
line = base.substring(1) + " = " + valueToStore.getText();
|
||||||
break;
|
break;
|
||||||
case UINT8:
|
case UINT8:
|
||||||
line = "*((uint8_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((uint8_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case INT16:
|
case INT16:
|
||||||
line = "*((int16_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((int16_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case UINT16:
|
case UINT16:
|
||||||
line = "*((uint16_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((uint16_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case INT32:
|
case INT32:
|
||||||
line = "*((int32_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((int32_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case UINT32:
|
case UINT32:
|
||||||
line = "*((uint32_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((uint32_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
case INT64:
|
case INT64:
|
||||||
line = "*((int64_t *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";";
|
line = "*((int64_t *) " + base + ") = " + valueToStore.getText() + ";";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
|
@ -979,8 +983,8 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
result.getLines().addAll(valueToStore.getLines());
|
result.getLines().addAll(valueToStore.getLines());
|
||||||
|
|
||||||
result.addLine("*((float *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";",
|
result.addLine("*((float *) &wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]) = "
|
||||||
expression.getLocation());
|
+ valueToStore.getText() + ";", expression.getLocation());
|
||||||
|
|
||||||
value = result;
|
value = result;
|
||||||
}
|
}
|
||||||
|
@ -1000,8 +1004,8 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
|
||||||
result.getLines().addAll(index.getLines());
|
result.getLines().addAll(index.getLines());
|
||||||
result.getLines().addAll(valueToStore.getLines());
|
result.getLines().addAll(valueToStore.getLines());
|
||||||
|
|
||||||
result.addLine("*((double *) &wasm_heap[" + index.getText() + "]) = " + valueToStore.getText() + ";",
|
result.addLine("*((double *) &wasm_heap[" + index.getText() + " + " + expression.getOffset() + "]) = "
|
||||||
expression.getLocation());
|
+ valueToStore.getText() + ";", expression.getLocation());
|
||||||
|
|
||||||
value = result;
|
value = result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,6 +399,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
append(" align=" + expression.getAlignment());
|
append(" align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -430,6 +433,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
append(" align=" + expression.getAlignment());
|
append(" align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -437,6 +443,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(WasmLoadFloat32 expression) {
|
public void visit(WasmLoadFloat32 expression) {
|
||||||
open().append("f32.load align=" + expression.getAlignment());
|
open().append("f32.load align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -444,6 +453,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(WasmLoadFloat64 expression) {
|
public void visit(WasmLoadFloat64 expression) {
|
||||||
open().append("f64.load align=" + expression.getAlignment());
|
open().append("f64.load align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -465,6 +477,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
append(" align=" + expression.getAlignment());
|
append(" align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
line(expression.getValue());
|
line(expression.getValue());
|
||||||
close();
|
close();
|
||||||
|
@ -491,6 +506,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
append(" align=" + expression.getAlignment());
|
append(" align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
line(expression.getValue());
|
line(expression.getValue());
|
||||||
close();
|
close();
|
||||||
|
@ -499,6 +517,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(WasmStoreFloat32 expression) {
|
public void visit(WasmStoreFloat32 expression) {
|
||||||
open().append("f32.store align=" + expression.getAlignment());
|
open().append("f32.store align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
line(expression.getValue());
|
line(expression.getValue());
|
||||||
close();
|
close();
|
||||||
|
@ -507,6 +528,9 @@ class WasmRenderingVisitor implements WasmExpressionVisitor {
|
||||||
@Override
|
@Override
|
||||||
public void visit(WasmStoreFloat64 expression) {
|
public void visit(WasmStoreFloat64 expression) {
|
||||||
open().append("f64.store align=" + expression.getAlignment());
|
open().append("f64.store align=" + expression.getAlignment());
|
||||||
|
if (expression.getOffset() > 0) {
|
||||||
|
append(" offset=" + expression.getOffset());
|
||||||
|
}
|
||||||
line(expression.getIndex());
|
line(expression.getIndex());
|
||||||
line(expression.getValue());
|
line(expression.getValue());
|
||||||
close();
|
close();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user