diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-25 16:43:04 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-25 16:43:04 -0500 |
commit | 516e3520940959b378c71a8738456cc91878eb49 (patch) | |
tree | a781f145634b7c9814f2cd4eee359a9ce91316cb | |
parent | 213cacba7d36062b8a3bdc4b05bb3dc2eeeb4a06 (diff) |
Rename stubs file to <Module>_patch.c
-rw-r--r-- | c2haskell.hs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/c2haskell.hs b/c2haskell.hs index e55e9a9..8b1d843 100644 --- a/c2haskell.hs +++ b/c2haskell.hs | |||
@@ -207,21 +207,23 @@ notKnown "Int16" = False | |||
207 | notKnown "Int32" = False | 207 | notKnown "Int32" = False |
208 | notKnown "Int64" = False | 208 | notKnown "Int64" = False |
209 | notKnown "Bool" = False | 209 | notKnown "Bool" = False |
210 | notKnown "Word" = False | ||
210 | notKnown "Int" = False | 211 | notKnown "Int" = False |
211 | notKnown "Char" = False | 212 | notKnown "Char" = False |
212 | notKnown "()" = False | 213 | notKnown "()" = False |
213 | notKnown _ = True | 214 | notKnown _ = True |
214 | 215 | ||
215 | hsTypeSpec :: CDeclarationSpecifier t -> [Either Ident String] | 216 | hsTypeSpec :: CDeclarationSpecifier t -> [Either Ident String] |
216 | hsTypeSpec (CTypeSpec (CVoidType _)) = [ Right "()" ] | 217 | hsTypeSpec (CTypeSpec (CVoidType _)) = [ Right "()" ] |
218 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "size_t" _ _) _)) = [ Right "Word"] | ||
217 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint8_t" _ _) _)) = [ Right "Word8"] | 219 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint8_t" _ _) _)) = [ Right "Word8"] |
218 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint16_t" _ _) _)) = [ Right "Word16"] | 220 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint16_t" _ _) _)) = [ Right "Word16"] |
219 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint32_t" _ _) _)) = [ Right "Word32"] | 221 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint32_t" _ _) _)) = [ Right "Word32"] |
220 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint64_t" _ _) _)) = [ Right "Word64"] | 222 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "uint64_t" _ _) _)) = [ Right "Word64"] |
221 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int8_t" _ _) _)) = [ Right "Int8"] | 223 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int8_t" _ _) _)) = [ Right "Int8"] |
222 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int16_t" _ _) _)) = [ Right "Int16"] | 224 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int16_t" _ _) _)) = [ Right "Int16"] |
223 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int32_t" _ _) _)) = [ Right "Int32"] | 225 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int32_t" _ _) _)) = [ Right "Int32"] |
224 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int64_t" _ _) _)) = [ Right "Int64"] | 226 | hsTypeSpec (CTypeSpec (CTypeDef (C.Ident "int64_t" _ _) _)) = [ Right "Int64"] |
225 | hsTypeSpec (CTypeSpec (CTypeDef ctyp _)) = [ Left ctyp ] | 227 | hsTypeSpec (CTypeSpec (CTypeDef ctyp _)) = [ Left ctyp ] |
226 | hsTypeSpec (CTypeSpec (CBoolType _)) = [ Right "Bool"] | 228 | hsTypeSpec (CTypeSpec (CBoolType _)) = [ Right "Bool"] |
227 | hsTypeSpec (CTypeSpec (CIntType _)) = [ Right "Int"] | 229 | hsTypeSpec (CTypeSpec (CIntType _)) = [ Right "Int"] |
@@ -253,7 +255,8 @@ hsTransField ctyps vars | |||
253 | var <- vars | 255 | var <- vars |
254 | trace ("var="++show var) $ return () | 256 | trace ("var="++show var) $ return () |
255 | -- CDeclr (Just fident) ptrdeclr Nothing [] _ <- maybeToList var | 257 | -- CDeclr (Just fident) ptrdeclr Nothing [] _ <- maybeToList var |
256 | let CDeclr mfident ptrdeclr Nothing [] _ = var | 258 | let CDeclr mfident ptrdeclr Nothing [] _ = var -- TODO: Look into: Irrefutable pattern failed (ctox/toxcore/DHT.c) |
259 | -- let CDeclr mfident ptrdeclr _ _ _ = var | ||
257 | trace ("fident="++show mfident) $ return () | 260 | trace ("fident="++show mfident) $ return () |
258 | trace ("ptrdeclr="++show ptrdeclr) $ return () | 261 | trace ("ptrdeclr="++show ptrdeclr) $ return () |
259 | let btyp = HS.TyCon () typname | 262 | let btyp = HS.TyCon () typname |
@@ -462,7 +465,7 @@ c2haskell opts cs cmodname missings incs (CTranslUnit edecls _) = do | |||
462 | (ext,_:rname) -> reverse rname | 465 | (ext,_:rname) -> reverse rname |
463 | (rname,_) -> reverse rname | 466 | (rname,_) -> reverse rname |
464 | modname = capitalize $ basename cmodname | 467 | modname = capitalize $ basename cmodname |
465 | stubsname = "MonkeyPatch/t_stubs.c" -- todo | 468 | stubsname = "MonkeyPatch/" ++ modname ++ "_patch.c" |
466 | putStrLn $ "writing " ++ fname | 469 | putStrLn $ "writing " ++ fname |
467 | withFile fname WriteMode $ \haskmod -> do | 470 | withFile fname WriteMode $ \haskmod -> do |
468 | hPutStrLn haskmod $ "module MonkeyPatch." ++ modname ++" where" | 471 | hPutStrLn haskmod $ "module MonkeyPatch." ++ modname ++" where" |
@@ -485,12 +488,12 @@ c2haskell opts cs cmodname missings incs (CTranslUnit edecls _) = do | |||
485 | hPutStrLn haskmod $ "data " ++ t | 488 | hPutStrLn haskmod $ "data " ++ t |
486 | forM_ sigs $ \(_,(k,hs,d)) -> do | 489 | forM_ sigs $ \(_,(k,hs,d)) -> do |
487 | forM_ hs $ \hdecl -> do | 490 | forM_ hs $ \hdecl -> do |
491 | {- | ||
488 | hPutStr haskmod (commented k) | 492 | hPutStr haskmod (commented k) |
489 | hPutStr haskmod (commented $ show $ pretty d) | 493 | hPutStr haskmod (commented $ show $ pretty d) |
490 | hPutStr haskmod (commented $ show $ getReturnValue d) | 494 | hPutStr haskmod (commented $ show $ getReturnValue d) |
491 | hPutStr haskmod (commented $ show hdecl) | 495 | hPutStr haskmod (commented $ show hdecl) |
492 | -- hPutStr haskmod $ commented $ show $ length $ symbolSource si | 496 | -- hPutStr haskmod $ commented $ show $ length $ symbolSource si |
493 | {- | ||
494 | forM_ (take 1 $ symbolSource si) $ \d -> do | 497 | forM_ (take 1 $ symbolSource si) $ \d -> do |
495 | let ts = filter notKnown $ map tname $ pointers $ concatMap types $ sigf hsTransSig d | 498 | let ts = filter notKnown $ map tname $ pointers $ concatMap types $ sigf hsTransSig d |
496 | -- putStr $ commented (ppShow (fmap (const ()) d)) | 499 | -- putStr $ commented (ppShow (fmap (const ()) d)) |