diff options
author | Mike Gerwitz <mike.gerwitz@ryansg.com> | 2020-01-02 23:29:49 -0500 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@ryansg.com> | 2020-02-24 14:56:28 -0500 |
commit | ff0c8bb34fbf2616143205a9fb0848bc783f60a4 (patch) | |
tree | c5a2e9b50e30de5212ccee2a20d47a879319e636 /src | |
parent | 1f4db84f248332a1a891e4d9b7ca28cf3afc547d (diff) | |
download | tame-ff0c8bb34fbf2616143205a9fb0848bc783f60a4.tar.gz tame-ff0c8bb34fbf2616143205a9fb0848bc783f60a4.tar.bz2 tame-ff0c8bb34fbf2616143205a9fb0848bc783f60a4.zip |
Order symtable, sym-dep, fragments
This ordering will simplify streaming processing of xmlo files in
TAMER. Specifically, we know that symbols will have been declared by the
time dependencies are added to the graph (and so we should only be creating
edges to existing nodes); and we can halt reading as soon as the closing
fragments tag is encountered, avoiding parsing the entirety of these massive
XML files.
On one particularly large program, this cuts time down from ~0.333s to
~0.300 in the POC linker.
Diffstat (limited to 'src')
-rw-r--r-- | src/current/compiler/fragments.xsl | 43 | ||||
-rw-r--r-- | src/current/compiler/map.xsl | 10 | ||||
-rw-r--r-- | src/current/include/depgen.xsl | 20 |
3 files changed, 57 insertions, 16 deletions
diff --git a/src/current/compiler/fragments.xsl b/src/current/compiler/fragments.xsl index 7a4cbad..cf41132 100644 --- a/src/current/compiler/fragments.xsl +++ b/src/current/compiler/fragments.xsl @@ -31,21 +31,42 @@ <template mode="preproc:compile-fragments" priority="9" match="lv:package"> + <copy> + <sequence select="@*" /> + + <apply-templates select="*" mode="preproc:compile-fragments-root" /> + </copy> +</template> + + +<template mode="preproc:compile-fragments-root" priority="1" + match="node()"> + <sequence select="." /> +</template> + + +<!-- Position fragments directly after dependencies. This allows TAMER to + halt processing early on, rather than having to read the rest of the + file (fragments used to be placed at the end). --> +<template mode="preproc:compile-fragments-root" priority="5" + match="preproc:sym-deps"> + <sequence select="." /> + + <variable name="package" as="element( lv:package )" + select="parent::lv:package" /> + <variable name="symtable-map" as="map( xs:string, element( preproc:sym ) )" select="map:merge( - for $sym in preproc:symtable/preproc:sym + for $sym in $package/preproc:symtable/preproc:sym return map{ string( $sym/@name ) : $sym } )" /> - <copy> - <sequence select="@*, *" /> - - <preproc:fragments> - <apply-templates mode="preproc:compile-fragments"> - <with-param name="symtable-map" select="$symtable-map" - tunnel="yes" /> - </apply-templates> - </preproc:fragments> - </copy> + <preproc:fragments> + <apply-templates select="$package/*" + mode="preproc:compile-fragments"> + <with-param name="symtable-map" select="$symtable-map" + tunnel="yes" /> + </apply-templates> + </preproc:fragments> </template> diff --git a/src/current/compiler/map.xsl b/src/current/compiler/map.xsl index e2620e4..1a1a9a2 100644 --- a/src/current/compiler/map.xsl +++ b/src/current/compiler/map.xsl @@ -123,7 +123,8 @@ <!-- final result with compiled fragments --> <lv:package> <sequence select="$pkg-with-symtable/@*, - $pkg-with-symtable/node()" /> + $pkg-with-symtable/preproc:sym-deps/preceding-sibling::*, + $pkg-with-symtable/preproc:sym-deps" /> <preproc:fragments> <!-- special fragment to be output as the head --> @@ -148,6 +149,8 @@ <text>};</text> </preproc:fragment> </preproc:fragments> + + <sequence select="$pkg-with-symtable/preproc:sym-deps/following-sibling::*" /> </lv:package> </template> @@ -197,7 +200,8 @@ <!-- final result with compiled fragments --> <lv:package> <sequence select="$pkg-with-symtable/@*, - $pkg-with-symtable/node()" /> + $pkg-with-symtable/preproc:sym-deps/preceding-sibling::*, + $pkg-with-symtable/preproc:sym-deps" /> <preproc:fragments> <!-- special fragment to be output as the head --> @@ -222,6 +226,8 @@ <text>};</text> </preproc:fragment> </preproc:fragments> + + <sequence select="$pkg-with-symtable/preproc:sym-deps/following-sibling::*" /> </lv:package> </template> diff --git a/src/current/include/depgen.xsl b/src/current/include/depgen.xsl index 8decc67..8f7c73f 100644 --- a/src/current/include/depgen.xsl +++ b/src/current/include/depgen.xsl @@ -66,13 +66,27 @@ <text>[depgen] *determining symbol dependencies...</text> </message> - <apply-templates select="preproc:symtable" mode="preproc:depgen" /> - - <sequence select="*" /> + <apply-templates select="*" mode="preproc:depgen-root" /> </copy> </template> +<template mode="preproc:depgen-root" priority="1" + match="node()"> + <sequence select="." /> +</template> + + +<template mode="preproc:depgen-root" priority="5" + match="preproc:symtable"> + <!-- Place symbol table _before_ dependencies. This simplifies + streaming processing in TAMER. --> + <sequence select="." /> + + <apply-templates select="." mode="preproc:depgen" /> +</template> + + <template match="preproc:symtable" mode="preproc:depgen" priority="9"> <variable name="symtable" select="." /> |