Created
October 1, 2013 16:40
-
-
Save alexkasko/6781413 to your computer and use it in GitHub Desktop.
Changes added to krakatau sources to run them on jython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Krakatau/assembler/assembler.py b/Krakatau/assembler/assembler.py | |
index a6eec35..a875268 100644 | |
--- a/Krakatau/assembler/assembler.py | |
+++ b/Krakatau/assembler/assembler.py | |
@@ -66,7 +66,7 @@ class PoolInfo(object): | |
self.pool.copyItem(used, index) | |
_format_ops = collections.defaultdict(tuple) | |
-_format_ops[''] = instructions.instrs_noarg | |
+_format_ops['>'] = instructions.instrs_noarg | |
_format_ops['>B'] = 'iload', 'lload', 'fload', 'dload', 'aload', 'istore', 'lstore', 'fstore', 'dstore', 'astore', 'ret' | |
_format_ops['>h'] = 'ifeq', 'ifne', 'iflt', 'ifge', 'ifgt', 'ifle', 'if_icmpeq', 'if_icmpne', 'if_icmplt', 'if_icmpge', 'if_icmpgt', 'if_icmple', 'if_acmpeq', 'if_acmpne', 'goto', 'jsr', 'ifnull', 'ifnonnull' | |
_format_ops['>H'] = 'ldc_w', 'ldc2_w', 'getstatic', 'putstatic', 'getfield', 'putfield', 'invokevirtual', 'invokespecial', 'invokestatic', 'new', 'anewarray', 'checkcast', 'instanceof' | |
diff --git a/Krakatau/java/ast.py b/Krakatau/java/ast.py | |
index 486c570..6cac5b1 100644 | |
--- a/Krakatau/java/ast.py | |
+++ b/Krakatau/java/ast.py | |
@@ -111,8 +111,8 @@ class TryStatement(LazyLabelBase): | |
def print_(self): | |
tryb = self.tryb.print_() | |
- parts = ['catch({})\n{}'.format(x.print_(), y.print_()) for x,y in self.pairs] | |
- return '{}try\n{}\n{}'.format(self.getLabelPrefix(), tryb, '\n'.join(parts)) | |
+ parts = ['catch ({}) {}'.format(x.print_(), y.print_()) for x,y in self.pairs] | |
+ return '{}try {} {}'.format(self.getLabelPrefix(), tryb, '\n'.join(parts)) | |
class IfStatement(LazyLabelBase): | |
def __init__(self, labelfunc, begink, endk, expr, scopes): | |
@@ -129,17 +129,17 @@ class IfStatement(LazyLabelBase): | |
if len(self.scopes) == 1: | |
parts = [x.print_() for x in parts] | |
- return '{}if({})\n{}'.format(lbl, *parts) | |
+ return '{}if ({}) {}'.format(lbl, *parts) | |
# Special case handling for 'else if' | |
- sep = '\n' #else seperator depends on if we have else if | |
+ sep = ' ' #else seperator depends on if we have else if | |
fblock = self.scopes[1] | |
if len(fblock.statements) == 1: | |
stmt = fblock.statements[-1] | |
if isinstance(stmt, IfStatement) and stmt.label is None: | |
sep, parts[-1] = ' ', stmt | |
parts = [x.print_() for x in parts] | |
- return '{}if({})\n{}\nelse{sep}{}'.format(lbl, *parts, sep=sep) | |
+ return '{}if ({}) {} else{sep}{}'.format(lbl, *parts, sep=sep) | |
class SwitchStatement(LazyLabelBase): | |
def __init__(self, labelfunc, begink, endk, expr, pairs): | |
@@ -178,7 +178,7 @@ class WhileStatement(LazyLabelBase): | |
def print_(self): | |
parts = self.expr.print_(), self.parts[0].print_() | |
- return '{}while({})\n{}'.format(self.getLabelPrefix(), *parts) | |
+ return '{}while ({}) {}'.format(self.getLabelPrefix(), *parts) | |
class StatementBlock(LazyLabelBase): | |
def __init__(self, labelfunc, begink, endk, statements, jumpk, labelable=True): | |
diff --git a/Krakatau/java/ast2.py b/Krakatau/java/ast2.py | |
index ff0069d..8c7c77d 100644 | |
--- a/Krakatau/java/ast2.py | |
+++ b/Krakatau/java/ast2.py | |
@@ -33,7 +33,7 @@ class MethodDef(object): | |
if self.body is None: | |
return header + ';\n' | |
else: | |
- return header + '\n' + self.body.print_() | |
+ return header + ' ' + self.body.print_() | |
class FieldDef(object): | |
def __init__(self, flags, type_, name, expr=None): | |
@@ -82,5 +82,5 @@ class ClassDef(object): | |
else: | |
header += ' implements ' + ', '.join(x.print_() for x in self.interfaces) | |
- lines = [header + ' {'] + indented + ['}'] | |
+ lines = [header + ' {\n'] + indented + ['}'] | |
return '\n'.join(lines) | |
\ No newline at end of file | |
diff --git a/Krakatau/verifier/descriptors.py b/Krakatau/verifier/descriptors.py | |
index d299a2a..c13ff58 100644 | |
--- a/Krakatau/verifier/descriptors.py | |
+++ b/Krakatau/verifier/descriptors.py | |
@@ -1,4 +1,4 @@ | |
-from .verifier_types import * | |
+from Krakatau.verifier.verifier_types import * | |
def parseFieldDescriptors(desc_str, unsynthesize=True): | |
baseTypes = {'B':T_BYTE, 'C':T_CHAR, 'D':T_DOUBLE, 'F':T_FLOAT, | |
diff --git a/Krakatau/verifier/inference_verifier.py b/Krakatau/verifier/inference_verifier.py | |
index 3d99914..3a7c5f2 100644 | |
--- a/Krakatau/verifier/inference_verifier.py | |
+++ b/Krakatau/verifier/inference_verifier.py | |
@@ -3,8 +3,8 @@ import itertools | |
from .. import error as error_types | |
from .. import opnames | |
from .. import bytecode | |
-from .verifier_types import * | |
-from .descriptors import * | |
+from Krakatau.verifier.verifier_types import * | |
+from Krakatau.verifier.descriptors import * | |
#This verifier is intended to closely replicate the behavior of Hotspot's inference verifier | |
#http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/tip/src/share/native/common/check_code.c | |
diff --git a/decompile.py b/decompile.py | |
index 453b156..00d836a 100644 | |
--- a/decompile.py | |
+++ b/decompile.py | |
@@ -133,4 +133,4 @@ if __name__== "__main__": | |
targets = script_util.findFiles(args.target, args.r, '.class') | |
targets = map(script_util.normalizeClassname, targets) | |
- decompileClass(path, targets, args.out, plugins) | |
\ No newline at end of file | |
+ decompileClass(path, targets, args.out, plugins) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment