Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class Driver {
CPPMode,
CLMode,
FlangMode,
DXCMode
DXCMode,
C2000Mode
} Mode;

enum SaveTempsMode {
Expand Down Expand Up @@ -253,6 +254,9 @@ class Driver {
/// Whether the driver should follow dxc.exe like behavior.
bool IsDXCMode() const { return Mode == DXCMode; }

// Whether the driver should follow cl2000.exe like behaviour.
bool IsC2000Mode() const { return Mode == C2000Mode; }

/// Only print tool bindings, don't build any jobs.
LLVM_PREFERRED_TYPE(bool)
unsigned CCCPrintBindings : 1;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum ClangVisibility {
FlangOption = (1 << 4),
FC1Option = (1 << 5),
DXCOption = (1 << 6),
CL2000Option = (1 << 7)
};

enum ID {
Expand Down
74 changes: 64 additions & 10 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def FC1Option : OptionVisibility;
// are made available when the driver is running in DXC compatibility mode.
def DXCOption : OptionVisibility;

// CL2000Option - This is a cl2000.exe compatibility option. Options with this flag
// are made available when the driver is running in cl2000 compatibility mode.
def CL2000Option : OptionVisibility;

/////////
// Docs

Expand Down Expand Up @@ -201,6 +205,9 @@ def hlsl_Group : OptionGroup<"<HLSL group>">, Group<f_Group>,
DocName<"HLSL options">,
Visibility<[ClangOption]>;

def cl2000_group : OptionGroup<"<cl2000 group>">,
Visibility<[CL2000Option]>;

// Feature groups - these take command line options that correspond directly to
// target specific features and can be translated directly from command line
// options.
Expand Down Expand Up @@ -672,7 +679,7 @@ class InternalDriverOpt : Group<internal_driver_Group>,
Flags<[NoXarchOption, HelpHidden]>;
def driver_mode : Joined<["--"], "driver-mode=">, Group<internal_driver_Group>,
Flags<[NoXarchOption, HelpHidden]>,
Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>,
Visibility<[ClangOption, FlangOption, CLOption, DXCOption, CL2000Option]>,
HelpText<"Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 'flang'">;
def rsp_quoting : Joined<["--"], "rsp-quoting=">, Group<internal_driver_Group>,
Flags<[NoXarchOption, HelpHidden]>,
Expand Down Expand Up @@ -843,7 +850,7 @@ def C : Flag<["-"], "C">, Visibility<[ClangOption, CC1Option]>,
HelpText<"Include comments in preprocessed output">,
MarshallingInfoFlag<PreprocessorOutputOpts<"ShowComments">>;
def D : JoinedOrSeparate<["-"], "D">, Group<Preprocessor_Group>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option, DXCOption]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option, DXCOption, CL2000Option]>,
MetaVarName<"<macro>=<value>">,
HelpText<"Define <macro> to <value> (or 1 if <value> omitted)">;
def E : Flag<["-"], "E">, Flags<[NoXarchOption]>,
Expand Down Expand Up @@ -929,7 +936,7 @@ def ObjCXX : Flag<["-"], "ObjC++">, Flags<[NoXarchOption]>,
def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>,
HelpText<"Treat source input files as Objective-C inputs">;
def O : Joined<["-"], "O">, Group<O_Group>,
Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>;
Visibility<[ClangOption, CC1Option, FC1Option, FlangOption, CL2000Option]>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C2000 compiler accepts '-o' or '--opt_level' to define the optimization level as well.

This overlaps with clang's -o outfile specification, so there would need to be some sort of translation from TI's --output_file to clang's -o. Perhaps parsing the option would be enough, since there is no output from clangd?

def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
Alias<O>, AliasArgs<["1"]>;
def Ofast : Joined<["-"], "Ofast">, Group<O_Group>,
Expand Down Expand Up @@ -1035,10 +1042,10 @@ def Xassembler : Separate<["-"], "Xassembler">,
Group<CompileOnly_Group>;
def Xclang : Separate<["-"], "Xclang">,
HelpText<"Pass <arg> to clang -cc1">, MetaVarName<"<arg>">,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption, CL2000Option]>,
Group<CompileOnly_Group>;
def : Joined<["-"], "Xclang=">, Group<CompileOnly_Group>,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption, CL2000Option]>,
Alias<Xclang>,
HelpText<"Alias for -Xclang">, MetaVarName<"<arg>">;
def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
Expand Down Expand Up @@ -4023,7 +4030,7 @@ def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption]>,
Group<Action_Group>, HelpText<"Only run the driver.">;
def fsyntax_only : Flag<["-"], "fsyntax-only">,
Flags<[NoXarchOption]>,
Visibility<[ClangOption, CLOption, DXCOption, CC1Option, FC1Option, FlangOption]>,
Visibility<[ClangOption, CLOption, DXCOption, CC1Option, FC1Option, FlangOption, CL2000Option]>,
Group<Action_Group>,
HelpText<"Run the preprocessor, parser and semantic analysis stages">;
def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group<f_Group>;
Expand Down Expand Up @@ -4470,7 +4477,7 @@ defm emit_compact_unwind_non_canonical : BoolFOption<"emit-compact-unwind-non-ca
"Try emitting Compact-Unwind for non-canonical entries. Maybe overridden by other constraints">,
NegFlag<SetFalse>>;
def g_Flag : Flag<["-"], "g">, Group<g_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, CL2000Option]>,
HelpText<"Generate source-level debug information">;
def gline_tables_only : Flag<["-"], "gline-tables-only">, Group<gN_Group>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Expand Down Expand Up @@ -5817,11 +5824,11 @@ def rdynamic : Flag<["-"], "rdynamic">, Group<Link_Group>,
Visibility<[ClangOption, FlangOption]>;
def resource_dir : Separate<["-"], "resource-dir">,
Flags<[NoXarchOption, HelpHidden]>,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option]>,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption, FC1Option, CL2000Option]>,
HelpText<"The directory which holds the compiler resource files">,
MarshallingInfoString<HeaderSearchOpts<"ResourceDir">>;
def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption, CL2000Option]>,
Alias<resource_dir>;
def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group<Link_Group>,
Visibility<[ClangOption, FlangOption]>;
Expand Down Expand Up @@ -6020,7 +6027,7 @@ def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
MarshallingInfoFlag<DiagnosticOpts<"IgnoreWarnings">>;
def x : JoinedOrSeparate<["-"], "x">,
Flags<[NoXarchOption]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option, CLOption]>,
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option, CLOption, CL2000Option]>,
HelpText<"Treat subsequent input files as having type <language>">,
MetaVarName<"<language>">;
def y : Joined<["-"], "y">;
Expand Down Expand Up @@ -9111,3 +9118,50 @@ def wasm_opt : Flag<["--"], "wasm-opt">,
Group<m_Group>,
HelpText<"Enable the wasm-opt optimizer (default)">,
MarshallingInfoNegativeFlag<LangOpts<"NoWasmOpt">>;



//===----------------------------------------------------------------------===//
// cl2000 Options
//===----------------------------------------------------------------------===//




def cl2000_include_path : Joined<["--"], "include_path=">, Group<cl2000_group>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use-case for this particular set of options? I'd suggest that options which may change internal definitions or affect the parse should be here. Perhaps everything else can somehow be ignored silently.

  • -ml for large_model is shorthand for --large_memory_model, but that's not present in this list.
  • --preinclude=, which should be identical to 'include_' above
  • --define and --undefine for -D and -U, respectively
  • Language options --c89, --c99, --c1, --c++03
  • --cpp_default (-fg), which is similar to (but not identical to) -x cpp
  • --c_file/-fc and --cpp_file/-fp to set single file language types

These are mostly presented as examples. If only a subset of these options are merged, then I fear that the commit becomes very narrow in its use-case. If upstream is fine with that, then I'd be fine too.

Copy link
Author

@student433 student433 Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, this change was adhered specifically to our use case and it was diagnosed that all other flags got ignored silently once only the first few in compile commands were defined here, but of course, that is an individual case, so it would be better to add all flags for future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently about to add the language options support, but would like to know how to go about defining the strict_ansi and relaxed_ansi options. These disable the GNU extensions and also enable some TI specific keyword usage in code like interrupt, and also go with the other c/c++ language options. Would be nice to have a path if you already know :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict_ansi/relaxed_ansi should map to the clang -std option: -std=c99 is strict mode, -std=gnu99 is relaxed mode. The difference is small enough that you could probably just ignore the options, though.

HelpText<"specify include search paths for cl2000 driver mode">, Alias<isystem>;

def eabi : Joined<["--"], "abi=">, Group<cl2000_group>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned of adding driver options (perhaps mostly ignored). A better way is to change language servers and clang-tidy to ignore options. These tools can simply set an environment variable

CCC_OVERRIDE_OPTIONS=#x-fxxx clang -fsyntax-only -fxxx /tmp/t/a.c   # does not error on -fxxx

HelpText<"abi">;
def strict_ansi : Joined<["--"], "strict_ansi">, Group<cl2000_group>,
HelpText<"strict ANSI/ISO Mode">;
def fp_mode : Joined<["--"], "fp_mode=">, Group<cl2000_group>,
HelpText<"fp mode">;
def cla_support : Joined<["--"], "cla_support=">, Group<cl2000_group>,
HelpText<"cla Support">;
def float_support : Joined<["--"], "float_support=">, Group<cl2000_group>,
HelpText<"Float Support">;
def idiv_support : Joined<["--"], "idiv_support=">, Group<cl2000_group>,
HelpText<"idiv Support">;
def tmu_support : Joined<["--"], "tmu_support=">, Group<cl2000_group>,
HelpText<"tmu Support">;
def vcu_support : Joined<["--"], "vcu_support=">, Group<cl2000_group>,
HelpText<"vcu Support">;
def opt_level : Joined<["--"], "opt_level=">, Group<cl2000_group>,
HelpText<"opt level">, Alias<O>;
def silicon_version : Joined<["-"], "v28">, Group<cl2000_group>,
HelpText<"silicon version">;
def large_model : Joined<["-"], "ml">, Group<cl2000_group>,
HelpText<"large model">;
def unified_memory : Joined<["-"], "mt">, Group<cl2000_group>,
HelpText<"unified memory">;
def output_file : Joined<["--"], "output_file=">, Group<cl2000_group>,
HelpText<"output file">, Alias<o>;
def source_file : Joined<["--"], "">, Group<cl2000_group>,
HelpText<"source file">;
def symdebug_dwarf : Joined<["--"], "symdebug:dwarf">, Group<cl2000_group>,
HelpText<"Alias for -g">, Alias<g_Flag>;
def relaxed_ansi : Joined<["--"], "relaxed_ansi">, Group<cl2000_group>,
HelpText<"relaxed ansi mode">;
def compile_only : Joined<["--"], "compile_only">, Group<cl2000_group>,
HelpText<"compile only">, Alias<c>;
1 change: 1 addition & 0 deletions clang/lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ add_clang_library(clangBasic
Targets/ARM.cpp
Targets/AVR.cpp
Targets/BPF.cpp
Targets/C2000.cpp
Targets/CSKY.cpp
Targets/DirectX.cpp
Targets/Hexagon.cpp
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Targets/ARM.h"
#include "Targets/AVR.h"
#include "Targets/BPF.h"
#include "Targets/C2000.h"
#include "Targets/CSKY.h"
#include "Targets/DirectX.h"
#include "Targets/Hexagon.h"
Expand Down Expand Up @@ -272,6 +273,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::msp430:
return std::make_unique<MSP430TargetInfo>(Triple, Opts);

case llvm::Triple::c2000:
return std::make_unique<C2000TargetInfo>(Triple, Opts);

case llvm::Triple::mips:
switch (os) {
case llvm::Triple::Linux:
Expand Down
Loading
Loading