vhdl_tb 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cd1879cca3683122f2deaf4d3e42937f5a4fe870
4
- data.tar.gz: 700d2f736b29de611e5b2834ea0e500e8e189a90
2
+ SHA256:
3
+ metadata.gz: 60412d4e16c8f944834bc400eea61eb617c2006713e12125a51c38f15ffc39af
4
+ data.tar.gz: 9a35251fc2315d50c88fb29d0e0ffd7be194db91cce91bc2af1937122f5f0a30
5
5
  SHA512:
6
- metadata.gz: c131814294a059dbe6eb5eaf1a557be6a0326cbcf0fb81014e5c608feb2ed77fbb737cdbc085c331a85c164ab5ce6eeb6015b15f4eb7058e733cdcbf17ba0aea
7
- data.tar.gz: 5f300c1af6f426f300d7a87478e44cf4de5d3daacef47df740628508a017c1fe92c2ccddb1d70ae5e04ac975ca97c4d2a90673d77dabe2102e7961d2bfe38ce4
6
+ metadata.gz: 9dcaaae2c60bf8c91536c9e8a5c8f6f2c5ec7a57728dcbeb338b11300247f96bdd708c8609bb65b7932bd5c1936cdb026c0c3f04cae9146c327e71640eac158e
7
+ data.tar.gz: '0229d739111e76d6523876542dde9c0017d154725c6177116d15d5ca86ee77c8a832526d59de64a7550cba467a8c8d90fdf6e7ed985bffd3662ec9dd55fbc8d5'
@@ -11,7 +11,7 @@ module VHDL_TB
11
11
 
12
12
  class Compiler
13
13
 
14
- VERSION = "0.6.5"
14
+ VERSION = "0.7.0"
15
15
 
16
16
  def initialize
17
17
  #puts __dir__
@@ -68,6 +68,7 @@ module VHDL_TB
68
68
  File.open(tb_filename,'w'){|f| f.puts tb_txt}
69
69
  puts "testbench generated : #{tb_filename}"
70
70
  rescue Exception => e
71
+ puts e
71
72
  abort
72
73
  end
73
74
  end
@@ -77,6 +78,7 @@ module VHDL_TB
77
78
 
78
79
  root=Parser.new.parse entity_filename
79
80
 
81
+ #puts "parsed #{entity_filename}. Good."
80
82
  @entity=root.design_units.find{|du| du.class==Entity}
81
83
  puts "entity found : #{@entity.name} (#{@entity.ports.size} ports)"
82
84
 
@@ -14,7 +14,7 @@ class GenericLexer
14
14
  end
15
15
 
16
16
  def keyword str
17
- @rules.unshift [str.to_sym,/#{str}\b/]
17
+ @rules.unshift [str.to_sym,/#{str}\b/i]
18
18
  end
19
19
 
20
20
  def token hash
@@ -56,7 +56,7 @@ class GenericLexer
56
56
  tokens << next_token() while not @ssc.eos?
57
57
  # while not @ssc.eos?
58
58
  # tokens << (p next_token)
59
- # end
59
+ # end #usefull for debug
60
60
  tokens
61
61
  end
62
62
  end
@@ -1,42 +1,145 @@
1
1
  require_relative 'generic_lexer'
2
+ require_relative 'generic_parser'
2
3
 
3
- class Lexer < GenericLexer
4
- def initialize
5
- super
6
- ignore /\s+/
4
+ module VHDL_TB
5
+ class Lexer < GenericLexer
6
+ def initialize
7
+ super
8
+ keyword 'abs'
9
+ keyword 'access'
10
+ keyword 'after'
11
+ keyword 'alias'
12
+ keyword 'all'
13
+ keyword 'and'
14
+ keyword 'architecture'
15
+ keyword 'array'
16
+ keyword 'assert'
17
+ keyword 'attribute'
18
+ keyword 'begin'
19
+ keyword 'block'
20
+ keyword 'body'
21
+ keyword 'buffer'
22
+ keyword 'bus'
23
+ keyword 'case'
24
+ keyword 'component'
25
+ keyword 'configuration'
26
+ keyword 'constant'
27
+ keyword 'disconnect'
28
+ keyword 'downto'
29
+ keyword 'else'
30
+ keyword 'elsif'
31
+ keyword 'end'
32
+ keyword 'entity'
33
+ keyword 'exit'
34
+ keyword 'file'
35
+ keyword 'for'
36
+ keyword 'function'
37
+ keyword 'generate'
38
+ keyword 'generic'
39
+ keyword 'group'
40
+ keyword 'guarded'
41
+ keyword 'if'
42
+ keyword 'impure'
43
+ keyword 'inertial'
44
+ keyword 'inout'
45
+ keyword 'in'
46
+ keyword 'is'
47
+ keyword 'label'
48
+ keyword 'library'
49
+ keyword 'linkage'
50
+ keyword 'literal'
51
+ keyword 'loop'
52
+ keyword 'map'
53
+ keyword 'mod'
54
+ keyword 'nand'
55
+ keyword 'natural'
56
+ keyword 'integer'
57
+ keyword 'boolean'
58
+ keyword 'positive'
59
+ keyword 'new'
60
+ keyword 'next'
61
+ keyword 'nor'
62
+ keyword 'not'
63
+ keyword 'null'
64
+ keyword 'of'
65
+ keyword 'on'
66
+ keyword 'open'
67
+ keyword 'or'
68
+ keyword 'others'
69
+ keyword 'out'
70
+ keyword 'package'
71
+ keyword 'port'
72
+ keyword 'postponed'
73
+ keyword 'procedure'
74
+ keyword 'process'
75
+ keyword 'pure'
76
+ keyword 'range'
77
+ keyword 'record'
78
+ keyword 'register'
79
+ keyword 'reject'
80
+ keyword 'report'
81
+ keyword 'return'
82
+ keyword 'rol'
83
+ keyword 'ror'
84
+ keyword 'select'
85
+ keyword 'severity'
86
+ keyword 'signal'
87
+ keyword 'shared'
88
+ keyword 'sla'
89
+ keyword 'sli'
90
+ keyword 'sra'
91
+ keyword 'srl'
92
+ keyword 'subtype'
93
+ keyword 'then'
94
+ keyword 'to'
95
+ keyword 'transport'
96
+ keyword 'type'
97
+ keyword 'unaffected'
98
+ keyword 'units'
99
+ keyword 'until'
100
+ keyword 'use'
101
+ keyword 'variable'
102
+ keyword 'wait'
103
+ keyword 'when'
104
+ keyword 'while'
105
+ keyword 'with'
106
+ keyword 'xnor'
107
+ keyword 'xorkeyword '
7
108
 
8
- #comments
9
- token :comment => /--(.*)$/
109
+ #.............................................................
110
+ token :comments => /\A\-\-(.*)$/
111
+ token :selected_name => /\w+(\.\w+)+/ # /\S+\w+\.\w+/
112
+ token :identifier => /[a-zA-Z]\w*/
10
113
 
11
- #....keywords
12
- keyword :entity
13
- keyword :is
14
- keyword :generic
15
- keyword :port
16
- keyword :in
17
- keyword :to
18
- keyword :downto
19
- keyword :out
20
- keyword :end
21
- keyword :architecture
22
- keyword :of
114
+ token :string_literal => /"[^"]*"/
115
+ token :char_literal => /'(\w+)'/
116
+ token :attribute_literal => /'(\w+)/
117
+ token :decimal_literal => /\d+(\.\d+)?(E([+-]?)\d+)?/
118
+ token :based_literal => /\d+#\w+(\.\w+)?#(E[+-]?\d+)/
119
+ token :bit_string_literal => /(b|o|x)"[^_]\w+"/
120
+ token :vassign => /\A\:\=/
121
+ token :comma => /\A\,/
122
+ token :colon => /\A\:/
123
+ token :semicolon => /\A\;/
124
+ token :lparen => /\A\(/
125
+ token :rparen => /\A\)/
126
+ token :plus => /\A\+/
127
+ token :minus => /\A\-/
128
+ token :times => /\A\*/
23
129
 
24
- #punctuation
25
- token :vassign => /\:\=/
26
- token :sassign => /\<\=/
27
- token :lparen => /\(/
28
- token :rparen => /\)/
29
- token :semicolon => /\;/
30
- token :colon => /\:/
31
- token :dot => /\./
32
- token :comma => /\,/
33
- token :rightarrow => /\=\>/
34
- token :"-" => /\-/
35
- token :"=" => /\=/
36
- #terminals
37
- token :id => /[a-zA-Z_][a-zA-Z0-9_]*/i
38
- token :int_lit => /[0-9]+/
39
- token :char_lit => /'[a-zA-Z0-9_]*'/
40
- token :str_lit => /\"(.*)\"/
41
- end
42
- end
130
+ token :sassign => /\A\<\=/
131
+ token :imply => /\A\=\>/
132
+ token :eq => /\A\=/
133
+ token :ampersand => /\A\&/
134
+ token :neq => /\A\/\=/
135
+ token :gte => /\A\>\=/
136
+ token :gt => /\A\>/
137
+ token :lt => /\A\</
138
+ token :urange => /\A<>/
139
+ #............................................................
140
+ token :newline => /[\n]/
141
+ token :space => /[ \t\r]+/
142
+
143
+ end #def
144
+ end #class
145
+ end #module
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require_relative 'generic_parser'
2
3
  require_relative 'ast'
3
4
  require_relative 'lexer'
@@ -11,20 +12,27 @@ module VHDL_TB
11
12
  attr_accessor :basename,:filename
12
13
 
13
14
  def initialize
15
+ #@verbose=true
14
16
  @lexer=Lexer.new
15
17
  end
16
18
 
17
- def parse filename
18
- str=IO.read(filename)
19
+ def lex filename
20
+ unless File.exists?(filename)
21
+ raise "ERROR : cannot find file '#{filename}'"
22
+ end
19
23
  begin
20
- @tokens=lexer.tokenize(str)
21
- @tokens=tokens.select{|t| t.class==Token} # filters [nil,nil,nil]
22
- @tokens=tokens.reject{|tok| tok.is_a? [:comment,:newline]}
24
+ str=IO.read(filename)
25
+ tokens=lexer.tokenize(str)
26
+ tokens=tokens.select{|t| t.class==Token} # filters [nil,nil,nil]
27
+ return tokens.reject{|tok| tok.is_a? [:comment,:newline,:space]}
23
28
  rescue Exception=>e
24
- puts e
25
29
  puts "an error occured during LEXICAL analysis. Sorry. Aborting."
26
30
  raise
27
31
  end
32
+ end
33
+
34
+ def parse filename
35
+ @tokens=lex(filename)
28
36
  root=Root.new([])
29
37
  begin
30
38
  consume_to :entity
@@ -34,7 +42,7 @@ module VHDL_TB
34
42
  root.design_units << archi=parse_architecture
35
43
 
36
44
  rescue Exception => e
37
- #puts e.backtrace
45
+ puts e.backtrace
38
46
  puts e
39
47
  puts "an error occured during SYNTACTIC analysis (around line #{showNext.pos.first}). Sorry. Aborting."
40
48
  raise
@@ -54,7 +62,7 @@ module VHDL_TB
54
62
  def parse_entity
55
63
  entity=Entity.new(nil,nil,[])
56
64
  expect :entity
57
- entity.name=expect :id
65
+ entity.name=expect :identifier
58
66
  expect :is
59
67
  if showNext.is_a? :generic
60
68
  entity.generics=parse_generics
@@ -63,6 +71,9 @@ module VHDL_TB
63
71
  entity.ports=parse_ports
64
72
  end
65
73
  expect :end
74
+ if showNext.is_a? :semicolon
75
+ acceptIt
76
+ end
66
77
  return entity
67
78
  end
68
79
 
@@ -84,10 +95,10 @@ module VHDL_TB
84
95
 
85
96
  def parse_generic
86
97
  ids=[]
87
- ids << expect(:id)
98
+ ids << expect(:identifier)
88
99
  while showNext.is_a? :comma
89
100
  acceptIt
90
- ids << expect(:id)
101
+ ids << expect(:identifier)
91
102
  end
92
103
  expect :colon
93
104
  type=parse_type
@@ -116,10 +127,10 @@ module VHDL_TB
116
127
 
117
128
  def parse_io
118
129
  ids=[]
119
- ids << expect(:id)
130
+ ids << expect(:identifier)
120
131
  while showNext.is_a? :comma
121
132
  acceptIt
122
- ids << expect(:id)
133
+ ids << expect(:identifier)
123
134
  end
124
135
  expect :colon
125
136
  if showNext.is_a? [:in,:out]
@@ -132,7 +143,7 @@ module VHDL_TB
132
143
 
133
144
  def parse_type
134
145
  type=Identifier.new
135
- type.tok=expect(:id)
146
+ type.tok=expect(:identifier)
136
147
  if showNext.is_a? :lparen
137
148
  acceptIt
138
149
  name=type.tok
@@ -153,11 +164,11 @@ module VHDL_TB
153
164
  end
154
165
 
155
166
  def parse_term
156
- if showNext.is_a? [:int_lit,:id]
167
+ if showNext.is_a? [:decimal_literal,:identifier]
157
168
  case showNext.kind
158
- when :int_lit
169
+ when :decimal_literal
159
170
  return IntLit.new(acceptIt)
160
- when :id
171
+ when :identifier
161
172
  return Identifier.new(acceptIt)
162
173
  else
163
174
  puts "cannot parse term"
@@ -168,9 +179,9 @@ module VHDL_TB
168
179
  def parse_architecture
169
180
  archi=Architecture.new
170
181
  expect :architecture
171
- archi.name=expect(:id)
182
+ archi.name=expect(:identifier)
172
183
  expect :of
173
- archi.entity=expect(:id)
184
+ archi.entity=expect(:identifier)
174
185
  archi
175
186
  end
176
187
  end
@@ -40,6 +40,10 @@ class Token
40
40
  Token.new [:id,str,[0,0]]
41
41
  end
42
42
 
43
+ # def inspect
44
+ # "(#{@kind.to_s.ljust(15,' ')},'#{@val}',#{@pos})"
45
+ # end
46
+
43
47
  def to_s
44
48
  val
45
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vhdl_tb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Christophe Le Lann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple testbench generator for VHDL
14
14
  email: jean-christophe.le_lann@ensta-bretagne.fr
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  requirements: []
51
51
  rubyforge_project:
52
- rubygems_version: 2.6.14
52
+ rubygems_version: 2.7.7
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: VHDL Testbench generator