Commit 9d978be0 authored by Théotime BOLLENGIER's avatar Théotime BOLLENGIER
Browse files

rewrite placement with IO locations

parent 568b0ffc
module ArGen
class PlacementLine
attr_reader :block_name, :x, :y, :subblk, :block_number
def initialize (block_name, x, y, subblk, block_number)
@block_name = block_name
@x = x
@y = y
@subblk = subblk
@block_number = block_number
end
def self.read_placement_line (line)
match = line.match(/^(\S+)\s+(\d+)\s+(\d+)\s+(-?\d+)(\s+#(\d+))?$/)
return nil if match.nil?
subblk = nil
subblk = match[6].to_i if match[5]
return PlacementLine.new(match[1], match[2].to_i, match[3].to_i, match[4].to_i, subblk)
end
end
class PlacementFile
attr_reader :header, :lines
def initialize (header = [], lines = [])
@header = header
@lines = lines
end
def merge (other)
other.lines.each do |ol|
my_same_line = @lines.find{|l| l.block_name == ol.block_name}
@lines.delete(my_same_line) if my_same_line
@lines << ol
end
end
def self.read_file (fileName)
header = []
lines = []
File.read(fileName).lines.each_with_index do |line, i|
line.chomp!
next if line.length == 0 or line[0] == '#'
pl = PlacementLine.read_placement_line(line)
if pl then
lines << pl
next
end
if line =~ /^Netlist file:/ then
header << line
next
end
if line =~ /^Array size:/
header << line
next
end
abort "ERROR: Line #{i+1} in file #{fileName}: cannot parse line: \"#{line}\""
end
return PlacementFile.new(header, lines)
end
def write_to_file (fileName)
ofile = File.open(fileName, 'w')
unless @header.empty? then
@header.each{|l| ofile.puts l}
ofile.puts
end
unless @lines.empty? then
max_name_length = (@lines.collect{|l| l.block_name.length} + [11]).max
max_x_length = (@lines.collect{|l| l.x.to_s.length} + [2]).max
max_y_length = (@lines.collect{|l| l.y.to_s.length} + [2]).max
max_subblk_length = (@lines.collect{|l| l.subblk.to_s.length} + [6]).max
str = "#block name".ljust(max_name_length) + "\t"
str += " x".rjust(max_x_length) + "\t"
str += " y".rjust(max_x_length) + "\t"
str += "subblk".rjust(max_subblk_length) + "\t"
str += "block number"
ofile.puts str
str = "#----------".ljust(max_name_length) + "\t"
str += "--".rjust(max_x_length) + "\t"
str += "--".rjust(max_x_length) + "\t"
str += "------".rjust(max_subblk_length) + "\t"
str += "------------"
ofile.puts str
@lines.each do |pl|
str = "#{pl.block_name.ljust(max_name_length)}\t"
str += pl.x.to_s.rjust(max_x_length) + "\t"
str += pl.y.to_s.rjust(max_y_length) + "\t"
str += pl.subblk.to_s.rjust(max_subblk_length) + "\t"
str += '#' + pl.block_number.to_s if pl.block_number
ofile.puts str
end
end
ofile.close
end
end
end
require 'optparse'
require_relative '../../lib/argen/version.rb'
require_relative '../../lib/argen/rewrite_placement_with_IO_locations.rb'
$copyright = "Copyright (C) 2017-2018 ENSTA Bretagne"
$authors = [
["Théotime Bollengier", "<theotime.bollengier@ensta-bretagne.fr>"]
]
$program_name = File.basename(__FILE__, '.*')
$program_version = ArGen::VERSION
$description = "This program modifies VPR output placement files to precisely constraint IO locations."
$description_string = "\nWelcome to #{$program_name} #{$program_version}, a component of the ArGen framework.\n#{$description}\n#{$copyright}\n#{$authors.collect.with_index{|a, i| "#{(i == 0) ? "Author#{($authors.length > 1) ? 's':''}: " : " #{($authors.length > 1) ? ' ':''} "}#{a.first} #{a.last}\n"}.join}"
STDOUT.sync = true
STDERR.sync = true
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options]"
options[:input_p] = nil
opts.on('-i', '--input_placement FILE', 'Placement input file') do |s|
options[:input_p] = s
end
options[:outut_p] = nil
opts.on('-o', '--output_placement FILE', 'Placement output file') do |s|
options[:output_p] = s
end
options[:loc] = nil
opts.on('-l', '--io_placement FILE', 'IO placement input file') do |s|
options[:loc] = s
end
opts.on('-h', '--help', 'Display this help') do
puts opts
puts $description_string
exit
end
end
begin
optparse.parse!
rescue Exception => e
if e.class == SystemExit then
exit 0
else
abort e.message + "\n" + optparse.to_s
end
end
STDERR.puts "WARNING: Unused commandline arguments: #{ARGV.join(' ')}" unless ARGV.empty?
if options[:input_p].nil? then
STDERR.puts "ERROR: you must specify a placement input file!"
abort optparse.to_s
end
if options[:loc].nil? then
STDERR.puts "ERROR: you must specify an IO placement input file!"
abort optparse.to_s
end
if options[:output_p].nil? then
STDERR.puts "ERROR: you must specify a placement output file!"
abort optparse.to_s
end
pfo = ArGen::PlacementFile.read_file options[:input_p]
pfa = ArGen::PlacementFile.read_file options[:loc]
pfo.merge(pfa)
pfo.write_to_file options[:output_p]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment