vertigo_vhdl 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/vertigo +7 -0
- data/lib/vertigo.rb +4 -0
- data/lib/vertigo/ast.rb +87 -0
- data/lib/vertigo/ast_vertigo_rkgen.rb +607 -0
- data/lib/vertigo/code.rb +57 -0
- data/lib/vertigo/compiler.rb +61 -0
- data/lib/vertigo/generic_lexer.rb +61 -0
- data/lib/vertigo/generic_parser.rb +44 -0
- data/lib/vertigo/indent.rb +20 -0
- data/lib/vertigo/lexer.rb +172 -0
- data/lib/vertigo/parser.rb +1458 -0
- data/lib/vertigo/pretty_printer.rb +749 -0
- data/lib/vertigo/runner.rb +115 -0
- data/lib/vertigo/tb_generator.rb +81 -0
- data/lib/vertigo/template.tb.vhd +72 -0
- data/lib/vertigo/token.rb +67 -0
- data/lib/vertigo/version.rb +3 -0
- data/lib/vertigo/vertigo.rkg +354 -0
- data/lib/vertigo/visitor_vertigo_rkgen.rb +447 -0
- data/tests/ghdl_tests/fsm.vhd +98 -0
- data/tests/ghdl_tests/fsm_synth.vhd +248 -0
- data/tests/ghdl_tests/test_fsm.vhd +162 -0
- data/tests/parser_tests/else.vhd +64 -0
- data/tests/parser_tests/test_MUST_fail.vhd +1 -0
- data/tests/parser_tests/test_accelerator.vhd +160 -0
- data/tests/parser_tests/test_accelerator_pp.vhd +144 -0
- data/tests/parser_tests/test_aggregate.vhd +17 -0
- data/tests/parser_tests/test_aggregate_pp.vhd +15 -0
- data/tests/parser_tests/test_archi_1.vhd +45 -0
- data/tests/parser_tests/test_archi_1_pp.vhd +41 -0
- data/tests/parser_tests/test_array_array_00.vhd +25 -0
- data/tests/parser_tests/test_array_array_00_pp.vhd +25 -0
- data/tests/parser_tests/test_array_urange.vhd +25 -0
- data/tests/parser_tests/test_array_urange_pp.vhd +25 -0
- data/tests/parser_tests/test_chu-1.vhd +80 -0
- data/tests/parser_tests/test_chu-1_pp.vhd +104 -0
- data/tests/parser_tests/test_concat.vhd +11 -0
- data/tests/parser_tests/test_concat_pp.vhd +14 -0
- data/tests/parser_tests/test_counter.vhd +35 -0
- data/tests/parser_tests/test_counter_pp.vhd +35 -0
- data/tests/parser_tests/test_de2.vhd +358 -0
- data/tests/parser_tests/test_de2_pp.vhd +274 -0
- data/tests/parser_tests/test_encode.vhd +2679 -0
- data/tests/parser_tests/test_encode_pp.vhd +2549 -0
- data/tests/parser_tests/test_fsm.vhd +162 -0
- data/tests/parser_tests/test_fsm_pp.vhd +125 -0
- data/tests/parser_tests/test_fsm_synth.vhd +248 -0
- data/tests/parser_tests/test_fsm_synth_pp.vhd +197 -0
- data/tests/parser_tests/test_function-01.vhd +33 -0
- data/tests/parser_tests/test_function-01_pp.vhd +18 -0
- data/tests/parser_tests/test_lfsr.vhd +75 -0
- data/tests/parser_tests/test_lfsr_pp.vhd +44 -0
- data/tests/parser_tests/test_microwatt_cache_ram.vhd +1 -0
- data/tests/parser_tests/test_microwatt_cache_ram_pp.vhd +68 -0
- data/tests/parser_tests/test_microwatt_common.vhd +1 -0
- data/tests/parser_tests/test_microwatt_common_pp.vhd +336 -0
- data/tests/parser_tests/test_microwatt_control.vhd +1 -0
- data/tests/parser_tests/test_microwatt_control_pp.vhd +187 -0
- data/tests/parser_tests/test_microwatt_core.vhd +1 -0
- data/tests/parser_tests/test_microwatt_core_debug.vhd +1 -0
- data/tests/parser_tests/test_microwatt_core_debug_pp.vhd +104 -0
- data/tests/parser_tests/test_microwatt_core_pp.vhd +231 -0
- data/tests/parser_tests/test_microwatt_core_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_core_tb_pp.vhd +43 -0
- data/tests/parser_tests/test_microwatt_countzero.vhd +1 -0
- data/tests/parser_tests/test_microwatt_countzero_pp.vhd +120 -0
- data/tests/parser_tests/test_microwatt_countzero_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_countzero_tb_pp.vhd +70 -0
- data/tests/parser_tests/test_microwatt_cr_file.vhd +1 -0
- data/tests/parser_tests/test_microwatt_cr_file_pp.vhd +74 -0
- data/tests/parser_tests/test_microwatt_cr_hazard.vhd +1 -0
- data/tests/parser_tests/test_microwatt_cr_hazard_pp.vhd +51 -0
- data/tests/parser_tests/test_microwatt_crhelpers.vhd +1 -0
- data/tests/parser_tests/test_microwatt_crhelpers_pp.vhd +48 -0
- data/tests/parser_tests/test_microwatt_dcache.vhd +1 -0
- data/tests/parser_tests/test_microwatt_dcache_pp.vhd +481 -0
- data/tests/parser_tests/test_microwatt_dcache_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_dcache_tb_pp.vhd +98 -0
- data/tests/parser_tests/test_microwatt_decode1.vhd +1 -0
- data/tests/parser_tests/test_microwatt_decode1_pp.vhd +138 -0
- data/tests/parser_tests/test_microwatt_decode2.vhd +1 -0
- data/tests/parser_tests/test_microwatt_decode2_pp.vhd +300 -0
- data/tests/parser_tests/test_microwatt_decode_types.vhd +1 -0
- data/tests/parser_tests/test_microwatt_decode_types_pp.vhd +67 -0
- data/tests/parser_tests/test_microwatt_divider.vhd +1 -0
- data/tests/parser_tests/test_microwatt_divider_pp.vhd +132 -0
- data/tests/parser_tests/test_microwatt_divider_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_divider_tb_pp.vhd +95 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_dummy.vhd +1 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_dummy_pp.vhd +29 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_tb_pp.vhd +197 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_xilinx.vhd +1 -0
- data/tests/parser_tests/test_microwatt_dmi_dtm_xilinx_pp.vhd +139 -0
- data/tests/parser_tests/test_microwatt_execute1.vhd +1 -0
- data/tests/parser_tests/test_microwatt_execute1_pp.vhd +689 -0
- data/tests/parser_tests/test_microwatt_fetch1.vhd +1 -0
- data/tests/parser_tests/test_microwatt_fetch1_pp.vhd +88 -0
- data/tests/parser_tests/test_microwatt_fetch2.vhd +1 -0
- data/tests/parser_tests/test_microwatt_fetch2_pp.vhd +79 -0
- data/tests/parser_tests/test_microwatt_glibc_random.vhd +1 -0
- data/tests/parser_tests/test_microwatt_glibc_random_helpers.vhd +1 -0
- data/tests/parser_tests/test_microwatt_glibc_random_helpers_pp.vhd +25 -0
- data/tests/parser_tests/test_microwatt_glibc_random_pp.vhd +41 -0
- data/tests/parser_tests/test_microwatt_gpr_hazard.vhd +1 -0
- data/tests/parser_tests/test_microwatt_gpr_hazard_pp.vhd +68 -0
- data/tests/parser_tests/test_microwatt_helpers.vhd +1 -0
- data/tests/parser_tests/test_microwatt_helpers_pp.vhd +153 -0
- data/tests/parser_tests/test_microwatt_icache.vhd +1 -0
- data/tests/parser_tests/test_microwatt_icache_pp.vhd +337 -0
- data/tests/parser_tests/test_microwatt_icache_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_icache_tb_pp.vhd +104 -0
- data/tests/parser_tests/test_microwatt_insn_helpers.vhd +1 -0
- data/tests/parser_tests/test_microwatt_insn_helpers_pp.vhd +208 -0
- data/tests/parser_tests/test_microwatt_loadstore1.vhd +1 -0
- data/tests/parser_tests/test_microwatt_loadstore1_pp.vhd +222 -0
- data/tests/parser_tests/test_microwatt_logical.vhd +1 -0
- data/tests/parser_tests/test_microwatt_logical_pp.vhd +87 -0
- data/tests/parser_tests/test_microwatt_multiply.vhd +1 -0
- data/tests/parser_tests/test_microwatt_multiply_pp.vhd +84 -0
- data/tests/parser_tests/test_microwatt_multiply_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_multiply_tb_pp.vhd +75 -0
- data/tests/parser_tests/test_microwatt_plru.vhd +1 -0
- data/tests/parser_tests/test_microwatt_plru_pp.vhd +46 -0
- data/tests/parser_tests/test_microwatt_plru_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_plru_tb_pp.vhd +93 -0
- data/tests/parser_tests/test_microwatt_ppc_fx_insns.vhd +1 -0
- data/tests/parser_tests/test_microwatt_ppc_fx_insns_pp.vhd +665 -0
- data/tests/parser_tests/test_microwatt_register_file.vhd +1 -0
- data/tests/parser_tests/test_microwatt_register_file_pp.vhd +86 -0
- data/tests/parser_tests/test_microwatt_rotator.vhd +1 -0
- data/tests/parser_tests/test_microwatt_rotator_pp.vhd +149 -0
- data/tests/parser_tests/test_microwatt_rotator_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_rotator_tb_pp.vhd +134 -0
- data/tests/parser_tests/test_microwatt_sim_bram.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_bram_helpers.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_bram_helpers_pp.vhd +52 -0
- data/tests/parser_tests/test_microwatt_sim_bram_pp.vhd +53 -0
- data/tests/parser_tests/test_microwatt_sim_console.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_console_pp.vhd +43 -0
- data/tests/parser_tests/test_microwatt_sim_jtag.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_jtag_pp.vhd +64 -0
- data/tests/parser_tests/test_microwatt_sim_jtag_socket.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_jtag_socket_pp.vhd +36 -0
- data/tests/parser_tests/test_microwatt_sim_uart.vhd +1 -0
- data/tests/parser_tests/test_microwatt_sim_uart_pp.vhd +90 -0
- data/tests/parser_tests/test_microwatt_soc.vhd +1 -0
- data/tests/parser_tests/test_microwatt_soc_pp.vhd +195 -0
- data/tests/parser_tests/test_microwatt_utils.vhd +1 -0
- data/tests/parser_tests/test_microwatt_utils_pp.vhd +39 -0
- data/tests/parser_tests/test_microwatt_wishbone_arbiter.vhd +1 -0
- data/tests/parser_tests/test_microwatt_wishbone_arbiter_pp.vhd +54 -0
- data/tests/parser_tests/test_microwatt_wishbone_bram_tb.vhd +1 -0
- data/tests/parser_tests/test_microwatt_wishbone_bram_tb_pp.vhd +157 -0
- data/tests/parser_tests/test_microwatt_wishbone_bram_wrapper.vhd +1 -0
- data/tests/parser_tests/test_microwatt_wishbone_bram_wrapper_pp.vhd +62 -0
- data/tests/parser_tests/test_microwatt_wishbone_debug_master.vhd +1 -0
- data/tests/parser_tests/test_microwatt_wishbone_debug_master_pp.vhd +124 -0
- data/tests/parser_tests/test_microwatt_wishbone_types.vhd +1 -0
- data/tests/parser_tests/test_microwatt_wishbone_types_pp.vhd +38 -0
- data/tests/parser_tests/test_microwatt_writeback.vhd +1 -0
- data/tests/parser_tests/test_microwatt_writeback_pp.vhd +87 -0
- data/tests/parser_tests/test_package-1.vhd +68 -0
- data/tests/parser_tests/test_package-1_pp.vhd +53 -0
- data/tests/parser_tests/test_precedence.vhd +13 -0
- data/tests/parser_tests/test_precedence_pp.vhd +16 -0
- data/tests/parser_tests/test_selected_sig.vhd +14 -0
- data/tests/parser_tests/test_selected_sig_pp.vhd +10 -0
- data/tests/parser_tests/test_slice.vhd +15 -0
- data/tests/parser_tests/test_slice_pp.vhd +16 -0
- data/tests/parser_tests/test_tb-00.vhd +94 -0
- data/tests/parser_tests/test_tb-00_pp.vhd +71 -0
- data/tests/parser_tests/test_type_decl_02.vhd +9 -0
- data/tests/parser_tests/test_type_decl_02_pp.vhd +11 -0
- data/tests/parser_tests/test_use.vhd +7 -0
- data/tests/parser_tests/test_use_pp.vhd +10 -0
- data/tests/parser_tests/test_while_1.vhd +38 -0
- data/tests/parser_tests/test_while_1_pp.vhd +26 -0
- data/tests/parser_tests/test_with-00.vhd +21 -0
- data/tests/parser_tests/test_with-00_pp.vhd +12 -0
- data/tests/tb_gen_tests/test_accelerator.vhd +160 -0
- metadata +224 -0
@@ -0,0 +1,749 @@
|
|
1
|
+
require_relative 'code'
|
2
|
+
|
3
|
+
module Vertigo
|
4
|
+
|
5
|
+
class PrettyPrinter
|
6
|
+
|
7
|
+
def print ast
|
8
|
+
code=Code.new
|
9
|
+
code << "-- generated by Vertigo VHDL tool"
|
10
|
+
code << ast.accept(self)
|
11
|
+
code
|
12
|
+
end
|
13
|
+
|
14
|
+
def visitRoot(root,args=nil)
|
15
|
+
code=Code.new
|
16
|
+
root.design_units.each{|design_unit_| code << design_unit_.accept(self,args)}
|
17
|
+
code
|
18
|
+
end
|
19
|
+
|
20
|
+
def visitToken token,args=nil
|
21
|
+
token.val
|
22
|
+
end
|
23
|
+
|
24
|
+
def visitComment(comment_,args=nil)
|
25
|
+
"-- #{comment_.str}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def visitLibrary(library,args=nil)vhdl=Code.new
|
29
|
+
name=library.name.accept(self,args)
|
30
|
+
"library #{name};"
|
31
|
+
end
|
32
|
+
|
33
|
+
def visitUse(use,args=nil)
|
34
|
+
library=use.library.accept(self,args)
|
35
|
+
package=use.package.accept(self,args)
|
36
|
+
element=use.element.accept(self,args)
|
37
|
+
"use #{library}.#{package}.#{element};"
|
38
|
+
end
|
39
|
+
|
40
|
+
def visitEntity(entity,args=nil)
|
41
|
+
code=Code.new
|
42
|
+
name=entity.name.accept(self,args)
|
43
|
+
code.newline
|
44
|
+
code << "entity #{name} is"
|
45
|
+
code.indent=2
|
46
|
+
if entity.generics.any?
|
47
|
+
code << "generic("
|
48
|
+
code.indent=4
|
49
|
+
entity.generics.each{|generic_| code << generic_.accept(self,args)}
|
50
|
+
code.indent=2
|
51
|
+
code << ");"
|
52
|
+
end
|
53
|
+
if entity.ports.any?
|
54
|
+
code << "port("
|
55
|
+
code.indent=4
|
56
|
+
entity.ports.each{|port_| code << port_.accept(self,args)}
|
57
|
+
code.indent=2
|
58
|
+
code << ");"
|
59
|
+
end
|
60
|
+
code.indent=0
|
61
|
+
code << "end entity #{name};"
|
62
|
+
code.newline
|
63
|
+
code
|
64
|
+
end
|
65
|
+
|
66
|
+
def visitGeneric(generic,args=nil)
|
67
|
+
name=generic.name.accept(self,args)
|
68
|
+
type=generic.type.accept(self,args)
|
69
|
+
init=generic.init.accept(self,args) if generic.init
|
70
|
+
init+=" := #{init}" if init
|
71
|
+
"#{name} : #{type}#{init};"
|
72
|
+
end
|
73
|
+
|
74
|
+
def visitInput(input,args=nil)
|
75
|
+
name=input.name.accept(self,args)
|
76
|
+
type=input.type.accept(self,args)
|
77
|
+
init=input.init.accept(self,args) if input.init
|
78
|
+
"#{name} : in #{type}#{init};"
|
79
|
+
end
|
80
|
+
|
81
|
+
def visitOutput(output,args=nil)
|
82
|
+
name=output.name.accept(self,args)
|
83
|
+
type=output.type.accept(self,args)
|
84
|
+
init=output.init.accept(self,args) if output.init
|
85
|
+
"#{name} : out #{type}#{init};"
|
86
|
+
end
|
87
|
+
|
88
|
+
def visitInOut(inout,args=nil)
|
89
|
+
name=inout.name.accept(self,args)
|
90
|
+
type=inout.type.accept(self,args)
|
91
|
+
init=inout.init.accept(self,args) if inout.init
|
92
|
+
"#{name} : inout #{type}#{init};"
|
93
|
+
end
|
94
|
+
|
95
|
+
# ====================================================
|
96
|
+
def visitPackage package_,args=nil
|
97
|
+
name=package_.name.accept(self,args)
|
98
|
+
code=Code.new
|
99
|
+
code.newline
|
100
|
+
code << "package #{name} is"
|
101
|
+
code.indent=2
|
102
|
+
package_.decls.each{|decl_| code << decl_.accept(self,args)}
|
103
|
+
code.indent=0
|
104
|
+
code.newline
|
105
|
+
code << "end #{name};"
|
106
|
+
code.newline
|
107
|
+
code
|
108
|
+
end
|
109
|
+
|
110
|
+
def visitPackageBody(packagebody_,args=nil)
|
111
|
+
name=packagebody_.name.accept(self,args)
|
112
|
+
code=Code.new
|
113
|
+
code << "package body #{name} is"
|
114
|
+
code.indent=2
|
115
|
+
packagebody_.decls.each{|decl_| code << decl_.accept(self,args)}
|
116
|
+
code.indent=0
|
117
|
+
code << "end #{name};"
|
118
|
+
code
|
119
|
+
end
|
120
|
+
|
121
|
+
def visitProcedureDecl(proceduredecl_,args=nil)
|
122
|
+
name=proceduredecl_.name.accept(self,args)
|
123
|
+
code=Code.new
|
124
|
+
code.newline
|
125
|
+
code << "procedure #{name}("
|
126
|
+
code.indent=2
|
127
|
+
proceduredecl_.formal_args.map{|formal_arg_| code << formal_arg_.accept(self,args)+";"}
|
128
|
+
code.indent=0
|
129
|
+
code.last << ")"
|
130
|
+
if proceduredecl_.decls.any? or !proceduredecl_.body.nil?
|
131
|
+
code.last << " is"
|
132
|
+
decls=proceduredecl_.decls.each{|decl_| decl_.accept(self,args)}
|
133
|
+
body =proceduredecl_.body.accept(self,args) if proceduredecl_.body
|
134
|
+
code.indent=2
|
135
|
+
code << decls
|
136
|
+
code.indent=0
|
137
|
+
code << "begin"
|
138
|
+
code.indent=2
|
139
|
+
code << body
|
140
|
+
code.indent=0
|
141
|
+
code << "end #{name};"
|
142
|
+
else
|
143
|
+
code.last << ";"
|
144
|
+
end
|
145
|
+
code
|
146
|
+
end
|
147
|
+
|
148
|
+
def visitFormalArg formalarg_,args=nil
|
149
|
+
sig =formalarg_.signal.accept(self,args) if formalarg_.signal
|
150
|
+
dir =formalarg_.direction.accept(self,args) if formalarg_.direction
|
151
|
+
dir+=" " if dir
|
152
|
+
name=formalarg_.name.accept(self,args)
|
153
|
+
type=formalarg_.type.accept(self,args)
|
154
|
+
"#{sig}#{name} : #{dir}#{type}"
|
155
|
+
end
|
156
|
+
|
157
|
+
def visitProcedureCall(procedurecall_,args=nil)
|
158
|
+
name=procedurecall_.name.accept(self,args)
|
159
|
+
args=name=procedurecall_.actual_args.map{|actual_arg_| actual_arg_.accept(self,args)}.join(',')
|
160
|
+
args="(#{args})" if args
|
161
|
+
"#{name}#{args}"
|
162
|
+
end
|
163
|
+
|
164
|
+
# ====================================================
|
165
|
+
def visitArchitecture(architecture,args=nil)
|
166
|
+
code=Code.new
|
167
|
+
name=architecture.name.accept(self,args)
|
168
|
+
entity_name=architecture.entity_name.accept(self,args)
|
169
|
+
body=architecture.body.accept(self,args) if architecture.body
|
170
|
+
|
171
|
+
code << "architecture #{name} of #{entity_name} is"
|
172
|
+
code.indent=2
|
173
|
+
architecture.decls.each{|decl_| code << decl_.accept(self,args)}
|
174
|
+
code.indent=0
|
175
|
+
code << "begin"
|
176
|
+
code.newline
|
177
|
+
code.indent=2
|
178
|
+
code << body
|
179
|
+
code.indent=0
|
180
|
+
code << "end #{name};"
|
181
|
+
code
|
182
|
+
end
|
183
|
+
|
184
|
+
def visitTypeDecl type_decl,args=nil
|
185
|
+
name=type_decl.name.accept(self)
|
186
|
+
type_spec=type_decl.spec.accept(self)
|
187
|
+
code=Code.new
|
188
|
+
code.newline
|
189
|
+
code << "type #{name} is #{type_spec};"
|
190
|
+
code.newline
|
191
|
+
code
|
192
|
+
end
|
193
|
+
|
194
|
+
def visitSubTypeDecl sub_type_decl,args=nil
|
195
|
+
name=sub_type_decl.name.accept(self)
|
196
|
+
type_spec=sub_type_decl.spec.accept(self)
|
197
|
+
code=Code.new
|
198
|
+
code.newline
|
199
|
+
code << "subtype #{name} is #{type_spec};"
|
200
|
+
code.newline
|
201
|
+
code
|
202
|
+
end
|
203
|
+
|
204
|
+
def visitEnumDecl enum,args=nil
|
205
|
+
elems=enum.elements.map{|e| e.accept(self)}
|
206
|
+
"(#{elems.join(',')})"
|
207
|
+
end
|
208
|
+
|
209
|
+
def visitRecordDecl rec,args=nil
|
210
|
+
code=Code.new
|
211
|
+
code << "record"
|
212
|
+
code.indent=4
|
213
|
+
rec.elements.map{|e| code << e.accept(self)}
|
214
|
+
code.indent=2
|
215
|
+
code << "end record"
|
216
|
+
code.finalize
|
217
|
+
end
|
218
|
+
|
219
|
+
def visitRecordItem ri,args=nil
|
220
|
+
name=ri.name.accept(self)
|
221
|
+
type=ri.type.accept(self)
|
222
|
+
"#{name} : #{type};"
|
223
|
+
end
|
224
|
+
|
225
|
+
def visitArrayDecl(arraydecl_,args=nil)
|
226
|
+
ranges=arraydecl_.dim_decls.map{|dim_decl_| dim_decl_.accept(self,args)}
|
227
|
+
type=arraydecl_.type.accept(self)
|
228
|
+
"array(#{ranges.join(',')}) of #{type}"
|
229
|
+
end
|
230
|
+
|
231
|
+
def visitArrayDimDecl(arraydimdecl_,args=nil)
|
232
|
+
type_mark=arraydimdecl_.type_mark.accept(self)+" " if arraydimdecl_.type_mark
|
233
|
+
type_mark_range="#{type_mark}range " if arraydimdecl_.type_mark
|
234
|
+
range=arraydimdecl_.range.accept(self,args)
|
235
|
+
"#{type_mark_range}#{range}"
|
236
|
+
end
|
237
|
+
|
238
|
+
def visitConstant cst,args=nil
|
239
|
+
name=cst.name.accept(self)
|
240
|
+
type=cst.type.accept(self)
|
241
|
+
expr=cst.expr.accept(self)
|
242
|
+
"constant #{name} : #{type} := #{expr};"
|
243
|
+
end
|
244
|
+
|
245
|
+
def visitSignal signal,args=nil
|
246
|
+
name=signal.name.accept(self)
|
247
|
+
type=signal.type.accept(self)
|
248
|
+
init=signal.init.accept(self) if signal.init
|
249
|
+
init=" := #{init}" if init
|
250
|
+
"signal #{name} : #{type}#{init};"
|
251
|
+
end
|
252
|
+
|
253
|
+
def visitVariable variable,args=nil
|
254
|
+
name=variable.name.accept(self)
|
255
|
+
type=variable.type.accept(self)
|
256
|
+
init=variable.init.accept(self) if variable.init
|
257
|
+
init=" := #{init}" if init
|
258
|
+
"variable #{name} : #{type}#{init};"
|
259
|
+
end
|
260
|
+
|
261
|
+
def visitAlias(alias_,args=nil)
|
262
|
+
designator= alias_.designator.accept(self,args)
|
263
|
+
type = alias_.type.accept(self,args)
|
264
|
+
name = alias_.name.accept(self,args)
|
265
|
+
signature = alias_.signature.accept(self,args) if alias_.signature
|
266
|
+
"alias #{designator} : #{type} is #{name} #{};"
|
267
|
+
end
|
268
|
+
|
269
|
+
def visitBody(body,args=nil)
|
270
|
+
code=Code.new
|
271
|
+
body.elements.each{|element_| code << element_.accept(self,args)}
|
272
|
+
code
|
273
|
+
end
|
274
|
+
|
275
|
+
def visitLabel label,args=nil
|
276
|
+
id=label.ident.accept(self)
|
277
|
+
"#{id} : "
|
278
|
+
end
|
279
|
+
|
280
|
+
def visitIf if_,args=nil
|
281
|
+
label=if_.label.accept(self) if if_.label
|
282
|
+
cond=if_.cond.accept(self)
|
283
|
+
body=if_.body.accept(self)
|
284
|
+
elsifs_=if_.elsifs.map{|elsif_| elsif_.accept(self)} if if_.elsifs.any?
|
285
|
+
else_=if_.else_.accept(self) if if_.else_
|
286
|
+
code=Code.new
|
287
|
+
code << "#{label}if #{cond} then"
|
288
|
+
code.indent=2
|
289
|
+
code << body
|
290
|
+
code.indent=0
|
291
|
+
if if_.elsifs.any?
|
292
|
+
elsifs_.each{|elsif_| code << elsif_}
|
293
|
+
end
|
294
|
+
if if_.else_
|
295
|
+
code << else_
|
296
|
+
end
|
297
|
+
code << "end if;"
|
298
|
+
code
|
299
|
+
end
|
300
|
+
|
301
|
+
def visitElsif elsif_,args=nil
|
302
|
+
cond=elsif_.cond.accept(self)
|
303
|
+
body=elsif_.body.accept(self)
|
304
|
+
code=Code.new
|
305
|
+
code << "elsif #{cond} then"
|
306
|
+
code.indent=2
|
307
|
+
code << body
|
308
|
+
code.indent=0
|
309
|
+
code
|
310
|
+
end
|
311
|
+
|
312
|
+
def visitElse else_,args=nil
|
313
|
+
body=else_.body.accept(self)
|
314
|
+
code=Code.new
|
315
|
+
code << "else"
|
316
|
+
code.indent=2
|
317
|
+
code << body
|
318
|
+
code.indent=0
|
319
|
+
code
|
320
|
+
end
|
321
|
+
|
322
|
+
def visitCase case_,args=nil
|
323
|
+
expr=case_.expr.accept(self)
|
324
|
+
whens=case_.whens.map{|when_| when_.accept(self)}
|
325
|
+
code=Code.new
|
326
|
+
code << "case #{expr} is"
|
327
|
+
code.indent=2
|
328
|
+
case_.whens.map{|when_| code << when_.accept(self)}
|
329
|
+
code.indent=0
|
330
|
+
code << "end case;"
|
331
|
+
code
|
332
|
+
end
|
333
|
+
|
334
|
+
def visitCaseWhen cwhen,args=nil
|
335
|
+
expr=cwhen.expr.accept(self)
|
336
|
+
body=cwhen.body.accept(self)
|
337
|
+
code=Code.new
|
338
|
+
code << "when #{expr} =>"
|
339
|
+
code.indent=2
|
340
|
+
code << body
|
341
|
+
code.indent=0
|
342
|
+
code
|
343
|
+
end
|
344
|
+
|
345
|
+
def visitAlternative(alternative_,args=nil)
|
346
|
+
alternative_.elements.map{|element_| element_.accept(self,args)}.join(" | ")
|
347
|
+
end
|
348
|
+
|
349
|
+
def visitNullStmt null_,args=nil
|
350
|
+
"null;"
|
351
|
+
end
|
352
|
+
|
353
|
+
def visitAssert assert,args=nil
|
354
|
+
cond=assert.cond.accept(self)
|
355
|
+
repo=assert.report.accept(self) if assert.report
|
356
|
+
code=Code.new
|
357
|
+
code << "assert #{cond}"
|
358
|
+
code.indent=2
|
359
|
+
code << repo if repo
|
360
|
+
code.indent=0
|
361
|
+
code.last << ";"
|
362
|
+
code
|
363
|
+
end
|
364
|
+
|
365
|
+
def visitReport report,args=nil
|
366
|
+
expr=report.expr.accept(self)
|
367
|
+
sevr=report.severity.accept(self) if report.severity
|
368
|
+
severity=" severity #{sevr}" if sevr
|
369
|
+
"report #{expr}#{severity};"
|
370
|
+
end
|
371
|
+
|
372
|
+
def visitReturn(return_,args=nil)
|
373
|
+
expr=return_.expr.accept(self,args) if return_.expr
|
374
|
+
expr=" #{expr}" if expr
|
375
|
+
"return#{expr};"
|
376
|
+
end
|
377
|
+
|
378
|
+
def visitWithSelect(withselect_,args=nil)
|
379
|
+
expr=withselect_.with_expr.accept(self,args)
|
380
|
+
assigned=withselect_.assigned.accept(self,args)
|
381
|
+
|
382
|
+
code=Code.new
|
383
|
+
code << "with #{expr} select #{assigned} <="
|
384
|
+
code.indent=2
|
385
|
+
withselect_.selected_whens.each{|selected_when_| code << selected_when_.accept(self,args)+","}
|
386
|
+
code.indent=0
|
387
|
+
code.last << ";"
|
388
|
+
code
|
389
|
+
end
|
390
|
+
|
391
|
+
def visitSelectedWhen(selectedwhen_,args=nil)
|
392
|
+
lhs=selectedwhen_.lhs.accept(self,args)
|
393
|
+
rhs=selectedwhen_.rhs.accept(self,args)
|
394
|
+
"#{lhs} when #{rhs}"
|
395
|
+
end
|
396
|
+
|
397
|
+
def visitIfGenerate(ifgenerate_,args=nil)
|
398
|
+
cond=ifgenerate_.cond.accept(self,args)
|
399
|
+
body=ifgenerate_.body.accept(self,args)
|
400
|
+
code=Code.new
|
401
|
+
code << "if #{cond} generate"
|
402
|
+
code.indent=2
|
403
|
+
code << body
|
404
|
+
code.indent=0
|
405
|
+
code << "end generate;"
|
406
|
+
code
|
407
|
+
end
|
408
|
+
|
409
|
+
def visitForGenerate(forgenerate_,args=nil)
|
410
|
+
idx =forgenerate_.index.accept(self,args)
|
411
|
+
range=forgenerate_.range.accept(self,args)
|
412
|
+
decls=forgenerate_.decls.each{|decl_| decl_.accept(self,args)} if forgenerate_.decls
|
413
|
+
body =forgenerate_.body.accept(self,args)
|
414
|
+
code=Code.new
|
415
|
+
code << "for #{idx} in #{range} generate"
|
416
|
+
code.indent=2
|
417
|
+
code << decls if decls
|
418
|
+
code << body
|
419
|
+
code.indent=0
|
420
|
+
code << "end generate;"
|
421
|
+
code
|
422
|
+
end
|
423
|
+
|
424
|
+
#====================================
|
425
|
+
def visitEntityInstance inst,args=nil
|
426
|
+
code=Code.new
|
427
|
+
label=inst.label.accept(self) if inst.label
|
428
|
+
full_name=inst.full_name.accept(self)
|
429
|
+
arch_name=inst.arch_name.accept(self) if inst.arch_name
|
430
|
+
gen_map =inst.generic_map.accept(self) if inst.generic_map
|
431
|
+
port_map =inst.port_map.accept(self) if inst.port_map
|
432
|
+
code << "#{label}entity #{full_name}#{arch_name}"
|
433
|
+
code.indent=2
|
434
|
+
code << port_map
|
435
|
+
code.indent=0
|
436
|
+
code.newline
|
437
|
+
code
|
438
|
+
end
|
439
|
+
|
440
|
+
def visitPortMap port_map,args=nil
|
441
|
+
code=Code.new
|
442
|
+
code << "port map("
|
443
|
+
code.indent=2
|
444
|
+
port_map.elements.each{|e| code << e.accept(self)+","}
|
445
|
+
code.indent=0
|
446
|
+
code << ");"
|
447
|
+
code
|
448
|
+
end
|
449
|
+
|
450
|
+
def visitMap map,args=nil
|
451
|
+
lhs=map.lhs.accept(self)
|
452
|
+
rhs=map.rhs.accept(self) if map.rhs
|
453
|
+
rhs=" => #{rhs}" if rhs
|
454
|
+
"#{lhs}#{rhs}"
|
455
|
+
end
|
456
|
+
|
457
|
+
def visitAttributeDecl(attributedecl_,args=nil)
|
458
|
+
name=attributedecl_.name.accept(self,args)
|
459
|
+
type=attributedecl_.type.accept(self,args)
|
460
|
+
"attribute #{name} : #{type};"
|
461
|
+
end
|
462
|
+
|
463
|
+
def visitAttributeSpec(attributespec_,args=nil)
|
464
|
+
name =attributespec_.name.accept(self,args)
|
465
|
+
entity_spec=attributespec_.entity_spec.accept(self,args)
|
466
|
+
expr =attributespec_.expr.accept(self,args)
|
467
|
+
"attribute #{name} of #{entity_spec} is #{expr};"
|
468
|
+
end
|
469
|
+
|
470
|
+
def visitEntitySpec(entityspec_,args=nil)
|
471
|
+
elements=entityspec_.elements.map{|element_| element_.accept(self,args)}
|
472
|
+
entity_class=entityspec_.entity_class.accept(self,args)
|
473
|
+
"#{elements.join(',')} : #{entity_class}"
|
474
|
+
end
|
475
|
+
|
476
|
+
def visitGenericMap generic_map,args=nil
|
477
|
+
code=Code.new
|
478
|
+
code << "generic map("
|
479
|
+
code.indent=2
|
480
|
+
generic_map.elements.each{|e| code << e.accept(self)+","}
|
481
|
+
code.indent=0
|
482
|
+
code << ");"
|
483
|
+
code
|
484
|
+
end
|
485
|
+
|
486
|
+
def visitProcess(process,args=nil)
|
487
|
+
code=Code.new
|
488
|
+
code.newline
|
489
|
+
label=process.label.accept(self) if process.label
|
490
|
+
sensitity=process.sensitivity.accept(self,args) if process.sensitivity
|
491
|
+
sensitity="(#{sensitity})" if sensitity
|
492
|
+
body=process.body.accept(self,args) if process.body
|
493
|
+
code << "#{label}process#{sensitity}"
|
494
|
+
code.indent=2
|
495
|
+
process.decls.each{|decl_| code << decl_.accept(self,args)}
|
496
|
+
code.indent=0
|
497
|
+
code << "begin"
|
498
|
+
code.indent=2
|
499
|
+
code << body
|
500
|
+
code.indent=0
|
501
|
+
code << "end process;"
|
502
|
+
code
|
503
|
+
end
|
504
|
+
|
505
|
+
def visitSensitivity(sensitivity,args=nil)
|
506
|
+
list=sensitivity.elements.map{|element_| element_.accept(self,args)}
|
507
|
+
list.join(',')
|
508
|
+
end
|
509
|
+
|
510
|
+
def visitComponentDecl(componentdecl_,args=nil)
|
511
|
+
name=componentdecl_.name.accept(self,args)
|
512
|
+
code=Code.new
|
513
|
+
code << "component #{name} is"
|
514
|
+
code.indent=2
|
515
|
+
if componentdecl_.generics.any?
|
516
|
+
code.indent=4
|
517
|
+
code << "generic("
|
518
|
+
code.indent=6
|
519
|
+
componentdecl_.generics.map{|generic_| code << generic_.accept(self,args)}
|
520
|
+
code.indent=4
|
521
|
+
code << ");"
|
522
|
+
code.indent=2
|
523
|
+
end
|
524
|
+
code << "port("
|
525
|
+
code.indent=6
|
526
|
+
componentdecl_.ports.each{|port_| code << port_.accept(self,args)}
|
527
|
+
code.indent=4
|
528
|
+
code << ");"
|
529
|
+
code.indent=0
|
530
|
+
code << "end component;"
|
531
|
+
code
|
532
|
+
end
|
533
|
+
|
534
|
+
def visitComponentInstance(componentinstance_,args=nil)
|
535
|
+
label = componentinstance_.label.accept(self) if componentinstance_.label
|
536
|
+
name = componentinstance_.name.accept(self,args)
|
537
|
+
gen_map = componentinstance_.generic_map.accept(self,args) if componentinstance_.generic_map
|
538
|
+
port_map = componentinstance_.port_map.accept(self,args)
|
539
|
+
code=Code.new
|
540
|
+
code << "#{label}component #{name}"
|
541
|
+
code.indent=2
|
542
|
+
code << gen_map if gen_map
|
543
|
+
code << port_map
|
544
|
+
code.indent=0
|
545
|
+
code.newline
|
546
|
+
code
|
547
|
+
end
|
548
|
+
|
549
|
+
def visitSigAssign(sigassign,args=nil)
|
550
|
+
#pp sigassign
|
551
|
+
lhs=sigassign.lhs.accept(self,args)
|
552
|
+
rhs=sigassign.rhs.accept(self,args)
|
553
|
+
"#{lhs} <= #{rhs};"
|
554
|
+
end
|
555
|
+
|
556
|
+
def visitVarAssign(varassign,args=nil)
|
557
|
+
lhs=varassign.lhs.accept(self,args)
|
558
|
+
rhs=varassign.rhs.accept(self,args)
|
559
|
+
"#{lhs} := #{rhs};"
|
560
|
+
end
|
561
|
+
|
562
|
+
def visitWait(wait,args=nil)
|
563
|
+
expr=wait.until_.accept(self,args) if wait.until_
|
564
|
+
expr=wait.for_.accept(self,args) if wait.for_
|
565
|
+
"wait #{expr};"
|
566
|
+
end
|
567
|
+
|
568
|
+
def visitStdType(stdtype,args=nil)
|
569
|
+
stdtype.ident.accept(self,args)
|
570
|
+
end
|
571
|
+
|
572
|
+
def visitRangedType(rangedtype_,args=nil)
|
573
|
+
type=rangedtype_.type.accept(self,args)
|
574
|
+
range=rangedtype_.range.accept(self,args)
|
575
|
+
"#{type} range #{range}"
|
576
|
+
end
|
577
|
+
|
578
|
+
def visitNamedType(namedtype,args=nil)
|
579
|
+
namedtype.ident.accept(self,args)
|
580
|
+
end
|
581
|
+
|
582
|
+
def visitArrayType(arraytype,args=nil)
|
583
|
+
name=arraytype.name.accept(self,args)
|
584
|
+
ranges=[]
|
585
|
+
arraytype.discrete_ranges.each{|discrete_range_| ranges << discrete_range_.accept(self,args)}
|
586
|
+
"#{name}(#{ranges.join(',')})"
|
587
|
+
end
|
588
|
+
|
589
|
+
def visitDiscreteRange(discreterange,args=nil)
|
590
|
+
lhs=discreterange.lhs.accept(self,args)
|
591
|
+
dir=discreterange.dir.accept(self,args)
|
592
|
+
rhs=discreterange.rhs.accept(self,args)
|
593
|
+
"#{lhs} #{dir} #{rhs}"
|
594
|
+
end
|
595
|
+
|
596
|
+
def visitWaveform(waveform,args=nil)
|
597
|
+
elements=waveform.elements.map{|element_| element_.accept(self,args)}
|
598
|
+
elements.join(',')
|
599
|
+
end
|
600
|
+
|
601
|
+
def visitCondExpr(condexpr,args=nil)
|
602
|
+
code=Code.new
|
603
|
+
whens=condexpr.whens.map{|when_| when_.accept(self,args)}
|
604
|
+
else_=condexpr.else_.accept(self,args)
|
605
|
+
code << "#{whens.join} #{else_}"
|
606
|
+
code.finalize
|
607
|
+
end
|
608
|
+
|
609
|
+
def visitWhen(when_,args=nil)
|
610
|
+
expr=when_.expr.accept(self,args)
|
611
|
+
cond=when_.cond.accept(self,args)
|
612
|
+
"#{expr} when #{cond} else "
|
613
|
+
end
|
614
|
+
|
615
|
+
def visitBinary(binary_,args=nil)
|
616
|
+
lhs=binary_.lhs.accept(self,args)
|
617
|
+
op=binary_.op.accept(self,args)
|
618
|
+
rhs=binary_.rhs.accept(self,args)
|
619
|
+
"#{lhs} #{op} #{rhs}"
|
620
|
+
end
|
621
|
+
|
622
|
+
def visitIdent(ident,args=nil)
|
623
|
+
ident.tok.accept(self,args)
|
624
|
+
end
|
625
|
+
|
626
|
+
def visitIntLit(intlit,args=nil)
|
627
|
+
intlit.tok.accept(self,args)
|
628
|
+
end
|
629
|
+
|
630
|
+
def visitCharLit(lit,args=nil)
|
631
|
+
lit.tok.accept(self,args)
|
632
|
+
end
|
633
|
+
|
634
|
+
def visitBoolLit(boollit_,args=nil)
|
635
|
+
boollit_.tok.accept(self,args)
|
636
|
+
end
|
637
|
+
|
638
|
+
def visitSelectedName(selectedname,args=nil)
|
639
|
+
lhs=selectedname.lhs.accept(self,args)
|
640
|
+
rhs=selectedname.rhs.accept(self,args)
|
641
|
+
"#{lhs}.#{rhs}"
|
642
|
+
end
|
643
|
+
|
644
|
+
def visitAfter after,args=nil
|
645
|
+
lhs=after.lhs.accept(self,args)
|
646
|
+
rhs=after.rhs.accept(self,args)
|
647
|
+
"#{lhs} after #{rhs}"
|
648
|
+
end
|
649
|
+
|
650
|
+
def visitTimed(timed,args=nil)
|
651
|
+
lhs=timed.lhs.accept(self,args)
|
652
|
+
rhs=timed.rhs.accept(self,args)
|
653
|
+
"#{lhs} #{rhs}"
|
654
|
+
end
|
655
|
+
|
656
|
+
def visitAttributed(attributed_,args=nil)
|
657
|
+
lhs=attributed_.lhs.accept(self,args)
|
658
|
+
rhs=attributed_.rhs.accept(self,args)
|
659
|
+
"#{lhs}#{rhs}"
|
660
|
+
end
|
661
|
+
|
662
|
+
def visitConcat(concat_,args=nil)
|
663
|
+
lhs=concat_.lhs.accept(self,args)
|
664
|
+
rhs=concat_.rhs.accept(self,args)
|
665
|
+
"#{lhs} & #{rhs}"
|
666
|
+
end
|
667
|
+
|
668
|
+
def visitQualified(qualified_,args=nil)
|
669
|
+
lhs=qualified_.lhs.accept(self,args)
|
670
|
+
rhs=qualified_.rhs.accept(self,args)
|
671
|
+
"#{lhs}'#{rhs}"
|
672
|
+
end
|
673
|
+
|
674
|
+
def visitSliced(sliced_,args=nil)
|
675
|
+
exp=sliced_.expr.accept(self,args)
|
676
|
+
lhs=sliced_.lhs.accept(self,args)
|
677
|
+
dir=sliced_.dir.accept(self,args)
|
678
|
+
rhs=sliced_.rhs.accept(self,args)
|
679
|
+
"#{exp}(#{lhs} #{dir} #{rhs})"
|
680
|
+
end
|
681
|
+
|
682
|
+
def visitFuncProtoDecl(funcprotodecl_,args=nil)
|
683
|
+
name=funcprotodecl_.name.accept(self,args)
|
684
|
+
args=funcprotodecl_.formal_args.map{|formal_arg_| formal_arg_.accept(self,args)}.join(";")
|
685
|
+
type=funcprotodecl_.return_type.accept(self)
|
686
|
+
args="(#{args})" if args
|
687
|
+
"function #{name}#{args} return #{type}"
|
688
|
+
end
|
689
|
+
|
690
|
+
def visitFuncDecl(funcdecl_,args=nil)
|
691
|
+
name=funcdecl_.name.accept(self,args)
|
692
|
+
args=funcdecl_.formal_args.map{|formal_arg_| formal_arg_.accept(self,args)}.join(";")
|
693
|
+
type=funcdecl_.return_type.accept(self)
|
694
|
+
args="(#{args})" if args
|
695
|
+
code=Code.new
|
696
|
+
code.newline
|
697
|
+
code << "function #{name}#{args} return #{type} is"
|
698
|
+
code.indent=2
|
699
|
+
funcdecl_.decls.each{|decl| code << decl.accept(self)}
|
700
|
+
code.indent=0
|
701
|
+
code << "begin"
|
702
|
+
code.indent=2
|
703
|
+
code << funcdecl_.body.accept(self)
|
704
|
+
code.indent=0
|
705
|
+
code << "end function #{name};"
|
706
|
+
code
|
707
|
+
end
|
708
|
+
|
709
|
+
def visitFuncCall funcall,args=nil
|
710
|
+
name=funcall.name.accept(self)
|
711
|
+
args=funcall.actual_args.map{|arg| arg.accept(self)}.join(',')
|
712
|
+
"#{name}(#{args})"
|
713
|
+
end
|
714
|
+
|
715
|
+
def visitParenth parenth,args=nil
|
716
|
+
expr=parenth.expr.accept(self)
|
717
|
+
"(#{expr})"
|
718
|
+
end
|
719
|
+
|
720
|
+
def visitAggregate aggregate,args=nil
|
721
|
+
elems=(elements=aggregate.elements).map{|e| e.accept(self)}
|
722
|
+
# here we prototype a multiline method, for long aggregates
|
723
|
+
ret="\n\t(\n\t#{elems.join(',')})"
|
724
|
+
if ret.size>5
|
725
|
+
klasses=elements.map{|e| e.class}
|
726
|
+
#if klasses.include?(Aggregate)
|
727
|
+
code=Code.new
|
728
|
+
code << '('
|
729
|
+
code.indent=col=5
|
730
|
+
elements.each{|e|
|
731
|
+
code << e.accept(self)+","
|
732
|
+
}
|
733
|
+
code.indent=col-2
|
734
|
+
code.newline
|
735
|
+
code << ")"
|
736
|
+
ret=code.finalize
|
737
|
+
#end
|
738
|
+
end
|
739
|
+
ret
|
740
|
+
end
|
741
|
+
|
742
|
+
def visitAssoc assoc,args=nil
|
743
|
+
lhs=assoc.lhs.accept(self)
|
744
|
+
rhs=assoc.rhs.accept(self)
|
745
|
+
"(#{lhs} => #{rhs})"
|
746
|
+
end
|
747
|
+
|
748
|
+
end
|
749
|
+
end
|