# Path: awake/address.py
# BANK_SIZE = 0x4000
# class BadAddressException(Exception):
# class Address(object):
#     def __init__(self, addr):
#     def __str__(self):
# def fromVirtual(virtual):
# def fromVirtualAndBank(virtual, bank):
# def fromVirtualAndCurrent(virtual, current):
# def fromPhysical(physical):
# def fromConventional(conventional):
#     def __init__(self, address):
#     def virtual(self):
#     def bank(self):
#     def isAmbiguous(self):
#     def inBankedSpace(self):
#     def inPhysicalMem(self):
#     def physical(self):
#     def offset(self, offset):
#     def withBankSpecified(self, bank):
#     def __lt__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def __repr__(self):
# 
# Path: awake/operand.py
# class Constant(Operand):
#     def __init__(self, value):
#         assert isinstance(value, int)
#         self.value = value
# 
#     def __str__(self):
#         if 0 <= self.value <= 9:
#             return str(self.value)
#         return hex(self.value)
# 
#     def render(self, renderer):
#         renderer.add(str(self), 'constant')
# 
#     def __hash__(self):
#         return hash(self.value)
# 
#     def __eq__(self, other):
#         try:
#             return self.value == other.value
#         except AttributeError:
#             return False
# 
#     @property
#     def bits(self):
#         if self.value > 0xFF:
#             return 16
#         else:
#             return 8
# 
# class Condition(Register):
#     bits = 1
# 
#     def negated(self):
#         return Condition(dict(FZ='FNZ', FNZ='FZ', FC='FNC', FNC='FC')[self.name])
# 
#     def alwaysTrue(self):
#         return self.name == 'ALWAYS'
# 
#     @property
#     def value(self):
#         if self.alwaysTrue():
#             return 1
#         else:
#             return None
# 
# class Dereference(Operand):
#     def __init__(self, target, addr=None):
#         self.addr = addr
#         if hasattr(target, "getAddress"):
#             self.target = target
#         elif target.value is not None:
#             if addr is not None:
#                 self.target = DataAddress(address.fromVirtualAndCurrent(target.value, addr))
#             else:
#                 self.target = DataAddress(address.fromVirtual(target.value))
#         else:
#             self.target = target
# 
#         self.childs = (self.target,)
# 
#     def __str__(self):
#         return '[{0}]'.format(self.target)
# 
#     def render(self, renderer):
#         renderer.add('[')
#         self.target.render(renderer)
#         renderer.add(']')
# 
#     def optimizedWithContext(self, ctx):
#         target = self.target.optimizedWithContext(ctx)
#         if not hasattr(target, 'getAddress') and target.value is not None:
#             target = DataAddress(address.fromVirtual(target.value)).optimizedWithContext(ctx)
#         return Dereference(target, self.addr)
# 
#     def getDependencies(self):
#         out = set(['mem']) | self.target.getDependencies()
#         if hasattr(self.target, 'getAddress'):
#             out |= set([self.target.getAddress()])
#         return out
# 
#     def __hash__(self):
#         return hash((Dereference, self.target))
# 
#     def __eq__(self, other):
#         return isinstance(other, Dereference) and self.target == other.target
# 
#     # XXX
#     #def getMemreads(self):
#     #    if hasattr(self.target, 'getAddress'):
#     #        return set([self.target.getAddress()])
#     #    return set()
# 
# class Register(Operand):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         return self.name
# 
#     def render(self, renderer):
#         renderer.add(str(self), 'register')
# 
#     def optimizedWithContext(self, ctx):
#         if ctx.hasValue(self.name):
#             return ctx.getValue(self.name)
#         return self
# 
#     def getDependencies(self):
#         return splitRegister(self.name)
# 
#     def __hash__(self):
#         return hash((Register, self.name))
# 
#     def __eq__(self, other):
#         return isinstance(other, Register) and self.name == other.name
# 
#     @property
#     def bits(self):
#         if self.name in REGS16:
#             return 16
#         else:
#             return 8


from awake import address
from awake.operand import Constant, Condition, Dereference, Register
# This file is part of Awake - GB decompiler.
# Copyright (C) 2012  Wojciech Marczenko (devdri) <wojtek.marczenko@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


BC = Register("BC")
DE = Register("DE")
HL = Register("HL")
SP = Register("SP")
AF = Register("AF")

B = Register("B")
C = Register("C")
D = Register("D")
E = Register("E")
H = Register("H")
L = Register("L")
A = Register("A")

# Path: awake/address.py
# BANK_SIZE = 0x4000
# class BadAddressException(Exception):
# class Address(object):
#     def __init__(self, addr):
#     def __str__(self):
# def fromVirtual(virtual):
# def fromVirtualAndBank(virtual, bank):
# def fromVirtualAndCurrent(virtual, current):
# def fromPhysical(physical):
# def fromConventional(conventional):
#     def __init__(self, address):
#     def virtual(self):
#     def bank(self):
#     def isAmbiguous(self):
#     def inBankedSpace(self):
#     def inPhysicalMem(self):
#     def physical(self):
#     def offset(self, offset):
#     def withBankSpecified(self, bank):
#     def __lt__(self, other):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def __repr__(self):
# 
# Path: awake/operand.py
# class Constant(Operand):
#     def __init__(self, value):
#         assert isinstance(value, int)
#         self.value = value
# 
#     def __str__(self):
#         if 0 <= self.value <= 9:
#             return str(self.value)
#         return hex(self.value)
# 
#     def render(self, renderer):
#         renderer.add(str(self), 'constant')
# 
#     def __hash__(self):
#         return hash(self.value)
# 
#     def __eq__(self, other):
#         try:
#             return self.value == other.value
#         except AttributeError:
#             return False
# 
#     @property
#     def bits(self):
#         if self.value > 0xFF:
#             return 16
#         else:
#             return 8
# 
# class Condition(Register):
#     bits = 1
# 
#     def negated(self):
#         return Condition(dict(FZ='FNZ', FNZ='FZ', FC='FNC', FNC='FC')[self.name])
# 
#     def alwaysTrue(self):
#         return self.name == 'ALWAYS'
# 
#     @property
#     def value(self):
#         if self.alwaysTrue():
#             return 1
#         else:
#             return None
# 
# class Dereference(Operand):
#     def __init__(self, target, addr=None):
#         self.addr = addr
#         if hasattr(target, "getAddress"):
#             self.target = target
#         elif target.value is not None:
#             if addr is not None:
#                 self.target = DataAddress(address.fromVirtualAndCurrent(target.value, addr))
#             else:
#                 self.target = DataAddress(address.fromVirtual(target.value))
#         else:
#             self.target = target
# 
#         self.childs = (self.target,)
# 
#     def __str__(self):
#         return '[{0}]'.format(self.target)
# 
#     def render(self, renderer):
#         renderer.add('[')
#         self.target.render(renderer)
#         renderer.add(']')
# 
#     def optimizedWithContext(self, ctx):
#         target = self.target.optimizedWithContext(ctx)
#         if not hasattr(target, 'getAddress') and target.value is not None:
#             target = DataAddress(address.fromVirtual(target.value)).optimizedWithContext(ctx)
#         return Dereference(target, self.addr)
# 
#     def getDependencies(self):
#         out = set(['mem']) | self.target.getDependencies()
#         if hasattr(self.target, 'getAddress'):
#             out |= set([self.target.getAddress()])
#         return out
# 
#     def __hash__(self):
#         return hash((Dereference, self.target))
# 
#     def __eq__(self, other):
#         return isinstance(other, Dereference) and self.target == other.target
# 
#     # XXX
#     #def getMemreads(self):
#     #    if hasattr(self.target, 'getAddress'):
#     #        return set([self.target.getAddress()])
#     #    return set()
# 
# class Register(Operand):
#     def __init__(self, name):
#         self.name = name
# 
#     def __str__(self):
#         return self.name
# 
#     def render(self, renderer):
#         renderer.add(str(self), 'register')
# 
#     def optimizedWithContext(self, ctx):
#         if ctx.hasValue(self.name):
#             return ctx.getValue(self.name)
#         return self
# 
#     def getDependencies(self):
#         return splitRegister(self.name)
# 
#     def __hash__(self):
#         return hash((Register, self.name))
# 
#     def __eq__(self, other):
#         return isinstance(other, Register) and self.name == other.name
# 
#     @property
#     def bits(self):
#         if self.name in REGS16:
#             return 16
#         else:
#             return 8


# Path: awake/placeholders.py
from awake import address
from awake.operand import Constant, Condition, Dereference, Register

# This file is part of Awake - GB decompiler.
# Copyright (C) 2012  Wojciech Marczenko (devdri) <wojtek.marczenko@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


BC = Register("BC")
DE = Register("DE")
HL = Register("HL")
SP = Register("SP")
AF = Register("AF")

B = Register("B")
C = Register("C")
D = Register("D")
E = Register("E")
H = Register("H")
L = Register("L")
A = Register("A")

deref_HL = Dereference(HL, address.fromVirtual(0))  # XXX: TODO: very very bad