class RubyRTL::ASTBuilder
Attributes
ast[RW]
Public Instance Methods
Else(&block)
click to toggle source
# 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)
click to toggle source
# 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
If(cond,&block)
click to toggle source
# 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
assign(var_expr_leq)
click to toggle source
syntax : ASSIGN( y <= e), instead of ASSIGN(y,e)
# 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)
click to toggle source
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.
# 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
Also aliased as: comb
comment(str)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 42 def comment str (@last.comments||=[]) << Comment.new(str) end
component(name_obj_or_class_h)
click to toggle source
# 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)
click to toggle source
# 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
fsm(name, &block)
click to toggle source
input(*arg)
click to toggle source
no 'initialize' :
- @ast is not initialized here - this allows to avoid calling "super" in every circuit. - dont forget the parenthesis !
# File lib/ruby_rtl/ast_builder.rb, line 13 def input *arg @ast||=Root.new process_sig_decl(:input,*arg) end
name()
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 111 def name self.class.to_s end
next_state(name)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 127 def next_state name @ast.body << Next.new(name) end
output(*arg)
click to toggle source
# 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)
click to toggle source
# 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
Also aliased as: seq
state(name, &block)
click to toggle source
# 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)
click to toggle source
define a type
# 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)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 36 def wire *arg process_sig_decl(:sig,*arg) end
Also aliased as: signal
Private Instance Methods
Case(arg,&block)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 173 def Case(arg,&block) diff=differential_ast(&block) @ast.body << Case.new(arg,Body.new(diff)) end
When(arg,&block)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 178 def When(arg,&block) diff=differential_ast(&block) @ast.body << When.new(arg,Body.new(diff)) end
decl_sig(kind,vname_sym,type=:bit)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 162 def decl_sig kind,vname_sym,type=:bit @ast||=Root.new klass=Object.const_get(kind.capitalize) io=klass.new(vname_sym,type) vname="@#{vname_sym}" instance_variable_set(vname, io) self.class.__send__(:attr_accessor, vname_sym) @ast.decls << sig=SigDecl.new(vname_sym.to_s,io) sig end
process_sig_decl(kind,*arg)
click to toggle source
# File lib/ruby_rtl/ast_builder.rb, line 132 def process_sig_decl kind,*arg case arg when String decl_sig(kind,vname=arg.to_sym,type=:bit) when Symbol decl_sig(kind,vname=arg,type=:bit) when Array # strange ! recursivity seems to fail # output(element) # FAILS. arg.each do |element| case element when String decl_sig(kind,vname=element.to_sym,type=:bit) when Symbol decl_sig(kind,vname=element,type=:bit) when Hash element.each do |vname,type| decl_sig(kind,vname,type) end else "ERROR : wrong output declaration in list : '#{arg}'" end end when Record decl_sig(:input,vname=arg,type) else raise "ERROR : wrong input declaration '#{arg}'" end end