Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
Aug 12, 2013
add += operator to fragment e12187a
add ternary operator sel ? a : b 6f9f08f
16  migen/fhdl/structure.py
@@ -94,6 +94,9 @@ def __init__(self, op, operands):
94 94
 		self.op = op
95 95
 		self.operands = operands
96 96
 
  97
+def Mux(sel, val1, val0):
  98
+	return _Operator("m", [sel, val1, val0])
  99
+
97 100
 class _Slice(Value):
98 101
 	def __init__(self, value, start, stop):
99 102
 		Value.__init__(self)
@@ -275,3 +278,16 @@ def __add__(self, other):
275 278
 			self.specials | other.specials,
276 279
 			self.clock_domains + other.clock_domains,
277 280
 			self.sim + other.sim)
  281
+
  282
+	def __iadd__(self, other):
  283
+		newsync = defaultdict(list)
  284
+		for k, v in self.sync.items():
  285
+			newsync[k] = v[:]
  286
+		for k, v in other.sync.items():
  287
+			newsync[k].extend(v)
  288
+		self.comb += other.comb
  289
+		self.sync = newsync
  290
+		self.specials |= other.specials
  291
+		self.clock_domains += other.clock_domains
  292
+		self.sim += other.sim
  293
+		return self
10  migen/fhdl/verilog.py
@@ -58,6 +58,16 @@ def _printexpr(ns, node):
58 58
 					r2 = "$signed({1'd0, " + r2 + "})"
59 59
 			r = r1 + " " + node.op + " " + r2
60 60
 			s = s1 or s2
  61
+		elif arity == 3:
  62
+			assert node.op == "m"
  63
+			r2, s2 = _printexpr(ns, node.operands[1])
  64
+			r3, s3 = _printexpr(ns, node.operands[2])
  65
+			if s2 and not s3:
  66
+				r3 = "$signed({1'd0, " + r3 + "})"
  67
+			if s3 and not s2:
  68
+				r2 = "$signed({1'd0, " + r2 + "})"
  69
+			r = r1 + " ? " + r2 + " : " + r3
  70
+			s = s2 or s3
61 71
 		else:
62 72
 			raise TypeError
63 73
 		return "(" + r + ")", s

No commit comments for this range

Something went wrong with that request. Please try again.