Skip to content

Commit cc40f6d

Browse files
Merge pull request #208 from tweag/fd/initializerCStub
Use initializerCStub to create C stubs with constructor functions
2 parents 230ba99 + 8538bf5 commit cc40f6d

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/GhcPlugins/Extras.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ module GhcPlugins.Extras
77
, module GhcPlugins.Extras
88
, module GHC.Core.TyCo.Rep
99
, module GHC.Types.ForeignStubs
10+
, module GHC.Cmm.CLabel
1011
) where
1112

1213
import Control.Monad.Writer
1314
import Data.Data (Data)
1415
import Data.Maybe (mapMaybe)
16+
import GHC.Cmm.CLabel (mkInitializerStubLabel)
1517
import GHC.Core.FamInstEnv
1618
import GHC.Core.Reduction (Reduction(..))
1719
import GHC.Core.TyCo.Rep

src/Language/Java/Inline/Plugin.hs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import Prelude hiding ((<>))
4949
--
5050
-- Finally, it calls the java compiler to produce the bytecode and
5151
-- arranges to have it inserted in the bytecode table in constructor functions
52-
-- (cConstructors).
52+
-- (cConstructor).
5353

5454
plugin :: Plugin
5555
plugin = defaultPlugin
@@ -82,15 +82,15 @@ plugin = defaultPlugin
8282
dcs <- buildJava guts qqOccs jimports
8383
>>= maybeDumpJava args
8484
>>= buildBytecode args
85+
dflags <- getDynFlags
86+
let cstub =
87+
cConstructor
88+
dflags
89+
(mg_module guts)
90+
(text bctable_header $$ dotClasses dcs)
8591
return guts
8692
{ mg_binds = binds
87-
, mg_foreign = appendStubC (mg_foreign guts) $
88-
CStub
89-
( text bctable_header
90-
$$ dotClasses dcs
91-
$$ cConstructors
92-
)
93-
[] []
93+
, mg_foreign = appendStubC (mg_foreign guts) cstub
9494
}
9595

9696
-- The contents of bctable.h
@@ -460,9 +460,10 @@ dotClasses dcs = vcat $
460460

461461
-- | Produces the constructor function which inserts the static structures
462462
-- generated by 'dotClasses' into the bytecode table.
463-
cConstructors :: SDoc
464-
cConstructors = vcat
465-
[ text "static void hs_inline_java_init(void) __attribute__((constructor));"
466-
, text "static void hs_inline_java_init(void)"
467-
, text "{ inline_java_bctable = inline_java_new_pack(inline_java_bctable, dcs, dc_count); }"
468-
]
463+
cConstructor :: DynFlags -> Module -> SDoc -> CStub
464+
cConstructor dflags this_mod decls =
465+
initializerCStub
466+
(targetPlatform dflags)
467+
(mkInitializerStubLabel this_mod "inline_java_bctable")
468+
decls
469+
(text "{ inline_java_bctable = inline_java_new_pack(inline_java_bctable, dcs, dc_count); }")

0 commit comments

Comments
 (0)