Merge pull request #15 from JCWasmx86/master

Typo, replaced crlf with lf in some files
This commit is contained in:
Volker Berlin 2020-05-25 19:15:58 +02:00 committed by GitHub
commit 87199e46ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 478 additions and 478 deletions

View File

@ -1,95 +1,95 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* @author Volker Berlin
*/
public class Attributes {
private final AttributeInfo[] attributes;
private final ConstantPool constantPool;
Attributes( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
this.constantPool = constantPool;
this.attributes = readAttributs( input );
}
private AttributeInfo[] readAttributs( @Nonnull DataInputStream input ) throws IOException {
AttributeInfo[] attrs = new AttributeInfo[input.readUnsignedShort()];
for( int i = 0; i < attrs.length; i++ ) {
attrs[i] = new AttributeInfo( input, constantPool );
}
return attrs;
}
@Nullable
AttributeInfo get( String name ) {
for( AttributeInfo attr : attributes ) {
if( attr.getName().equals( name ) ) {
return attr;
}
}
return null;
}
static class AttributeInfo {
private final String name;
private final byte[] info;
AttributeInfo( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
this.name = (String)constantPool.get( input.readUnsignedShort() );
this.info = new byte[input.readInt()];
input.readFully( this.info );
}
String getName() {
return name;
}
byte[] getData() {
return info;
}
DataInputStream getDataInputStream(){
return new DataInputStream( new ByteArrayInputStream( info ) );
}
}
/**
* Get value of SourceFile if available.
* @return the source file name or null.
* @throws IOException if an I/O error occurs.
*/
public String getSourceFile() throws IOException{
AttributeInfo data = get( "SourceFile" );
if( data == null ) {
return null;
}
return (String)constantPool.get( data.getDataInputStream().readUnsignedShort() );
}
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* @author Volker Berlin
*/
public class Attributes {
private final AttributeInfo[] attributes;
private final ConstantPool constantPool;
Attributes( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
this.constantPool = constantPool;
this.attributes = readAttributs( input );
}
private AttributeInfo[] readAttributs( @Nonnull DataInputStream input ) throws IOException {
AttributeInfo[] attrs = new AttributeInfo[input.readUnsignedShort()];
for( int i = 0; i < attrs.length; i++ ) {
attrs[i] = new AttributeInfo( input, constantPool );
}
return attrs;
}
@Nullable
AttributeInfo get( String name ) {
for( AttributeInfo attr : attributes ) {
if( attr.getName().equals( name ) ) {
return attr;
}
}
return null;
}
static class AttributeInfo {
private final String name;
private final byte[] info;
AttributeInfo( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
this.name = (String)constantPool.get( input.readUnsignedShort() );
this.info = new byte[input.readInt()];
input.readFully( this.info );
}
String getName() {
return name;
}
byte[] getData() {
return info;
}
DataInputStream getDataInputStream(){
return new DataInputStream( new ByteArrayInputStream( info ) );
}
}
/**
* Get value of SourceFile if available.
* @return the source file name or null.
* @throws IOException if an I/O error occurs.
*/
public String getSourceFile() throws IOException{
AttributeInfo data = get( "SourceFile" );
if( data == null ) {
return null;
}
return (String)constantPool.get( data.getDataInputStream().readUnsignedShort() );
}
}

View File

@ -1,32 +1,32 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantClass {
private final String name;
ConstantClass( String name ) {
this.name = name;
}
public String getName() {
return name;
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantClass {
private final String name;
ConstantClass( String name ) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -1,27 +1,27 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantFieldRef extends ConstantRef {
ConstantFieldRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantFieldRef extends ConstantRef {
ConstantFieldRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
}

View File

@ -1,27 +1,27 @@
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantInterfaceRef extends ConstantRef {
ConstantInterfaceRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
}
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantInterfaceRef extends ConstantRef {
ConstantInterfaceRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
}

View File

@ -1,27 +1,27 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantMethodRef extends ConstantRef {
ConstantMethodRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantMethodRef extends ConstantRef {
ConstantMethodRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
super( constClass, nameAndType );
}
}

View File

@ -1,43 +1,43 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantNameAndType{
private final String name;
private final String type;
public ConstantNameAndType(String name, String type){
this.name = name;
this.type = type;
}
public String getName(){
return name;
}
/**
* The type of the variable in class file syntax.
* @return the type
*/
public String getType(){
return type;
}
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
/**
* @author Volker Berlin
*/
public class ConstantNameAndType{
private final String name;
private final String type;
public ConstantNameAndType(String name, String type){
this.name = name;
this.type = type;
}
public String getName(){
return name;
}
/**
* The type of the variable in class file syntax.
* @return the type
*/
public String getType(){
return type;
}
}

View File

@ -1,52 +1,52 @@
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
/**
* Exceptions attribute of methods.
*
* @author Volker Berlin
*/
public class Exceptions {
ConstantClass[] classes;
/**
* Read the Exceptions structure.
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.5
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#3129
*
* @param input
* @param constantPool
* @throws IOException
*/
Exceptions( DataInputStream input, ConstantPool constantPool ) throws IOException {
int count = input.readUnsignedShort();
classes = new ConstantClass[count];
for( int i = 0; i < count; i++ ) {
int idx = input.readUnsignedShort();
classes[i] = (ConstantClass)constantPool.get( idx );
}
}
public ConstantClass[] getClasses() {
return classes;
}
}
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
/**
* Exceptions attribute of methods.
*
* @author Volker Berlin
*/
public class Exceptions {
ConstantClass[] classes;
/**
* Read the Exceptions structure.
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.5
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#3129
*
* @param input
* @param constantPool
* @throws IOException
*/
Exceptions( DataInputStream input, ConstantPool constantPool ) throws IOException {
int count = input.readUnsignedShort();
classes = new ConstantClass[count];
for( int i = 0; i < count; i++ ) {
int idx = input.readUnsignedShort();
classes[i] = (ConstantClass)constantPool.get( idx );
}
}
public ConstantClass[] getClasses() {
return classes;
}
}

View File

@ -1,104 +1,104 @@
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
/**
* @author Volker Berlin
*/
public class LineNumberTable {
private final int start_pc[];
private final int line_number[];
/**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.12
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#22856
*
* @param input
* the stream of the class
* @throws IOException
*/
LineNumberTable( DataInputStream input ) throws IOException {
int count = input.readUnsignedShort();
start_pc = new int[count];
line_number = new int[count];
for( int i = 0; i < count; i++ ) {
start_pc[i] = input.readUnsignedShort();
line_number[i] = input.readUnsignedShort();
}
}
/**
* Count of entries
*
* @return the count
*/
public int size() {
return start_pc.length;
}
/**
* Get the offset of the code
*
* @param idx
* the table position
* @return the code offset
*/
public int getStartOffset( int idx ) {
return start_pc[idx];
}
/**
* Get the line number
*
* @param idx
* the table position
* @return the line number
*/
public int getLineNumber( int idx ) {
return line_number[idx];
}
/**
* Get the line number of the last code block.
* @return
*/
public int getLastLineNr() {
return line_number[line_number.length - 1];
}
public int getMinLineNr(){
int min = 0xFFFF;
for( int nr : line_number ){
min = Math.min( min, nr );
}
return min;
}
public int getMaxLineNr(){
int max = -1;
for( int nr : line_number ){
max = Math.max( max, nr );
}
return max;
}
}
/*
Copyright 2011 - 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
/**
* @author Volker Berlin
*/
public class LineNumberTable {
private final int start_pc[];
private final int line_number[];
/**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.12
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#22856
*
* @param input
* the stream of the class
* @throws IOException
*/
LineNumberTable( DataInputStream input ) throws IOException {
int count = input.readUnsignedShort();
start_pc = new int[count];
line_number = new int[count];
for( int i = 0; i < count; i++ ) {
start_pc[i] = input.readUnsignedShort();
line_number[i] = input.readUnsignedShort();
}
}
/**
* Count of entries
*
* @return the count
*/
public int size() {
return start_pc.length;
}
/**
* Get the offset of the code
*
* @param idx
* the table position
* @return the code offset
*/
public int getStartOffset( int idx ) {
return start_pc[idx];
}
/**
* Get the line number
*
* @param idx
* the table position
* @return the line number
*/
public int getLineNumber( int idx ) {
return line_number[idx];
}
/**
* Get the line number of the last code block.
* @return
*/
public int getLastLineNr() {
return line_number[line_number.length - 1];
}
public int getMinLineNr(){
int min = 0xFFFF;
for( int nr : line_number ){
min = Math.min( min, nr );
}
return min;
}
public int getMaxLineNr(){
int max = -1;
for( int nr : line_number ){
max = Math.max( max, nr );
}
return max;
}
}

View File

@ -1,71 +1,71 @@
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
import javax.annotation.Nonnull;
/**
* @author Volker Berlin
*/
public class TryCatchFinally {
private final int start;
private final int end;
private final int handler;
private final ConstantClass type;
/**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.3
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546
*
* @param input
* @param constantPool
* @throws IOException
*/
TryCatchFinally( DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
start = input.readUnsignedShort();
end = input.readUnsignedShort();
handler = input.readUnsignedShort();
type = (ConstantClass)constantPool.get( input.readUnsignedShort() );
}
public int getStart() {
return start;
}
public int getEnd() {
return end;
}
public int getHandler() {
return handler;
}
public ConstantClass getType() {
return type;
}
public boolean isFinally() {
return type == null;
}
}
/*
Copyright 2017 Volker Berlin (i-net software)
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 de.inetsoftware.classparser;
import java.io.DataInputStream;
import java.io.IOException;
import javax.annotation.Nonnull;
/**
* @author Volker Berlin
*/
public class TryCatchFinally {
private final int start;
private final int end;
private final int handler;
private final ConstantClass type;
/**
* http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.3
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546
*
* @param input
* @param constantPool
* @throws IOException
*/
TryCatchFinally( DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
start = input.readUnsignedShort();
end = input.readUnsignedShort();
handler = input.readUnsignedShort();
type = (ConstantClass)constantPool.get( input.readUnsignedShort() );
}
public int getStart() {
return start;
}
public int getEnd() {
return end;
}
public int getHandler() {
return handler;
}
public ConstantClass getType() {
return type;
}
public boolean isFinally() {
return type == null;
}
}

View File

@ -33,7 +33,7 @@ class CodeOptimizer {
* @param instructions
* the list of instructions
*/
void optimze( List<WasmInstruction> instructions ) {
void optimize( List<WasmInstruction> instructions ) {
for( int i = instructions.size()-1; i >= 0; i-- ) {
WasmInstruction instr = instructions.get( i );
switch( instr.getType() ) {

View File

@ -574,7 +574,7 @@ public class ModuleGenerator {
writeMethodSignature( name, FunctionType.Code, codeBuilder );
List<WasmInstruction> instructions = codeBuilder.getInstructions();
optimizer.optimze( instructions );
optimizer.optimize( instructions );
int lastJavaSourceLine = -1;
for( WasmInstruction instruction : instructions ) {