grammar,compiler: Add Support For Fixed-Width Integers
Distinguishing between signed and unsigned fixed-width integer types must still be done. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -424,19 +424,30 @@ public class P4BooleanValue: P4DataValue {
|
||||
}
|
||||
}
|
||||
|
||||
public enum BitWidth: Equatable {
|
||||
case Infinite
|
||||
case Width(Int)
|
||||
}
|
||||
|
||||
/// A P4 int type
|
||||
public struct P4Int: P4Type {
|
||||
public init() {}
|
||||
let width: BitWidth
|
||||
|
||||
public init(_ width: BitWidth = BitWidth.Infinite) {
|
||||
self.width = width
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return "Int"
|
||||
return "Int (width: \(self.width))"
|
||||
}
|
||||
|
||||
public func eq(rhs: P4Type) -> Bool {
|
||||
return switch rhs {
|
||||
case is P4Int: true
|
||||
case let rrhs as P4Int: rrhs.width == self.width
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
public func def() -> P4DataValue? {
|
||||
return P4IntValue(withValue: 0)
|
||||
}
|
||||
@@ -444,12 +455,16 @@ public struct P4Int: P4Type {
|
||||
|
||||
/// An instance of a P4 integer
|
||||
public class P4IntValue: P4DataValue {
|
||||
|
||||
let int_type: P4Int
|
||||
|
||||
public func type() -> P4Type {
|
||||
return P4Int()
|
||||
return int_type
|
||||
}
|
||||
|
||||
let value: Int
|
||||
public init(withValue value: Int) {
|
||||
public init(withValue value: Int, andWidth width: BitWidth = BitWidth.Infinite) {
|
||||
self.int_type = P4Int(width)
|
||||
self.value = value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user