origen_verilog 0.2.2 → 0.3.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
2
  SHA1:
3
- metadata.gz: 3c7a81cc003052c9650effbc42a5ddb3a096399b
4
- data.tar.gz: 584f7d83ee912aa617705c30e5beb92789646c6f
3
+ metadata.gz: 46d8c90c2eace5e9de51b9391ae680e63107604e
4
+ data.tar.gz: e15f496480ad467f7c472c1179d5d7376958b6b4
5
5
  SHA512:
6
- metadata.gz: ecd84377d882d00eb80e8e4699f84fb9ec55d9fe858c2c0357ae8a13fa8cf26ac8594cfb84b378d2321c3a759f1bb8d2b35110f2bc5229ba9635f117e6d528d0
7
- data.tar.gz: 4c442636d46e2dffd3371ab0d75189936b52fcf2cde00bc323ee20e03ad4492f702383054bcaf00031d8ee78bbecc2e027572a75ecf9526b362a4f81d3a52942
6
+ metadata.gz: 4c92146efefda632b524ed0e7aac52c0c499d12e23398fb33abd2f596ffc8164b0c5cf035f18d17de2daa75ec03154dd2b7e8411c277140593014c44e3c37f1e
7
+ data.tar.gz: d7c47379ab7e2eba83b5637166f956f970feeffaac0fe1f299d35f478316dda88e4a477ce8c46b59895fc5d342d65668330812208cc8db17e24771110da7cf82
data/config/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module OrigenVerilog
2
2
  MAJOR = 0
3
- MINOR = 2
4
- BUGFIX = 2
3
+ MINOR = 3
4
+ BUGFIX = 0
5
5
  DEV = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
data/grammars/verilog.rb CHANGED
@@ -2335,6 +2335,72 @@ module OrigenVerilog
2335
2335
  r0
2336
2336
  end
2337
2337
 
2338
+ module ModuleItem0
2339
+ def port_declaration
2340
+ elements[0]
2341
+ end
2342
+
2343
+ def s
2344
+ elements[1]
2345
+ end
2346
+
2347
+ end
2348
+
2349
+ def _nt_module_item
2350
+ start_index = index
2351
+ if node_cache[:module_item].has_key?(index)
2352
+ cached = node_cache[:module_item][index]
2353
+ if cached
2354
+ node_cache[:module_item][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
2355
+ @index = cached.interval.end
2356
+ end
2357
+ return cached
2358
+ end
2359
+
2360
+ i0 = index
2361
+ i1, s1 = index, []
2362
+ r2 = _nt_port_declaration
2363
+ s1 << r2
2364
+ if r2
2365
+ r3 = _nt_s
2366
+ s1 << r3
2367
+ if r3
2368
+ if (match_len = has_terminal?(";", false, index))
2369
+ r4 = true
2370
+ @index += match_len
2371
+ else
2372
+ terminal_parse_failure('";"')
2373
+ r4 = nil
2374
+ end
2375
+ s1 << r4
2376
+ end
2377
+ end
2378
+ if s1.last
2379
+ r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
2380
+ r1.extend(ModuleItem0)
2381
+ else
2382
+ @index = i1
2383
+ r1 = nil
2384
+ end
2385
+ if r1
2386
+ r1 = SyntaxNode.new(input, (index-1)...index) if r1 == true
2387
+ r0 = r1
2388
+ else
2389
+ r5 = _nt_non_port_module_item
2390
+ if r5
2391
+ r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
2392
+ r0 = r5
2393
+ else
2394
+ @index = i0
2395
+ r0 = nil
2396
+ end
2397
+ end
2398
+
2399
+ node_cache[:module_item][start_index] = r0
2400
+
2401
+ r0
2402
+ end
2403
+
2338
2404
  module ModuleOrGenerateItem0
2339
2405
  def s1
2340
2406
  elements[0]
@@ -7738,38 +7804,38 @@ module OrigenVerilog
7738
7804
  end
7739
7805
 
7740
7806
  module VariableType0
7741
- def s
7807
+ def variable_identifier
7742
7808
  elements[0]
7743
7809
  end
7744
7810
 
7745
- def dimension
7811
+ def s1
7746
7812
  elements[1]
7747
7813
  end
7748
- end
7749
7814
 
7750
- module VariableType1
7751
- def variable_identifier
7752
- elements[0]
7815
+ def s2
7816
+ elements[3]
7753
7817
  end
7754
7818
 
7819
+ def constant_expression
7820
+ elements[4]
7821
+ end
7755
7822
  end
7756
7823
 
7757
- module VariableType2
7758
- def variable_identifier
7824
+ module VariableType1
7825
+ def s
7759
7826
  elements[0]
7760
7827
  end
7761
7828
 
7762
- def s1
7829
+ def dimension
7763
7830
  elements[1]
7764
7831
  end
7832
+ end
7765
7833
 
7766
- def s2
7767
- elements[3]
7834
+ module VariableType2
7835
+ def variable_identifier
7836
+ elements[0]
7768
7837
  end
7769
7838
 
7770
- def constant_expression
7771
- elements[4]
7772
- end
7773
7839
  end
7774
7840
 
7775
7841
  module VariableType3
@@ -7794,34 +7860,30 @@ module OrigenVerilog
7794
7860
  r2 = _nt_variable_identifier
7795
7861
  s1 << r2
7796
7862
  if r2
7797
- s3, i3 = [], index
7798
- loop do
7799
- i4, s4 = index, []
7800
- r5 = _nt_s
7801
- s4 << r5
7802
- if r5
7803
- r6 = _nt_dimension
7804
- s4 << r6
7805
- end
7806
- if s4.last
7807
- r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
7808
- r4.extend(VariableType0)
7863
+ r3 = _nt_s
7864
+ s1 << r3
7865
+ if r3
7866
+ if (match_len = has_terminal?("=", false, index))
7867
+ r4 = true
7868
+ @index += match_len
7809
7869
  else
7810
- @index = i4
7870
+ terminal_parse_failure('"="')
7811
7871
  r4 = nil
7812
7872
  end
7873
+ s1 << r4
7813
7874
  if r4
7814
- s3 << r4
7815
- else
7816
- break
7875
+ r5 = _nt_s
7876
+ s1 << r5
7877
+ if r5
7878
+ r6 = _nt_constant_expression
7879
+ s1 << r6
7880
+ end
7817
7881
  end
7818
7882
  end
7819
- r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
7820
- s1 << r3
7821
7883
  end
7822
7884
  if s1.last
7823
7885
  r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
7824
- r1.extend(VariableType1)
7886
+ r1.extend(VariableType0)
7825
7887
  else
7826
7888
  @index = i1
7827
7889
  r1 = nil
@@ -7836,26 +7898,30 @@ module OrigenVerilog
7836
7898
  r8 = _nt_variable_identifier
7837
7899
  s7 << r8
7838
7900
  if r8
7839
- r9 = _nt_s
7840
- s7 << r9
7841
- if r9
7842
- if (match_len = has_terminal?("=", false, index))
7843
- r10 = true
7844
- @index += match_len
7901
+ s9, i9 = [], index
7902
+ loop do
7903
+ i10, s10 = index, []
7904
+ r11 = _nt_s
7905
+ s10 << r11
7906
+ if r11
7907
+ r12 = _nt_dimension
7908
+ s10 << r12
7909
+ end
7910
+ if s10.last
7911
+ r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
7912
+ r10.extend(VariableType1)
7845
7913
  else
7846
- terminal_parse_failure('"="')
7914
+ @index = i10
7847
7915
  r10 = nil
7848
7916
  end
7849
- s7 << r10
7850
7917
  if r10
7851
- r11 = _nt_s
7852
- s7 << r11
7853
- if r11
7854
- r12 = _nt_constant_expression
7855
- s7 << r12
7856
- end
7918
+ s9 << r10
7919
+ else
7920
+ break
7857
7921
  end
7858
7922
  end
7923
+ r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
7924
+ s7 << r9
7859
7925
  end
7860
7926
  if s7.last
7861
7927
  r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
@@ -26,9 +26,13 @@ module OrigenVerilog
26
26
 
27
27
  # Returns an AST for the given file
28
28
  def self.parse_file(file, options = {})
29
+ top_dir = Pathname.new(file).dirname
30
+ options[:source_dirs] ||= []
31
+ options[:source_dirs] << top_dir unless options[:source_dirs].include?(top_dir)
29
32
  # Evaluates all compiler directives
30
- ast = Preprocessor::Parser.parse_file(file).process
33
+ ast = Preprocessor::Parser.parse_file(file, options).process(options)
34
+
31
35
  # Now parse as verilog
32
- Verilog::Parser.parse(ast.to_s)
36
+ Verilog::Parser.parse(ast.to_s, options)
33
37
  end
34
38
  end
@@ -8,7 +8,6 @@ module OrigenVerilog
8
8
  @name = options[:ast].to_a[0]
9
9
 
10
10
  options[:ast].pins.each do |node|
11
- name = node.to_a.last
12
11
  if node.type == :input_declaration
13
12
  direction = :input
14
13
  elsif node.type == :ouput_declaration
@@ -21,7 +20,10 @@ module OrigenVerilog
21
20
  else
22
21
  size = 1
23
22
  end
24
- add_pin name, direction: direction, size: size
23
+ n = node.to_a.dup
24
+ while n.last.is_a?(String)
25
+ add_pin n.pop, direction: direction, size: size
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -11,22 +11,45 @@ module OrigenVerilog
11
11
  end
12
12
  end
13
13
 
14
- # Returns an array containing the names of all top-level modules in
15
- # the AST
16
- def module_names
17
- find_all(:module_declaration).map { |n| n.to_a[0] }
18
- end
19
-
20
14
  # Returns an array containing the AST node for all modules in the AST
21
15
  def modules
22
16
  find_all(:module_declaration)
23
17
  end
24
18
 
19
+ # Similar to the modules method, but removes any modules which are instantiated
20
+ # within other modules, therefore leaving only those which could be considered top
21
+ # level
22
+ def top_level_modules
23
+ mods = modules
24
+ modules.reject { |m| mods.any? { |mod| mod.instantiates?(m) } }
25
+ end
26
+
27
+ # Returns true if the node instantiates the given module node or module name
28
+ def instantiates?(module_or_name)
29
+ name = module_or_name.respond_to?(:to_a) ? module_or_name.to_a[0] : module_or_name
30
+ instantiations = find_all(:module_instantiation)
31
+ if instantiations.empty?
32
+ false
33
+ else
34
+ instantiations.any? { |i| i.to_a[0].to_s == name.to_s }
35
+ end
36
+ end
37
+
25
38
  # Returns the AST node for the module with the given name
26
39
  def module(name)
27
40
  find_all(:module_declaration).find { |n| n.to_a[0].to_s == name.to_s }
28
41
  end
29
42
 
43
+ # Returns the name of the node, will raise an error if called on a node type for
44
+ # which the name extraction is not yet implemented
45
+ def name
46
+ if type == :module_declaration
47
+ to_a[0]
48
+ else
49
+ fail "Don't know how to extract the name from a #{type} node yet!"
50
+ end
51
+ end
52
+
30
53
  # Returns an array containing all input, output and inout AST nodes
31
54
  def pins
32
55
  find_all(:input_declaration, :output_declaration, :inout_declaration)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: origen_verilog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: 1.8.11
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.5.2
93
+ rubygems_version: 2.6.8
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: A parser and generator for Verilog (IEEE 1364)