Commit c59334ce by Zachary Snow

allow preproc idents to begin with macro arguments

parent 10b30d7d
...@@ -218,36 +218,39 @@ isIdentChar ch = ...@@ -218,36 +218,39 @@ isIdentChar ch =
takeIdentifier :: PPS String takeIdentifier :: PPS String
takeIdentifier = do takeIdentifier = do
str <- getInput str <- getInput
macroStack <- getMacroStack
if null macroStack
then do
let (ident, rest) = span isIdentChar str let (ident, rest) = span isIdentChar str
advancePositions ident advancePositions ident
macroStack <- getMacroStack
setInput rest setInput rest
if null macroStack return ident
then return ident else takeIdentifierFollow True
else do takeIdentifierFollow :: Bool -> PPS String
identFollow <- takeIdentifierFollow takeIdentifierFollow firstPass = do
return $ ident ++ identFollow
takeIdentifierFollow :: PPS String
takeIdentifierFollow = do
str <- getInput str <- getInput
case str of case str of
'`' : '`' : '`' : _ -> '`' : '`' : '`' : _ -> do
'`' <- takeChar
'`' <- takeChar
process $ handleDirective True process $ handleDirective True
'`' : '`' : _ -> '`' : '`' : _ -> do
'`' <- takeChar
'`' <- takeChar
process consumeWithSubstitution process consumeWithSubstitution
_ -> return "" _ -> if firstPass
then process consumeWithSubstitution
else return ""
where where
process :: (PPS ()) -> PPS String process :: (PPS ()) -> PPS String
process action = do process action = do
'`' <- takeChar
'`' <- takeChar
outputFollow <- getOutput outputFollow <- getOutput
setOutput [] setOutput []
() <- action () <- action
outputIdent <- getOutput outputIdent <- getOutput
setOutput outputFollow setOutput outputFollow
let ident = reverse $ map fst outputIdent let ident = reverse $ map fst outputIdent
identFollow <- takeIdentifierFollow identFollow <- takeIdentifierFollow False
return $ ident ++ identFollow return $ ident ++ identFollow
-- read tokens after the name until the first (un-escaped) newline -- read tokens after the name until the first (un-escaped) newline
......
module top; endmodule
`define MODULE(str) module str; initial $display(`"hello str`"); endmodule
`define MACRO_A(inv, str) `inv(str)
`define MACRO_B(inv, str) ```inv(str)
`define MACRO_C(inv1, inv2, str) `inv1``inv2(str)
`MODULE(example1)
`MACRO_A(MODULE, example2)
`MACRO_B(MODULE, example3)
`MACRO_C(MOD, ULE, example4)
`MACRO_C(M, ODULE, example5)
`MACRO_C(, MODULE, example6)
module top; endmodule
`define MODULE(str) module str; initial $display(`"hello str`"); endmodule
`MODULE(example1)
`MODULE(example2)
`MODULE(example3)
`MODULE(example4)
`MODULE(example5)
`MODULE(example6)
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