llvm.org GIT mirror llvm / 1434f66
Rename lisp-like functions as suggested by Gabor Greif as loooong time ago. This is both easier to learn and easier to read. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123001 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 8 years ago
10 changed file(s) with 41 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
411411
For each member 'b' of dag or list 'a' apply operator 'c.' 'b' is a
412412 dummy variable that should be declared as a member variable of an instantiated
413413 class. This operation is analogous to $(foreach) in GNU make.
414
!car(a)
414
!head(a)
415415
The first element of list 'a.'
416
!cdr(a)
416
!tail(a)
417417
The 2nd-N elements of list 'a.'
418
!null(a)
418
!empty(a)
419419
An integer {0,1} indicating whether list 'a' is empty.
420420
!if(a,b,c)
421421
'b' if the result of 'int' or 'bit' operator 'a' is nonzero,
66 }
77
88 class Bla _bli>
9 : Blicar(_bli).t>
9 : Blihead(_bli).t>
1010 {
1111 }
6565 multiclass scalar opcode, string asmstr = "", list> patterns = []> {
6666 def SSrr : Inst
6767 !strconcat(asmstr, "\t$dst, $src"),
68 !if(!null(patterns),[],patterns[0])>;
68 !if(!empty(patterns),[],patterns[0])>;
6969 def SSrm : Inst
7070 !strconcat(asmstr, "\t$dst, $src"),
71 !if(!null(patterns),[],!if(!null(!cdr(patterns)),patterns[0],patterns[1]))>;
71 !if(!empty(patterns),[],!if(!empty(!tail(patterns)),patterns[0],patterns[1]))>;
7272 }
7373
7474 multiclass vscalar opcode, string asmstr = "", list> patterns = []> {
7575 def V#NAME#SSrr : Inst
7676 !strconcat(asmstr, "\t$dst, $src"),
77 !if(!null(patterns),[],patterns[0])>;
77 !if(!empty(patterns),[],patterns[0])>;
7878 def V#NAME#SSrm : Inst
7979 !strconcat(asmstr, "\t$dst, $src"),
80 !if(!null(patterns),[],!if(!null(!cdr(patterns)),patterns[0],patterns[1]))>;
80 !if(!empty(patterns),[],!if(!empty(!tail(patterns)),patterns[0],patterns[1]))>;
8181 }
8282
8383 multiclass myscalar opcode, string asmstr = "", list> patterns = []> :
2727
2828 class A> vals> {
2929 list first = vals[0];
30 list rest = !if(!null(!cdr(vals)), vals[0], vals[1]);
30 list rest = !if(!empty(!tail(vals)), vals[0], vals[1]);
3131 }
3232
3333 def One : A<[[1,2,3]]>;
3737 list vals = v;
3838 }
3939
40 class BB> vals> : Bnull(!cdr(vals)), vals[0], vals[1])>;
40 class BB> vals> : Bempty(!tail(vals)), vals[0], vals[1])>;
4141 class BBB> vals> : BB;
4242
4343 def OneB : BBB<[[1,2,3]]>;
1414 }
1515
1616 class NameList Names> :
17 List, CARcar(Names)>, CDR(Names))>;
17 List, CARhead(Names)>, CDR(Names))>;
1818
1919 def Three : NameList<["Tom", "Dick", "Harry"]>;
2020
589589 }
590590 break;
591591 }
592 case CAR: {
592 case HEAD: {
593593 ListInit *LHSl = dynamic_cast(LHS);
594594 if (LHSl) {
595595 if (LHSl->getSize() == 0) {
600600 }
601601 break;
602602 }
603 case CDR: {
603 case TAIL: {
604604 ListInit *LHSl = dynamic_cast(LHS);
605605 if (LHSl) {
606606 if (LHSl->getSize() == 0) {
613613 }
614614 break;
615615 }
616 case LNULL: {
616 case EMPTY: {
617617 ListInit *LHSl = dynamic_cast(LHS);
618618 if (LHSl) {
619619 if (LHSl->getSize() == 0) {
649649 std::string Result;
650650 switch (Opc) {
651651 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
652 case CAR: Result = "!car"; break;
653 case CDR: Result = "!cdr"; break;
654 case LNULL: Result = "!null"; break;
652 case HEAD: Result = "!head"; break;
653 case TAIL: Result = "!tail"; break;
654 case EMPTY: Result = "!empty"; break;
655655 }
656656 return Result + "(" + LHS->getAsString() + ")";
657657 }
810810 ///
811811 class UnOpInit : public OpInit {
812812 public:
813 enum UnaryOp { CAST, CAR, CDR, LNULL };
813 enum UnaryOp { CAST, HEAD, TAIL, EMPTY };
814814 private:
815815 UnaryOp Opc;
816816 Init *LHS;
423423 StringSwitch(StringRef(Start, CurPtr - Start))
424424 .Case("eq", tgtok::XEq)
425425 .Case("if", tgtok::XIf)
426 .Case("car", tgtok::XCar)
427 .Case("cdr", tgtok::XCdr)
426 .Case("head", tgtok::XHead)
427 .Case("tail", tgtok::XTail)
428428 .Case("con", tgtok::XConcat)
429429 .Case("shl", tgtok::XSHL)
430430 .Case("sra", tgtok::XSRA)
431431 .Case("srl", tgtok::XSRL)
432432 .Case("cast", tgtok::XCast)
433 .Case("null", tgtok::XNull)
433 .Case("empty", tgtok::XEmpty)
434434 .Case("subst", tgtok::XSubst)
435435 .Case("foreach", tgtok::XForEach)
436436 .Case("strconcat", tgtok::XStrConcat)
4545
4646 // !keywords.
4747 XConcat, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
48 XForEach, XCar, XCdr, XNull, XIf, XEq,
48 XForEach, XHead, XTail, XEmpty, XIf, XEq,
4949
5050 // Integer value.
5151 IntVal,
682682 TokError("unknown operation");
683683 return 0;
684684 break;
685 case tgtok::XCar:
686 case tgtok::XCdr:
687 case tgtok::XNull:
685 case tgtok::XHead:
686 case tgtok::XTail:
687 case tgtok::XEmpty:
688688 case tgtok::XCast: { // Value ::= !unop '(' Value ')'
689689 UnOpInit::UnaryOp Code;
690690 RecTy *Type = 0;
703703 }
704704
705705 break;
706 case tgtok::XCar:
706 case tgtok::XHead:
707707 Lex.Lex(); // eat the operation
708 Code = UnOpInit::CAR;
708 Code = UnOpInit::HEAD;
709709 break;
710 case tgtok::XCdr:
710 case tgtok::XTail:
711711 Lex.Lex(); // eat the operation
712 Code = UnOpInit::CDR;
712 Code = UnOpInit::TAIL;
713713 break;
714 case tgtok::XNull:
714 case tgtok::XEmpty:
715715 Lex.Lex(); // eat the operation
716 Code = UnOpInit::LNULL;
716 Code = UnOpInit::EMPTY;
717717 Type = new IntRecTy;
718718 break;
719719 }
726726 Init *LHS = ParseValue(CurRec);
727727 if (LHS == 0) return 0;
728728
729 if (Code == UnOpInit::CAR
730 || Code == UnOpInit::CDR
731 || Code == UnOpInit::LNULL) {
729 if (Code == UnOpInit::HEAD
730 || Code == UnOpInit::TAIL
731 || Code == UnOpInit::EMPTY) {
732732 ListInit *LHSl = dynamic_cast(LHS);
733733 StringInit *LHSs = dynamic_cast(LHS);
734734 TypedInit *LHSt = dynamic_cast(LHS);
745745 }
746746 }
747747
748 if (Code == UnOpInit::CAR
749 || Code == UnOpInit::CDR) {
748 if (Code == UnOpInit::HEAD
749 || Code == UnOpInit::TAIL) {
750750 if (LHSl == 0 && LHSt == 0) {
751751 TokError("expected list type argumnet in unary operator");
752752 return 0;
763763 TokError("untyped list element in unary operator");
764764 return 0;
765765 }
766 if (Code == UnOpInit::CAR) {
766 if (Code == UnOpInit::HEAD) {
767767 Type = Itemt->getType();
768768 } else {
769769 Type = new ListRecTy(Itemt->getType());
775775 TokError("expected list type argumnet in unary operator");
776776 return 0;
777777 }
778 if (Code == UnOpInit::CAR) {
778 if (Code == UnOpInit::HEAD) {
779779 Type = LType->getElementType();
780780 } else {
781781 Type = LType;
12721272 return new DagInit(Operator, OperatorName, DagArgs);
12731273 }
12741274
1275 case tgtok::XCar:
1276 case tgtok::XCdr:
1277 case tgtok::XNull:
1275 case tgtok::XHead:
1276 case tgtok::XTail:
1277 case tgtok::XEmpty:
12781278 case tgtok::XCast: // Value ::= !unop '(' Value ')'
12791279 case tgtok::XConcat:
12801280 case tgtok::XSRA: