Commit 167c65db by Zachary Snow

pass through downstream compiler directives

parent 6d79e0b4
...@@ -68,7 +68,6 @@ convertDescription ports orig = ...@@ -68,7 +68,6 @@ convertDescription ports orig =
Part _ _ Module _ _ _ _ -> True Part _ _ Module _ _ _ _ -> True
PackageItem _ -> True PackageItem _ -> True
Package _ _ _ -> False Package _ _ _ -> False
Directive _ -> False
origIdents = execWriter (collectModuleItemsM regIdents orig) origIdents = execWriter (collectModuleItemsM regIdents orig)
fixed = traverseModuleItems fixModuleItem orig fixed = traverseModuleItems fixModuleItem orig
......
...@@ -100,3 +100,4 @@ piName (Decl (ParamType _ ident _)) = Just ident ...@@ -100,3 +100,4 @@ piName (Decl (ParamType _ ident _)) = Just ident
piName (Import x y) = Just $ show $ Import x y piName (Import x y) = Just $ show $ Import x y
piName (Export _) = Nothing piName (Export _) = Nothing
piName (Comment _) = Nothing piName (Comment _) = Nothing
piName (Directive _) = Nothing
...@@ -186,3 +186,4 @@ piName (Decl (ParamType _ ident _)) = Just ident ...@@ -186,3 +186,4 @@ piName (Decl (ParamType _ ident _)) = Just ident
piName (Import _ _) = Nothing piName (Import _ _) = Nothing
piName (Export _) = Nothing piName (Export _) = Nothing
piName (Comment _) = Nothing piName (Comment _) = Nothing
piName (Directive _) = Nothing
...@@ -174,7 +174,6 @@ traverseModuleItemsM mapper (Package lifetime name packageItems) = do ...@@ -174,7 +174,6 @@ traverseModuleItemsM mapper (Package lifetime name packageItems) = do
_ -> error $ "redirected Package traverse failed: " _ -> error $ "redirected Package traverse failed: "
++ show converted ++ show converted
return $ Package lifetime name $ map (\(MIPackageItem item) -> item) items' return $ Package lifetime name $ map (\(MIPackageItem item) -> item) items'
traverseModuleItemsM _ (Directive str) = return $ Directive str
traverseModuleItems :: Mapper ModuleItem -> Mapper Description traverseModuleItems :: Mapper ModuleItem -> Mapper Description
traverseModuleItems = unmonad traverseModuleItemsM traverseModuleItems = unmonad traverseModuleItemsM
...@@ -623,6 +622,8 @@ traverseExprsM' strat exprMapper = moduleItemMapper ...@@ -623,6 +622,8 @@ traverseExprsM' strat exprMapper = moduleItemMapper
moduleItemMapper (Generate items) = do moduleItemMapper (Generate items) = do
items' <- mapM (traverseNestedGenItemsM genItemMapper) items items' <- mapM (traverseNestedGenItemsM genItemMapper) items
return $ Generate items' return $ Generate items'
moduleItemMapper (MIPackageItem (Directive c)) =
return $ MIPackageItem $ Directive c
moduleItemMapper (MIPackageItem (Comment c)) = moduleItemMapper (MIPackageItem (Comment c)) =
return $ MIPackageItem $ Comment c return $ MIPackageItem $ Comment c
moduleItemMapper (MIPackageItem (Import x y)) = moduleItemMapper (MIPackageItem (Import x y)) =
......
...@@ -28,7 +28,6 @@ data Description ...@@ -28,7 +28,6 @@ data Description
= Part [Attr] Bool PartKW (Maybe Lifetime) Identifier [Identifier] [ModuleItem] = Part [Attr] Bool PartKW (Maybe Lifetime) Identifier [Identifier] [ModuleItem]
| PackageItem PackageItem | PackageItem PackageItem
| Package (Maybe Lifetime) Identifier [PackageItem] | Package (Maybe Lifetime) Identifier [PackageItem]
| Directive String -- currently unused
deriving Eq deriving Eq
instance Show Description where instance Show Description where
...@@ -53,7 +52,6 @@ instance Show Description where ...@@ -53,7 +52,6 @@ instance Show Description where
where where
bodyStr = indent $ unlines' $ map show items bodyStr = indent $ unlines' $ map show items
show (PackageItem i) = show i show (PackageItem i) = show i
show (Directive str) = str
data PackageItem data PackageItem
= Typedef Type Identifier = Typedef Type Identifier
...@@ -62,6 +60,7 @@ data PackageItem ...@@ -62,6 +60,7 @@ data PackageItem
| Import Identifier (Maybe Identifier) | Import Identifier (Maybe Identifier)
| Export (Maybe (Identifier, Maybe Identifier)) | Export (Maybe (Identifier, Maybe Identifier))
| Decl Decl | Decl Decl
| Directive String
| Comment String | Comment String
deriving Eq deriving Eq
...@@ -79,6 +78,7 @@ instance Show PackageItem where ...@@ -79,6 +78,7 @@ instance Show PackageItem where
show (Export Nothing) = "export *::*"; show (Export Nothing) = "export *::*";
show (Export (Just (x, y))) = printf "export %s::%s;" x (fromMaybe "*" y) show (Export (Just (x, y))) = printf "export %s::%s;" x (fromMaybe "*" y)
show (Decl decl) = show decl show (Decl decl) = show decl
show (Directive str) = str
show (Comment c) = show (Comment c) =
if elem '\n' c if elem '\n' c
then "// " ++ show c then "// " ++ show c
......
...@@ -884,6 +884,10 @@ handleDirective (posOrig, _, _, strOrig) len = do ...@@ -884,6 +884,10 @@ handleDirective (posOrig, _, _, strOrig) len = do
env <- gets lsEnv env <- gets lsEnv
tempInput <- alexGetInput tempInput <- alexGetInput
let dropUntilNewline = removeUntil "\n" tempInput 0 let dropUntilNewline = removeUntil "\n" tempInput 0
let passThrough = do
rest <- takeUntilNewline
let str = '`' : directive ++ rest
tok Spe_Directive (posOrig, ' ', [], strOrig) (length str)
condStack <- gets lsCondStack condStack <- gets lsCondStack
if any (/= CurrentlyTrue) condStack if any (/= CurrentlyTrue) condStack
...@@ -891,9 +895,18 @@ handleDirective (posOrig, _, _, strOrig) len = do ...@@ -891,9 +895,18 @@ handleDirective (posOrig, _, _, strOrig) len = do
then alexMonadScan then alexMonadScan
else case directive of else case directive of
"default_nettype" -> dropUntilNewline
"timescale" -> dropUntilNewline "timescale" -> dropUntilNewline
"celldefine" -> passThrough
"endcelldefine" -> passThrough
"unconnected_drive" -> passThrough
"nounconnected_drive" -> passThrough
"default_nettype" -> passThrough
"pragma" -> passThrough
"resetall" -> passThrough
"__FILE__" -> do "__FILE__" -> do
tokPos <- toTokPos posOrig tokPos <- toTokPos posOrig
currFile <- gets lsCurrFile currFile <- gets lsCurrFile
......
...@@ -293,6 +293,7 @@ systemIdentifier { Token Id_system _ _ } ...@@ -293,6 +293,7 @@ systemIdentifier { Token Id_system _ _ }
number { Token Lit_number _ _ } number { Token Lit_number _ _ }
string { Token Lit_string _ _ } string { Token Lit_string _ _ }
time { Token Lit_time _ _ } time { Token Lit_time _ _ }
directive { Token Spe_Directive _ _ }
"(" { Token Sym_paren_l _ _ } "(" { Token Sym_paren_l _ _ }
")" { Token Sym_paren_r _ _ } ")" { Token Sym_paren_r _ _ }
...@@ -775,6 +776,7 @@ NonDeclPackageItem :: { [PackageItem] } ...@@ -775,6 +776,7 @@ NonDeclPackageItem :: { [PackageItem] }
| "export" "*" "::" "*" ";" { [Export Nothing] } -- "Nothing" being no restrictions | "export" "*" "::" "*" ";" { [Export Nothing] } -- "Nothing" being no restrictions
| ForwardTypedef ";" { $1 } | ForwardTypedef ";" { $1 }
| TimeunitsDeclaration { $1 } | TimeunitsDeclaration { $1 }
| Directive { [Directive $1] }
ForwardTypedef :: { [PackageItem] } ForwardTypedef :: { [PackageItem] }
: "typedef" Identifier { [] } : "typedef" Identifier { [] }
| "typedef" "enum" Identifier { [] } | "typedef" "enum" Identifier { [] }
...@@ -785,6 +787,9 @@ TimeunitsDeclaration :: { [PackageItem] } ...@@ -785,6 +787,9 @@ TimeunitsDeclaration :: { [PackageItem] }
| "timeunit" Time "/" Time ";" { [] } | "timeunit" Time "/" Time ";" { [] }
| "timeprecision" Time ";" { [] } | "timeprecision" Time ";" { [] }
Directive :: { String }
: directive { tokenString $1 }
PackageImportItems :: { [(Identifier, Maybe Identifier)] } PackageImportItems :: { [(Identifier, Maybe Identifier)] }
: PackageImportItem { [$1] } : PackageImportItem { [$1] }
| PackageImportItems "," PackageImportItem { $1 ++ [$3] } | PackageImportItems "," PackageImportItem { $1 ++ [$3] }
......
...@@ -378,6 +378,7 @@ data TokenName ...@@ -378,6 +378,7 @@ data TokenName
| Sym_amp_amp_amp | Sym_amp_amp_amp
| Sym_lt_lt_lt_eq | Sym_lt_lt_lt_eq
| Sym_gt_gt_gt_eq | Sym_gt_gt_gt_eq
| Spe_Directive
| Unknown | Unknown
| MacroBoundary | MacroBoundary
deriving (Show, Eq) deriving (Show, Eq)
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