Class: RubyRTL::ASTBuilder
- Inherits:
-
Object
- Object
- RubyRTL::ASTBuilder
- Defined in:
- lib/ruby_rtl/ast_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
Instance Method Summary collapse
-
#assign(var_expr_leq) ⇒ Object
syntax : ASSIGN( y <= e), instead of ASSIGN(y,e).
-
#combinatorial(label = nil, &block) ⇒ Object
(also: #comb)
here, we need a trick to evaluate the block.
- #comment(str) ⇒ Object
- #component(name_obj_or_class_h) ⇒ Object
- #differential_ast(&block) ⇒ Object
- #Else(&block) ⇒ Object
- #Elsif(cond, &block) ⇒ Object
-
#fsm(name, &block) ⇒ Object
fsm stuff.
- #If(cond, &block) ⇒ Object
-
#input(*arg) ⇒ Object
no ‘initialize’ : - @ast is not initialized here - this allows to avoid calling “super” in every circuit.
- #name ⇒ Object
- #next_state(name) ⇒ Object
- #output(*arg) ⇒ Object
- #sequential(label = nil, &block) ⇒ Object (also: #seq)
- #state(name, &block) ⇒ Object
-
#typedef(h) ⇒ Object
define a type.
- #wire(*arg) ⇒ Object (also: #signal)
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
5 6 7 |
# File 'lib/ruby_rtl/ast_builder.rb', line 5 def ast @ast end |
Instance Method Details
#assign(var_expr_leq) ⇒ Object
syntax : ASSIGN( y <= e), instead of ASSIGN(y,e)
61 62 63 64 65 |
# File 'lib/ruby_rtl/ast_builder.rb', line 61 def assign(var_expr_leq) @ast||=Root.new var,expr=var_expr_leq.lhs,var_expr_leq.rhs @ast.body << Assign.new(var,expr) end |
#combinatorial(label = nil, &block) ⇒ Object Also known as: comb
here, we need a trick to evaluate the block. we ask the current ast builder object to evaluate the block, in its current context. We then try to find the difference between ast before and after the evaluation.
96 97 98 99 |
# File 'lib/ruby_rtl/ast_builder.rb', line 96 def combinatorial(label=nil,&block) diff=differential_ast(&block) @ast.body << Combinatorial.new(name,Body.new(diff)) end |
#comment(str) ⇒ Object
42 43 44 |
# File 'lib/ruby_rtl/ast_builder.rb', line 42 def comment str (@last.comments||=[]) << Comment.new(str) end |
#component(name_obj_or_class_h) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby_rtl/ast_builder.rb', line 46 def component name_obj_or_class_h comp_name,obj_or_klass=name_obj_or_class_h.first comp_name=comp_name.to_sym if comp_name.is_a? String case klass=comp=obj_or_klass when Class comp=klass.new # but no parameters :-( end cname="@#{comp_name}" instance_variable_set(cname,comp) self.class.__send__(:attr_accessor, comp_name) @ast.body << CompDecl.new(comp_name,comp) comp end |
#differential_ast(&block) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/ruby_rtl/ast_builder.rb', line 67 def differential_ast &block before=@ast.body.stmts.clone instance_eval(&block) after=@ast.body.stmts diff=after-before @ast.body.stmts=before return diff end |
#Else(&block) ⇒ Object
86 87 88 89 |
# File 'lib/ruby_rtl/ast_builder.rb', line 86 def Else(&block) diff=differential_ast(&block) @ast.body << Else.new(Body.new(diff)) end |
#Elsif(cond, &block) ⇒ Object
81 82 83 84 |
# File 'lib/ruby_rtl/ast_builder.rb', line 81 def Elsif(cond,&block) diff=differential_ast(&block) @ast.body << Elsif.new(cond,Body.new(diff)) end |
#fsm(name, &block) ⇒ Object
fsm stuff
115 116 117 118 119 |
# File 'lib/ruby_rtl/ast_builder.rb', line 115 def fsm name, &block @has_sequential_statements=true diff=differential_ast(&block) @ast.body << Fsm.new(name,Body.new(diff)) end |
#If(cond, &block) ⇒ Object
76 77 78 79 |
# File 'lib/ruby_rtl/ast_builder.rb', line 76 def If(cond,&block) diff=differential_ast(&block) @ast.body << If.new(cond,Body.new(diff)) end |
#input(*arg) ⇒ Object
no ‘initialize’ :
- @ast is not initialized here
- this allows to avoid calling "super" in every circuit.
- dont forget the parenthesis !
13 14 15 16 |
# File 'lib/ruby_rtl/ast_builder.rb', line 13 def input *arg @ast||=Root.new process_sig_decl(:input,*arg) end |
#name ⇒ Object
111 112 113 |
# File 'lib/ruby_rtl/ast_builder.rb', line 111 def name self.class.to_s end |
#next_state(name) ⇒ Object
127 128 129 |
# File 'lib/ruby_rtl/ast_builder.rb', line 127 def next_state name @ast.body << Next.new(name) end |
#output(*arg) ⇒ Object
18 19 20 21 22 |
# File 'lib/ruby_rtl/ast_builder.rb', line 18 def output *arg @ast||=Root.new @last=@ast process_sig_decl(:output,*arg) end |
#sequential(label = nil, &block) ⇒ Object Also known as: seq
103 104 105 106 107 |
# File 'lib/ruby_rtl/ast_builder.rb', line 103 def sequential(label=nil,&block) @has_sequential_statements=true diff=differential_ast(&block) @ast.body << Sequential.new(label,Body.new(diff)) end |
#state(name, &block) ⇒ Object
121 122 123 124 125 |
# File 'lib/ruby_rtl/ast_builder.rb', line 121 def state name, &block @has_sequential_statements=true diff=differential_ast(&block) @ast.body << State.new(name,Body.new(diff)) end |
#typedef(h) ⇒ Object
define a type
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_rtl/ast_builder.rb', line 25 def typedef h @ast||=Root.new @last=@ast name_sym,definition=h.first @ast.decls << decl=TypeDecl.new(name_sym,definition) @last=decl $typedefs||={} # Global var ! $typedefs[name_sym]=definition decl end |
#wire(*arg) ⇒ Object Also known as: signal
36 37 38 |
# File 'lib/ruby_rtl/ast_builder.rb', line 36 def wire *arg process_sig_decl(:sig,*arg) end |