wasm: fixing debug C generator

This commit is contained in:
Alexey Andreev 2023-09-30 20:19:22 +02:00
parent fc3d92f58d
commit 7806a699c5
2 changed files with 23 additions and 4 deletions

View File

@ -1064,20 +1064,24 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
public void visit(WasmFill expression) { public void visit(WasmFill expression) {
var result = new CExpression(); var result = new CExpression();
requiredType = WasmType.INT32;
expression.getIndex().acceptVisitor(this); expression.getIndex().acceptVisitor(this);
var dest = value; var dest = value;
requiredType = WasmType.INT32;
expression.getValue().acceptVisitor(this); expression.getValue().acceptVisitor(this);
var v = value; var v = value;
expression.getValue().acceptVisitor(this); requiredType = WasmType.INT32;
expression.getCount().acceptVisitor(this);
var num = value; var num = value;
result.getLines().addAll(dest.getLines()); result.getLines().addAll(dest.getLines());
result.getLines().addAll(v.getLines()); result.getLines().addAll(v.getLines());
result.getLines().addAll(num.getLines()); result.getLines().addAll(num.getLines());
result.addLine("memset(" + dest.getText() + ", " + v.getText() + ", " + num.getText() + ");"); result.addLine("memset(wasm_heap + " + dest.getText() + ", " + v.getText()
+ ", " + num.getText() + ");");
value = result; value = result;
} }
@ -1085,12 +1089,15 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
public void visit(WasmCopy expression) { public void visit(WasmCopy expression) {
var result = new CExpression(); var result = new CExpression();
requiredType = WasmType.INT32;
expression.getDestinationIndex().acceptVisitor(this); expression.getDestinationIndex().acceptVisitor(this);
var dest = value; var dest = value;
requiredType = WasmType.INT32;
expression.getSourceIndex().acceptVisitor(this); expression.getSourceIndex().acceptVisitor(this);
var src = value; var src = value;
requiredType = WasmType.INT32;
expression.getCount().acceptVisitor(this); expression.getCount().acceptVisitor(this);
var num = value; var num = value;
@ -1098,7 +1105,8 @@ class WasmCRenderingVisitor implements WasmExpressionVisitor {
result.getLines().addAll(src.getLines()); result.getLines().addAll(src.getLines());
result.getLines().addAll(num.getLines()); result.getLines().addAll(num.getLines());
result.addLine("memcpy(" + dest.getText() + ", " + src.getText() + ", " + num.getText() + ");"); result.addLine("memcpy(wasm_heap + " + dest.getText() + ", wasm_heap + " + src.getText() + ", "
+ num.getText() + ");");
value = result; value = result;
} }

View File

@ -21,7 +21,11 @@ static char** wasm_argv;
#define teavmMath_ceil ceil #define teavmMath_ceil ceil
#define teavmMath_floor floor #define teavmMath_floor floor
int64_t teavm_currentTimeMillis() { double teavmMath_random() {
return rand() / (double) RAND_MAX;
}
double teavm_currentTimeMillis() {
struct timespec time; struct timespec time;
clock_gettime(CLOCK_REALTIME, &time); clock_gettime(CLOCK_REALTIME, &time);
@ -148,4 +152,11 @@ int32_t wasi_snapshot_preview1_fd_write(int32_t fd, int32_t iovs, int32_t count,
int32_t* resultPtr = (int32_t*) (wasm_heap + result); int32_t* resultPtr = (int32_t*) (wasm_heap + result);
*resultPtr = written; *resultPtr = written;
return 0; return 0;
}
void teavm_putwcharsOut(int32_t chars, int32_t count) {
int16_t* chars_array = (int16_t*) (wasm_heap + chars);
for (int32_t i = 0; i < count; ++i) {
putwchar(chars_array[i]);
}
} }