mirror of https://github.com/zachjs/sv2v.git
support macro names comprised of macro args and macros
This commit is contained in:
parent
9af38e7870
commit
ad21277eb5
|
|
@ -154,8 +154,35 @@ takeIdentifier = do
|
|||
str <- getInput
|
||||
let (ident, rest) = span isIdentChar str
|
||||
advancePositions ident
|
||||
macroStack <- getMacroStack
|
||||
setInput rest
|
||||
return ident
|
||||
if null macroStack
|
||||
then return ident
|
||||
else do
|
||||
identFollow <- takeIdentifierFollow
|
||||
return $ ident ++ identFollow
|
||||
takeIdentifierFollow :: PPS String
|
||||
takeIdentifierFollow = do
|
||||
str <- getInput
|
||||
case str of
|
||||
'`' : '`' : '`' : _ ->
|
||||
process $ handleDirective True
|
||||
'`' : '`' : _ ->
|
||||
process consumeWithSubstitution
|
||||
_ -> return ""
|
||||
where
|
||||
process :: (PPS ()) -> PPS String
|
||||
process action = do
|
||||
'`' <- takeChar
|
||||
'`' <- takeChar
|
||||
outputFollow <- getOutput
|
||||
setOutput []
|
||||
() <- action
|
||||
outputIdent <- getOutput
|
||||
setOutput outputFollow
|
||||
let ident = reverse $ map fst outputIdent
|
||||
identFollow <- takeIdentifierFollow
|
||||
return $ ident ++ identFollow
|
||||
|
||||
-- read tokens after the name until the first (un-escaped) newline
|
||||
takeUntilNewline :: PPS String
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
`define SUFFIX _MAGIC
|
||||
`define CHOICE_FOO 1
|
||||
`define CHOICE_BAR 2
|
||||
`define CHOICE_FOO_MAGIC 3
|
||||
`define CHOICE_BAR_MAGIC 4
|
||||
`define CHOICE__MAGIC 5
|
||||
`define MACRO1(A, B) \
|
||||
`CHOICE_``A , `CHOICE_``B
|
||||
`define MACRO2(A, B) \
|
||||
`CHOICE_``A```SUFFIX , `CHOICE_``B```SUFFIX
|
||||
`define MACRO3 \
|
||||
`CHOICE_```SUFFIX , `CHOICE_```SUFFIX
|
||||
module top;
|
||||
initial begin
|
||||
$display(`MACRO1(FOO, BAR));
|
||||
$display(`MACRO2(FOO, BAR));
|
||||
$display(`MACRO3);
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
module top;
|
||||
initial begin
|
||||
$display(1, 2);
|
||||
$display(3, 4);
|
||||
$display(5, 5);
|
||||
end
|
||||
endmodule
|
||||
Loading…
Reference in New Issue