Module: HDLRuby::High::High2C
- Defined in:
- lib/HDLRuby/hruby_rcsim.rb
Overview
Provides tools for converting HDLRuby::High objects to C.
Constant Summary collapse
- @@hdrobj2c =
{}
Class Method Summary collapse
-
.c_name(name) ⇒ Object
Converts a +name+ to a C-compatible name.
-
.c_string(str) ⇒ Object
Converts string +str+ to a C-compatible string.
-
.int_width ⇒ Object
Gives the width of an int in the current computer.
-
.obj_name(obj) ⇒ Object
Generates a uniq name for an object.
-
.type_name(obj) ⇒ Object
Generates the name of a type.
-
.unit_name(obj) ⇒ Object
Generates the name of a unit.
Class Method Details
.c_name(name) ⇒ Object
Converts a +name+ to a C-compatible name.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 33 def self.c_name(name) name = name.to_s # Convert special characters. name = name.each_char.map do |c| if c=~ /[a-z0-9]/ then c elsif c == "_" then "__" else "_" + c.ord.to_s end end.join # First character: only letter is possible. unless name[0] =~ /[a-z_]/ then name = "_" + name end return name end |
.c_string(str) ⇒ Object
Converts string +str+ to a C-compatible string.
26 27 28 29 30 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 26 def self.c_string(str) str = str.gsub(/\n/,"\\n") str.gsub!(/\t/,"\\t") return str end |
.int_width ⇒ Object
Gives the width of an int in the current computer.
21 22 23 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 21 def self.int_width return [1.to_i].pack("i").size*8 end |
.obj_name(obj) ⇒ Object
Generates a uniq name for an object.
55 56 57 58 59 60 61 62 63 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 55 def self.obj_name(obj) id = obj.hierarchy.map! {|obj| obj.object_id} oname = @@hdrobj2c[id] unless oname then oname = "_" << @@hdrobj2c.size.to_s(36) @@hdrobj2c[id] = oname end return oname end |
.type_name(obj) ⇒ Object
Generates the name of a type.
66 67 68 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 66 def self.type_name(obj) return "type#{Low2C.obj_name(obj)}" end |
.unit_name(obj) ⇒ Object
Generates the name of a unit.
71 72 73 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 71 def self.unit_name(obj) return "#{obj.to_s.upcase}" end |