[svn:parrot] r44185 - in trunk: . config/gen/makefiles src src/nci tools/dev

plobsing at svn.parrot.org plobsing at svn.parrot.org
Fri Feb 19 16:13:23 UTC 2010


Author: plobsing
Date: Fri Feb 19 16:13:19 2010
New Revision: 44185
URL: https://trac.parrot.org/parrot/changeset/44185

Log:
add --dynext option to parrot_nci_thunk_gen to ease building parrot dynext libraries

the existance of dynext nci thunk libraries pushes nci_func init up into global init, but that's fairly cheap now and going to become cheaper once we ditch all the thunks that core doesn't need.

add extra_nci_thunks dynext library to prove the concept

Modified:
   trunk/MANIFEST.SKIP
   trunk/config/gen/makefiles/root.in
   trunk/src/   (props changed)
   trunk/src/global_setup.c
   trunk/src/nci/api.c
   trunk/src/nci/core_thunks.c
   trunk/src/nci/extra_thunks.c
   trunk/tools/dev/nci_thunk_gen.pir

Modified: trunk/MANIFEST.SKIP
==============================================================================
--- trunk/MANIFEST.SKIP	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/MANIFEST.SKIP	Fri Feb 19 16:13:19 2010	(r44185)
@@ -1,6 +1,6 @@
 # ex: set ro:
 # $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Feb 19 05:52:57 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri Feb 19 16:09:15 2010 UT
 #
 # This file should contain a transcript of the svn:ignore properties
 # of the directories in the Parrot subversion repository. (Needed for
@@ -645,6 +645,8 @@
 ^src/exec_dep\.h/
 ^src/extend_vtable\.c$
 ^src/extend_vtable\.c/
+^src/extra_nci_thunks\.c$
+^src/extra_nci_thunks\.c/
 ^src/fingerprint\.c$
 ^src/fingerprint\.c/
 ^src/glut_callbacks\.c$

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/config/gen/makefiles/root.in	Fri Feb 19 16:13:19 2010	(r44185)
@@ -557,6 +557,7 @@
 DYNEXT_DIR          = runtime/parrot/dynext
 LIBNCI_TEST_SO      = $(DYNEXT_DIR)/libnci_test$(LOAD_EXT)
 LIBGLUTCB_SO        = $(DYNEXT_DIR)/libglutcb$(LOAD_EXT)
+EXTRANCITHUNKS_SO = $(DYNEXT_DIR)/extra_nci_thunks$(LOAD_EXT)
 
 ###############################################################################
 #
@@ -604,6 +605,7 @@
     corevm \
     docs \
 #IF(has_glut):    $(LIBGLUTCB_SO) \
+    $(EXTRANCITHUNKS_SO) \
     $(DIS) \
     $(PARROT_CONFIG) \
     $(PBC_TO_EXE) \
@@ -1864,6 +1866,8 @@
     src/glut_callbacks$(O) \
     src/glut_nci_thunks$(O) \
     $(LIBGLUTCB_SO) \
+    src/extra_nci_thunks$(O) \
+    $(EXTRANCITHUNKS_SO) \
     install_config.fpmc
 	$(PERL) $(BUILD_TOOLS_DIR)/c2str.pl --init
 	$(RM_F) \
@@ -1902,6 +1906,8 @@
     $(LIBNCI_TEST_SO) \
     src/glut_callbacks$(O) \
     $(LIBGLUTCB_SO) \
+    src/extra_nci_thunks$(O) \
+    $(EXTRA_NCI_THUNKS) \
     $(LIBPARROT_STATIC) \
     $(LIBPARROT_SHARED)
 
@@ -2443,6 +2449,16 @@
     @ld_out@$@ src/glut_callbacks$(O) src/glut_nci_thunks$(O) \
     $(ALL_PARROT_LIBS) @opengl_lib@
 
+src/extra_nci_thunks.c : src/nci/extra_thunks.nci $(PARROT_NCI_THUNK_GEN)
+	$(PARROT_NCI_THUNK_GEN) --dynext --output=src/extra_nci_thunks.c <src/nci/extra_thunks.nci
+
+src/extra_nci_thunks$(O): $(GENERAL_H_FILES)
+
+$(EXTRANCITHUNKS_SO) : $(LIBPARROT) src/extra_nci_thunks$(O)
+	$(LD) $(LD_LOAD_FLAGS) $(LDFLAGS) \
+    @ld_out@$@ src/extra_nci_thunks$(O) \
+    $(ALL_PARROT_LIBS)
+
 # emacs etags
 # this needs exuberant-ctags
 

Modified: trunk/src/global_setup.c
==============================================================================
--- trunk/src/global_setup.c	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/src/global_setup.c	Fri Feb 19 16:13:19 2010	(r44185)
@@ -190,6 +190,11 @@
 
     pmc = pmc_new(interp, enum_class_Hash);
     VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_DYN_LIBS, pmc);
+
+    pmc = pmc_new(interp, enum_class_Hash);
+    VTABLE_set_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS, pmc);
+    Parrot_nci_load_core_thunks(interp);
+    Parrot_nci_load_extra_thunks(interp);
 }
 
 /*

Modified: trunk/src/nci/api.c
==============================================================================
--- trunk/src/nci/api.c	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/src/nci/api.c	Fri Feb 19 16:13:19 2010	(r44185)
@@ -18,14 +18,6 @@
 /* HEADERIZER HFILE: include/parrot/nci.h */
 /* HEADERIZER STOP */
 
-static void
-init_nci_funcs(PARROT_INTERP) {
-    VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_NCI_FUNCS,
-        pmc_new(interp, enum_class_Hash));
-    Parrot_nci_load_core_thunks(interp);
-    Parrot_nci_load_extra_thunks(interp);
-}
-
 /* This function serves a single purpose. It takes the function
    signature for a C function we want to call and returns a pointer
    to a function that can call it. */
@@ -45,10 +37,8 @@
         PANIC(interp, "iglobals isn't created yet");
 
     nci_funcs = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS);
-    if (PMC_IS_NULL(nci_funcs)) {
-        init_nci_funcs(interp);
-        nci_funcs = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS);
-    }
+    if (PMC_IS_NULL(nci_funcs))
+        PANIC(interp, "iglobals.nci_funcs isn't created yet");
 
     thunk = VTABLE_get_pmc_keyed_str(interp, nci_funcs, signature);
 

Modified: trunk/src/nci/core_thunks.c
==============================================================================
--- trunk/src/nci/core_thunks.c	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/src/nci/core_thunks.c	Fri Feb 19 16:13:19 2010	(r44185)
@@ -1050,13 +1050,11 @@
     PMC        *HashPointer   = NULL;
 
     iglobals = interp->iglobals;
-    if (PMC_IS_NULL(iglobals))
-        PANIC(interp, "iglobals isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(iglobals));
 
     HashPointer = VTABLE_get_pmc_keyed_int(interp, iglobals,
             IGLOBALS_NCI_FUNCS);
-    if (PMC_IS_NULL(HashPointer))
-        PANIC(interp, "iglobals.nci_funcs isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(HashPointer));
 
     temp_pmc = pmc_new(interp, enum_class_UnManagedStruct);
     VTABLE_set_pointer(interp, temp_pmc, (void *)pcf_d_JOd);

Modified: trunk/src/nci/extra_thunks.c
==============================================================================
--- trunk/src/nci/extra_thunks.c	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/src/nci/extra_thunks.c	Fri Feb 19 16:13:19 2010	(r44185)
@@ -6202,13 +6202,11 @@
     PMC        *HashPointer   = NULL;
 
     iglobals = interp->iglobals;
-    if (PMC_IS_NULL(iglobals))
-        PANIC(interp, "iglobals isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(iglobals));
 
     HashPointer = VTABLE_get_pmc_keyed_int(interp, iglobals,
             IGLOBALS_NCI_FUNCS);
-    if (PMC_IS_NULL(HashPointer))
-        PANIC(interp, "iglobals.nci_funcs isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(HashPointer));
 
     temp_pmc = pmc_new(interp, enum_class_UnManagedStruct);
     VTABLE_set_pointer(interp, temp_pmc, (void *)pcf_v_J);

Modified: trunk/tools/dev/nci_thunk_gen.pir
==============================================================================
--- trunk/tools/dev/nci_thunk_gen.pir	Fri Feb 19 13:51:57 2010	(r44184)
+++ trunk/tools/dev/nci_thunk_gen.pir	Fri Feb 19 16:13:19 2010	(r44185)
@@ -46,13 +46,15 @@
     $P0 = open $S0, 'w'
     setstdout $P0
 
-    if targ == 'head'   goto get_targ
-    if targ == 'thunks' goto get_targ
-    if targ == 'loader' goto get_targ
-    if targ == 'coda'   goto get_targ
-    if targ == 'all'    goto all
-    if targ == 'names'  goto names
-    if targ == 'signatures'   goto signatures
+    if targ == 'head'          goto get_targ
+    if targ == 'thunks'        goto get_targ
+    if targ == 'loader'        goto get_targ
+    if targ == 'dynext-loader' goto get_dynext_loader
+    if targ == 'coda'          goto get_targ
+    if targ == 'all'           goto all
+    if targ == 'all-dynext'    goto all_dynext
+    if targ == 'names'         goto names
+    if targ == 'signatures'    goto signatures
 
     # unknown target
     $S0 = 'sprintf'("Unknown target type '%s'", targ)
@@ -69,6 +71,22 @@
     say $S0
     exit 0
 
+  all_dynext:
+    $S0 = 'get_head'(sigs)
+    say $S0
+    $S0 = 'get_thunks'(sigs)
+    say $S0
+    $S0 = 'get_dynext_loader'(sigs)
+    say $S0
+    $S0 = 'get_coda'(sigs)
+    say $S0
+    exit 0
+
+  get_dynext_loader:
+    $S0 = 'get_dynext_loader'(sigs)
+    say $S0
+    exit 0
+
   get_targ:
     $S0 = concat 'get_', targ
     $P0 = get_global $S0
@@ -101,6 +119,7 @@
     push getopt, 'help|h'
     push getopt, 'version|v'
     push getopt, 'core'
+    push getopt, 'dynext'
     push getopt, 'output|o=s'
     push getopt, 'target=s'
     push getopt, 'thunk-storage-class=s'
@@ -179,6 +198,30 @@
         opts['core'] = 'true'
     end_core:
 
+    $I0 = defined opts['dynext']
+    if $I0 goto is_dynext
+        opts['dynext'] = ''
+        goto end_dynext
+    is_dynext:
+        $I0 = defined opts['target']
+        if $I0 goto end_dynext_target
+            opts['target'] = 'all-dynext'
+        end_dynext_target:
+
+        $I0 = defined opts['loader-storage-class']
+        if $I0 goto end_dynext_loader_storage_class
+            opts['loader-storage-class'] = 'PARROT_DYNEXT_EXPORT'
+        end_dynext_loader_storage_class:
+
+        $I0 = defined opts['loader-name']
+        if $I0 goto end_dynext_loader_name
+            $S0 = opts['output']
+            ($S0, $S1, $S2) = 'file_basename'($S0, '.c')
+            $S0 = 'sprintf'('Parrot_lib_%s_init', $S1)
+            opts['loader-name'] = $S0
+        end_dynext_loader_name:
+    end_dynext:
+
     $I0 = defined opts['target']
     if $I0 goto end_target
         opts['target'] = 'all'
@@ -231,7 +274,7 @@
 
 # }}}
 
-# get_{head,thunks,loader,coda} {{{
+# get_{head,thunks,loader,dynext_loader,coda} {{{
 
 .sub 'get_head'
     .param pmc ignored :slurpy
@@ -249,15 +292,8 @@
     c_file = 'read_from_opts'(.OUTPUT)
 
     .local string str_file
-    str_file = clone c_file
-    substr str_file, -2, 2, '.str'
-    strip_str_file_loop:
-        $I0 = index str_file, '/'
-        if $I0 < 0 goto end_strip_str_file_loop
-        $I0 += 1
-        str_file = substr str_file, $I0
-        goto strip_str_file_loop
-    end_strip_str_file_loop:
+    ($S0, str_file, $S1) = 'file_basename'(c_file, '.c')
+    str_file = concat str_file, '.str'
 
     .local string head
     head = 'sprintf'(<<'HEAD', c_file, ext_defn, str_file)
@@ -343,13 +379,70 @@
     PMC        *HashPointer   = NULL;
 
     iglobals = interp->iglobals;
-    if (PMC_IS_NULL(iglobals))
-        PANIC(interp, "iglobals isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(iglobals));
+
+    HashPointer = VTABLE_get_pmc_keyed_int(interp, iglobals,
+            IGLOBALS_NCI_FUNCS);
+    PARROT_ASSERT(!PMC_IS_NULL(HashPointer));
+
+FN_HEADER
+
+    .local int i, n
+    i = 0
+    n = sigs
+    loop:
+        if i >= n goto end_loop
+
+        .local pmc sig
+        sig = shift sigs
+
+        .local string fn_name
+        fn_name = 'sig_to_fn_name'(sig :flat)
+
+        .local string key
+        key = join '', sig
+
+        $S0 = 'sprintf'(<<'TEMPLATE', fn_name, key)
+    temp_pmc = pmc_new(interp, enum_class_UnManagedStruct);
+    VTABLE_set_pointer(interp, temp_pmc, (void *)%s);
+    VTABLE_set_pmc_keyed_str(interp, HashPointer, CONST_STRING(interp, "%s"), temp_pmc);
+
+TEMPLATE
+        code = concat code, $S0
+
+        inc i
+        goto loop
+    end_loop:
+
+    code = concat code, <<'FN_FOOTER'
+}
+FN_FOOTER
+
+    .return (code)
+.end
+
+.sub 'get_dynext_loader'
+    .param pmc sigs
+
+    $S0 = 'read_from_opts'(.LOADER_STORAGE_CLASS)
+    $S1 = 'read_from_opts'(.LOADER_NAME)
+    .local string code
+    code = 'sprintf'(<<'FN_HEADER', $S0, $S1)
+
+%s void
+%s(PARROT_INTERP, SHIM(PMC *lib))
+{
+    PMC        *iglobals;
+    PMC        *temp_pmc;
+
+    PMC        *HashPointer   = NULL;
+
+    iglobals = interp->iglobals;
+    PARROT_ASSERT(!PMC_IS_NULL(iglobals));
 
     HashPointer = VTABLE_get_pmc_keyed_int(interp, iglobals,
             IGLOBALS_NCI_FUNCS);
-    if (PMC_IS_NULL(HashPointer))
-        PANIC(interp, "iglobals.nci_funcs isn't created yet");
+    PARROT_ASSERT(!PMC_IS_NULL(HashPointer));
 
 FN_HEADER
 
@@ -990,6 +1083,41 @@
     .return (output)
 .end
 
+.sub 'file_basename'
+    .param string full_path
+    .param pmc extns :slurpy
+
+    .local string dir, file, extn
+
+    file = clone full_path
+
+    extn_loop:
+        unless extns goto end_extn_loop
+        $S0 = shift extns
+        $I0 = length $S0
+        $I1 = -$I0
+        $S1 = substr file, $I1, $I0
+        unless $S1 == $S0 goto extn_loop
+        extn = $S1
+        substr file, $I1, $I0, ''
+    end_extn_loop:
+
+    # TODO: make this portable
+    .const string file_sep = '/'
+
+    strip_dir_loop:
+        $I0 = index file, file_sep
+        if $I0 < 0 goto end_strip_dir_loop
+        inc $I0
+        $S0 = substr file, 0, $I0
+        dir = concat dir, $S0
+        file = substr file, $I0
+        goto strip_dir_loop
+    end_strip_dir_loop:
+
+    .return (dir, file, extn)
+.end
+
 # }}}
 
 # Local Variables:


More information about the parrot-commits mailing list