From c222d406b09de529388fcd248476e9ae258895b8 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 5 May 2012 02:55:38 -0400 Subject: converting to new reply/cookie scheme --- nexgb/xgbgen/expression.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'nexgb/xgbgen/expression.go') diff --git a/nexgb/xgbgen/expression.go b/nexgb/xgbgen/expression.go index 12bcb19..6a8aa52 100644 --- a/nexgb/xgbgen/expression.go +++ b/nexgb/xgbgen/expression.go @@ -158,6 +158,33 @@ func (e *UnaryOp) Initialize(p *Protocol) { e.Expr.Initialize(p) } +type Padding struct { + Expr Expression +} + +func (e *Padding) Concrete() bool { + return e.Expr.Concrete() +} + +func (e *Padding) Eval() uint { + return uint(pad(int(e.Expr.Eval()))) +} + +func (e *Padding) Reduce(prefix string) string { + if e.Concrete() { + return fmt.Sprintf("%d", e.Eval()) + } + return fmt.Sprintf("pad(%s)", e.Expr.Reduce(prefix)) +} + +func (e *Padding) String() string { + return e.Reduce("") +} + +func (e *Padding) Initialize(p *Protocol) { + e.Expr.Initialize(p) +} + type PopCount struct { Expr Expression } -- cgit v1.2.3