soc_maker 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/History.txt +4 -0
  4. data/LICENSE +678 -0
  5. data/README.rdoc +228 -0
  6. data/Rakefile +46 -0
  7. data/bin/soc_maker_cli +80 -0
  8. data/bin/soc_maker_parser +85 -0
  9. data/core_lib/cores/adv_debug_sys/01_adv_debug_sys.yaml +245 -0
  10. data/core_lib/cores/or1200_rel2/01_or1200.yaml +208 -0
  11. data/core_lib/cores/or1200_rel2/02_or1200_files.yaml +421 -0
  12. data/core_lib/cores/or1200_rel2/03_or1200_sparam.yaml +188 -0
  13. data/core_lib/cores/or1200_rel2/or1200_defines.v.in +1799 -0
  14. data/core_lib/cores/ram_wb/ram_wb.yaml +102 -0
  15. data/core_lib/cores/ram_wb/ram_wb_b3.v.in +259 -0
  16. data/core_lib/cores/uart16550/01_uart16550.yaml +99 -0
  17. data/core_lib/cores/uart16550/02_uart16550_files.yaml +70 -0
  18. data/core_lib/cores/wb_connect/minsoc_tc_top.v +1802 -0
  19. data/core_lib/cores/wb_connect/wb_connect.yaml +733 -0
  20. data/core_lib/inc.yaml +13 -0
  21. data/core_lib/interfaces/clk_rst/clk.yaml +9 -0
  22. data/core_lib/interfaces/clk_rst/rst.yaml +9 -0
  23. data/core_lib/interfaces/clk_rst/single.yaml +7 -0
  24. data/core_lib/interfaces/debug/debug.yaml +32 -0
  25. data/core_lib/interfaces/jtag/jtag.yaml +13 -0
  26. data/core_lib/interfaces/jtag/jtag_tap.yaml +22 -0
  27. data/core_lib/interfaces/power/or_power.yaml +25 -0
  28. data/core_lib/interfaces/uart/uart.yaml +21 -0
  29. data/core_lib/interfaces/wishbone/wishbone_ma_b3.yaml +54 -0
  30. data/core_lib/interfaces/wishbone/wishbone_sl_b3.yaml +51 -0
  31. data/doc/class_arch.uml +5113 -0
  32. data/doc/fig/hierarchical.svg +273 -0
  33. data/examples/or1200_test/or1200_test.cmd +78 -0
  34. data/examples/or1200_test/or1200_test.rb +136 -0
  35. data/examples/or1200_test/rtl/or1200_test_top.vhd +274 -0
  36. data/examples/or1200_test/rtl/s3astarter.ucf +10 -0
  37. data/examples/or1200_test/rtl/xilinx_internal_jtag.v +438 -0
  38. data/examples/or1200_test/rtl/xilinx_internal_jtag_options.v +12 -0
  39. data/examples/or1200_test/sw/README.txt +35 -0
  40. data/examples/or1200_test/sw/bin2vmem.c +159 -0
  41. data/examples/or1200_test/sw/board.h +24 -0
  42. data/examples/or1200_test/sw/compile.sh +18 -0
  43. data/examples/or1200_test/sw/except.S +152 -0
  44. data/examples/or1200_test/sw/int.c +79 -0
  45. data/examples/or1200_test/sw/int.h +14 -0
  46. data/examples/or1200_test/sw/interconnect.h +17 -0
  47. data/examples/or1200_test/sw/interrupts.c +14 -0
  48. data/examples/or1200_test/sw/main.c +16 -0
  49. data/examples/or1200_test/sw/or1200.h +454 -0
  50. data/examples/or1200_test/sw/orp.ld +60 -0
  51. data/examples/or1200_test/sw/reset.S +112 -0
  52. data/examples/or1200_test/sw/support.c +123 -0
  53. data/examples/or1200_test/sw/support.h +33 -0
  54. data/examples/or1200_test/sw/tick.c +30 -0
  55. data/examples/or1200_test/sw/tick.h +2 -0
  56. data/examples/or1200_test/sw/uart.c +136 -0
  57. data/examples/or1200_test/sw/uart.h +126 -0
  58. data/lib/soc_maker.rb +324 -0
  59. data/lib/soc_maker/cli.rb +544 -0
  60. data/lib/soc_maker/conf.rb +310 -0
  61. data/lib/soc_maker/core_def.rb +579 -0
  62. data/lib/soc_maker/core_inst.rb +305 -0
  63. data/lib/soc_maker/err.rb +211 -0
  64. data/lib/soc_maker/hdl_coder.rb +500 -0
  65. data/lib/soc_maker/hdl_file.rb +166 -0
  66. data/lib/soc_maker/hdl_parser.rb +431 -0
  67. data/lib/soc_maker/ifc_def.rb +193 -0
  68. data/lib/soc_maker/ifc_port.rb +133 -0
  69. data/lib/soc_maker/ifc_spc.rb +180 -0
  70. data/lib/soc_maker/lib.rb +289 -0
  71. data/lib/soc_maker/lib_inc.rb +109 -0
  72. data/lib/soc_maker/parameter.rb +149 -0
  73. data/lib/soc_maker/soc_def.rb +847 -0
  74. data/lib/soc_maker/sparameter.rb +289 -0
  75. data/lib/soc_maker/version.rb +8 -0
  76. data/lib/soc_maker/ypp.rb +130 -0
  77. data/soc_maker.gemspec +28 -0
  78. data/spec/cli_cmds1.txt +39 -0
  79. data/spec/cli_spec.rb +49 -0
  80. data/spec/conf_spec.rb +44 -0
  81. data/spec/core_def_spec.rb +503 -0
  82. data/spec/core_inst_spec.rb +169 -0
  83. data/spec/hdl_file_spec.rb +154 -0
  84. data/spec/hdl_parser_spec.rb +201 -0
  85. data/spec/ifc_def_spec.rb +121 -0
  86. data/spec/ifc_port_spec.rb +92 -0
  87. data/spec/ifc_spc_spec.rb +196 -0
  88. data/spec/lib_inc_spec.rb +99 -0
  89. data/spec/lib_spec.rb +209 -0
  90. data/spec/parameter_spec.rb +86 -0
  91. data/spec/soc_def_spec.rb +611 -0
  92. data/spec/soc_maker_spec.rb +7 -0
  93. data/spec/sparameter_spec.rb +182 -0
  94. data/spec/spec_helper.rb +78 -0
  95. data/spec/test_soc.yaml +105 -0
  96. data/spec/test_soc2.yaml +60 -0
  97. data/spec/test_soc_lib/cores/core_A_rel1/00_core_a.yaml +75 -0
  98. data/spec/test_soc_lib/cores/core_A_rel1/01_core_a.yaml +57 -0
  99. data/spec/test_soc_lib/cores/core_A_rel1/core_a.vhd +29 -0
  100. data/spec/test_soc_lib/cores/core_A_rel1/core_a_pkg.vhd.src +3 -0
  101. data/spec/test_soc_lib/cores/core_A_rel1/core_a_pkg2.vhd.src +4 -0
  102. data/spec/test_soc_lib/cores/core_A_rel1/core_a_pkg3.v.src +6 -0
  103. data/spec/test_soc_lib/cores/core_B_rel1/core_b.vhd +25 -0
  104. data/spec/test_soc_lib/cores/core_B_rel1/core_b.yaml +36 -0
  105. data/spec/test_soc_lib/cores/core_C_v1/core_C.vhd +57 -0
  106. data/spec/test_soc_lib/cores/core_C_v1/core_c.yaml +42 -0
  107. data/spec/test_soc_lib/cores/soc_A/soc_A.yaml +12 -0
  108. data/spec/test_soc_lib/cores/soc_maker_include.yaml +6 -0
  109. data/spec/test_soc_lib/ifcs/core_AB_ifc/bidir_ifc.yaml +19 -0
  110. data/spec/test_soc_lib/ifcs/core_AB_ifc/core_AB_ifc.yaml +15 -0
  111. data/spec/test_soc_lib/ifcs/core_AB_ifc/top_ifc.yaml +9 -0
  112. data/spec/test_soc_lib/soc_maker_include.yaml +4 -0
  113. data/spec/yaml_examples.rb +367 -0
  114. data/spec/ypp_spec.rb +156 -0
  115. data/test/test_soc_maker.rb +0 -0
  116. metadata +255 -0
@@ -0,0 +1,169 @@
1
+ ###############################################################
2
+ #
3
+ # File: core_inst_spec.rb
4
+ #
5
+ # Author: Christian Hättich
6
+ #
7
+ # Project: System-On-Chip Maker
8
+ #
9
+ # Target: Linux / Windows / Mac
10
+ #
11
+ # Language: ruby
12
+ #
13
+ #
14
+ ###############################################################
15
+ #
16
+ #
17
+ # Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
18
+ #
19
+ # This program is free software: you can redistribute it and/or modify
20
+ # it under the terms of the GNU General Public License as published by
21
+ # the Free Software Foundation, either version 3 of the License, or
22
+ # (at your option) any later version.
23
+ #
24
+ # This program is distributed in the hope that it will be useful,
25
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ # GNU General Public License for more details.
28
+ #
29
+ # You should have received a copy of the GNU General Public License
30
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+ #
32
+ #
33
+ ###############################################################
34
+ #
35
+ # Description:
36
+ #
37
+ #
38
+ #
39
+ #
40
+ ###############################################################
41
+ require_relative( 'spec_helper' )
42
+
43
+
44
+ describe SOCMaker::CoreInst do
45
+
46
+
47
+ before( :each ) do
48
+
49
+ p1 = SOCMaker::IfcPort.new( "p1", 12 )
50
+ @core = SOCMaker::CoreDef.new( "mycore", "mycore,rel1", "core_top",
51
+ "interfaces" => { "my_ifc" => SOCMaker::IfcDef.new( "i1", "i1,v1", 0, { m_p1: p1 } ) },
52
+ "inst_parameters" => { "param1".to_sym => SOCMaker::Parameter.new( "integer" ) } )
53
+
54
+
55
+ ifc_spc = SOCMaker::IfcSpc.new( "Ifc 1", "i1,v1", 'ports' => { p1:{dir:1} } )
56
+ SOCMaker::lib.add_ifc( ifc_spc )
57
+ SOCMaker::lib.add_core( @core )
58
+ end
59
+
60
+ after( :each ) do
61
+ SOCMaker::lib.clear
62
+ end
63
+
64
+
65
+ describe "#initialize" do
66
+
67
+ it "raises an error, if the type is nil" do
68
+ # add with nil type
69
+ expect{ SOCMaker::CoreInst.new( nil, { "aparameter".to_sym => 4 } ) } .
70
+ to raise_error( SOCMaker::ERR::InitError )
71
+ end
72
+
73
+ context "creates an instance" do
74
+ # add with mycore,rel1 type
75
+ subject{ SOCMaker::CoreInst.new( "mycore,rel1", { "aparameter".to_sym => 4 } ) }
76
+ its( :class ) { should == SOCMaker::CoreInst }
77
+ its( :type ) { should == :"mycore,rel1" }
78
+ end
79
+
80
+ it "raises an error, if parameters are not given as hash" do
81
+ expect{ SOCMaker::CoreInst.new( "mycorerel1", "not a hash" ) }.
82
+ to raise_error( SOCMaker::ERR::InitError )
83
+ end
84
+
85
+
86
+ it "raises an error, if parameters are given, which doesn't exist in the definition" do
87
+ expect{ inst = SOCMaker::CoreInst.new( "mycore,rel1", { "aparameter".to_sym => 4 } )
88
+ inst.consistence_check }.
89
+ to raise_error( SOCMaker::ERR::ConsistenceError )
90
+ end
91
+
92
+ it "auto-completes generics with default values" do
93
+
94
+ inst = SOCMaker::CoreInst.new( "mycore,rel1", {} )
95
+ inst.consistence_check
96
+ expect( inst.params[ :param1 ] ).to be == 0
97
+ end
98
+ end
99
+
100
+ describe "object handling, en-decoding:" do
101
+
102
+ it "should be possible to encode and decode a core instance" do
103
+ o1 = SOCMaker::CoreInst.new( "mycore,rel1", {} )
104
+ yaml_str = o1.to_yaml
105
+ o2 = YAML::load( yaml_str )
106
+ expect( o1 ).to eq( o2 )
107
+ end
108
+
109
+ it "should return false for two non-equal objects" do
110
+ o1 = SOCMaker::CoreInst.new( "mycore,rel1" )
111
+ o1.consistence_check
112
+ o2 = Marshal::load(Marshal.dump(o1))
113
+ o2.type = ( o2.type.to_s + "X" ).to_sym
114
+ expect( o2 == o1 ).to eq( false )
115
+ o2 = Marshal::load(Marshal.dump(o1))
116
+ o2.params[ :param1 ] = 1
117
+ expect( o2 == o1 ).to eq( false )
118
+ end
119
+ end
120
+
121
+
122
+
123
+ describe "#consistence_check" do
124
+ it "raises an error, if a core def doesn't exist" do
125
+ expect{ SOCMaker::CoreInst.new( "mycore,rel2", {} ).consistence_check }
126
+ .to raise_error( SOCMaker::ERR::ConsistenceError )
127
+ end
128
+ end
129
+
130
+
131
+ describe "#core_definition" do
132
+ before( :each ) do
133
+ @soc = SOCMaker::SOCDef.new( "mysoc", "mysoc,v1", "soc_top" )
134
+ SOCMaker::lib.add_core( @soc )
135
+ @inst = SOCMaker::CoreInst.new( "mycore,rel1", {} )
136
+ @inst.consistence_check
137
+ end
138
+ end
139
+
140
+
141
+
142
+ describe "#port_length" do
143
+ before( :each ) do
144
+ p1 = SOCMaker::IfcPort.new( "p1", 21 )
145
+
146
+ @inst1 = SOCMaker::CoreInst.new( "mycore,rel1", {} )
147
+ @soc = SOCMaker::SOCDef.new( "mysoc", "mysoc,v1", "soc_top",
148
+ "interfaces" => { "my_ifc" => SOCMaker::IfcDef.new( "i1", "i1,v1", 0, { m_p1: p1 } ) },
149
+ "cores" => { core_inst: @inst1 } )
150
+
151
+ SOCMaker::lib.add_core( @soc )
152
+
153
+ @inst2 = SOCMaker::CoreInst.new( "mysoc,v1", {} )
154
+ @inst2.consistence_check
155
+ end
156
+
157
+ it "returns the correct port length" do
158
+ expect( @inst1.port_length( "my_ifc", :p1 ) ).to be( 12 )
159
+ end
160
+
161
+ end
162
+
163
+
164
+
165
+ end
166
+
167
+
168
+
169
+ # vim: noai:ts=2:sw=2
@@ -0,0 +1,154 @@
1
+ ###############################################################
2
+ #
3
+ # File: hdl_file_spec.rb
4
+ #
5
+ # Author: Christian Hättich
6
+ #
7
+ # Project: System-On-Chip Maker
8
+ #
9
+ # Target: Linux / Windows / Mac
10
+ #
11
+ # Language: ruby
12
+ #
13
+ #
14
+ ###############################################################
15
+ #
16
+ #
17
+ # Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
18
+ #
19
+ # This program is free software: you can redistribute it and/or modify
20
+ # it under the terms of the GNU General Public License as published by
21
+ # the Free Software Foundation, either version 3 of the License, or
22
+ # (at your option) any later version.
23
+ #
24
+ # This program is distributed in the hope that it will be useful,
25
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ # GNU General Public License for more details.
28
+ #
29
+ # You should have received a copy of the GNU General Public License
30
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+ #
32
+ #
33
+ ###############################################################
34
+ #
35
+ # Description:
36
+ # Test specification for SOCMaker::HDLFile
37
+ #
38
+ #
39
+ #
40
+ ###############################################################
41
+ require_relative( 'spec_helper' )
42
+
43
+ require "yaml_examples.rb"
44
+
45
+
46
+
47
+ describe SOCMaker::HDLFile do
48
+
49
+ include_context "yaml examples"
50
+
51
+ describe "#initialize" do
52
+
53
+ context "with the minimum number of input argumnets" do
54
+ subject{ SOCMaker::HDLFile.new( "./path/to/file.vhd" ) }
55
+ its( :class ) { should == SOCMaker::HDLFile }
56
+ its( :use_syn ) { should == true }
57
+ its( :use_mod_sim ) { should == true }
58
+ its( :use_sys_sim ) { should == true }
59
+ end
60
+
61
+
62
+ it "raise an error, if an invalid file type is provided" do
63
+ expect { SOCMaker::HDLFile.new( "./path/to/invalid_file.vhx" ) }.
64
+ to raise_error( SOCMaker::ERR::InitError )
65
+ end
66
+
67
+ it "raise an error, if no path is given (empty string)" do
68
+ expect { SOCMaker::HDLFile.new( "" ) }.
69
+ to raise_error( SOCMaker::ERR::InitError )
70
+ end
71
+
72
+ it "raise an error, if no path is given (nil)" do
73
+ expect { SOCMaker::HDLFile.new( nil ) }.
74
+ to raise_error( SOCMaker::ERR::InitError )
75
+ end
76
+
77
+ it "raise an error, if path is not a string" do
78
+ expect { SOCMaker::HDLFile.new( 3 ) }.
79
+ to raise_error( SOCMaker::ERR::InitError )
80
+ end
81
+
82
+ it "raise an error, if use_syn is not boolean" do
83
+ expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_syn" => "not boolean" ) }.
84
+ to raise_error( SOCMaker::ERR::InitError )
85
+ end
86
+
87
+ it "raise an error, if use_sys_sim is not boolean" do
88
+ expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_sys_sim" => "not boolean" ) }.
89
+ to raise_error( SOCMaker::ERR::InitError )
90
+ end
91
+
92
+ it "raise an error, if use_mod_sim is not boolean" do
93
+ expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", "use_mod_sim" => "not boolean" ) }.
94
+ to raise_error( SOCMaker::ERR::InitError )
95
+ end
96
+
97
+ it "auto-detect verilog files" do
98
+ o = SOCMaker::HDLFile.new( "./path/to/file.v" )
99
+ expect( o.type ).to eq( "verilog" )
100
+ end
101
+
102
+ it "auto-detect vhdl files" do
103
+ o = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
104
+ expect( o.type ).to eq( "vhdl" )
105
+ end
106
+
107
+ %w[ use_syn use_sys_sim use_mod_sim ].each do |m|
108
+ it "raise an error if #{m} is not false or true" do
109
+ expect { SOCMaker::HDLFile.new( "./path/to/file.vhd", { m => 4 } ) }.
110
+ to raise_error( SOCMaker::ERR::InitError )
111
+ end
112
+ end
113
+
114
+
115
+ end
116
+
117
+ describe "object handling" do
118
+ describe "via SOCMaker::from_s" do
119
+ it "raise an error, if the HDL file info is nil" do
120
+ expect { SOCMaker::from_s( @F_MIN_YAML_FIlE_NIL ) }.
121
+ to raise_error( SOCMaker::ERR::InitError )
122
+ end
123
+
124
+ it "raise an error, if an invalid file type is given" do
125
+ expect { SOCMaker::from_s( @F_YAML_FILE_TYPE ) }.
126
+ to raise_error( SOCMaker::ERR::InitError )
127
+ end
128
+ end
129
+
130
+
131
+ it "return false for two non-equal objects" do
132
+ o1 = SOCMaker::HDLFile.new( "./path/to/file.vhd" )
133
+ o2 = Marshal::load(Marshal.dump(o1))
134
+ o2.use_syn = !o2.use_syn
135
+ expect( o2 == o1 ).to be( false )
136
+ end
137
+
138
+ it "be possible to encode and decode a HDL file object" do
139
+ o1 = SOCMaker::HDLFile.new( "./path/to/file.vhd",
140
+ 'use_syn' => false,
141
+ 'use_mod_sim' => false,
142
+ 'use_sys_sim' => false )
143
+ yaml_str = o1.to_yaml
144
+ o2 = YAML::load( yaml_str )
145
+ expect( o1 ).to eq( o2 )
146
+ end
147
+ end
148
+
149
+
150
+ end
151
+
152
+
153
+ # vim: noai:ts=2:sw=2
154
+
@@ -0,0 +1,201 @@
1
+ ###############################################################
2
+ #
3
+ # File: hd_parser_spec.rb
4
+ #
5
+ # Author: Christian Hättich
6
+ #
7
+ # Project: System-On-Chip Maker
8
+ #
9
+ # Target: Linux / Windows / Mac
10
+ #
11
+ # Language: ruby
12
+ #
13
+ #
14
+ ###############################################################
15
+ #
16
+ #
17
+ # Copyright (C) 2015 Christian Hättich - feddischson [ at ] opencores.org
18
+ #
19
+ # This program is free software: you can redistribute it and/or modify
20
+ # it under the terms of the GNU General Public License as published by
21
+ # the Free Software Foundation, either version 3 of the License, or
22
+ # (at your option) any later version.
23
+ #
24
+ # This program is distributed in the hope that it will be useful,
25
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ # GNU General Public License for more details.
28
+ #
29
+ # You should have received a copy of the GNU General Public License
30
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+ #
32
+ #
33
+ ###############################################################
34
+ #
35
+ # Description:
36
+ # Test specification for SOCMaker::HDLFile
37
+ #
38
+ #
39
+ #
40
+ ###############################################################
41
+ require_relative( 'spec_helper' )
42
+
43
+
44
+
45
+
46
+ describe SOCMaker::HDLParser do
47
+
48
+ before( :each ){ @inst = SOCMaker::HDLParser.instance }
49
+
50
+
51
+ describe "#get_extension" do
52
+ it "returns '.vhd' for a vhdl file" do
53
+ expect( @inst.get_extension( "./some/file.vhd" ) ).to eq( ".vhd")
54
+ end
55
+ it "returns '.v' for a verilog file" do
56
+ expect( @inst.get_extension( "./some/file.v" ) ).to eq( ".v")
57
+ end
58
+ end
59
+
60
+
61
+ describe "#parse_core" do
62
+ it "should return a string" do
63
+ result = SOCMaker::HDLParser.instance.parse_core(
64
+ "spec/test_soc_lib/cores/core_A_rel1/core_a.vhd",
65
+ "spec/test_soc_lib/cores/core_A_rel1/*.vhd" )
66
+ expect( result ).to be_a( String )
67
+ end
68
+ end
69
+
70
+
71
+ end
72
+
73
+
74
+ describe SOCMaker::VHDLParser do
75
+
76
+ before( :each ){
77
+ @inst = SOCMaker::VHDLParser.instance
78
+ @example = "
79
+ entity mux is
80
+ generic(
81
+ w1 : natural := 4;
82
+ w2 : natural := 4;
83
+ wx : std_logic_vector( 123-1 downto 0 )
84
+ );
85
+ port (
86
+ din_0 :in std_logic_vector( 4-1 downto 0 ); -- first input
87
+ din_1 :in std_logic_vector( w1-1 downto 0 ); -- second input
88
+ sel :in std_logic;-- Select input 1
89
+ mux_out :out std_logic_vector( 4-1-3+2+1 downto 0 ); -- Mux output
90
+ sel2 : std_logic; -- Select input 2 (unused at the moment)
91
+ sel3 : std_logic_vector( 3 to 5 ) -- Select input 3 (unused at the moment)
92
+ );
93
+ end entity;
94
+
95
+ architecture behavior of mux is
96
+
97
+ begin
98
+ with (sel) select
99
+ mux_out <= din_0 when '0',
100
+ din_1 when others;
101
+ end architecture; "
102
+
103
+ }
104
+
105
+ describe "#parse_toplevel" do
106
+
107
+ it "returns extracts all necessary information" do
108
+
109
+ result = @inst.parse_toplevel( @example )
110
+ expect( result ).to eq(
111
+ { :name =>"mux",
112
+ :generic => {
113
+ "w1" => { :type=>"natural", :name=>"w1", :default=>"4"},
114
+ "w2" => { :type=>"natural", :name=>"w2", :default=>"4"},
115
+ "wx" => { :type=>"std_logic_vector", :name=>"wx", :range=>" 123-1 downto 0 "}
116
+ },
117
+ :port =>
118
+ { "din_0" => { :name=>"din_0", :type=>"std_logic_vector", :direction=>"in", :range=>" 4-1 downto 0 "},
119
+ "din_1" => { :name=>"din_1", :type=>"std_logic_vector", :direction=>"in", :range=>" w1-1 downto 0 "},
120
+ "sel" => { :name=>"sel", :type=>"std_logic", :direction=>"in" },
121
+ "sel2" => { :name=>"sel2", :type=>"std_logic", :direction=>"in" },
122
+ "mux_out"=> { :name=>"mux_out", :type=>"std_logic_vector", :direction=>"out", :range=>" 4-1-3+2+1 downto 0 "},
123
+ "sel3" => { :name=>"sel3", :type=>"std_logic_vector", :direction=>"in", :range=>" 3 to 5 "} } } )
124
+
125
+ end
126
+
127
+ it "should extract the length information" do
128
+
129
+ result = @inst.parse_toplevel( @example )
130
+ result = @inst.extract_length( result )
131
+
132
+ expect( result[ :port][ "din_0" ][ :length ] ).to equal( 4 )
133
+ expect( result[ :port][ "din_1" ][ :length ] ).to eq( "w1" )
134
+ expect( result[ :port][ "sel" ][ :length ] ).to equal( 1 )
135
+ expect( result[ :port][ "sel2" ][ :length ] ).to equal( 1 )
136
+ expect( result[ :port][ "sel3" ][ :length ] ).to equal( 3 )
137
+ expect( result[ :port][ "mux_out" ] [ :length ] ).to equal( 4 )
138
+
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ describe SOCMaker::VerilogParser do
146
+
147
+ before( :each ){
148
+ @inst = SOCMaker::VerilogParser.instance
149
+ @example = "
150
+
151
+ module mux( din_0, din_1, sel, mux_out );
152
+ parameter w1 = 4;
153
+ parameter w2 = 4;
154
+ input [4-1 : 0] din_0;
155
+ input [w1-1 : 0] din_1;
156
+ input sel;
157
+ input sel2;
158
+ input [4:3] sel3;
159
+ output [4-1:0] mux_out;
160
+
161
+ wire mux_out;
162
+ assign mux_out = (sel) ? din_1 : din_0;
163
+ endmodule "
164
+ }
165
+
166
+ it "returns extracts all necessary information" do
167
+
168
+ result = @inst.parse_toplevel( @example )
169
+ expect( result ).to eq(
170
+ { :name => "mux",
171
+ :generic => {
172
+ "w1" => { :name =>"w1", :default =>"4", :type=>"integer"},
173
+ "w2" => { :name =>"w2", :default =>"4", :type=>"integer"} },
174
+ :port=>{ "din_0" => { :name=>"din_0", :dir=>"in", :range=>"4-1 : 0" },
175
+ "din_1" => { :name=>"din_1", :dir=>"in", :range=>"w1-1 : 0" },
176
+ "sel" => { :name=>"sel", :dir=>"in"},
177
+ "sel2" => { :name=>"sel2", :dir=>"in"},
178
+ "sel3" => { :name=>"sel3", :dir=>"in", :range=>"4:3"},
179
+ "mux_out" => { :name=>"mux_out", :dir=>"out", :range=>"4-1:0"} } } )
180
+ end
181
+
182
+
183
+
184
+
185
+ it "should extract the length information" do
186
+
187
+ result = @inst.parse_toplevel( @example )
188
+ result = @inst.extract_length( result )
189
+
190
+
191
+ expect( result[ :port][ "din_0" ][ :length ] ).to equal( 4 )
192
+ expect( result[ :port][ "din_1" ][ :length ] ).to eq( "w1" )
193
+ expect( result[ :port][ "sel" ][ :length ] ).to equal( 1 )
194
+ expect( result[ :port][ "sel2" ][ :length ] ).to equal( 1 )
195
+ expect( result[ :port][ "sel3" ][ :length ] ).to equal( 2 )
196
+ expect( result[ :port][ "mux_out" ] [ :length ] ).to equal( 4 )
197
+
198
+ end
199
+
200
+
201
+ end