Example #1
0
class LocationRoot():
    '''
    Present data as a location within various CPU constructs.
    Has methods to return snippets that access the data. 
    The class only presents the root of the datatype i.e. the top level.
    It unifies access methods across the CPU constructs. 
    It also allows transfer of values round the CPU constructs with
    clear syntax. 
    Both the access and the transfer methods can avoid or block
    nonsense that can occur accidentally such as mistaking an address 
    for a value.
     
    lid 
        a register name, a stack offset, or label to segment data.
    '''
    arch = architecture.architectureSolve(architecture.x64)
    isAddressLoc = None
    isReadOnly = False
    
    # If the src was a label, then an assembler will track the loc,
    # and these classes fo not need to.
    # However, a label var value may be transferred to some other 
    # location. If so, we need to know the what the original
    # location was. Then if the var is displaced it can be returned to
    # the label value, rather than occupying stack space.
    # We do this by stashing the label (as the original location)
    labelLoc = None
    
    def __init__(self, lid):
        self._validInitialLID(lid)
        self.lid = lid
        
    def _validInitialLID(self, lid):
        return NotImplementedError()
                
    def __repr__(self):
        return "{}(lid: '{}')".format(self.__class__.__name__, self.lid)
        
    def __str__(self):
        return str(self.lid)
Example #2
0
import unittest
from exceptions import BuilderError
import architecture
from tpl_autostore import (
    AutoStoreReg,
    AutoStoreStack,
    AutoStoreX64
)
import tpl_locationRoot as Loc
from tpl_vars import Var, NoVar
import tpl_types as Type


 
arch = architecture.architectureSolve(architecture.x64)

# python3 -m unittest test.test_auto_store
class TestAutoStoreRegEmpty(unittest.TestCase):
    def setUp(self):
        self.a = AutoStoreReg(arch['generalPurposeRegisters'])
        
    def test_regcount(self):        
        self.assertEqual(self.a.regCount, 14)

    def test_call(self):        
        with self.assertRaises(BuilderError):
            self.a('r14')

    def test_isAllocated(self):        
        self.assertFalse(self.a.isAllocated('r14'))