mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Implements "add" for all data types
This commit is contained in:
parent
119d5ed7f4
commit
e698ba3607
@ -23,6 +23,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||
import de.inetsoftware.jwebassembly.module.ValueType;
|
||||
|
||||
@ -283,8 +285,21 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeAddInt() throws IOException {
|
||||
codeStream.write( I32_ADD );
|
||||
protected void writeAdd( @Nullable ValueType valueType ) throws IOException {
|
||||
switch( valueType ) {
|
||||
case i32:
|
||||
codeStream.write( I32_ADD );
|
||||
break;
|
||||
case i64:
|
||||
codeStream.write( I64_ADD );
|
||||
break;
|
||||
case f32:
|
||||
codeStream.write( F32_ADD );
|
||||
break;
|
||||
case f64:
|
||||
codeStream.write( F64_ADD );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.classparser.Annotations;
|
||||
import de.inetsoftware.classparser.ClassFile;
|
||||
@ -269,6 +270,24 @@ public abstract class ModuleWriter implements Closeable {
|
||||
case 29: // iload_3
|
||||
writeLoadStore( true, ValueType.i32, op - 26 );
|
||||
break;
|
||||
case 30: // lload_0
|
||||
case 31: // lload_1
|
||||
case 32: // lload_2
|
||||
case 33: // lload_3
|
||||
writeLoadStore( true, ValueType.i64, op - 30 );
|
||||
break;
|
||||
case 34: // fload_0
|
||||
case 35: // fload_1
|
||||
case 36: // fload_2
|
||||
case 37: // fload_3
|
||||
writeLoadStore( true, ValueType.f32, op - 34 );
|
||||
break;
|
||||
case 38: // dload_0
|
||||
case 39: // dload_1
|
||||
case 40: // dload_2
|
||||
case 41: // dload_3
|
||||
writeLoadStore( true, ValueType.f64, op - 38 );
|
||||
break;
|
||||
case 59: // istore_0
|
||||
case 60: // istore_1
|
||||
case 61: // istore_2
|
||||
@ -276,7 +295,10 @@ public abstract class ModuleWriter implements Closeable {
|
||||
writeLoadStore( false, ValueType.i32, op - 59 );
|
||||
break;
|
||||
case 96: // iadd
|
||||
writeAddInt();
|
||||
writeAdd( ValueType.i32);
|
||||
break;
|
||||
case 98: // fadd
|
||||
writeAdd( ValueType.f32 );
|
||||
break;
|
||||
case 172: // ireturn
|
||||
case 173: // lreturn
|
||||
@ -412,10 +434,13 @@ public abstract class ModuleWriter implements Closeable {
|
||||
/**
|
||||
* Write a add operator
|
||||
*
|
||||
* @param valueType
|
||||
* the type of the parameters
|
||||
*
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeAddInt() throws IOException;
|
||||
protected abstract void writeAdd( @Nullable ValueType valueType ) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a return
|
||||
|
@ -18,6 +18,8 @@ package de.inetsoftware.jwebassembly.text;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||
import de.inetsoftware.jwebassembly.module.ValueType;
|
||||
|
||||
@ -160,9 +162,9 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeAddInt() throws IOException {
|
||||
protected void writeAdd( @Nullable ValueType valueType ) throws IOException {
|
||||
newline( methodOutput );
|
||||
methodOutput.append( "i32.add" );
|
||||
methodOutput.append( valueType ).append( ".add" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user