Changeset 2765 for trunk/src/kmk


Ignore:
Timestamp:
Jan 30, 2015, 1:27:51 AM (10 years ago)
Author:
bird
Message:

Started on a make expression and string expansion 'compiler'.

Location:
trunk/src/kmk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r2752 r2765  
    193193        CONFIG_WITH_LAZY_DEPS_VARS \
    194194        CONFIG_WITH_MEMORY_OPTIMIZATIONS \
     195        CONFIG_WITH_COMPILER \
    195196        \
    196197        KBUILD_HOST=\"$(KBUILD_TARGET)\" \
     
    207208kmk_SOURCES = \
    208209        main.c \
    209         kbuild.c \
    210         kbuild-object.c \
    211210        read.c \
    212         expreval.c \
    213         incdep.c \
    214211        hash.c \
    215212        strcache.c \
    216         strcache2.c \
    217213        variable.c \
    218214        ar.c \
     
    227223        job.c \
    228224        misc.c \
    229         alloccache.c \
    230225        remake.c \
    231226        rule.c \
     
    233228        version.c \
    234229        vpath.c \
    235         remote-stub.c
     230        remote-stub.c \
     231       \
     232        alloccache.c \
     233        expreval.c \
     234        incdep.c \
     235        strcache2.c \
     236       kmk_cc_exec.c \
     237        kbuild.c \
     238        kbuild-object.c
    236239
    237240kmk_DEFS.freebsd.x86 = CONFIG_WITHOUT_THREADS
  • trunk/src/kmk/expand.c

    r2591 r2765  
    2626#include "variable.h"
    2727#include "rule.h"
     28#ifdef CONFIG_WITH_COMPILER
     29# include "kmk_cc_exec.h"
     30#endif
    2831
    2932/* Initially, any errors reported when expanding strings will be reported
     
    248251  v->expanding = 1;
    249252  if (!v->append)
    250     /* Expand directly into the variable buffer.  */
    251     variable_expand_string_2 (o, v->value, v->value_length, &o);
     253    {
     254      /* Expand directly into the variable buffer.  */
     255# ifdef CONFIG_WITH_COMPILER
     256      v->expand_count++;
     257      if (   v->expandprog
     258          || (v->expand_count == 10 && kmk_cc_compile_variable_for_expand (v)) )
     259        o = kmk_exec_expand_to_var_buf (v, o);
     260      else
     261        variable_expand_string_2 (o, v->value, v->value_length, &o);
     262# else
     263      MAKE_STATS_2 (v->expand_count++);
     264      variable_expand_string_2 (o, v->value, v->value_length, &o);
     265# endif
     266    }
    252267  else
    253268    {
  • trunk/src/kmk/function.c

    r2758 r2765  
    4343#  include <limits.h>
    4444# endif
     45#endif
     46#ifdef CONFIG_WITH_COMPILER
     47# include "kmk_cc_exec.h"
    4548#endif
    4649#include <assert.h> /* bird */
     
    20432046      size_t off;
    20442047      const struct floc *reading_file_saved = reading_file;
    2045 #ifdef CONFIG_WITH_MAKE_STATS
     2048# ifdef CONFIG_WITH_MAKE_STATS
    20462049      unsigned long long uStartTick = CURRENT_CLOCK_TICK();
    2047       MAKE_STATS_2(v->cEvalVals++);
    2048 #endif
    2049 
    2050       /* Make a copy of the value to the variable buffer since
    2051          eval_buffer will make changes to its input. */
    2052 
    2053       off = o - variable_buffer;
    2054       variable_buffer_output (o, v->value, v->value_length + 1);
    2055       o = variable_buffer + off;
    2056 
    2057       /* Eval the value.  Pop the current variable buffer setting so that the
    2058          eval'd code can use its own without conflicting. (really necessary?)  */
    2059 
    2060       install_variable_buffer (&buf, &len);
     2050#  ifndef CONFIG_WITH_COMPILER
     2051      MAKE_STATS_2(v->evalval_count++);
     2052#  endif
     2053# endif
     2054
    20612055      var_ctx = !strcmp (funcname, "evalvalctx");
    20622056      if (var_ctx)
     
    20652059        reading_file = &v->fileinfo;
    20662060
    2067       assert (!o[v->value_length]);
    2068       eval_buffer (o, o + v->value_length);
     2061# ifdef CONFIG_WITH_COMPILER
     2062      /* If this variable has been evaluated more than a few times, it make
     2063         sense to compile it to speed up the processing. */
     2064
     2065      v->evalval_count++;
     2066      if (   v->evalprog
     2067          || (v->evalval_count == 3 && kmk_cc_compile_variable_for_eval (v)))
     2068        {
     2069          install_variable_buffer (&buf, &len); /* Really necessary? */
     2070          kmk_exec_evalval (v);
     2071          restore_variable_buffer (buf, len);
     2072        }
     2073      else
     2074# endif
     2075      {
     2076        /* Make a copy of the value to the variable buffer first since
     2077           eval_buffer will make changes to its input. */
     2078
     2079        off = o - variable_buffer;
     2080        variable_buffer_output (o, v->value, v->value_length + 1);
     2081        o = variable_buffer + off;
     2082        assert (!o[v->value_length]);
     2083
     2084        install_variable_buffer (&buf, &len); /* Really necessary? */
     2085        eval_buffer (o, o + v->value_length);
     2086        restore_variable_buffer (buf, len);
     2087      }
    20692088
    20702089      reading_file = reading_file_saved;
    20712090      if (var_ctx)
    20722091        pop_variable_scope ();
    2073       restore_variable_buffer (buf, len);
    20742092
    20752093      MAKE_STATS_2(v->cTicksEvalVal += CURRENT_CLOCK_TICK() - uStartTick);
     
    21422160              v->value_length = dst - v->value;
    21432161            }
     2162
     2163# ifdef CONFIG_WITH_COMPILER
     2164          /* Compile the variable for evalval, evalctx and expansion. */
     2165
     2166          if (!v->evalprog)
     2167            kmk_cc_compile_variable_for_eval (v);
     2168          if (!v->expandprog)
     2169            kmk_cc_compile_variable_for_expand (v);
     2170# endif
    21442171        }
    21452172      else if (v)
  • trunk/src/kmk/variable.c

    r2758 r2765  
    4141#ifdef CONFIG_WITH_STRCACHE2
    4242# include <stddef.h>
     43#endif
     44#ifdef CONFIG_WITH_COMPILER
     45# include "kmk_cc_exec.h"
    4346#endif
    4447
     
    383386          v->origin = origin;
    384387          v->recursive = recursive;
    385           MAKE_STATS_2(v->changes++);
     388         MAKE_STATS_2(v->changes++);
     389#ifdef CONFIG_WITH_COMPILER
     390         if (v->evalprog || v->expandprog)
     391           kmk_cc_variable_changed (v);
     392#endif
    386393        }
    387394      return v;
     
    445452#endif
    446453  v->export = v_default;
     454#ifdef CONFIG_WITH_COMPILER
     455  v->evalprog = 0;
     456  v->expandprog = 0;
     457  v->evalval_count = 0;
     458  v->expand_count = 0;
     459#else
     460  MAKE_STATS_2(v->expand_count = 0);
     461  MAKE_STATS_2(v->evalval_count = 0);
     462#endif
    447463  MAKE_STATS_2(v->changes = 0);
    448464  MAKE_STATS_2(v->reallocs = 0);
    449465  MAKE_STATS_2(v->references = 0);
    450   MAKE_STATS_2(v->cEvalVals = 0);
    451466  MAKE_STATS_2(v->cTicksEvalVal = 0);
    452467
     
    589604          free (v->value);
    590605      MAKE_STATS_2(v->changes++);
     606#ifdef CONFIG_WITH_COMPILER
     607      if (v->evalprog || v->expandprog)
     608        kmk_cc_variable_changed (v);
     609#endif
    591610    }
    592611  else
     
    605624      v->aliased = 0;
    606625      v->export = v_default;
     626#ifdef CONFIG_WITH_COMPILER
     627      v->evalprog = 0;
     628      v->expandprog = 0;
     629      v->evalval_count = 0;
     630      v->expand_count = 0;
     631#else
     632      MAKE_STATS_2(v->expand_count = 0);
     633      MAKE_STATS_2(v->evalval_count = 0);
     634#endif
    607635      MAKE_STATS_2(v->changes = 0);
    608636      MAKE_STATS_2(v->reallocs = 0);
    609637      MAKE_STATS_2(v->references = 0);
    610       MAKE_STATS_2(v->cEvalVals = 0);
    611638      MAKE_STATS_2(v->cTicksEvalVal = 0);
    612639      v->exportable = 1;
     
    12421269#ifndef CONFIG_WITH_STRCACHE2
    12431270  free (v->name);
     1271#endif
     1272#ifdef CONFIG_WITH_COMPILER
     1273  if (v->evalprog || v->expandprog)
     1274    kmk_cc_variable_deleted (v);
    12441275#endif
    12451276#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     
    13621393            if (from_var->alias)
    13631394              fatal(NULL, ("Attempting to delete variable aliased '%s'"), from_var->name);
     1395#endif
     1396#ifdef CONFIG_WITH_COMPILER
     1397            if (from_var->evalprog || from_var->expandprog)
     1398              kmk_cc_variable_deleted (from_var);
    13641399#endif
    13651400#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
     
    23352370               free (free_value);
    23362371            MAKE_STATS_2(v->changes++);
     2372# ifdef CONFIG_WITH_COMPILER
     2373            if (v->evalprog || v->expandprog)
     2374              kmk_cc_variable_changed (v);
     2375# endif
    23372376            return v;
    23382377#else /* !CONFIG_WITH_VALUE_LENGTH */
     
    27652804
    27662805
     2806#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     2807static unsigned long var_stats_evalvals, var_stats_evalvaled;
     2808static unsigned long var_stats_expands, var_stats_expanded;
     2809#endif
    27672810#ifdef CONFIG_WITH_MAKE_STATS
    27682811static unsigned long var_stats_changes, var_stats_changed;
    27692812static unsigned long var_stats_reallocs, var_stats_realloced;
    27702813static unsigned long var_stats_references, var_stats_referenced;
    2771 static unsigned long var_stats_evalvals, var_stats_evalvaled;
    2772 static uintmax_t var_stats_evalval_ticks;
    27732814static unsigned long var_stats_val_len, var_stats_val_alloc_len;
    27742815static unsigned long var_stats_val_rdonly_len;
     
    28382879#endif /* KMK */
    28392880
     2881#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     2882  if (v->evalval_count != 0)
     2883# ifdef CONFIG_WITH_MAKE_STATS
     2884    printf (_(", %u evalvals (%llu ticks)"), v->evalval_count, v->cTicksEvalVal);
     2885# else
     2886    printf (_(", %u evalvals"), v->evalval_count);
     2887# endif
     2888  var_stats_evalvals += v->evalval_count;
     2889  var_stats_evalvaled += (v->evalval_count != 0);
     2890
     2891  if (v->expand_count != 0)
     2892    printf (_(", %u expands"), v->expand_count);
     2893  var_stats_expands += v->expand_count;
     2894  var_stats_expanded += (v->expand_count != 0);
     2895# ifdef CONFIG_WITH_COMPILER
     2896  if (v->evalprog != 0)
     2897    printf (_(", evalprog"));
     2898  if (v->expandprog != 0)
     2899    printf (_(", expandprog"));
     2900# endif
     2901#endif
     2902
    28402903#ifdef CONFIG_WITH_MAKE_STATS
    28412904  if (v->changes != 0)
    2842       printf (_(", %u changes"), v->changes);
     2905    printf (_(", %u changes"), v->changes);
    28432906  var_stats_changes += v->changes;
    28442907  var_stats_changed += (v->changes != 0);
    28452908
    28462909  if (v->reallocs != 0)
    2847       printf (_(", %u reallocs"), v->reallocs);
     2910    printf (_(", %u reallocs"), v->reallocs);
    28482911  var_stats_reallocs += v->reallocs;
    28492912  var_stats_realloced += (v->reallocs != 0);
    28502913
    28512914  if (v->references != 0)
    2852       printf (_(", %u references"), v->references);
     2915    printf (_(", %u references"), v->references);
    28532916  var_stats_references += v->references;
    28542917  var_stats_referenced += (v->references != 0);
    2855 
    2856   if (v->cEvalVals != 0)
    2857       //printf (_(", %u evalvals (%llu ticks)"), v->cEvalVals, v->cTicksEvalVal);
    2858       printf (_(", %u evalvals (%llu ms)"), v->cEvalVals, v->cTicksEvalVal / 3299998);
    2859   var_stats_evalvals += v->cEvalVals;
    2860   var_stats_evalvaled += (v->cEvalVals != 0);
    28612918
    28622919  var_stats_val_len += v->value_length;
     
    29142971print_variable_set (struct variable_set *set, char *prefix)
    29152972{
     2973#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     2974  var_stats_expands = var_stats_expanded = var_stats_evalvals
     2975    = var_stats_evalvaled = 0;
     2976#endif
    29162977#ifdef CONFIG_WITH_MAKE_STATS
    29172978  var_stats_changes = var_stats_changed = var_stats_reallocs
     
    29192980    = var_stats_val_len = var_stats_val_alloc_len
    29202981    = var_stats_val_rdonly_len = 0;
     2982#endif
    29212983
    29222984  hash_map_arg (&set->table, print_variable, prefix);
     
    29242986  if (set->table.ht_fill)
    29252987    {
     2988#ifdef CONFIG_WITH_MAKE_STATS
    29262989      unsigned long fragmentation;
    29272990
     
    29533016               (unsigned int)((100.0 * var_stats_referenced) / set->table.ht_fill),
    29543017               var_stats_references);
     3018#endif
     3019#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     3020      if (var_stats_evalvals)
     3021        printf(_("#   evalvaled %5lu (%2u%%),    evalval calls %6lu\n"),
     3022               var_stats_evalvaled,
     3023               (unsigned int)((100.0 * var_stats_evalvaled) / set->table.ht_fill),
     3024               var_stats_evalvals);
     3025      if (var_stats_expands)
     3026        printf(_("#    expanded %5lu (%2u%%),          expands %6lu\n"),
     3027               var_stats_expanded,
     3028               (unsigned int)((100.0 * var_stats_expanded) / set->table.ht_fill),
     3029               var_stats_expands);
     3030#endif
    29553031      }
    2956 #else
    2957   hash_map_arg (&set->table, print_variable, prefix);
    2958 #endif
    29593032
    29603033  fputs (_("# variable set hash-table stats:\n"), stdout);
  • trunk/src/kmk/variable.h

    r2758 r2765  
    113113    unsigned int reallocs;     /* Realloc on value count.  */
    114114    unsigned int references;   /* Lookup count.  */
    115     unsigned cEvalVals;        /* $(evalval v) or $(evalvalctx v) count */
    116115    unsigned long long cTicksEvalVal; /* Number of ticks spend in cEvalVal. */
     116#endif
     117#if defined (CONFIG_WITH_COMPILER) || defined (CONFIG_WITH_MAKE_STATS)
     118    unsigned int evalval_count; /* Times used with $(evalval ) or $(evalctx ). */
     119    unsigned int expand_count;  /* Times expanded (not to be confused with exp_count). */
     120#endif
     121#ifdef CONFIG_WITH_COMPILER
     122    struct cceval *evalprog;    /* Pointer to evalval/evalctx "program". */
     123    struct ccexpand *expandprog; /* Pointer to variable expand "program". */
    117124#endif
    118125  };
Note: See TracChangeset for help on using the changeset viewer.