Only ASCII strings as comment

This commit is contained in:
Volker Berlin 2020-04-26 19:47:51 +02:00
parent fd27656b65
commit 7eb0406db8

View File

@ -458,7 +458,11 @@ public abstract class WasmCodeBuilder {
Integer id = strings.get( value );
FunctionName name = strings.getStringConstantFunction();
instructions.add( new WasmConstInstruction( id, ValueType.i32, javaCodePos, lineNumber ) );
instructions.add( new WasmCallInstruction( name, javaCodePos, lineNumber, types, false, (String)value ) );
String comment = (String)value;
if( !isAscii( comment ) ) {
comment = null;
}
instructions.add( new WasmCallInstruction( name, javaCodePos, lineNumber, types, false, comment ) );
} else if( value instanceof Number ) {
instructions.add( new WasmConstInstruction( (Number)value, javaCodePos, lineNumber ) );
} else if( value instanceof ConstantClass ) {
@ -473,6 +477,25 @@ public abstract class WasmCodeBuilder {
}
}
/**
* if the string contains only ASCCI characters
*
* @param str
* the staring
* @return true, if only ASCII
*/
private static boolean isAscii( String str ) {
int length = str.length();
for( int i = 0; i < length; i++ ) {
int c = str.charAt( i );
if( c >= 0x20 && c < 0x7F ) {
continue;
}
return false;
}
return true;
}
/**
* Add a numeric operation instruction
*