OpenCores
URL https://opencores.org/ocsvn/tcp_socket/tcp_socket/trunk

Subversion Repositories tcp_socket

[/] [tcp_socket/] [trunk/] [chips2/] [chips/] [compiler/] [allocator.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jondawson
__author__ = "Jon Dawson"
2
__copyright__ = "Copyright (C) 2012, Jonathan P Dawson"
3
__version__ = "0.1"
4
 
5
class Allocator:
6
 
7 4 jondawson
    """Maintain a pool of registers, variables and arrays. Keep track of what they are used for."""
8 2 jondawson
 
9 4 jondawson
    def __init__(self, reuse):
10
        self.registers = []
11
        self.all_registers = {}
12
        self.memory_size_2 = 0
13
        self.memory_size_4 = 0
14
        self.reuse = reuse
15
        self.memory_content_2 = {}
16
        self.memory_content_4 = {}
17 2 jondawson
 
18 4 jondawson
    def new_array(self, size, contents, element_size):
19
        if element_size == 2:
20
            reg = self.memory_size_2
21
            self.memory_size_2 += int(size)
22
            if contents is not None:
23
                for location, value in enumerate(contents, reg):
24
                    self.memory_content_2[location] = value
25
            return reg
26
        elif element_size == 4:
27
            reg = self.memory_size_4
28
            self.memory_size_4 += int(size)
29
            if contents is not None:
30
                for location, value in enumerate(contents, reg):
31
                    self.memory_content_4[location] = value
32
            return reg
33 2 jondawson
 
34 4 jondawson
    def regsize(self, reg):
35
        return self.all_registers[reg][1]
36 2 jondawson
 
37 4 jondawson
    def new(self, size, name="temporary_register"):
38
        assert type(size) == int
39
        reg = 0
40
        while reg in self.registers or (reg in self.all_registers and self.regsize(reg) != size):
41
            reg += 1
42
        self.registers.append(reg)
43
        self.all_registers[reg] = (name, size)
44
        return reg
45 2 jondawson
 
46 4 jondawson
    def free(self, register):
47
        if register in self.registers and self.reuse:
48
            self.registers.remove(register)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.