History

expression optimization

bellard committed 23 years ago

Commit a9f08651 parent 9e180471 file · +119 −29Browse files

Unified · Split

tcc.c+119−29
@@ -553,7 +553,6 @@ extern long double strtold (const char *__nptr, char **__endptr); · 552 unmodified lines
553static char *pstrcpy(char *buf, int buf_size, const char *s);553static char *pstrcpy(char *buf, int buf_size, const char *s);
554static char *pstrcat(char *buf, int buf_size, const char *s);554static char *pstrcat(char *buf, int buf_size, const char *s);
555 555
556static void sum(int l);
557static void next(void);556static void next(void);
558static void next_nomacro(void);557static void next_nomacro(void);
559static void parse_expr_type(CType *type);558static void parse_expr_type(CType *type);
@@ -6478,39 +6477,130 @@ static void uneq(void) · 5918 unmodified lines
6478 }6477 }
6479}6478}
6480 6479
6481static void sum(int l)6480static void expr_prod(void)
6482{6481{
6483 int t;6482 int t;
6484 6483
6485 if (l == 0)6484 uneq();
6485 while (tok == '*' || tok == '/' || tok == '%') {
6486 t = tok;
6487 next();
6486 uneq();6488 uneq();
6487 else {6489 gen_op(t);
6488 sum(--l);6490 }
6489 while ((l == 0 && (tok == '*' || tok == '/' || tok == '%')) ||6491}
6490 (l == 1 && (tok == '+' || tok == '-')) ||6492
6491 (l == 2 && (tok == TOK_SHL || tok == TOK_SAR)) ||6493static void expr_sum(void)
6492 (l == 3 && ((tok >= TOK_ULE && tok <= TOK_GT) ||6494{
6493 tok == TOK_ULT || tok == TOK_UGE)) ||6495 int t;
6494 (l == 4 && (tok == TOK_EQ || tok == TOK_NE)) ||6496
6495 (l == 5 && tok == '&') ||6497 expr_prod();
6496 (l == 6 && tok == '^') ||6498 while (tok == '+' || tok == '-') {
6497 (l == 7 && tok == '|') ||6499 t = tok;
6498 (l == 8 && tok == TOK_LAND) ||6500 next();
6499 (l == 9 && tok == TOK_LOR)) {6501 expr_prod();
6500 t = tok;6502 gen_op(t);
6501 next();6503 }
6502 sum(l);6504}
6503 gen_op(t);6505
6504 }6506static void expr_shift(void)
6507{
6508 int t;
6509
6510 expr_sum();
6511 while (tok == TOK_SHL || tok == TOK_SAR) {
6512 t = tok;
6513 next();
6514 expr_sum();
6515 gen_op(t);
6516 }
6517}
6518
6519static void expr_cmp(void)
6520{
6521 int t;
6522
6523 expr_shift();
6524 while ((tok >= TOK_ULE && tok <= TOK_GT) ||
6525 tok == TOK_ULT || tok == TOK_UGE) {
6526 t = tok;
6527 next();
6528 expr_shift();
6529 gen_op(t);
6530 }
6531}
6532
6533static void expr_cmpeq(void)
6534{
6535 int t;
6536
6537 expr_cmp();
6538 while (tok == TOK_EQ || tok == TOK_NE) {
6539 t = tok;
6540 next();
6541 expr_cmp();
6542 gen_op(t);
6543 }
6544}
6545
6546static void expr_and(void)
6547{
6548 expr_cmpeq();
6549 while (tok == '&') {
6550 next();
6551 expr_cmpeq();
6552 gen_op('&');
6553 }
6554}
6555
6556static void expr_xor(void)
6557{
6558 expr_and();
6559 while (tok == '^') {
6560 next();
6561 expr_and();
6562 gen_op('^');
6563 }
6564}
6565
6566static void expr_or(void)
6567{
6568 expr_xor();
6569 while (tok == '|') {
6570 next();
6571 expr_xor();
6572 gen_op('|');
6573 }
6574}
6575
6576/* XXX: suppress this mess */
6577static void expr_land_const(void)
6578{
6579 expr_or();
6580 while (tok == TOK_LAND) {
6581 next();
6582 expr_or();
6583 gen_op(TOK_LAND);
6584 }
6585}
6586
6587/* XXX: suppress this mess */
6588static void expr_lor_const(void)
6589{
6590 expr_land_const();
6591 while (tok == TOK_LOR) {
6592 next();
6593 expr_land_const();
6594 gen_op(TOK_LOR);
6505 }6595 }
6506}6596}
6507 6597
6508/* only used if non constant */6598/* only used if non constant */
6509static void eand(void)6599static void expr_land(void)
6510{6600{
6511 int t;6601 int t;
6512 6602
6513 sum(8);6603 expr_or();
6514 t = 0;6604 t = 0;
6515 while (1) {6605 while (1) {
6516 if (tok != TOK_LAND) {6606 if (tok != TOK_LAND) {
@@ -6522,15 +6612,15 @@ static void eand(void) · 5 unmodified lines
6522 }6612 }
6523 t = gtst(1, t);6613 t = gtst(1, t);
6524 next();6614 next();
6525 sum(8);6615 expr_or();
6526 }6616 }
6527}6617}
6528 6618
6529static void eor(void)6619static void expr_lor(void)
6530{6620{
6531 int t;6621 int t;
6532 6622
6533 eand();6623 expr_land();
6534 t = 0;6624 t = 0;
6535 while (1) {6625 while (1) {
6536 if (tok != TOK_LOR) {6626 if (tok != TOK_LOR) {
@@ -6542,7 +6632,7 @@ static void eor(void) · 5 unmodified lines
6542 }6632 }
6543 t = gtst(0, t);6633 t = gtst(0, t);
6544 next();6634 next();
6545 eand();6635 expr_land();
6546 }6636 }
6547}6637}
6548 6638
@@ -6555,7 +6645,7 @@ static void expr_eq(void) · 6 unmodified lines
6555 6645
6556 if (const_wanted) {6646 if (const_wanted) {
6557 int c1, c;6647 int c1, c;
6558 sum(10);6648 expr_lor_const();
6559 if (tok == '?') {6649 if (tok == '?') {
6560 c = vtop->c.i;6650 c = vtop->c.i;
6561 vpop();6651 vpop();
@@ -6569,7 +6659,7 @@ static void expr_eq(void) · 7 unmodified lines
6569 vtop->c.i = c1;6659 vtop->c.i = c1;
6570 }6660 }
6571 } else {6661 } else {
6572 eor();6662 expr_lor();
6573 if (tok == '?') {6663 if (tok == '?') {
6574 next();6664 next();
6575 save_regs(1); /* we need to save all registers here except6665 save_regs(1); /* we need to save all registers here except

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t