Commit f035504b authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot

Add support for ASM foreign files (.s) in TH (#16180)

parent 6e7aa5e9
......@@ -306,11 +306,12 @@ compileForeign :: HscEnv -> ForeignSrcLang -> FilePath -> IO FilePath
compileForeign _ RawObject object_file = return object_file
compileForeign hsc_env lang stub_c = do
let phase = case lang of
LangC -> Cc
LangCxx -> Ccxx
LangObjc -> Cobjc
LangC -> Cc
LangCxx -> Ccxx
LangObjc -> Cobjc
LangObjcxx -> Cobjcxx
RawObject -> panic "compileForeign: should be unreachable"
LangAsm -> As True -- allow CPP
RawObject -> panic "compileForeign: should be unreachable"
(_, stub_o) <- runPipeline StopLn hsc_env
(stub_c, Just (RealPhase phase))
Nothing (Temporary TFL_GhcSession)
......
......@@ -6,6 +6,12 @@ module GHC.ForeignSrcLang.Type
import Prelude -- See note [Why do we import Prelude here?]
import GHC.Generics (Generic)
-- | Foreign formats supported by GHC via TH
data ForeignSrcLang
= LangC | LangCxx | LangObjc | LangObjcxx | RawObject
= LangC -- ^ C
| LangCxx -- ^ C++
| LangObjc -- ^ Objective C
| LangObjcxx -- ^ Objective C++
| LangAsm -- ^ Assembly language (.s)
| RawObject -- ^ Object (.o)
deriving (Eq, Show, Generic)
......@@ -503,11 +503,12 @@ addForeignFile = addForeignSource
addForeignSource :: ForeignSrcLang -> String -> Q ()
addForeignSource lang src = do
let suffix = case lang of
LangC -> "c"
LangCxx -> "cpp"
LangObjc -> "m"
LangC -> "c"
LangCxx -> "cpp"
LangObjc -> "m"
LangObjcxx -> "mm"
RawObject -> "a"
LangAsm -> "s"
RawObject -> "a"
path <- addTempFile suffix
runIO $ writeFile path src
addForeignFilePath lang path
......
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Language.Haskell.TH.Syntax
import Foreign.C.String
$(do
-- some architectures require a "_" symbol prefix...
-- GHC defines a LEADING_UNDERSCORE CPP constant to indicate this.
addForeignSource LangAsm
"#if defined(LEADING_UNDERSCORE)\n\
\.global \"_mydata\"\n\
\_mydata:\n\
\#else\n\
\.global \"mydata\"\n\
\mydata:\n\
\#endif\n\
\.ascii \"Hello world\\0\"\n"
return [])
foreign import ccall "&mydata" mystring :: CString
main :: IO ()
main = putStrLn =<< peekCString mystring
......@@ -467,3 +467,4 @@ test('T15437', expect_broken(15437), multimod_compile,
test('T15985', normal, compile, [''])
test('T16133', normal, compile_fail, [''])
test('T15471', normal, multimod_compile, ['T15471.hs', '-v0'])
test('T16180', normal, compile_and_run, [''])
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