class HDLRuby::Low::Allocator

An allocator.

Attributes

range[R]

The space range for the allocation.

word[R]

The word size.

Public Class Methods

new(range, word = 8) click to toggle source

Creates a new allocator within range memory space whose word size is word.

# File lib/HDLRuby/backend/hruby_allocator.rb, line 22
def initialize(range, word = 8)
    # Check and set the range.
    first = range.first.to_i
    last = range.last.to_i
    @range = first < last ? first..last : last..first
    # Check and set the word size.
    @word = word.to_i
    # Initialize the allocation counter.
    @head = first
    # Initialize the allocation table.
    @table = {}
end

Public Instance Methods

allocate(signal) click to toggle source

Allocates space for signal. NOTE: if the signal is already allocated, returns the previous

allocation result.
# File lib/HDLRuby/backend/hruby_allocator.rb, line 38
def allocate(signal)
    # Has the signal been already allocated?
    if @table.key?(signal) then
        # Yes return the allocation result.
        return @table[signal]
    end
    # Get the size to allocate in word.
    size = signal.type.width / @word
    size += 1 unless signal.type.width % word == 0
    # Is there any room left?
    if @head + size > @range.last then
        raise AnyError, "Address range overflow."
    end
    # Ok, performs the allocation.
    res = @head
    @head += size
    @table[signal] = res
    return res
end
each() click to toggle source

Iterate over the allocated signals and their corresponding address.

# File lib/HDLRuby/backend/hruby_allocator.rb, line 64
def each
    @table.each
end
get(signal) click to toggle source

Get the address of signal if allocated.

# File lib/HDLRuby/backend/hruby_allocator.rb, line 59
def get(signal)
    return @table[signal]
end