Commit ecee8b33 by Zachary Snow

support for interface based typedefs

parent 1ba5ab27
......@@ -107,8 +107,8 @@ Other:
## Supported Features
sv2v supports most synthesizable SystemVerilog features. Current notable
exceptions include `defparam` on interface instances and references to typedefs
within interface instances. Assertions are also supported, but are simply
exceptions include `defparam` on interface instances and certain synthesizable
usages of parameterized classes. Assertions are also supported, but are simply
dropped during conversion.
If you find a bug or have a feature request, please create an issue. Preference
......
......@@ -821,6 +821,7 @@ traverseSinglyNestedTypesM mapper = tm
tm (IntegerAtom kw sg ) = return $ IntegerAtom kw sg
tm (NonInteger kw ) = return $ NonInteger kw
tm (TypeOf expr ) = return $ TypeOf expr
tm (TypedefRef expr ) = return $ TypedefRef expr
tm (InterfaceT x y r) = return $ InterfaceT x y r
tm (Enum t vals r) = do
t' <- mapper t
......@@ -879,6 +880,7 @@ traverseTypeExprsM exprMapper =
typeOrExprMapper (Right e) = exprMapper e >>= return . Right
typeMapper (TypeOf expr) =
exprMapper expr >>= return . TypeOf
-- TypedefRef is excluded because it isn't really an expression
typeMapper (CSAlias ps pm xx rs) = do
vals' <- mapM typeOrExprMapper $ map snd pm
let pm' = zip (map fst pm) vals'
......
......@@ -95,6 +95,11 @@ traverseTypeM (Alias st rs1) = do
Just (_, _, UnknownType) -> Alias st rs1'
Just (_, _, typ) -> tf $ rs1' ++ rs2
where (tf, rs2) = typeRanges typ
traverseTypeM (TypedefRef expr) = do
details <- lookupElemM expr
return $ case details of
Nothing -> TypedefRef expr
Just (_, _, typ) -> typ
traverseTypeM other =
traverseSinglyNestedTypesM traverseTypeM other
>>= traverseTypeExprsM traverseExprM
......
......@@ -51,6 +51,7 @@ data Type
| Union Packing [Field] [Range]
| InterfaceT Identifier Identifier [Range]
| TypeOf Expr
| TypedefRef Expr
| UnpackedType Type [Range] -- used internally
deriving (Eq, Ord)
......@@ -74,6 +75,7 @@ instance Show Type where
show (Union p items r) = printf "union %s{\n%s\n}%s" (showPad p) (showFields items) (showRanges r)
show (TypeOf expr) = printf "type(%s)" (show expr)
show (UnpackedType t rs) = printf "UnpackedType(%s, %s)" (show t) (showRanges rs)
show (TypedefRef e) = show e
showFields :: [Field] -> String
showFields items = itemsStr
......@@ -112,6 +114,7 @@ typeRanges typ =
IntegerAtom kw sg -> (nullRange $ IntegerAtom kw sg, [])
NonInteger kw -> (nullRange $ NonInteger kw , [])
TypeOf expr -> (nullRange $ TypeOf expr, [])
TypedefRef expr -> (nullRange $ TypedefRef expr, [])
nullRange :: Type -> ([Range] -> Type)
nullRange t [] = t
......
......@@ -848,6 +848,7 @@ PackageItem :: { [PackageItem] }
NonDeclPackageItem :: { [PackageItem] }
: "typedef" Type Identifier ";" { [Decl $ ParamType Localparam $3 $2] }
| "typedef" Type Identifier DimensionsNonEmpty ";" { [Decl $ ParamType Localparam $3 (UnpackedType $2 $4)] }
| "typedef" TypedefRef Identifier ";" { [Decl $ ParamType Localparam $3 $2] }
| "function" Lifetime FuncRetAndName TFItems DeclsAndStmts endfunction opt(Tag) { [Function $2 (fst $3) (snd $3) (map makeInput $4 ++ fst $5) (snd $5)] }
| "function" Lifetime "void" Identifier TFItems DeclsAndStmts endfunction opt(Tag) { [Task $2 $4 ($5 ++ fst $6) (snd $6)] }
| "task" Lifetime Identifier TFItems DeclsAndStmts endtask opt(Tag) { [Task $2 $3 ($4 ++ fst $5) (snd $5)] }
......@@ -857,6 +858,9 @@ NonDeclPackageItem :: { [PackageItem] }
| ForwardTypedef ";" { $1 }
| TimeunitsDeclaration { $1 }
| Directive { [Directive $1] }
TypedefRef :: { Type }
: Identifier "." Identifier { TypedefRef $ Dot (Ident $1) $3 }
| Identifier "[" Expr "]" "." Identifier { TypedefRef $ Dot (Bit (Ident $1) $3) $6 }
ForwardTypedef :: { [PackageItem] }
: "typedef" Identifier { [] }
| "typedef" "enum" Identifier { [] }
......
interface intf_i;
typedef int data_t;
endinterface
module sub(intf_i p, intf_i q [2]);
typedef p.data_t p_data_t; // interface based typedef
typedef q[0].data_t q_data_t; // interface based typedef
p_data_t p_data;
q_data_t q_data;
initial $display("p %0d %b", $bits(p_data), p_data);
initial $display("q %0d %b", $bits(q_data), q_data);
endmodule
module top;
intf_i p();
intf_i q[2]();
sub s(p, q);
endmodule
module top;
initial $display("p %0d %b", 32, 32'bx);
initial $display("q %0d %b", 32, 32'bx);
endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment