From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 897763858D1E for ; Wed, 30 Nov 2022 15:58:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 897763858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 13A4021AFD; Wed, 30 Nov 2022 15:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1669823921; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vqWdMBwetsp5DK+0+yKVaOA2GcW7S0I3F84oh/jiG4s=; b=JWavgl+YnTQkEC/71ttdW3a538sl1b3ASyhfHpF0vUuuqfmalWj/ghIBw7fAJy0dQokner ITN1zVmuZP9Hr5b4lpxG1ZoWpstIipx9bz1BR+HWpWuArOKVlNJMp+/mqgmKYGDCa51FY6 XJsAmrWDDxb78xVHdd2aM482kMfnX8U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1669823921; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vqWdMBwetsp5DK+0+yKVaOA2GcW7S0I3F84oh/jiG4s=; b=ENXtPXrJ0sF47oalglv155/akvpSWFRBTAcYxZTr0IBpYUbsHD6a7c8TeJwgS+ATSlL0Dp zgqr7ilv4dBljrBA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EC7312C14F; Wed, 30 Nov 2022 15:58:40 +0000 (UTC) Received: by wotan.suse.de (Postfix, from userid 10510) id CC411645D; Wed, 30 Nov 2022 15:58:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by wotan.suse.de (Postfix) with ESMTP id CA46D6111; Wed, 30 Nov 2022 15:58:40 +0000 (UTC) Date: Wed, 30 Nov 2022 15:58:40 +0000 (UTC) From: Michael Matz To: "James K. Lowden" cc: gcc@gcc.gnu.org Subject: Re: access to include path in front end In-Reply-To: <20221129100804.c5b3e5bc669ff92f2100c3a3@schemamania.org> Message-ID: References: <20221129100804.c5b3e5bc669ff92f2100c3a3@schemamania.org> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, On Tue, 29 Nov 2022, James K. Lowden wrote: > I don't understand how to access in a front end the arguments to the -I > option on the command line. > > Cobol has a feature similar to the C preprecessor, known as the > Compiler Directing Facility (CDF). The CDF has a COPY statement that > resembles an #include directive in C, and shares the property that COPY > names a file that is normally found in a "copybook" which, for our > purposes, is a directory of such files. The name of that directory is > defined outside the Cobol program. > > I would like to use the -I option to pass the names of copybook > directories to the cobol front end. A bit of exploration yesterday left > me with the sense that the -I argument, in C at least, is not passed to > the compiler, but to the preprocessor. Access to -fmax-errors I think > I've figured out, but -I is a mystery. > > I'm a little puzzled by the status quo as I understand it. Unless I > missed it, it's not discussed in gccint. ISTM ideally there would be > some kind of getopt(3) processing, and the whole set of command-line > options captured in an array of structures accessible to any front > end. There is, it's just much more complicated than getopt :) If you're looking at the C frontends for inspiration, then: c-family/c.opt defines which options are recognized and several specifics about them, e.g. for -I it has: ---- I C ObjC C++ ObjC++ Joined Separate MissingArgError(missing path after %qs) -I Add to the end of the main include path. ---- (look at some other examples therein, also in common.opt to get a feel). Then code in c-family/c-opts.c:c_common_handle_option actually handles the option: case OPT_I: if (strcmp (arg, "-")) add_path (xstrdup (arg), INC_BRACKET, 0, true); else .,. That function is made a langhook for option processing so that it's actually called via c/c-objc-common.h: #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option If you're also using the model of a compiler driver (i.e. the gcc program, source in gcc.cc) that actually calls compiler (cc1), assembler and linker, then you also need to arrange for that program to pass all -I options to the compiler proper. That is done with the spec language, by somewhere having '{I*}' in the specs for invoking the cobol compiler. E.g. look in gcc.cc for '@c' (matching the file extension) how that entry uses '%(cpp_unique_options)', and how cpp_unique_options is defined for the specs language: INIT_STATIC_SPEC ("cpp_unique_options", &cpp_unique_options), and static const char *cpp_unique_options = "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\ (the specs language used here is documented in a lengthy comment early in gcc.cc, "The Specs Language") The "%@{I*F*}" is the one that makes gcc pass -Iwhatever to cc1 (and ensures relative order with -F options is retained and puts all these into an @file if one is given on the cmdline, otherwise leaves it on cmdline). If you use the compiler driver then using '-v' when invoking it will quickly tell you if that options passing worked, as it will show the concrete command it exec's for the compiler proper. Hope this helps. Ciao, Michael.