mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Merge pull request #15 from JCWasmx86/master
Typo, replaced crlf with lf in some files
This commit is contained in:
commit
87199e46ba
@ -1,95 +1,95 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class Attributes {
|
public class Attributes {
|
||||||
|
|
||||||
private final AttributeInfo[] attributes;
|
private final AttributeInfo[] attributes;
|
||||||
|
|
||||||
private final ConstantPool constantPool;
|
private final ConstantPool constantPool;
|
||||||
|
|
||||||
Attributes( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
Attributes( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
||||||
this.constantPool = constantPool;
|
this.constantPool = constantPool;
|
||||||
this.attributes = readAttributs( input );
|
this.attributes = readAttributs( input );
|
||||||
}
|
}
|
||||||
|
|
||||||
private AttributeInfo[] readAttributs( @Nonnull DataInputStream input ) throws IOException {
|
private AttributeInfo[] readAttributs( @Nonnull DataInputStream input ) throws IOException {
|
||||||
AttributeInfo[] attrs = new AttributeInfo[input.readUnsignedShort()];
|
AttributeInfo[] attrs = new AttributeInfo[input.readUnsignedShort()];
|
||||||
for( int i = 0; i < attrs.length; i++ ) {
|
for( int i = 0; i < attrs.length; i++ ) {
|
||||||
attrs[i] = new AttributeInfo( input, constantPool );
|
attrs[i] = new AttributeInfo( input, constantPool );
|
||||||
}
|
}
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
AttributeInfo get( String name ) {
|
AttributeInfo get( String name ) {
|
||||||
for( AttributeInfo attr : attributes ) {
|
for( AttributeInfo attr : attributes ) {
|
||||||
if( attr.getName().equals( name ) ) {
|
if( attr.getName().equals( name ) ) {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class AttributeInfo {
|
static class AttributeInfo {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private final byte[] info;
|
private final byte[] info;
|
||||||
|
|
||||||
AttributeInfo( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
AttributeInfo( @Nonnull DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
||||||
this.name = (String)constantPool.get( input.readUnsignedShort() );
|
this.name = (String)constantPool.get( input.readUnsignedShort() );
|
||||||
this.info = new byte[input.readInt()];
|
this.info = new byte[input.readInt()];
|
||||||
input.readFully( this.info );
|
input.readFully( this.info );
|
||||||
}
|
}
|
||||||
|
|
||||||
String getName() {
|
String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] getData() {
|
byte[] getData() {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataInputStream getDataInputStream(){
|
DataInputStream getDataInputStream(){
|
||||||
return new DataInputStream( new ByteArrayInputStream( info ) );
|
return new DataInputStream( new ByteArrayInputStream( info ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value of SourceFile if available.
|
* Get value of SourceFile if available.
|
||||||
* @return the source file name or null.
|
* @return the source file name or null.
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public String getSourceFile() throws IOException{
|
public String getSourceFile() throws IOException{
|
||||||
AttributeInfo data = get( "SourceFile" );
|
AttributeInfo data = get( "SourceFile" );
|
||||||
if( data == null ) {
|
if( data == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (String)constantPool.get( data.getDataInputStream().readUnsignedShort() );
|
return (String)constantPool.get( data.getDataInputStream().readUnsignedShort() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class ConstantClass {
|
public class ConstantClass {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
ConstantClass( String name ) {
|
ConstantClass( String name ) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class ConstantFieldRef extends ConstantRef {
|
public class ConstantFieldRef extends ConstantRef {
|
||||||
|
|
||||||
ConstantFieldRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
ConstantFieldRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
||||||
super( constClass, nameAndType );
|
super( constClass, nameAndType );
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Volker Berlin (i-net software)
|
Copyright 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class ConstantInterfaceRef extends ConstantRef {
|
public class ConstantInterfaceRef extends ConstantRef {
|
||||||
|
|
||||||
ConstantInterfaceRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
ConstantInterfaceRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
||||||
super( constClass, nameAndType );
|
super( constClass, nameAndType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class ConstantMethodRef extends ConstantRef {
|
public class ConstantMethodRef extends ConstantRef {
|
||||||
|
|
||||||
ConstantMethodRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
ConstantMethodRef( ConstantClass constClass, ConstantNameAndType nameAndType ) {
|
||||||
super( constClass, nameAndType );
|
super( constClass, nameAndType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,43 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class ConstantNameAndType{
|
public class ConstantNameAndType{
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
public ConstantNameAndType(String name, String type){
|
public ConstantNameAndType(String name, String type){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName(){
|
public String getName(){
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of the variable in class file syntax.
|
* The type of the variable in class file syntax.
|
||||||
* @return the type
|
* @return the type
|
||||||
*/
|
*/
|
||||||
public String getType(){
|
public String getType(){
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,52 +1,52 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Volker Berlin (i-net software)
|
Copyright 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exceptions attribute of methods.
|
* Exceptions attribute of methods.
|
||||||
*
|
*
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class Exceptions {
|
public class Exceptions {
|
||||||
|
|
||||||
ConstantClass[] classes;
|
ConstantClass[] classes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the Exceptions structure.
|
* 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/se7/html/jvms-4.html#jvms-4.7.5
|
||||||
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#3129
|
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#3129
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* @param constantPool
|
* @param constantPool
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
Exceptions( DataInputStream input, ConstantPool constantPool ) throws IOException {
|
Exceptions( DataInputStream input, ConstantPool constantPool ) throws IOException {
|
||||||
int count = input.readUnsignedShort();
|
int count = input.readUnsignedShort();
|
||||||
classes = new ConstantClass[count];
|
classes = new ConstantClass[count];
|
||||||
for( int i = 0; i < count; i++ ) {
|
for( int i = 0; i < count; i++ ) {
|
||||||
int idx = input.readUnsignedShort();
|
int idx = input.readUnsignedShort();
|
||||||
classes[i] = (ConstantClass)constantPool.get( idx );
|
classes[i] = (ConstantClass)constantPool.get( idx );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstantClass[] getClasses() {
|
public ConstantClass[] getClasses() {
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,104 +1,104 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
Copyright 2011 - 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class LineNumberTable {
|
public class LineNumberTable {
|
||||||
|
|
||||||
private final int start_pc[];
|
private final int start_pc[];
|
||||||
|
|
||||||
private final int line_number[];
|
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/se7/html/jvms-4.html#jvms-4.7.12
|
||||||
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#22856
|
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#22856
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* the stream of the class
|
* the stream of the class
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
LineNumberTable( DataInputStream input ) throws IOException {
|
LineNumberTable( DataInputStream input ) throws IOException {
|
||||||
int count = input.readUnsignedShort();
|
int count = input.readUnsignedShort();
|
||||||
start_pc = new int[count];
|
start_pc = new int[count];
|
||||||
line_number = new int[count];
|
line_number = new int[count];
|
||||||
for( int i = 0; i < count; i++ ) {
|
for( int i = 0; i < count; i++ ) {
|
||||||
start_pc[i] = input.readUnsignedShort();
|
start_pc[i] = input.readUnsignedShort();
|
||||||
line_number[i] = input.readUnsignedShort();
|
line_number[i] = input.readUnsignedShort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count of entries
|
* Count of entries
|
||||||
*
|
*
|
||||||
* @return the count
|
* @return the count
|
||||||
*/
|
*/
|
||||||
public int size() {
|
public int size() {
|
||||||
return start_pc.length;
|
return start_pc.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the offset of the code
|
* Get the offset of the code
|
||||||
*
|
*
|
||||||
* @param idx
|
* @param idx
|
||||||
* the table position
|
* the table position
|
||||||
* @return the code offset
|
* @return the code offset
|
||||||
*/
|
*/
|
||||||
public int getStartOffset( int idx ) {
|
public int getStartOffset( int idx ) {
|
||||||
return start_pc[idx];
|
return start_pc[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the line number
|
* Get the line number
|
||||||
*
|
*
|
||||||
* @param idx
|
* @param idx
|
||||||
* the table position
|
* the table position
|
||||||
* @return the line number
|
* @return the line number
|
||||||
*/
|
*/
|
||||||
public int getLineNumber( int idx ) {
|
public int getLineNumber( int idx ) {
|
||||||
return line_number[idx];
|
return line_number[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the line number of the last code block.
|
* Get the line number of the last code block.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getLastLineNr() {
|
public int getLastLineNr() {
|
||||||
return line_number[line_number.length - 1];
|
return line_number[line_number.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinLineNr(){
|
public int getMinLineNr(){
|
||||||
int min = 0xFFFF;
|
int min = 0xFFFF;
|
||||||
for( int nr : line_number ){
|
for( int nr : line_number ){
|
||||||
min = Math.min( min, nr );
|
min = Math.min( min, nr );
|
||||||
}
|
}
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxLineNr(){
|
public int getMaxLineNr(){
|
||||||
int max = -1;
|
int max = -1;
|
||||||
for( int nr : line_number ){
|
for( int nr : line_number ){
|
||||||
max = Math.max( max, nr );
|
max = Math.max( max, nr );
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,71 +1,71 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Volker Berlin (i-net software)
|
Copyright 2017 Volker Berlin (i-net software)
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package de.inetsoftware.classparser;
|
package de.inetsoftware.classparser;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public class TryCatchFinally {
|
public class TryCatchFinally {
|
||||||
|
|
||||||
private final int start;
|
private final int start;
|
||||||
|
|
||||||
private final int end;
|
private final int end;
|
||||||
|
|
||||||
private final int handler;
|
private final int handler;
|
||||||
|
|
||||||
private final ConstantClass type;
|
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/se7/html/jvms-4.html#jvms-4.7.3
|
||||||
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546
|
* http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1546
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
* @param constantPool
|
* @param constantPool
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
TryCatchFinally( DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
TryCatchFinally( DataInputStream input, @Nonnull ConstantPool constantPool ) throws IOException {
|
||||||
start = input.readUnsignedShort();
|
start = input.readUnsignedShort();
|
||||||
end = input.readUnsignedShort();
|
end = input.readUnsignedShort();
|
||||||
handler = input.readUnsignedShort();
|
handler = input.readUnsignedShort();
|
||||||
type = (ConstantClass)constantPool.get( input.readUnsignedShort() );
|
type = (ConstantClass)constantPool.get( input.readUnsignedShort() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStart() {
|
public int getStart() {
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnd() {
|
public int getEnd() {
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHandler() {
|
public int getHandler() {
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstantClass getType() {
|
public ConstantClass getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFinally() {
|
public boolean isFinally() {
|
||||||
return type == null;
|
return type == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class CodeOptimizer {
|
|||||||
* @param instructions
|
* @param instructions
|
||||||
* the list of instructions
|
* the list of instructions
|
||||||
*/
|
*/
|
||||||
void optimze( List<WasmInstruction> instructions ) {
|
void optimize( List<WasmInstruction> instructions ) {
|
||||||
for( int i = instructions.size()-1; i >= 0; i-- ) {
|
for( int i = instructions.size()-1; i >= 0; i-- ) {
|
||||||
WasmInstruction instr = instructions.get( i );
|
WasmInstruction instr = instructions.get( i );
|
||||||
switch( instr.getType() ) {
|
switch( instr.getType() ) {
|
||||||
|
@ -574,7 +574,7 @@ public class ModuleGenerator {
|
|||||||
writeMethodSignature( name, FunctionType.Code, codeBuilder );
|
writeMethodSignature( name, FunctionType.Code, codeBuilder );
|
||||||
|
|
||||||
List<WasmInstruction> instructions = codeBuilder.getInstructions();
|
List<WasmInstruction> instructions = codeBuilder.getInstructions();
|
||||||
optimizer.optimze( instructions );
|
optimizer.optimize( instructions );
|
||||||
|
|
||||||
int lastJavaSourceLine = -1;
|
int lastJavaSourceLine = -1;
|
||||||
for( WasmInstruction instruction : instructions ) {
|
for( WasmInstruction instruction : instructions ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user