Пример #1
0
 def __init__(self):
     self.private = "public"
     self.address = 0
     self.param_key = []
     self.params = VarTable()
     self.return_type = SparkyType()
     self.varTable = VarTable()
     self.funMemory = MemoryMap("function")
     self.tempMemory = MemoryMap("temporal")
Пример #2
0
def main():
    mem = Memory(32 * 1024 * 1024)
    high = Memory(32 * 1024 * 1024)
    m = MemoryMap([
        (0, mem),
        (0xffffffff - len(high) + 1, high),
        (40000000, SimpleIO()),
    ])
    with open(sys.argv[1], 'rb') as f:
        mem.write_bin(0, f.read())
    cpu = CPU(m, debug_trace=False)
    while not cpu.ebreak:
        cpu.step()
    print(cpu.regs)
Пример #3
0
 def __init__(self):
     self.BASE = 0  # Starting location for Quadruples //list starts with empty so its -1
     self.Quads = []
     self.globalMemory = MemoryMap("program")
     self.ConsMemory = MemoryMap("Constant")
     self.varTable = VarTable()
     self.funDir = FunctionDirectory()
     self.ClassDir = ClassTable()
     self.semanticCube = SemanticCube()
     self.pJumps = []  #
     self.VP = []  # Polish vector
     self.pOper = []
     self.pType = []
     self.pArray = []
     self.pIDs = []
     self.pEras = []
     self.pendingQuads = []
     self.current_quad = ()
     self.current_param_num = 0
     self.current_class = Class()
     self.current_object = Object()
     self.current_var = Var()
     self.current_function = Function()
     self.current_params = VarTable()
     self.current_type = SparkyType()
     self.local_class_func = FunctionDirectory()
     self.local_func = Function()
     self.local_class = Class()
     self.local_type = SparkyType()
     self.current_value = 0
     self.current_class_name = ""
     self.current_var_name = ""
     self.current_function_name = ""
     self.called_function = Function()
     self.current_scope = ""  # Working inside the global program
     self.class_stage = False  # Working either in a class or a function
     self.current_id_is_func = False
Пример #4
0
 def __init__(self):
     self.funDir = FunctionDirectory()
     self.varTable = VarTable()
     self.claMemory = MemoryMap("class")
Пример #5
0
    def __init__(self,
                 arch,
                 listfile,
                 binfile,
                 options,
                 logLevel=0,
                 logfile=None):
        self.options = options
        self.verbose = options.verbose
        self.debug = options.debug
        self.logfile = logfile
        self.assembler = None
        self.arch = arch
        self.listfile = listfile
        self.binfile = binfile
        self.srcfile = None
        self.opcodes = OPCODES[self.arch]
        self.symtab = SymbolTable(self)
        self.linenum = 0
        self.global_linenum = 0
        self.mode = OpcodeType.BASIC
        self.memmap = MemoryMap(arch, options.verbose)
        self.lastEbank = 0
        self.previousWasEbankEquals = False
        self.previousWasSbankEquals = False
        self.previousWasIndex = False
        self.code = []
        self.records = []
        self.srcline = None
        self.interpMode = False
        self.interpInstCount = 0
        self.interpArgs = 0
        self.interpArgCount = 0
        self.interpArgTypes = [None, None, None, None]
        self.interpArgCodes = [0, 0, 0, 0]
        self.interpArgIncrement = [False, False, False, False]
        self.indexed = False
        self.currentRecord = None
        self.previousRecord = None
        self.addSymbol = True
        self.reparse = False
        self.passnum = 0
        self.complementNext = False  # STADR complements the following instruction(s).
        self.errorMsg = None
        self.warningMsg = None

        # Log level:
        #  0 - None.
        #  1 - Errors.
        #  2 - Warnings.
        #  3 - Info messages.
        #  4 - Bank changes, binary generation.
        #  5 - LOC changes, detailed interpretive logging.
        #  6 - Symbol information, address conversion.
        #  7 - Parser operation.
        #  8 - Symbol resolution.
        self.logLevel = logLevel

        self.loc = 0  # Assembler PC, i.e. current position in erasable or fixed memory.
        self.ebank = 0  # Current E-Bank.
        self.fbank = 0  # Current F-Bank.
        self.super = 0  # Superbank bit (0/1).
        self.lastSuper = 0

        self.ebankloc = {}  # Saved current location for each erasable bank.
        self.fbankloc = {}  # Saved current location for each fixed bank.

        for bank in range(len(self.memmap.banks[MemoryType.ERASABLE])):
            self.ebankloc[bank] = 0
        for bank in range(len(self.memmap.banks[MemoryType.FIXED])):
            self.fbankloc[bank] = 0

        self.errors = 0
        self.warnings = 0
Пример #6
0
    def __init__(self, test_vectors_file=None, debug=False):
        self.debug = debug

        self.test_vectors_file = test_vectors_file
        mkdir_safe(config.gen_path)
        mkdir_safe(os.path.join(config.gen_path, config.vhdl_path))
        mkdir_safe(os.path.join(config.gen_path, 'c'))
        mkdir_safe(os.path.join(config.gen_path, config.ipcore_path))

        if self.test_vectors_file:
            global_symb = {}
            execfile(self.test_vectors_file, global_symb)
            self.test_vectors = global_symb['test_vectors']
        else:
            self.test_vectors = None

        self.ast_list = []
        if config.design_tool == 'pa':
            from poroto.plan_ahead import PlanAhead
            self.designer = PlanAhead()
        elif config.design_tool == 'ghdl':
            from poroto.ghdl import Ghdl
            self.designer = Ghdl()
        else:
            raise Exception("Unknown design tool '%s'" % config.design_tool)
        FunctionInstance.designer = self.designer
        self.registers_map = RegisterMap(self.debug)
        self.mems_map = MemoryMap(self.debug)
        self.functions = FunctionsRegistry(self.designer, self.mems_map,
                                           self.debug)
        self.streams_map = StreamMap(self.mems_map, self.functions, self.debug)
        self.pragma_registry = PragmaRegistry(self.debug)
        if config.converter == 'roccc':
            self.converter = ROCCC(self.debug)
        else:
            raise Exception("Unknown converter '%s'" % config.converter)
        self.converter.init(self.pragma_registry)
        if config.device_vendor == "xilinx":
            from poroto.xilinx import XilinxPlatform
            self.platform = XilinxPlatform(self.designer, self.debug)
        elif config.device_vendor == "sim":
            from poroto.sim import SimPlatform
            self.platform = SimPlatform(self.designer, self.debug)
        else:
            raise Exception("Unknown device vendor '%s'" %
                            config.platform_vendor)
        if config.sdk == "alphadata":
            from poroto.alphadata import AlphaDataSDK
            self.sdk = AlphaDataSDK(self.platform, self.designer,
                                    self.functions.functions,
                                    self.registers_map, self.mems_map,
                                    self.streams_map, self.test_vectors,
                                    self.debug)
        elif config.sdk == "none":
            from poroto.none import NoneSDK
            self.sdk = NoneSDK(self.platform, self.designer,
                               self.functions.functions, self.registers_map,
                               self.mems_map, self.streams_map,
                               self.test_vectors, self.debug)
        elif config.sdk == "riffa":
            from poroto.riffa import RiffaSDK
            self.sdk = RiffaSDK(self.platform, self.designer,
                                self.functions.functions, self.registers_map,
                                self.mems_map, self.streams_map,
                                self.test_vectors, self.debug)
        else:
            raise Exception("Unknown sdk '%s'" % config.sdk)
        self.pragma_registry.add_pragma_type('file',
                                             FilePragmaHandler(self.debug))
        self.pragma_registry.add_pragma_type('template',
                                             TemplatePragmaHandler(self.debug))
        self.pragma_registry.add_pragma_type(
            'memory',
            MemoryPragmaHandler(self.functions, self.mems_map, self.sdk,
                                self.debug))
        self.pragma_registry.add_pragma_type(
            'stream', StreamPragmaHandler(self.streams_map, self.debug))
        self.pragma_registry.add_pragma_type('latency',
                                             LatencyPragmaHandler(self.debug))
        self.pragma_registry.add_pragma_type('array',
                                             ArrayPragmaHandler(self.debug))
        array.init(self.platform, self.converter, self.functions,
                   self.mems_map, self.streams_map)
        IPInstance.converter = self.converter
        FileTemplate.platform = self.platform