Created
May 22, 2012 23:45
-
-
Save Bigcheese/2772395 to your computer and use it in GitHub Desktop.
Clang/LLD tblegen option parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parser; | |
class String<list<string> values> : Parser { | |
list<string> Values = values; | |
} | |
class Multiple<list<Parser> parsers> : Parser { | |
list<Parser> Parsers = parsers; | |
} | |
class Optional<Parser parser> : Parser { | |
Parser P = parser; | |
} | |
class Separate<Parser parser> : Parser { | |
Parser P = parser; | |
} | |
class Joined<string by, Parser parser> : Parser { | |
string By = by; | |
Parser P = parser; | |
} | |
class Or<list<Parser> parsers> : Parser { | |
list<Parser> Parsers = parsers; | |
} | |
class List<list<string> seps, Parser parser> : Parser { | |
list<string> Seperators = seps; | |
Parser P = parser; | |
} | |
class Custom<string name, Parser parser> : Parser { | |
string Name = name; | |
Parser InputParser = parser; | |
} | |
class CannonicalOption<string name, Parser parser> { | |
string Name = name; | |
string HelpText = ?; | |
Parser P = parser; | |
string Default = ?; | |
} | |
class Accept<Parser parser, CannonicalOption CO> : Parser { | |
Parser P = parser; | |
CannonicalOption Opt = CO; | |
} | |
class HelpText<string text> { | |
string HelpText = text; | |
} | |
class Default<string text> { | |
string Default = text; | |
} | |
def target_tripple : CannonicalOption< "target-triple" | |
, Separate<Accept<String<?>, ?>>>; | |
def deadstrip : CannonicalOption<"deadstrip", ?>; | |
def no_deadstrip : CannonicalOption<"deadstrip", ?>; | |
def LIBRARYTYPES : String<["archive", "shared", "default"]>; | |
def library_type : CannonicalOption<"library-type", Separate<Accept<LIBRARYTYPES, ?>>>; | |
def no_export_from_libs : CannonicalOption<"no-export-from-libs", Separate<Accept<List<[",", ";"], String<?>>, ?>>>; | |
class OptionFlag; | |
def case_insensitive : OptionFlag; | |
class Option<string name, Parser parser> : CannonicalOption<name, parser> { | |
list<string> Introducers = []; | |
list<OptionFlag> Flags; | |
Option Alias = ?; | |
} | |
class Alias<Option alias> { | |
Option Alias = alias; | |
} | |
class Flags<list<OptionFlag> flags> { | |
list<OptionFlag> Flags = flags; | |
} | |
class Driver { | |
bit HasResponseFile = ?; | |
} | |
//===== ld tblgen file ===== | |
def LDDriver : Driver { | |
bit HasResponseFile = 1; | |
} | |
class LDSingleLetterOption<string name, Parser parser> | |
: Option<name, Or<[Joined<"", parser>, Separate<parser>]>> { | |
let Introducers = ["-"]; | |
} | |
class LDMultipleLetterOption<string name, Parser parser> | |
: Option<name, Or<[Joined<"=", parser>, Separate<parser>]>> { | |
let Introducers = ["-", "--"]; | |
} | |
def a : LDSingleLetterOption<"a", Accept<LIBRARYTYPES, library_type>>; | |
// Custom<"parseArch", String<?>> will take the string given by the option and | |
// convert it to a target triple which is then accepted as the target-tripple | |
// cannonical option. | |
def ARCHPARSER : Accept<Custom<"parseArch", String<?>>, target_tripple>; | |
def architechture : LDMultipleLetterOption<"architechture", ARCHPARSER>; | |
def A : LDSingleLetterOption<"A", ARCHPARSER>, Alias<architechture>; | |
def exclude_libs : LDMultipleLetterOption<"exclude-libs", Accept<List<[",", ";"], String<?>>, no_export_from_libs>>; | |
//===== link.exe tblgen file ===== | |
class LINKEXEOption<string name, Parser parser> : Option<name, parser> { | |
let Flags = [case_insensitive]; | |
let Introducers = ["-", "/"]; | |
} | |
def machine : LINKEXEOption< "machine" | |
, Joined< ":" | |
, Accept<Custom< "parseMSMachine" | |
// TODO: Figure out a way to mark this as case insenseitive. | |
, String<[ "ARM" | |
, "EBC" | |
, "IA64" | |
, "MIPS" | |
, "MIPS16" | |
, "MIPSFPU" | |
, "MIPSFPU16" | |
, "SH4" | |
, "THUMB" | |
, "X64" | |
, "X86"]>> | |
, target_tripple>>> | |
, HelpText<"Target machine to link for.">; | |
def opt : LINKEXEOption< "opt" | |
, Joined< ":" | |
, Or<[ Or<[Accept<String<["ref"]>, deadstrip>, Accept<String<["noref"]>, no_deadstrip>]> | |
, Or<[]>]>>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment