]> git.cryptolib.org Git - arm-crypto-lib.git/blob - host/create-algo-impl-relation.rb
Adding Khazad
[arm-crypto-lib.git] / host / create-algo-impl-relation.rb
1 #!/usr/bin/ruby 
2 # create-algo-impl-relation.rb
3 =begin
4     This file is part of the ARM-Crypto-Lib.
5     Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
6
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 SPEED_DIR = 'speed_log/'
22 SIZE_DIR  = 'size_log/'
23 OUT_DIR = 'algo_implementation/'
24
25 $debug = false
26 require 'rubygems'
27 require 'getopt/std'
28 require 'ftools'
29
30 def get_module_names(finname)
31   ret = Array.new
32   f = File.open(finname, 'r')
33   f.gets # first line is ignored
34   while(l=f.gets())
35     if m=l.match(/[\s]([^\s]*)$/)
36       ret << m[1]
37     end
38   end
39   f.close()
40   return ret
41 end
42
43
44 def mkalgoimplrelation_file(foutname, finname, algos)
45   if algos==nil
46     puts "ERROR: algos==nil! fout=#{foutname} fin=#{finname}"
47     return
48   end
49   if File.exists?(foutname)
50     puts "File #{foutname} already exists!"
51     return
52   end
53   modules = get_module_names(finname).join(' ')
54   f = File.open(foutname, 'w')
55   algos.each do |algo|
56     f.puts(algo+': '+modules)
57   end
58   f.close()
59 end
60
61
62 if not File.directory?(SPEED_DIR) 
63   puts "ERROR: #{SPEED_DIR} is no directory!"
64   return -1
65 end
66
67 if not File.directory?(SIZE_DIR) 
68   puts "ERROR: #{SIZE_DIR} is no directory!"
69   return -1
70 end
71
72 if not File.directory?(OUT_DIR) 
73   puts "ERROR: #{OUT_DIR} is no directory!"
74   return -1
75 end
76
77 list = Dir.entries(SPEED_DIR)
78 algo_list = Hash.new
79 list.each do |entry|
80   if m=entry.match(/([^.]*)\.([^.]*)\.txt/)
81     algo_list[m[2]] = Array.new if algo_list[m[2]]==nil
82     algo_list[m[2]] << m[1]
83   end
84 end
85
86 list = Dir.entries(SIZE_DIR)
87 list.each do |entry|
88   if m=entry.match(/([^.]*)\.size/)
89     mkalgoimplrelation_file(OUT_DIR+m[1]+'.algos', SIZE_DIR+entry, algo_list[m[1]])
90   end
91 end
92
93