class RubyRTL::SexpGenerator
Public Instance Methods
generate(circuit)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 7 def generate circuit puts "[+] S-exp code generation" root=circuit.ast code=Code.new code << "(circuit #{circuit.name}" code.indent=2 root.decls.each{|decl| code << decl.accept(self)} code << root.body.accept(self) code.indent=0 code << ")" puts code.finalize end
visitAssign(assign,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 33 def visitAssign assign,args=nil lhs=assign.lhs.accept(self) rhs=assign.rhs.accept(self) "(assign #{lhs} #{rhs})" end
visitBinary(node,args=nil)
click to toggle source
visitBody(body,args=nil)
click to toggle source
statements
# File lib/ruby_rtl/sexp_generator.rb, line 27 def visitBody body,args=nil code=Code.new body.each{|stmt| code << stmt.accept(self)} code end
visitCase(case_,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 122 def visitCase case_,args=nil code=Code.new code << "Case(){" code.indent=2 code << case_.body.accept(self) code.indent=0 code << "}" code end
visitEnumType(enum_type,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 113 def visitEnumType enum_type,args=nil "Enum(#{enum_type.items.join(",")})" end
visitFsm(fsm,args=nil)
click to toggle source
fsm
# File lib/ruby_rtl/sexp_generator.rb, line 55 def visitFsm fsm,args=nil code=Code.new code << "(fsm #{fsm.name}" code.indent=2 fsm.states.each{|state| code << state.accept(self)} code.indent=0 code << ")" code end
visitFuncCall(func,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 92 def visitFuncCall func,args=nil name=func.name argus=func.args.collect{|arg| arg.accept(self)}.join(" ") "(call #{name} #{argus})" end
visitIf(if_,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 39 def visitIf if_,args=nil code=Code.new cond=if_.cond.accept(self) code << "(if #{cond}" code.indent=2 code << "(then" code.indent=4 code << if_.body.accept(self) code.indent=2 code << ")" code.indent=0 code << ")" code end
visitIndexed(indexed,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 98 def visitIndexed indexed,args=nil lhs=indexed.lhs.accept(self) rhs=indexed.rhs.accept(self) "(indexed #{lhs} #{rhs})" end
visitMemoryType(mem_type,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 117 def visitMemoryType mem_type,args=nil typename=mem_type.type "Memory(#{mem_type.size},#{typename})" end
visitNext(node,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 75 def visitNext node,args=nil "(next_state #{node.name})" end
visitRecordType(rec_type,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 105 def visitRecordType rec_type,args=nil items=[] rec_type.hash.each{|item,type| items << "#{item} => #{type}" } "Record(#{items.join(",")})" end
visitSigDecl(sig_decl,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 20 def visitSigDecl sig_decl,args=nil name=sig_decl.name type=sig_decl.sig.type.accept(self) "(input #{name} #{type})" end
visitState(state,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 65 def visitState state,args=nil code=Code.new code << "(state #{state.name}" code.indent=2 code << state.body.accept(self) code.indent=0 code << ")" code end
visitUnary(node,args=nil)
click to toggle source
# File lib/ruby_rtl/sexp_generator.rb, line 87 def visitUnary node,args=nil expr=node.expr.accept(self) "(#{node.op} #{expr})" end