Skip to content

Commit d5b7d50

Browse files
committed
Move DriveBit implementation to drivertools.cc
1 parent e214add commit d5b7d50

File tree

2 files changed

+444
-268
lines changed

2 files changed

+444
-268
lines changed

kernel/drivertools.cc

+386
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,392 @@ unsigned int DriveBitMultiple::hash() const
153153
return multiple_.hash();
154154
}
155155

156+
DriveBit::DriveBit() {}
157+
158+
DriveBit::DriveBit(DriveBit const &other)
159+
{
160+
*this = other;
161+
}
162+
163+
DriveBit::DriveBit(DriveBit &&other)
164+
{
165+
*this = std::move(other);
166+
}
167+
168+
DriveBit::DriveBit(State constant)
169+
{
170+
*this = constant;
171+
}
172+
173+
DriveBit::DriveBit(DriveBitWire const &wire)
174+
{
175+
*this = wire;
176+
}
177+
178+
DriveBit::DriveBit(DriveBitWire &&wire)
179+
{
180+
*this = std::move(wire);
181+
}
182+
183+
DriveBit::DriveBit(DriveBitPort const &port)
184+
{
185+
*this = port;
186+
}
187+
188+
DriveBit::DriveBit(DriveBitPort &&port)
189+
{
190+
*this = std::move(port);
191+
}
192+
193+
DriveBit::DriveBit(DriveBitMarker const &marker)
194+
{
195+
*this = marker;
196+
}
197+
198+
DriveBit::DriveBit(DriveBitMarker &&marker)
199+
{
200+
*this = std::move(marker);
201+
}
202+
203+
DriveBit::DriveBit(DriveBitMultiple const &multiple)
204+
{
205+
*this = multiple;
206+
}
207+
208+
DriveBit::DriveBit(DriveBitMultiple &&multiple)
209+
{
210+
*this = std::move(multiple);
211+
}
212+
213+
DriveBit::~DriveBit()
214+
{
215+
set_none();
216+
}
217+
218+
void DriveBit::set_none()
219+
{
220+
switch (type_)
221+
{
222+
case DriveType::NONE:
223+
break;
224+
case DriveType::CONSTANT:
225+
break;
226+
case DriveType::WIRE:
227+
wire_.~DriveBitWire();
228+
break;
229+
case DriveType::PORT:
230+
port_.~DriveBitPort();
231+
break;
232+
case DriveType::MARKER:
233+
marker_.~DriveBitMarker();
234+
break;
235+
case DriveType::MULTIPLE:
236+
multiple_.~DriveBitMultiple();
237+
break;
238+
}
239+
type_ = DriveType::NONE;
240+
}
241+
242+
DriveBit &DriveBit::operator=(DriveBit const &other)
243+
{
244+
switch (other.type_)
245+
{
246+
case DriveType::NONE:
247+
set_none();
248+
break;
249+
case DriveType::CONSTANT:
250+
*this = other.constant_;
251+
break;
252+
case DriveType::WIRE:
253+
*this = other.wire_;
254+
break;
255+
case DriveType::PORT:
256+
*this = other.port_;
257+
break;
258+
case DriveType::MARKER:
259+
*this = other.marker_;
260+
break;
261+
case DriveType::MULTIPLE:
262+
*this = other.multiple_;
263+
break;
264+
}
265+
return *this;
266+
}
267+
268+
DriveBit &DriveBit::operator=(DriveBit &&other)
269+
{
270+
switch (other.type_)
271+
{
272+
case DriveType::NONE:
273+
set_none();
274+
break;
275+
case DriveType::CONSTANT:
276+
*this = std::move(other.constant_);
277+
break;
278+
case DriveType::WIRE:
279+
*this = std::move(other.wire_);
280+
break;
281+
case DriveType::PORT:
282+
*this = std::move(other.port_);
283+
break;
284+
case DriveType::MARKER:
285+
*this = std::move(other.marker_);
286+
break;
287+
case DriveType::MULTIPLE:
288+
*this = std::move(other.multiple_);
289+
break;
290+
}
291+
return *this;
292+
}
293+
294+
DriveBit &DriveBit::operator=(State constant)
295+
{
296+
set_none();
297+
constant_ = constant;
298+
type_ = DriveType::CONSTANT;
299+
return *this;
300+
}
301+
302+
DriveBit &DriveBit::operator=(DriveBitWire const &wire)
303+
{
304+
set_none();
305+
new (&wire_) DriveBitWire(wire);
306+
type_ = DriveType::WIRE;
307+
return *this;
308+
}
309+
310+
DriveBit &DriveBit::operator=(DriveBitWire &&wire)
311+
{
312+
set_none();
313+
new (&wire_) DriveBitWire(std::move(wire));
314+
type_ = DriveType::WIRE;
315+
return *this;
316+
}
317+
318+
DriveBit &DriveBit::operator=(DriveBitPort const &port)
319+
{
320+
set_none();
321+
new (&port_) DriveBitPort(port);
322+
type_ = DriveType::PORT;
323+
return *this;
324+
}
325+
326+
DriveBit &DriveBit::operator=(DriveBitPort &&port)
327+
{
328+
set_none();
329+
new (&port_) DriveBitPort(std::move(port));
330+
type_ = DriveType::PORT;
331+
return *this;
332+
}
333+
334+
DriveBit &DriveBit::operator=(DriveBitMarker const &marker)
335+
{
336+
set_none();
337+
new (&marker_) DriveBitMarker(marker);
338+
type_ = DriveType::MARKER;
339+
return *this;
340+
}
341+
342+
DriveBit &DriveBit::operator=(DriveBitMarker &&marker)
343+
{
344+
set_none();
345+
new (&marker_) DriveBitMarker(std::move(marker));
346+
type_ = DriveType::MARKER;
347+
return *this;
348+
}
349+
350+
DriveBit &DriveBit::operator=(DriveBitMultiple const &multiple)
351+
{
352+
set_none();
353+
if (multiple.multiple().empty())
354+
return *this;
355+
new (&multiple_) DriveBitMultiple(multiple);
356+
type_ = DriveType::MULTIPLE;
357+
return *this;
358+
}
359+
360+
DriveBit &DriveBit::operator=(DriveBitMultiple &&multiple)
361+
{
362+
set_none();
363+
if (multiple.multiple().empty())
364+
return *this;
365+
new (&multiple_) DriveBitMultiple(std::move(multiple));
366+
type_ = DriveType::MULTIPLE;
367+
return *this;
368+
}
369+
370+
unsigned int DriveBit::hash() const
371+
{
372+
unsigned int inner;
373+
switch (type_)
374+
{
375+
case DriveType::NONE:
376+
inner = 0;
377+
break;
378+
case DriveType::CONSTANT:
379+
inner = constant_;
380+
break;
381+
case DriveType::WIRE:
382+
inner = wire_.hash();
383+
break;
384+
case DriveType::PORT:
385+
inner = port_.hash();
386+
break;
387+
case DriveType::MARKER:
388+
inner = marker_.hash();
389+
break;
390+
case DriveType::MULTIPLE:
391+
inner = multiple_.hash();
392+
break;
393+
}
394+
return mkhash((unsigned int)type_, inner);
395+
}
396+
397+
bool DriveBit::operator==(const DriveBit &other) const
398+
{
399+
if (type_ != other.type_)
400+
return false;
401+
402+
switch (type_)
403+
{
404+
case DriveType::NONE:
405+
return true;
406+
case DriveType::CONSTANT:
407+
return constant_ == other.constant_;
408+
case DriveType::WIRE:
409+
return wire_ == other.wire_;
410+
case DriveType::PORT:
411+
return port_ == other.port_;
412+
case DriveType::MARKER:
413+
return marker_ == other.marker_;
414+
case DriveType::MULTIPLE:
415+
return multiple_ == other.multiple_;
416+
}
417+
log_assert(false);
418+
}
419+
420+
bool DriveBit::operator!=(const DriveBit &other) const
421+
{
422+
return !(*this == other);
423+
}
424+
425+
bool DriveBit::operator<(const DriveBit &other) const
426+
{
427+
if (type_ != other.type_)
428+
return type_ < other.type_;
429+
switch (type_)
430+
{
431+
case DriveType::NONE:
432+
return false;
433+
case DriveType::CONSTANT:
434+
return constant_ < other.constant_;
435+
case DriveType::WIRE:
436+
return wire_ < other.wire_;
437+
case DriveType::PORT:
438+
return port_ < other.port_;
439+
case DriveType::MARKER:
440+
return marker_ < other.marker_;
441+
case DriveType::MULTIPLE:
442+
log_assert(!"TODO");
443+
}
444+
log_abort();
445+
}
446+
447+
DriveType DriveBit::type() const
448+
{
449+
return type_;
450+
}
451+
452+
bool DriveBit::is_none() const
453+
{
454+
return type_ == DriveType::NONE;
455+
}
456+
457+
bool DriveBit::is_constant() const
458+
{
459+
return type_ == DriveType::CONSTANT;
460+
}
461+
462+
bool DriveBit::is_wire() const
463+
{
464+
return type_ == DriveType::WIRE;
465+
}
466+
467+
bool DriveBit::is_port() const
468+
{
469+
return type_ == DriveType::PORT;
470+
}
471+
472+
bool DriveBit::is_marker() const
473+
{
474+
return type_ == DriveType::MARKER;
475+
}
476+
477+
bool DriveBit::is_multiple() const
478+
{
479+
return type_ == DriveType::MULTIPLE;
480+
}
481+
482+
State &DriveBit::constant()
483+
{
484+
log_assert(is_constant());
485+
return constant_;
486+
}
487+
488+
State const &DriveBit::constant() const
489+
{
490+
log_assert(is_constant());
491+
return constant_;
492+
}
493+
494+
DriveBitWire &DriveBit::wire()
495+
{
496+
log_assert(is_wire());
497+
return wire_;
498+
}
499+
500+
DriveBitWire const &DriveBit::wire() const
501+
{
502+
log_assert(is_wire());
503+
return wire_;
504+
}
505+
506+
DriveBitPort &DriveBit::port()
507+
{
508+
log_assert(is_port());
509+
return port_;
510+
}
511+
512+
DriveBitPort const &DriveBit::port() const
513+
{
514+
log_assert(is_port());
515+
return port_;
516+
}
517+
518+
DriveBitMarker &DriveBit::marker()
519+
{
520+
log_assert(is_marker());
521+
return marker_;
522+
}
523+
524+
DriveBitMarker const &DriveBit::marker() const
525+
{
526+
log_assert(is_marker());
527+
return marker_;
528+
}
529+
530+
DriveBitMultiple &DriveBit::multiple()
531+
{
532+
log_assert(is_multiple());
533+
return multiple_;
534+
}
535+
536+
DriveBitMultiple const &DriveBit::multiple() const
537+
{
538+
log_assert(is_multiple());
539+
return multiple_;
540+
}
541+
156542
DriveBitMultiple DriveChunkMultiple::operator[](int i) const
157543
{
158544
DriveBitMultiple result;

0 commit comments

Comments
 (0)