Skip to content

Commit

Permalink
#3 now MCUs argument (both -mcpu and -mcu) are supported. Added known…
Browse files Browse the repository at this point in the history
… for me defines for some MCUs (TODO: support other).
  • Loading branch information
4ntoine committed Dec 22, 2014
1 parent d3c150f commit 9ec8fc4
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Flags<[DriverOption]>;
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>;
def mconstant_cfstrings : Flag<["-"], "mconstant-cfstrings">, Group<clang_ignored_m_Group>;
def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
def mmcu_EQ : Joined<["-"], "mmcu=">, Group<m_Group>;
def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group<m_Group>;
def mfix_and_continue : Flag<["-"], "mfix-and-continue">, Group<clang_ignored_m_Group>;
def mieee_fp : Flag<["-"], "mieee-fp">, Group<clang_ignored_m_Group>;
Expand Down
281 changes: 281 additions & 0 deletions lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5470,6 +5470,7 @@ namespace {

class AVRTargetInfo : public TargetInfo {
static const char * const GCCRegNames[];
std::string CPU;
public:
AVRTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
BigEndian = false;
Expand All @@ -5490,7 +5491,27 @@ namespace {
MacroBuilder &Builder) const override {
Builder.defineMacro("AVR");
Builder.defineMacro("__AVR__");

// FIXME: defines for different 'flavours' of MCU

if (CPU == "atmega328") {
Builder.defineMacro("__AVR_ATmega328__");
} else if (CPU == "atmega328p") {
Builder.defineMacro("__AVR_ATmega328P__");
} else if (CPU == "atmega168") {
Builder.defineMacro("__AVR_ATmega168__");
} else if (CPU == "atmega168p") {
Builder.defineMacro("__AVR_ATmega168p__");
} else if (CPU == "atmega1280") {
Builder.defineMacro("__AVR_ATmega1280__");
} else if (CPU == "atmega2560") {
Builder.defineMacro("__AVR_ATmega2560__");
} else if (CPU == "atmega32u4") {
Builder.defineMacro("__AVR_ATmega32U4__");
}

// TODO : support other MCUs

}
void getTargetBuiltins(const Builtin::Info *&Records,
unsigned &NumRecords) const override {
Expand Down Expand Up @@ -5523,6 +5544,266 @@ namespace {
// FIXME: implement
return TargetInfo::CharPtrBuiltinVaList;
}

const std::string& getCPU() const { return CPU; }

bool setCPU(const std::string &Name) override {
// should be consistent with AVR.td
bool CPUKnown = llvm::StringSwitch<bool>(Name)
.Case("generic", true)
.Case("avrxmega1", true)
.Case("avrxmega2", true)
.Case("avrxmega3", true)
.Case("avrxmega4", true)
.Case("avrxmega5", true)
.Case("avrxmega6", true)
.Case("avrxmega7", true)
.Case("avrtiny", true)
.Case("at90s1200", true)
.Case("attiny11", true)
.Case("attiny12", true)
.Case("attiny15", true)
.Case("attiny28", true)
.Case("at90s2313", true)
.Case("at90s2323", true)
.Case("at90s2333", true)
.Case("at90s2343", true)
.Case("attiny22", true)
.Case("attiny26", true)
.Case("at90s4414", true)
.Case("at90s4433", true)
.Case("at90s4434", true)
.Case("at90s8515", true)
.Case("at90c8534", true)
.Case("at90s8535", true)
.Case("ata5272", true)
.Case("attiny13", true)
.Case("attiny13a", true)
.Case("attiny2313", true)
.Case("attiny2313a", true)
.Case("attiny24", true)
.Case("attiny24a", true)
.Case("attiny4313", true)
.Case("attiny44", true)
.Case("attiny44a", true)
.Case("attiny84", true)
.Case("attiny84a", true)
.Case("attiny25", true)
.Case("attiny45", true)
.Case("attiny85", true)
.Case("attiny261", true)
.Case("attiny261a", true)
.Case("attiny461", true)
.Case("attiny461a", true)
.Case("attiny861", true)
.Case("attiny861a", true)
.Case("attiny87", true)
.Case("attiny43u", true)
.Case("attiny48", true)
.Case("attiny88", true)
.Case("attiny828", true)
.Case("at86rf401", true)
.Case("at43usb355", true)
.Case("at76c711", true)
.Case("atmega103", true)
.Case("at43usb320", true)
.Case("attiny167", true)
.Case("at90usb82", true)
.Case("at90usb162", true)
.Case("ata5505", true)
.Case("atmega8u2", true)
.Case("atmega16u2", true)
.Case("atmega32u2", true)
.Case("attiny1634", true)
.Case("atmega8", true)
.Case("ata6289", true)
.Case("atmega8a", true)
.Case("ata6285", true)
.Case("ata6286", true)
.Case("atmega48", true)
.Case("atmega48a", true)
.Case("atmega48pa", true)
.Case("atmega48p", true)
.Case("atmega88", true)
.Case("atmega88a", true)
.Case("atmega88p", true)
.Case("atmega88pa", true)
.Case("atmega8515", true)
.Case("atmega8535", true)
.Case("atmega8hva", true)
.Case("at90pwm1", true)
.Case("at90pwm2", true)
.Case("at90pwm2b", true)
.Case("at90pwm3", true)
.Case("at90pwm3b", true)
.Case("at90pwm81", true)
.Case("ata5790", true)
.Case("ata5795", true)
.Case("atmega16", true)
.Case("atmega16a", true)
.Case("atmega161", true)
.Case("atmega162", true)
.Case("atmega163", true)
.Case("atmega164a", true)
.Case("atmega164p", true)
.Case("atmega164pa", true)
.Case("atmega165", true)
.Case("atmega165a", true)
.Case("atmega165p", true)
.Case("atmega165pa", true)
.Case("atmega168", true)
.Case("atmega168a", true)
.Case("atmega168p", true)
.Case("atmega168pa", true)
.Case("atmega169", true)
.Case("atmega169a", true)
.Case("atmega169p", true)
.Case("atmega169pa", true)
.Case("atmega32", true)
.Case("atmega32a", true)
.Case("atmega323", true)
.Case("atmega324a", true)
.Case("atmega324p", true)
.Case("atmega324pa", true)
.Case("atmega325", true)
.Case("atmega325a", true)
.Case("atmega325p", true)
.Case("atmega325pa", true)
.Case("atmega3250", true)
.Case("atmega3250a", true)
.Case("atmega3250p", true)
.Case("atmega3250pa", true)
.Case("atmega328", true)
.Case("atmega328p", true)
.Case("atmega329", true)
.Case("atmega329a", true)
.Case("atmega329p", true)
.Case("atmega329pa", true)
.Case("atmega3290", true)
.Case("atmega3290a", true)
.Case("atmega3290p", true)
.Case("atmega3290pa", true)
.Case("atmega406", true)
.Case("atmega64", true)
.Case("atmega64a", true)
.Case("atmega640", true)
.Case("atmega644", true)
.Case("atmega644a", true)
.Case("atmega644p", true)
.Case("atmega644pa", true)
.Case("atmega645", true)
.Case("atmega645a", true)
.Case("atmega645p", true)
.Case("atmega649", true)
.Case("atmega649a", true)
.Case("atmega649p", true)
.Case("atmega6450", true)
.Case("atmega6450a", true)
.Case("atmega6450p", true)
.Case("atmega6490", true)
.Case("atmega6490a", true)
.Case("atmega6490p", true)
.Case("atmega64rfr2", true)
.Case("atmega644rfr2", true)
.Case("atmega16hva", true)
.Case("atmega16hva2", true)
.Case("atmega16hvb", true)
.Case("atmega16hvbrevb", true)
.Case("atmega32hvb", true)
.Case("atmega32hvbrevb", true)
.Case("atmega64hve", true)
.Case("at90can32", true)
.Case("at90can64", true)
.Case("at90pwm161", true)
.Case("at90pwm216", true)
.Case("at90pwm316", true)
.Case("atmega32c1", true)
.Case("atmega64c1", true)
.Case("atmega16m1", true)
.Case("atmega32m1", true)
.Case("atmega64m1", true)
.Case("atmega16u4", true)
.Case("atmega32u4", true)
.Case("atmega32u6", true)
.Case("at90usb646", true)
.Case("at90usb647", true)
.Case("at90scr100", true)
.Case("at94k", true)
.Case("m3000", true)
.Case("atmega128", true)
.Case("atmega128a", true)
.Case("atmega1280", true)
.Case("atmega1281", true)
.Case("atmega1284", true)
.Case("atmega1284p", true)
.Case("atmega128rfa1", true)
.Case("atmega128rfr2", true)
.Case("atmega1284rfr2", true)
.Case("at90can128", true)
.Case("at90usb1286", true)
.Case("at90usb1287", true)
.Case("atmega2560", true)
.Case("atmega2561", true)
.Case("atmega256rfr2", true)
.Case("atmega2564rfr2", true)
.Case("atxmega16a4", true)
.Case("atxmega16a4u", true)
.Case("atxmega16c4", true)
.Case("atxmega16d4", true)
.Case("atxmega32a4", true)
.Case("atxmega32a4u", true)
.Case("atxmega32c4", true)
.Case("atxmega32d4", true)
.Case("atxmega32e5", true)
.Case("atxmega16e5", true)
.Case("atxmega8e5", true)
.Case("atxmega32x1", true)
.Case("atxmega64a3", true)
.Case("atxmega64a3u", true)
.Case("atxmega64a4u", true)
.Case("atxmega64b1", true)
.Case("atxmega64b3", true)
.Case("atxmega64c3", true)
.Case("atxmega64d3", true)
.Case("atxmega64d4", true)
.Case("atxmega64a1", true)
.Case("atxmega64a1u", true)
.Case("atxmega128a3", true)
.Case("atxmega128a3u", true)
.Case("atxmega128b1", true)
.Case("atxmega128b3", true)
.Case("atxmega128c3", true)
.Case("atxmega128d3", true)
.Case("atxmega128d4", true)
.Case("atxmega192a3", true)
.Case("atxmega192a3u", true)
.Case("atxmega192c3", true)
.Case("atxmega192d3", true)
.Case("atxmega256a3", true)
.Case("atxmega256a3u", true)
.Case("atxmega256a3b", true)
.Case("atxmega256a3bu", true)
.Case("atxmega256c3", true)
.Case("atxmega256d3", true)
.Case("atxmega384c3", true)
.Case("atxmega384d3", true)
.Case("atxmega128a1", true)
.Case("atxmega128a1u", true)
.Case("atxmega128a4u", true)
.Case("attiny4", true)
.Case("attiny5", true)
.Case("attiny9", true)
.Case("attiny10", true)
.Case("attiny20", true)
.Case("attiny40", true)
.Default(false);

if (CPUKnown)
CPU = Name;

return CPUKnown;
}

};

const char * const AVRTargetInfo::GCCRegNames[] = {
Expand Down
19 changes: 19 additions & 0 deletions lib/Driver/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,23 @@ static std::string getAArch64TargetCPU(const ArgList &Args) {
return "generic";
}

static std::string getAvrTargetCPU(const ArgList &Args) {
Arg *A;

std::string CPU;
// If we have -mcpu, use that.
if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
StringRef Mcpu = A->getValue();
return Mcpu.split("+").first;
// If we have -mmcu (avr-gcc style)
} else if ((A = Args.getLastArg(options::OPT_mmcu_EQ))) {
StringRef Mcpu = A->getValue();
return Mcpu.split("+").first;
}

return "generic";
}

void Clang::AddAArch64TargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args);
Expand Down Expand Up @@ -1462,6 +1479,8 @@ static std::string getCPUName(const ArgList &Args, const llvm::Triple &T) {
default:
return "";

case llvm::Triple::avr:
return getAvrTargetCPU(Args);
case llvm::Triple::aarch64:
case llvm::Triple::aarch64_be:
return getAArch64TargetCPU(Args);
Expand Down

0 comments on commit 9ec8fc4

Please sign in to comment.