[llvm-commits] [llvm] r142523 - in /llvm/trunk/lib/TableGen: TGParser.cpp TGParser.h

David A. Greene greened at obbligato.org
Wed Oct 19 06:38:18 PDT 2011


"James Molloy" <james.molloy at arm.com> writes:

> Didn't your proposed LLVM git workflow include "squashing up local commits"?

Er...I'm not grasping what you're getting at...

                             -Dave

> -----Original Message-----
> From: llvm-commits-bounces at cs.uiuc.edu
> [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of David Greene
> Sent: 19 October 2011 14:05
> To: llvm-commits at cs.uiuc.edu
> Subject: [llvm-commits] [llvm] r142523 - in /llvm/trunk/lib/TableGen:
> TGParser.cpp TGParser.h
>
> Author: greened
> Date: Wed Oct 19 08:04:31 2011
> New Revision: 142523
>
> URL: http://llvm.org/viewvc/llvm-project?rev=142523&view=rev
> Log:
> Process Defm Prefix as Init
>
> Parse and process a defm prefix as an Init expression.  This allows
> paste operations to create defm prefixes.
>
> Modified:
>     llvm/trunk/lib/TableGen/TGParser.cpp
>     llvm/trunk/lib/TableGen/TGParser.h
>
> Modified: llvm/trunk/lib/TableGen/TGParser.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev
> =142523&r1=142522&r2=142523&view=diff
> ============================================================================
> ==
> --- llvm/trunk/lib/TableGen/TGParser.cpp (original)
> +++ llvm/trunk/lib/TableGen/TGParser.cpp Wed Oct 19 08:04:31 2011
> @@ -1970,24 +1970,50 @@
>  Record *TGParser::
>  InstantiateMulticlassDef(MultiClass &MC,
>                           Record *DefProto,
> -                         const std::string &DefmPrefix,
> +                         Init *DefmPrefix,
>                           SMLoc DefmPrefixLoc) {
> +  // We need to preserve DefProto so it can be reused for later
> +  // instantiations, so create a new Record to inherit from it.
> +
>    // Add in the defm name.  If the defm prefix is empty, give each
>    // instantiated def a unique name.  Otherwise, if "#NAME#" exists in the
>    // name, substitute the prefix for #NAME#.  Otherwise, use the defm name
>    // as a prefix.
> -  std::string DefName = DefProto->getName();
> -  if (DefmPrefix.empty()) {
> -    DefName = GetNewAnonymousName();
> -  } else {
> -    std::string::size_type idx = DefName.find("#NAME#");
> -    if (idx != std::string::npos) {
> -      DefName.replace(idx, 6, DefmPrefix);
> -    } else {
> -      // Add the suffix to the defm name to get the new name.
> -      DefName = DefmPrefix + DefName;
> -    }
> +  StringInit *DefNameString =
> +    dynamic_cast<StringInit *>(DefProto->getNameInit());
> +
> +  if (DefNameString == 0) {
> +    Error(DefmPrefixLoc, "Def name is not a string");
> +    return 0;
> +  }
> +
> +  if (DefmPrefix == 0)
> +    DefmPrefix = StringInit::get(GetNewAnonymousName());
> +
> +  Init *DefName = DefProto->getNameInit();
> +
> +  // See if we can substitute #NAME#.
> +  Init *NewDefName =
> +    TernOpInit::get(TernOpInit::SUBST,
> +                    StringInit::get("#NAME#"),
> +                    DefmPrefix,
> +                    DefName,
> +                    StringRecTy::get())->Fold(DefProto, &MC);
> +
> +  if (NewDefName == DefName) {
> +    // We did't do any substitution.  We should concatenate the given
> +    // prefix and name.
> +    if (DefmPrefix == 0)
> +      DefmPrefix = StringInit::get(GetNewAnonymousName());
> +
> +    DefName =
> +      BinOpInit::get(BinOpInit::STRCONCAT,
> +                     UnOpInit::get(UnOpInit::CAST, DefmPrefix,
> +                                   StringRecTy::get())->Fold(DefProto,
> &MC),
> +                     DefName, StringRecTy::get())->Fold(DefProto, &MC);
>    }
> +  else
> +    DefName = NewDefName;
>  
>    Record *CurRec = new Record(DefName, DefmPrefixLoc, Records);
>  
> @@ -2086,14 +2112,9 @@
>    assert(Lex.getCode() == tgtok::Defm && "Unexpected token!");
>  
>    Init *DefmPrefix = 0;
> -  std::string DefmPrefixString;
>  
>    if (Lex.Lex() == tgtok::Id) {  // eat the defm.
>      DefmPrefix = ParseObjectName(CurMultiClass);
> -    StringInit *DefmPrefixStringInit = dynamic_cast<StringInit
> *>(DefmPrefix);
> -    if (DefmPrefixStringInit == 0)
> -      return TokError("defm prefix is not a string");
> -    DefmPrefixString = DefmPrefixStringInit->getValue();
>    }
>  
>    SMLoc DefmPrefixLoc = Lex.getLoc();
> @@ -2132,8 +2153,7 @@
>      for (unsigned i = 0, e = MC->DefPrototypes.size(); i != e; ++i) {
>        Record *DefProto = MC->DefPrototypes[i];
>  
> -      Record *CurRec = InstantiateMulticlassDef(*MC, DefProto,
> DefmPrefixString,
> -                                                DefmPrefixLoc);
> +      Record *CurRec = InstantiateMulticlassDef(*MC, DefProto, DefmPrefix,
> DefmPrefixLoc);
>  
>        if (ResolveMulticlassDefArgs(*MC, CurRec, DefmPrefixLoc, SubClassLoc,
>                                     TArgs, TemplateVals, true/*Delete
> args*/))
>
> Modified: llvm/trunk/lib/TableGen/TGParser.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.h?rev=1
> 42523&r1=142522&r2=142523&view=diff
> ============================================================================
> ==
> --- llvm/trunk/lib/TableGen/TGParser.h (original)
> +++ llvm/trunk/lib/TableGen/TGParser.h Wed Oct 19 08:04:31 2011
> @@ -101,7 +101,7 @@
>    bool ParseMultiClass();
>    Record *InstantiateMulticlassDef(MultiClass &MC,
>                                     Record *DefProto,
> -                                   const std::string &DefmPrefix,
> +                                   Init *DefmPrefix,
>                                     SMLoc DefmPrefixLoc);
>    bool ResolveMulticlassDefArgs(MultiClass &MC,
>                                  Record *DefProto,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list