Class: Reggae::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/reggae/parser.rb

Instance Method Summary collapse

Instance Method Details

#fix_sexpistol_bug(str) ⇒ Object



23
24
25
26
# File 'lib/reggae/parser.rb', line 23

def fix_sexpistol_bug str
  s1=str.gsub(/0x(\w+)/,'\1') #0x....
  s2=s1.gsub(/(\d+)\.\.(\d+)/,'\1 \2') #range
end

#parse(filename) ⇒ Object



16
17
18
19
20
21
# File 'lib/reggae/parser.rb', line 16

def parse filename
  str=IO.read(filename)
  str=fix_sexpistol_bug(str)
  mm_a=SXP.read(str)
  parseMemoryMap(mm_a)
end

#parseAddress(ary) ⇒ Object



215
216
217
# File 'lib/reggae/parser.rb', line 215

def parseAddress ary
  parseHexa(ary.last)
end

#parseBit(ary) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/reggae/parser.rb', line 233

def parseBit ary
  bit=Bit.new(nil,nil,nil,nil)
  ary.shift
  bit.position=ary.shift.to_i
  while ary.any?
    case h=ary.first.header
    when :name
      bit.name=parseName(ary.shift)
    when :purpose
      bit.purpose=parsePurpose(ary.shift)
    when :toggle
      bit.toggle=parseToggle(ary.shift)
    end
  end
  bit
end

#parseBitfield(ary) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/reggae/parser.rb', line 262

def parseBitfield ary
  bf=Bitfield.new(nil,nil,nil,nil)
  ary.shift
  bf.position=[]
  bf.position << ary.shift.to_s.to_i
  bf.position << ary.shift.to_s.to_i
  while ary.any?
    case h=ary.first.header
    when :name
      bf.name=parseName(ary.shift)
    when :purpose
      bf.purpose=parsePurpose(ary.shift)
    when :toggle
      bf.toggle=parseToggle(ary.shift)
    end
  end
  bf
end

#parseBus(ary) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/reggae/parser.rb', line 72

def parseBus ary
  bus=Bus.new(nil,nil,nil)
  ary.shift
  while ary.any?
    case h=ary.first.header
    when :frequency
      bus.frequency=ary.first.last.to_i
    when :address_size
      bus.address_size=ary.first.last.to_i
    when :data_size
      bus.data_size=ary.first.last.to_i
    else
      raise "error during parseBus. Expecting 'frequency','address_size' or 'data_size'. Got '#{h}'"
    end
    ary.shift
  end
  bus
end

#parseComment(ary) ⇒ Object



48
49
50
51
52
53
# File 'lib/reggae/parser.rb', line 48

def parseComment ary
  comment=Comment.new(nil)
  ary.shift
  comment.txt=ary.shift
  comment
end

#parseConnect(ary) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/reggae/parser.rb', line 138

def parseConnect ary
  map=Connect.new(nil,nil)
  ary.shift
  map.formal=parseFormalIO(ary.shift)
  map.actual=parseRegSig(ary.shift)
  map
end

#parseFormalIO(ary) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/reggae/parser.rb', line 146

def parseFormalIO ary
  dir=ary.shift
  case dir
  when :input
    return Input.new(ary.shift)
  when :output
    return Output.new(ary.shift)
  else
    raise "error in formal io : #{ary}"
  end
end

#parseHexa(sym) ⇒ Object



91
92
93
# File 'lib/reggae/parser.rb', line 91

def parseHexa sym
  "0x#{sym}"
end

#parseInit(ary) ⇒ Object



219
220
221
# File 'lib/reggae/parser.rb', line 219

def parseInit ary
  parseHexa(ary.last)
end

#parseInstance(ary) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/reggae/parser.rb', line 123

def parseInstance ary
  inst=Instance.new(nil,[])
  ary.shift
  inst.name=ary.shift
  while ary.any?
    case h=ary.first.header
    when :connect
      inst.mapping << parseConnect(ary.shift)
    else
      raise "error during parseZone.Expecting 'connect'. Got '#{h}'"
    end
  end
  inst
end

#parseMemoryMap(ary) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/reggae/parser.rb', line 28

def parseMemoryMap ary
  mm=MemoryMap.new(nil,nil,[])
  ary.shift
  mm.name=ary.shift
  while ary.any?
    case h=ary.first.header
    when :comment
      mm.comments ||=[]
      mm.comments << parseComment(ary.shift)
    when :parameters
      mm.parameters=parseParameters(ary.shift)
    when :zone
      mm.zones << parseZone(ary.shift)
    else
      raise "error.expecting 'zone' or 'parameters'. got a '#{h}'"
    end
  end
  mm
end

#parseName(ary) ⇒ Object



250
251
252
# File 'lib/reggae/parser.rb', line 250

def parseName ary
  ary[1]
end

#parseParameters(ary) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/reggae/parser.rb', line 55

def parseParameters ary
  param=Parameters.new(nil,nil)
  ary.shift
  while ary.any?
    case h=ary.first.header
    when :bus
      param.bus=parseBus(ary.shift)
    when :range
      param.range=parseRange(ary.shift)
    else
      raise "error.expecting 'bus' or 'range'. Got a '#{h}'"
    end
  end
  @param=param
  param
end

#parsePurpose(ary) ⇒ Object



254
255
256
# File 'lib/reggae/parser.rb', line 254

def parsePurpose ary
  ary[1]
end

#parseRange(ary) ⇒ Object



95
96
97
98
99
100
# File 'lib/reggae/parser.rb', line 95

def parseRange ary
  rg=Range.new(nil,nil)
  rg.from=parseHexa(ary[1])
  rg.to=parseHexa(ary[2])
  rg
end

#parseRegister(ary) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/reggae/parser.rb', line 185

def parseRegister ary
  reg=Register.new(nil,nil,nil,nil,true,[],[])
  ary.shift
  reg.name=ary.shift
  while ary.any?
    case h=ary.first.header
    when :address
      reg.address=parseAddress(ary.shift)
    when :init
      reg.init=parseInit(ary.shift)
    when :sampling
      reg.sampling=parseSampling(ary.shift)
    when :writable
      reg.writable=parseWritable(ary.shift)
    when :bit
      reg.bits << parseBit(ary.shift)
    when :bitfield
      reg.bitfields << parseBitfield(ary.shift)
    else
      raise "Error during parseRegister"
    end
  end
  if reg.bits.empty? and reg.bitfields.empty?
    bus_size=@param.bus.data_size
    position=[bus_size-1,0]
    reg.bitfields << Bitfield.new(position,name=:value,nil,nil)
  end
  reg
end

#parseRegSig(ary) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/reggae/parser.rb', line 158

def parseRegSig ary
  sig=RegSig.new(nil,nil)
  ary.shift #register
  sig.name=ary.shift
  sig.field=ary.shift
  sig
end

#parseSampling(ary) ⇒ Object



223
224
225
226
# File 'lib/reggae/parser.rb', line 223

def parseSampling ary
  ary.shift
  ary.shift==:true
end

#parseSubZone(ary) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/reggae/parser.rb', line 166

def parseSubZone ary
  zone=Subzone.new(nil,nil,[],[])
  ary.shift
  zone.name=ary.shift
  while ary.any?
    case h=ary.first.header
    when :range
      zone.range=parseRange(ary.shift)
    when :register
      zone.registers << parseRegister(ary.shift)
    when :subzone
      zone.subzones << parseSubZone(ary.shift)
    else
      raise "error during parseZone.Expecting 'range' or 'register'. Got '#{h}'"
    end
  end
  zone
end

#parseToggle(ary) ⇒ Object



258
259
260
# File 'lib/reggae/parser.rb', line 258

def parseToggle ary
  ary[1]==:true
end

#parseWritable(ary) ⇒ Object



228
229
230
231
# File 'lib/reggae/parser.rb', line 228

def parseWritable ary
  ary.shift
  ary.shift==:true
end

#parseZone(ary) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/reggae/parser.rb', line 102

def parseZone ary
  zone=Zone.new(nil,nil,[],[],[])
  ary.shift
  zone.name=ary.shift
  while ary.any?
    case h=ary.first.header
    when :range
      zone.range=parseRange(ary.shift)
    when :register
      zone.registers << parseRegister(ary.shift)
    when :subzone
      zone.subzones << parseSubZone(ary.shift)
    when :instance
      zone.instances << parseInstance(ary.shift)
    else
      raise "error during parseZone.Expecting 'range' or 'register'. Got '#{h}'"
    end
  end
  zone
end