From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8916 invoked by alias); 26 Nov 2014 01:37:44 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 8857 invoked by uid 89); 26 Nov 2014 01:37:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 02/03] jit-playback: Move argv-creation to its own function Date: Wed, 01 Jan 2014 00:00:00 -0000 Message-Id: <1416966320-15713-3-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1416966320-15713-1-git-send-email-dmalcolm@redhat.com> References: <1416966320-15713-1-git-send-email-dmalcolm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-SW-Source: 2014-q4/txt/msg00217.txt.bz2 The body of playback::context::compile is rather long, at 200 lines. Start splitting it out parts of it into smaller member functions. Also, eliminate a fixed-size buffer with bounds check in favor of an auto_vec<>. gcc/jit/ChangeLog: * jit-playback.c (gcc::jit::playback::context::compile): Use an auto_vec rather than a const char *[20] for the top-level argv, and move the logic to build it to... (gcc::jit::playback::context::make_fake_args): New function. * jit-playback.h (gcc::jit::playback::context::make_fake_args): New function. --- gcc/jit/jit-playback.c | 149 ++++++++++++++++++++++++++----------------------- gcc/jit/jit-playback.h | 8 +++ 2 files changed, 86 insertions(+), 71 deletions(-) diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index cd124eb..b12584e 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -1548,8 +1548,6 @@ compile () void *handle = NULL; const char *ctxt_progname; result *result_obj = NULL; - const char *fake_args[20]; - unsigned int num_args; m_path_template = make_tempdir_path_template (); if (!m_path_template) @@ -1576,77 +1574,14 @@ compile () if (!ctxt_progname) ctxt_progname = "libgccjit.so"; - fake_args[0] = ctxt_progname; - fake_args[1] = m_path_c_file; - num_args = 2; - -#define ADD_ARG(arg) \ - do \ - { \ - gcc_assert(num_args < sizeof(fake_args)/sizeof(char*)); \ - fake_args[num_args++] = arg; \ - } \ - while (0) - - ADD_ARG ("-fPIC"); - - /* Handle int options: */ - switch (get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL)) - { - default: - add_error (NULL, - "unrecognized optimization level: %i", - get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL)); - return NULL; - - case 0: - ADD_ARG ("-O0"); - break; - - case 1: - ADD_ARG ("-O1"); - break; - - case 2: - ADD_ARG ("-O2"); - break; - - case 3: - ADD_ARG ("-O3"); - break; - } - /* What about -Os? */ - - /* Handle bool options: */ - if (get_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO)) - ADD_ARG ("-g"); - - /* Suppress timing (and other) info. */ - if (!get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_SUMMARY)) - { - ADD_ARG ("-quiet"); - quiet_flag = 1; - } - - /* Aggressively garbage-collect, to shake out bugs: */ - if (get_bool_option (GCC_JIT_BOOL_OPTION_SELFCHECK_GC)) - { - ADD_ARG ("--param"); - ADD_ARG ("ggc-min-expand=0"); - ADD_ARG ("--param"); - ADD_ARG ("ggc-min-heapsize=0"); - } - - if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING)) - { - ADD_ARG ("-fdump-tree-all"); - ADD_ARG ("-fdump-rtl-all"); - ADD_ARG ("-fdump-ipa-all"); - } + auto_vec fake_args; + make_fake_args (&fake_args, ctxt_progname); + if (errors_occurred ()) + return NULL; toplev toplev (false); - - toplev.main (num_args, const_cast (fake_args)); + toplev.main (fake_args.length (), + const_cast (fake_args.address ())); toplev.finalize (); active_playback_ctxt = NULL; @@ -1750,6 +1685,78 @@ compile () return result_obj; } +/* Helper functions for gcc::jit::playback::context::compile. */ + +/* Build a fake argv for toplev::main from the options set + by the user on the context . */ + +void +playback::context:: +make_fake_args (auto_vec *argvec, + const char *ctxt_progname) +{ +#define ADD_ARG(arg) argvec->safe_push (arg) + + ADD_ARG (ctxt_progname); + ADD_ARG (m_path_c_file); + ADD_ARG ("-fPIC"); + + /* Handle int options: */ + switch (get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL)) + { + default: + add_error (NULL, + "unrecognized optimization level: %i", + get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL)); + return; + + case 0: + ADD_ARG ("-O0"); + break; + + case 1: + ADD_ARG ("-O1"); + break; + + case 2: + ADD_ARG ("-O2"); + break; + + case 3: + ADD_ARG ("-O3"); + break; + } + /* What about -Os? */ + + /* Handle bool options: */ + if (get_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO)) + ADD_ARG ("-g"); + + /* Suppress timing (and other) info. */ + if (!get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_SUMMARY)) + { + ADD_ARG ("-quiet"); + quiet_flag = 1; + } + + /* Aggressively garbage-collect, to shake out bugs: */ + if (get_bool_option (GCC_JIT_BOOL_OPTION_SELFCHECK_GC)) + { + ADD_ARG ("--param"); + ADD_ARG ("ggc-min-expand=0"); + ADD_ARG ("--param"); + ADD_ARG ("ggc-min-heapsize=0"); + } + + if (get_bool_option (GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING)) + { + ADD_ARG ("-fdump-tree-all"); + ADD_ARG ("-fdump-rtl-all"); + ADD_ARG ("-fdump-ipa-all"); + } +#undef ADD_ARG +} + /* Top-level hook for playing back a recording context. This plays back m_recording_ctxt, and, if no errors diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 30e9229..5ffc869 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -227,6 +227,14 @@ private: void handle_locations (); private: + + /* Functions for implementing "compile". */ + + void + make_fake_args (auto_vec *argvec, + const char *ctxt_progname); + +private: ::gcc::jit::recording::context *m_recording_ctxt; /* Allocated using xmalloc (by xstrdup). */ -- 1.8.5.3