verilog_rename 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -0
- data/lib/verilog/rename.rb +1 -1
- data/lib/verilog_rename.rb +4 -1
- data/spec/scratch/fixtures/{TEST_ONE.v → TEST_TWO.v} +1 -1
- data/spec/scratch/fixtures/test_four.vh +1 -1
- data/spec/scratch/fixtures/test_three.v +2 -2
- metadata +9 -8
- data/lib/verilog/rename-backup.rb +0 -130
- data/lib/verilog/rename-oldf.rb +0 -195
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
verilog_rename
|
2
|
+
==============
|
3
|
+
|
4
|
+
Helpers to rename a verilog module and update refferences to it
|
5
|
+
|
6
|
+
Example (from the rename-verilog executable)
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'verilog_rename'
|
10
|
+
|
11
|
+
this_dir = Dir.pwd
|
12
|
+
|
13
|
+
path_files = Verilog::PathFiles.new( this_dir )
|
14
|
+
path_files.read_all
|
15
|
+
|
16
|
+
rename = Verilog::Rename.new('OLD_NAME', 'NEW_NAME', path_files)
|
17
|
+
rename.rename_module
|
18
|
+
|
19
|
+
TODO
|
20
|
+
----
|
21
|
+
|
22
|
+
In the future the rename executable will have options for prefix which can operate on whole directories.
|
data/lib/verilog/rename.rb
CHANGED
data/lib/verilog_rename.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verilog_rename
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morgan Prior
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-24 00:00:00 +01:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: verilog
|
@@ -43,12 +44,11 @@ extra_rdoc_files: []
|
|
43
44
|
|
44
45
|
files:
|
45
46
|
- LICENSE.rtf
|
47
|
+
- README.md
|
46
48
|
- Rakefile
|
47
49
|
- bin/rename-verilog
|
48
50
|
- lib/verilog/path_files.rb
|
49
51
|
- lib/verilog/prefix.rb
|
50
|
-
- lib/verilog/rename-backup.rb
|
51
|
-
- lib/verilog/rename-oldf.rb
|
52
52
|
- lib/verilog/rename.rb
|
53
53
|
- lib/verilog_rename.rb
|
54
54
|
- spec/example1/beta.v
|
@@ -64,8 +64,8 @@ files:
|
|
64
64
|
- spec/run_examples1.sh
|
65
65
|
- spec/run_examples2.sh
|
66
66
|
- spec/scratch/fixtures/test_four.vh
|
67
|
-
- spec/scratch/fixtures/TEST_ONE.v
|
68
67
|
- spec/scratch/fixtures/test_three.v
|
68
|
+
- spec/scratch/fixtures/TEST_TWO.v
|
69
69
|
- spec/spec_helper.rb
|
70
70
|
- spec/temp/BETA_R4.v
|
71
71
|
- spec/temp/BETA_R4_TH.v
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- spec/temp/BETA_R4_TH_pkg.v
|
74
74
|
- spec/temp/BETA_TH_sim.do
|
75
75
|
- spec/verilog_rename_spec.rb
|
76
|
+
has_rdoc: true
|
76
77
|
homepage: http://amaras-tech.co.uk/software/verilog_rename
|
77
78
|
licenses: []
|
78
79
|
|
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
requirements: []
|
103
104
|
|
104
105
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.6.2
|
106
107
|
signing_key:
|
107
108
|
specification_version: 3
|
108
109
|
summary: Extension to the verilog gem for renaming verilog files
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'FileUtils'
|
2
|
-
|
3
|
-
module Verilog
|
4
|
-
|
5
|
-
class Rename
|
6
|
-
attr_reader :path_files
|
7
|
-
attr_reader :old_name, :new_name
|
8
|
-
attr_reader :old_file, :new_file
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(old_name, new_name, path_files)
|
12
|
-
@old_name = old_name
|
13
|
-
@new_name = new_name
|
14
|
-
@path_files = path_files
|
15
|
-
end
|
16
|
-
|
17
|
-
def rename
|
18
|
-
#@old_file, @new_file = find_rename_verilog_file
|
19
|
-
|
20
|
-
#Analyse file and rename module
|
21
|
-
rename_module
|
22
|
-
|
23
|
-
#update_refferences
|
24
|
-
end
|
25
|
-
|
26
|
-
def update_refferences
|
27
|
-
files = Dir.glob('*.*')
|
28
|
-
#puts "File list searching for insatances of #{@old_name}"
|
29
|
-
files.each do |file|
|
30
|
-
next if File.directory?( file )
|
31
|
-
contents = Verilog::FileReader.get_file_as_string( file )
|
32
|
-
|
33
|
-
#Update Instatiations
|
34
|
-
updated_instance_b = contents.gsub!(
|
35
|
-
/(^\s*)#{@old_name}(\s\w+\s*\()/i, "\\1#{@new_name}\\2")
|
36
|
-
if updated_instance_b
|
37
|
-
puts "Updating instantiation of #{@old_name} to #{@new_name} in #{file.to_s}"
|
38
|
-
end
|
39
|
-
|
40
|
-
#Update inculde
|
41
|
-
## want filename of file being moved
|
42
|
-
updated_include_b = contents.gsub!(/(^\s*`include [\'\"])#{@old_file}([\'\"])/i, "\\1#{@new_file}\\2")
|
43
|
-
if updated_include_b
|
44
|
-
puts "Updating include of #{@old_file} to #{@new_file} in #{file.to_s}"
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
#Update lines in *.do runscripts
|
49
|
-
updated_run_b = contents.gsub!(/(\s+)#{@old_file}(\s+)/, "\\1#{@new_file}\\2")
|
50
|
-
if updated_instance_b
|
51
|
-
puts "Updating call to #{@old_file} to #{@new_file} in #{file.to_s}"
|
52
|
-
end
|
53
|
-
|
54
|
-
#Update File
|
55
|
-
if updated_instance_b or updated_include_b or updated_run_b
|
56
|
-
write_file_to_string( file, contents )
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def rename_module
|
65
|
-
|
66
|
-
#find the correct file first
|
67
|
-
puts @old_name
|
68
|
-
|
69
|
-
file_to_rename = @path_files.find_by_module( @old_name )
|
70
|
-
|
71
|
-
file_to_rename.contents.gsub!(/(^\s*module )#{@old_name}(\s+|;|\()/i, "\\1#{@new_name}\\2")
|
72
|
-
|
73
|
-
extension = ::File.extname( file_to_rename.filename )
|
74
|
-
|
75
|
-
#Need to change file name but keep extension
|
76
|
-
file_to_rename.filename = @new_name + extension
|
77
|
-
|
78
|
-
pp file_to_rename
|
79
|
-
|
80
|
-
#Save file, will use new name.
|
81
|
-
|
82
|
-
#Delete Old file
|
83
|
-
|
84
|
-
#Update other files refferencing it.
|
85
|
-
|
86
|
-
|
87
|
-
#file_contents = Verilog::FileReader.get_file_as_string( new_file )
|
88
|
-
|
89
|
-
#file_contents
|
90
|
-
|
91
|
-
# if updated_b
|
92
|
-
# Verilog::FileReader.write_file_to_string( new_file, file_contents )
|
93
|
-
# end
|
94
|
-
end
|
95
|
-
|
96
|
-
def find_rename_verilog_file
|
97
|
-
old_file, ext = find_module_file( @old_name )
|
98
|
-
|
99
|
-
if old_file
|
100
|
-
new_file = @new_name + ext
|
101
|
-
puts "Moving #{old_file} to #{new_file}"
|
102
|
-
FileUtils.move( old_file, new_file )
|
103
|
-
else
|
104
|
-
#Old_filename does not exists
|
105
|
-
# This could be second tim running script.
|
106
|
-
# Look for newfile incase already moved.
|
107
|
-
new_file, ext = find_module_file( @new_name )
|
108
|
-
end
|
109
|
-
|
110
|
-
return [old_file, new_file]
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
if $0 == __FILE__
|
119
|
-
#puts "Running Verilog Rename"
|
120
|
-
#operate on current directory (future parse testbench.f)
|
121
|
-
this_dir = Dir.pwd
|
122
|
-
|
123
|
-
#Parameter 1 old_name
|
124
|
-
old_name = ARGV[0]
|
125
|
-
#Parameter 2 new_name
|
126
|
-
new_name = ARGV[1]
|
127
|
-
|
128
|
-
a = Verilog::Rename::File.new(this_dir, old_name, new_name)
|
129
|
-
a.rename
|
130
|
-
end
|
data/lib/verilog/rename-oldf.rb
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'FileUtils'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
module Verilog
|
5
|
-
|
6
|
-
EXTENSIONS = [".v", ".bh.v", ".sv"]
|
7
|
-
|
8
|
-
class File
|
9
|
-
attr_reader :path
|
10
|
-
attr_reader :file_name
|
11
|
-
attr_reader :ext
|
12
|
-
|
13
|
-
def initialise( path, file_name="", ext="" )
|
14
|
-
#TODO if path is a file then create file_name and ext
|
15
|
-
@path = path
|
16
|
-
@file_name = file_name
|
17
|
-
#TODO check ext starts with .
|
18
|
-
@ext = ext
|
19
|
-
end
|
20
|
-
|
21
|
-
def absolute_path
|
22
|
-
File.join( File.expand_path( path ), file_name ext )
|
23
|
-
end
|
24
|
-
|
25
|
-
def read
|
26
|
-
if File.exist?( absolute_path )
|
27
|
-
data = ''
|
28
|
-
f = File.open(absolute_path, "r")
|
29
|
-
f.each_line do |line|
|
30
|
-
data += line
|
31
|
-
end
|
32
|
-
f.close
|
33
|
-
return data
|
34
|
-
else
|
35
|
-
#TODO raise correct exception here
|
36
|
-
puts "ERROR File Not Found #{absolute_path}"
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def save( contents )
|
42
|
-
f = File.open(absolute_path, "w")
|
43
|
-
f.write(contents)
|
44
|
-
f.close
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
class PathFiles
|
51
|
-
attr_reader :files
|
52
|
-
|
53
|
-
def initalize( path="" )
|
54
|
-
@files = []
|
55
|
-
load_path( path )
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_path( paths )
|
59
|
-
#path is single string or array of strings
|
60
|
-
paths.each do |path|
|
61
|
-
files = Dir.glob('*.*')
|
62
|
-
files.each do |file|
|
63
|
-
#Skip if Directory got passed *.* Filter
|
64
|
-
next if File.directory?( file )
|
65
|
-
|
66
|
-
file_extension = File.extname(file)
|
67
|
-
name = File.basename(file,file_extension)
|
68
|
-
@files << Verilog::File.new(path, name, file_extension)
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def <<( item )
|
75
|
-
@files
|
76
|
-
end
|
77
|
-
|
78
|
-
def find_module( name )
|
79
|
-
result = @files.select { |file| file.file_name == name }
|
80
|
-
|
81
|
-
if result.size == 1
|
82
|
-
return result
|
83
|
-
else
|
84
|
-
#TODO Fall back to scanning all files for module declarations
|
85
|
-
return false
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
module Rename
|
95
|
-
class Rename
|
96
|
-
attr_reader :dir, :old_name, :new_name
|
97
|
-
attr_reader :old_file, :new_file
|
98
|
-
|
99
|
-
|
100
|
-
def initialize(this_dir, old_name, new_name)
|
101
|
-
@dir = this_dir
|
102
|
-
@old_name = old_name
|
103
|
-
@new_name = new_name
|
104
|
-
end
|
105
|
-
|
106
|
-
def rename
|
107
|
-
@old_file, @new_file = find_rename_verilog_file
|
108
|
-
|
109
|
-
#Analyse file and rename module
|
110
|
-
rename_module( @new_file )
|
111
|
-
|
112
|
-
update_refferences
|
113
|
-
end
|
114
|
-
|
115
|
-
def update_refferences
|
116
|
-
files = Dir.glob('*.*')
|
117
|
-
#puts "File list searching for insatances of #{@old_name}"
|
118
|
-
files.each do |file|
|
119
|
-
next if File.directory?( file )
|
120
|
-
contents = Verilog::FileReader.get_file_as_string( file )
|
121
|
-
|
122
|
-
#Update Instatiations
|
123
|
-
updated_instance_b = contents.gsub!(/(^\s*)#{@old_name}(\s\w+\s*\()/i, "\\1#{@new_name}\\2")
|
124
|
-
if updated_instance_b
|
125
|
-
puts "Updating instantiation of #{@old_name} to #{@new_name} in #{file.to_s}"
|
126
|
-
end
|
127
|
-
|
128
|
-
#Update inculde
|
129
|
-
## want filename of file being moved
|
130
|
-
updated_include_b = contents.gsub!(/(^\s*`include [\'\"])#{@old_file}([\'\"])/i, "\\1#{@new_file}\\2")
|
131
|
-
if updated_include_b
|
132
|
-
puts "Updating include of #{@old_file} to #{@new_file} in #{file.to_s}"
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
#Update lines in *.do runscripts
|
137
|
-
updated_run_b = contents.gsub!(/(\s+)#{@old_file}(\s+)/, "\\1#{@new_file}\\2")
|
138
|
-
if updated_instance_b
|
139
|
-
puts "Updating call to #{@old_file} to #{@new_file} in #{file.to_s}"
|
140
|
-
end
|
141
|
-
|
142
|
-
#Update File
|
143
|
-
if updated_instance_b or updated_include_b or updated_run_b
|
144
|
-
write_file_to_string( file, contents )
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
def rename_module( new_file )
|
153
|
-
file_contents = Verilog::FileReader.get_file_as_string( new_file )
|
154
|
-
|
155
|
-
updated_b = file_contents.gsub!(/(^\s*module )#{@old_name}(\s+|;|\()/i, "\\1#{@new_name}\\2")
|
156
|
-
|
157
|
-
if updated_b
|
158
|
-
Verilog::FileReader.write_file_to_string( new_file, file_contents )
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def find_rename_verilog_file
|
163
|
-
old_file, ext = find_module_file( @old_name )
|
164
|
-
|
165
|
-
if old_file
|
166
|
-
new_file = @new_name + ext
|
167
|
-
puts "Moving #{old_file} to #{new_file}"
|
168
|
-
FileUtils.move( old_file, new_file )
|
169
|
-
else
|
170
|
-
#Old_filename does not exists
|
171
|
-
# This could be second tim running script.
|
172
|
-
# Look for newfile incase already moved.
|
173
|
-
new_file, ext = find_module_file( @new_name )
|
174
|
-
end
|
175
|
-
|
176
|
-
return [old_file, new_file]
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
if $0 == __FILE__
|
184
|
-
#puts "Running Verilog Rename"
|
185
|
-
#operate on current directory (future parse testbench.f)
|
186
|
-
this_dir = Dir.pwd
|
187
|
-
|
188
|
-
#Parameter 1 old_name
|
189
|
-
old_name = ARGV[0]
|
190
|
-
#Parameter 2 new_name
|
191
|
-
new_name = ARGV[1]
|
192
|
-
|
193
|
-
a = Verilog::Rename::File.new(this_dir, old_name, new_name)
|
194
|
-
a.rename
|
195
|
-
end
|