#
#     Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#

# EDG compiler specific options that apply to both C and C++.

append DEFDEFS=__GNUC__=$GCCMAJORVERSION __GNUC_MINOR__=$GCCMINORVERSION __GNUC_PATCHLEVEL__=$GCCPATCHVERSION;

# -idirafter directories
variable USRPOSTSTDINC is default();

# -iquote directories
variable USRQUOTEINC is default();

# -C is different for C than for Fortran
switch -C is
	help(Preserve comments in preprocessor output)
	helpgroup(prepro)
	append(CPP1ARGS=--comments);

switch --diag_error$arg is
    help(Override the severity of a diagnostic)
    helpgroup(overall)
    append(CPP1ARGS=--diag_error $arg);

switch --diag_remark$arg is
    help(Override the severity of a diagnostic)
    helpgroup(overall)
    append(CPP1ARGS=--diag_remark $arg);

switch --diag_suppress$arg is
    help(Override the severity of a diagnostic)
    helpgroup(overall)
    append(CPP1ARGS=--diag_suppress $arg);

switch --diag_warning$arg is
    help(Override the severity of a diagnostic)
    helpgroup(overall)
    append(CPP1ARGS=--diag_warning $arg);

switch --display_error_number is
    help(Display error message numbers)
    helpgroup(overall)
    append(CPP1ARGS=--display_error_number);

switch --no_display_error_number is
    help(Do not display error message numbers)
    helpgroup(overall)
    append(CPP1ARGS=--no_display_error_number);

switch --remarks is
    help(Enable remarks)
    helpgroup(language)
    append(CPP1ARGS=--remarks);

switch -fexceptions is
    helpname(-f[no-]exceptions)
    help(Enable (disable) C++ exceptions)
    helpgroup(language)
    set(EXCEPTIONS_ENABLED=1)
    append(CPP1ARGS=--exceptions);

switch -fno-exceptions is hide
    help(Disable C++ exceptions)
    helpgroup(language)
    set(EXCEPTIONS_ENABLED=0)
    append(CPP1ARGS=--no_exceptions);

# Options for the signedness of plain char.  There are three different names
# for these options.  See also -Mschar / -Muchar in ccrc.
switch --signed_chars is
    helpname(--signed_chars or -fsigned-char)
    help(Plain char is a signed type (default on x86))
    helpgroup(language)
    set(DEFUNSIGNED=)
    append(CPP1ARGS=--signed_chars);
switch --unsigned_chars is
    helpname(--unsigned_chars or -funsigned-char)
    help(Plain char is an unsigned type (default on Arm and Power))
    helpgroup(language)
    set(DEFUNSIGNED=YES)
    append(CPP1ARGS=--unsigned_chars);
switch -fsigned-char is hide
    shorthand(--signed_chars)
    helpgroup(language);
switch -funsigned-char is hide
    shorthand(--unsigned_chars)
    helpgroup(language);

switch -fvisibility is
	help(Set visibility of ELF symbols)
	helpgroup(overall)
	keyword(
	    default   (append(CPP1ARGS=--fvisibility_default))
	    hidden    (append(CPP1ARGS=--fvisibility_hidden))
	    protected (append(CPP1ARGS=--fvisibility_protected))
	    internal  (append(CPP1ARGS=--fvisibility_internal))
	)
	onekeyword;

switch -fvisibility-inlines-hidden is
	help(Set visibility of inline functions to hidden)
	helpgroup(overall)
	append(CPP1ARGS=--fvisibility_inlines_hidden);


switch -include$name is
    help(compatibility: File to include at start of compilation)
    helpgroup(language)
    append(CPP1ARGS=--preinclude $path($name));

switch -iquote$incdir is
    help(Add a directory to the beginning of the include file search path, and use it only when processing includes with quotes)
    helpgroup(prepro)
    append(USRQUOTEINC=$path($incdir));

switch -idirafter$incdir is
    help(Add a directory to the end of the include file search path, after the standard include directories, and mark it as a system include directory)
    helpgroup(prepro)
    append(USRPOSTSTDINC=$path($incdir));

switch -nostdinc is
	help(Do not search system directories for header files)
	helpgroup(prepro)
	set(SYSTEMINC=);
replace switch -Mnostdinc is hide shorthand(-nostdinc) helpgroup(prepro);

switch -Mcray is hide
	 help(Set Cray pointer semantics";" for Fortran only)
	 helpgroup(language)
	 keyword(
	     pointer()
	 );

switch -Mallocatable=version is hide
	early
	help(Select semantics for assignments to allocatables)
	helpgroup(language);

switch -Mcontiguous is hide
	help(Assume Fortran POINTERs are contiguous)
	helpname(-M[no]contiguous)
	helpgroup(language);
switch -Mnocontiguous is hide
	help(Do not assume Fortran POINTERs are contiguous)
	helpgroup(language);

switch -Mtarget_temps is hide
        helpgroup(opt)
        helpname(-M[no]target_temps)
        help(Enable [disable] a temporary when passing an array for a callee assumed-shape variable with the target attribute);

switch -Mnotarget_temps is hide
        helpgroup(opt)
        help(Disable a temporary when passing an array for a callee assumed-shape variable with the target attribute);

# set by -[no]pedantic and added to $CPP1ARGS
variable PEDANTIC is default();

switch -pedantic is
    help(Issue some additional warninings for non-standard extensions)
    helpname(-[no-]pedantic)
    helpgroup(overall)
    set(PEDANTIC=--strict_warnings); # enable strict/pedantic warnings in EDG

switch -no-pedantic is hide
    help(Do not issue ANSI warnings)
    helpgroup(overall)
    set(PEDANTIC=); # clear the $PEDANTIC variable

switch -Wpedantic == -pedantic;

switch -Wno-pedantic == -no-pedantic;

switch -std is
    help(C or C++ language dialect)
    helpgroup(language)
    keyword(
      c89( set(IS_CPLUS=0) append(DIALECTARGS=--c89) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c89) )
      c90=c89
      "iso9899:1990"=c89(hide)
      c99( set(IS_CPLUS=0) append(DIALECTARGS=--c99) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c99) )
      c9x=c99(hide)
      "iso9899:1999"=c99(hide)
      "iso9899:199x"=c99(hide)
      c11( set(IS_CPLUS=0) append(DIALECTARGS=--c11) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c11) )
      c1x=c11(hide)
      "iso9899:2011"=c11(hide)
      c17( set(IS_CPLUS=0) append(DIALECTARGS=--c17) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c17) )
      c18=c17
      "iso9899:2017"=c17(hide)
      "iso9899:2018"=c17(hide)
      c23( set(IS_CPLUS=0) append(DIALECTARGS=--c23) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c23) )
      "iso9899:2023"=c23(hide)
      gnu90( set(IS_CPLUS=0) append(DIALECTARGS=--c89) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu90) )
      gnu89=gnu90
      gnu99( set(IS_CPLUS=0) append(DIALECTARGS=--c99) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu99) )
      gnu9x=gnu99(hide)
      gnu11( set(IS_CPLUS=0) append(DIALECTARGS=--c11) set(GNU_EXTENSIONS=1) append(CPP1ARGS= --gnu_extensions) set(DIALECT_FLAG=-std=gnu11) )
      gnu1x=gnu11(hide)
      gnu17( set(IS_CPLUS=0) append(DIALECTARGS=--c17) set(GNU_EXTENSIONS=1) append(CPP1ARGS= --gnu_extensions) set(DIALECT_FLAG=-std=gnu17) )
      gnu18=gnu17
      gnu23( set(IS_CPLUS=0) append(DIALECTARGS=--c23) set(GNU_EXTENSIONS=1) append(CPP1ARGS= --gnu_extensions) set(DIALECT_FLAG=-std=gnu23) )
      "c++98"( set(IS_CPLUS=1) append(DIALECTARGS=--c++03) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++98) )
      "c++03"="c++98"
      "c++11"( set(IS_CPLUS=1) append(DIALECTARGS=--c++11) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++11) )
      "c++0x"="c++11"(hide)
      "c++14"( set(IS_CPLUS=1) append(DIALECTARGS=--c++14) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++14) )
      "c++1y"="c++14"(hide)
      "c++17"( set(IS_CPLUS=1) append(DIALECTARGS=--c++17) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++17) )
      "c++1z"="c++17"(hide)
      "c++20"( set(IS_CPLUS=1) append(DIALECTARGS=--c++20) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++20) )
      "c++2a"="c++20"(hide)
      "c++23"( set(IS_CPLUS=1) append(DIALECTARGS=--c++23) set(GNU_EXTENSIONS=0) set(DIALECT_FLAG=-std=c++23) )
      "gnu++98"( set(IS_CPLUS=1) append(DIALECTARGS=--c++03) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++98) )
      "gnu++03"="gnu++98"
      "gnu++11"( set(IS_CPLUS=1) append(DIALECTARGS=--c++11) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++11) )
      "gnu++0x"="gnu++11"(hide)
      "gnu++14"( set(IS_CPLUS=1) append(DIALECTARGS=--c++14) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++14) )
      "gnu++1y"="gnu++14"(hide)
      "gnu++17"( set(IS_CPLUS=1) append(DIALECTARGS=--c++17) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++17) )
      "gnu++1z"="gnu++17"(hide)
      "gnu++20"( set(IS_CPLUS=1) append(DIALECTARGS=--c++20) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++20) )
      "gnu++2a"="gnu++20"(hide)
      "gnu++23"( set(IS_CPLUS=1) append(DIALECTARGS=--c++23) set(GNU_EXTENSIONS=1) append(CPP1ARGS=--gnu_extensions) set(DIALECT_FLAG=-std=gnu++23) )
    )
    onekeyword;

error($if($land($IS_CPLUS, $equal($DRIVER,C)),The C++ language dialect $DIALECT_FLAG is only available for C++.  Please use nvc++.));

switch --std=arg is shorthand(-std=$arg) hide;

switch -Msafeptr is
	help(Specify pointers as safe)
	helpgroup(opt)
	helpname(-M[no]safeptr)
	set(safe=0)
	keyword(
	    all(or(safe=15) help(All pointers are safe))
	    arg(or(safe=1) help(Argument pointers are safe))
	    auto=local( help(Same as -Msafeptr=local))
	    dummy=arg( help(Same as -Msafeptr=arg))
	    global(or(safe=8) help(Global pointers are safe))
	    local(or(safe=2) help(Local pointers are safe))
	    static(or(safe=4) help(Static local pointers are safe))
	)
	nokeyword(or(safe=15) help(-Msafeptr=all))
	append(CARGS=-x 2 $safe);

switch -Mnosafeptr is hide
	help(Treat pointers as unsafe)
	helpgroup(opt)
	append(CARGS=-y 2 15);

# Option used to pass flags to Fortran FE - can be ignored.
switch -Wh,arg is hide
  help(Ignored, for compatibility with nvfortran)
  helpgroup(overall);

switch -Wdeprecated-declarations is
	help(Warn about the use of deprecated declarations)
	helpgroup(language)
	append(CPP1ARGS=--diag_warning 1216);

switch -Wno-deprecated-declarations is
	help(Suppress warnings about the use of deprecated declarations)
	helpgroup(language)
	append(CPP1ARGS=--diag_suppress 1216);

switch -Wunused-variable is
  help(Warn about unused variables)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 177);

switch -Wno-unused-variable is
  help(Suppress warnings about unused variables)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 177);

switch -Wshadow is
  help(Issue a warning whenever a variable hides another variable)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 1349);

switch -Wno-shadow is
  help(Suppress warnings when a variable hides another variable)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 1349);

switch -Wstrict-prototypes is
  help(C only. Warn if a function is declared or defined without specifying the argument types)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 3224);

switch -Wno-strict-prototypes is
  help(C only. Suppress warning when a function is declared or defined without specifying the argument types)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 3224);

switch -Wno-long-long is
    help(Suppress warnings about long long being nonstandard)
    helpgroup(language)
    append(CPP1ARGS=--diag_suppress 450);

switch -Wuninitialized is
  help(Warn about using uninitialized variables)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 549);

switch -Winit-self == -Wuninitialized;

switch -Wno-uninitialized is
  help(Suppress warnings about using uninitialized variables)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 549);

switch -Wno-init-self == -Wno-uninitialized;

switch -Wundef is
  help(Warn if an undefined definition is used in \#if)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 193);

switch -Wno-undef is
  help(Suppress warnings when an undefined definition is used in \#if)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 193);

switch -Wunused-parameter is
  help(Warn when a parameter is unused)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 827);

switch -Wno-unused-parameter is
  help(Suppress warnings when a parameter is unused)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 827);

switch -Wunused-but-set-parameter is
  help(Warn when a parameter is set but unused. Implies -Wno-unused-but-set-variable)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 550);

switch -Wno-unused-but-set-parameter is
  help(Suppress warnings when a parameter is set but unused. Implies -Wno-unused-but-set-variable)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 550);

switch -Wunused-but-set-variable is
  help(Warn when a variable is set but unused. Implies -Wunused-but-set-parameter)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 550);

switch -Wno-unused-but-set-variable is
  help(Suppress warnings when a variable is set but unused. Implies -Wno-unused-but-set-parameter)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 550);

switch -Wsign-compare is
  help(Warn when comparisons are made between signed and unsigned operands)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 1874);

switch -Wno-sign-compare is
  help(Suppress warnings when comparisons are made between signed and unsigned operands)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 1874);

switch -Woverloaded-virtual is
  help(Warn when a virtual function is hidden instead of overriden)
  helpgroup(language)
  append(CPP1ARGS=--diag_warning 998);

switch -Wno-overloaded-virtual is
  help(Suppess warnings when a virtual function is hidden instead of overriden)
  helpgroup(language)
  append(CPP1ARGS=--diag_suppress 998);

switch -Wunused == -Wunused-parameter -Wunused-variable -Wunused-function -Wunused-but-set-parameter -Wunused-but-set-variable;
switch -Wno-unused == -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-parameter -Wno-unused-but-set-variable;

switch --error_limit$num is
    help(Set an error limit)
    helpgroup(language)
    set(MAXERRORS=$if($isnum($num),--error_limit $num,$error(Illegal option to --error_limit)));

switch -ferror-limit$num is
    help(Set an error limit)
    helpgroup(language)
    set(MAXERRORS=$if($isnum($num),--error_limit $num,$error(Illegal option to -ferror-limit)));

# Warning flags that are implemented as noop for compatibility with gcc.
switch -Wpointer-arith is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-pointer-arith is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wcast-align is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-cast-align is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wwrite-strings is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-write-strings is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Waggregate-return is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-aggregate-return is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wmissing-prototypes is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-missing-prototypes is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wnested-externs is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-nested-externs is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wredundant-decls is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-redundant-decls is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-format-extra-args is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wcast-qual is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-cast-qual is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wc++-compat is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-c++-compat is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wdeclaration-after-statement is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-declaration-after-statement is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wfloat-equal is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-float-equal is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wstrict-aliasing is optional(arg) hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-strict-aliasing is optional(arg) hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wswitch-enum is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-switch-enum is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wvla is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-vla is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wformat is optional(arg) hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Winline is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-inline is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wswitch is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-switch is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wdangling-else is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-dangling-else is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wparentheses is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-parentheses is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wformat-security is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-format-security is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wformat-y2k is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-format-y2k is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wunused-function is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-unused-function is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wunused-local-typedefs is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-unused-local-typedefs is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

# This flag is very specific to gcc.
switch -Wdeprecated is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -Wno-deprecated is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

switch -mfpmath$arg is hide
  help(Ignored, for compatibility only)
  helpgroup(language);

replace switch -Mint128 is
	help(Enable 128-bit integer support, __int128 type)
	helpgroup(language)
	append(CPP1ARGS=--int128);

replace switch -Mnoint128 is
	help(Disable 128-bit integer support, __int128 type)
	helpgroup(language)
	append(CPP1ARGS=--noint128);

replace switch -Mm128 is
	help(Allow __m128, __m128d, __m128i data type extensions)
	helpgroup(language)
	helpname(-M[no]m128)
	append(CARGS=-y 127 0x20);

replace switch -Mnom128 is hide
	help(Do not allow __m128, __m128d, __m128i data type extensions)
	helpgroup(language)
	append(CARGS=-x 127 0x20);

switch --restrict-keyword is
    help(Treat \"restrict\" as a keyword)
    helpgroup(language)
    append(CPP1ARGS=--restrict);
switch --no-restrict-keyword is
    help(Don't treat \"restrict\" as a keyword)
    helpgroup(language)
    append(CPP1ARGS=--no_restrict);
