diff options
author | David Greene <greened@obbligato.org> | 2009-05-14 22:38:31 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2009-05-14 22:38:31 +0000 |
commit | 04c89a100940fa2649e4f8b1458a0e4a07e9d8ad (patch) | |
tree | bd237c2d0cb6a5ec6c114294dfdb5bd049d1501a /utils/TableGen/Record.cpp | |
parent | 2c38321556ce9b0ec69d7c228fe6cb7b07b6fd1e (diff) | |
download | external_llvm-04c89a100940fa2649e4f8b1458a0e4a07e9d8ad.zip external_llvm-04c89a100940fa2649e4f8b1458a0e4a07e9d8ad.tar.gz external_llvm-04c89a100940fa2649e4f8b1458a0e4a07e9d8ad.tar.bz2 |
Graduate LLVM to the big leagues by embedding a LISP processor into TableGen.
Ok, not really, but do support some common LISP functions:
* car
* cdr
* null
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71805 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r-- | utils/TableGen/Record.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index ade1702..ae2c2f3 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -520,6 +520,41 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { } break; } + case CAR: { + ListInit *LHSl = dynamic_cast<ListInit*>(LHS); + if (LHSl) { + if (LHSl->getSize() == 0) { + assert(0 && "Empty list in car"); + return 0; + } + return LHSl->getElement(0); + } + break; + } + case CDR: { + ListInit *LHSl = dynamic_cast<ListInit*>(LHS); + if (LHSl) { + if (LHSl->getSize() == 0) { + assert(0 && "Empty list in cdr"); + return 0; + } + ListInit *Result = new ListInit(LHSl->begin()+1, LHSl->end()); + return Result; + } + break; + } + case LNULL: { + ListInit *LHSl = dynamic_cast<ListInit*>(LHS); + if (LHSl) { + if (LHSl->getSize() == 0) { + return new IntInit(1); + } + else { + return new IntInit(0); + } + } + break; + } } return this; } @@ -536,6 +571,9 @@ std::string UnOpInit::getAsString() const { std::string Result; switch (Opc) { case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break; + case CAR: Result = "!car"; break; + case CDR: Result = "!cdr"; break; + case LNULL: Result = "!null"; break; } return Result + "(" + LHS->getAsString() + ")"; } |