Commit ad21277e by Zachary Snow

support macro names comprised of macro args and macros

parent 9af38e78
......@@ -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
......
`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
module top;
initial begin
$display(1, 2);
$display(3, 4);
$display(5, 5);
end
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