diff --git a/main.c b/main.c index d10f440..04522b9 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,8 @@ struct { bool xor, nxor; + bool lt, lte, gt, gte; + bool ternary; } use_operators; @@ -86,25 +88,33 @@ static void parse_args(int argc, char* const* argv) for (char* moving; (moving = strtok_r(NULL, ",", &optarg)); ) { - if (!strcmp(moving, "not")) + if (!strcmp(moving, "not") || !strcmp(moving, "!")) use_operators.not = true; - else if (!strcmp(moving, "or")) + else if (!strcmp(moving, "or") || !strcmp(moving, "||")) use_operators.or = true; - else if (!strcmp(moving, "orn")) + else if (!strcmp(moving, "orn") || !strcmp(moving, "|!")) use_operators.orn = true; - else if (!strcmp(moving, "nor")) + else if (!strcmp(moving, "nor") || !strcmp(moving, "!|")) use_operators.nor = true; - else if (!strcmp(moving, "and")) + else if (!strcmp(moving, "and") || !strcmp(moving, "&&")) use_operators.and = true; - else if (!strcmp(moving, "andn")) + else if (!strcmp(moving, "andn") || !strcmp(moving, "&!")) use_operators.andn = true; - else if (!strcmp(moving, "nand")) + else if (!strcmp(moving, "nand") || !strcmp(moving, "!&")) use_operators.nand = true; - else if (!strcmp(moving, "xor")) + else if (!strcmp(moving, "xor") || !strcmp(moving, "!=")) use_operators.xor = true; - else if (!strcmp(moving, "nxor")) + else if (!strcmp(moving, "nxor") || !strcmp(moving, "==")) use_operators.nxor = true; - else if (!strcmp(moving, "ternary")) + else if (!strcmp(moving, "<")) + use_operators.lt = true; + else if (!strcmp(moving, "<=")) + use_operators.lte = true; + else if (!strcmp(moving, ">")) + use_operators.gt = true; + else if (!strcmp(moving, ">=")) + use_operators.gte = true; + else if (!strcmp(moving, "ternary") || !strcmp(moving, "?:")) use_operators.ternary = true; else { @@ -157,6 +167,11 @@ enum kind { ek_xor, ek_nxor, + ek_lt, + ek_lte, + ek_gt, + ek_gte, + ek_ternary, }; @@ -223,6 +238,22 @@ static void print(uint16_t truthtable) printf("("), print(e->left), printf(" == "), print(e->right), printf(")"); break; + case ek_lt: + printf("("), print(e->left), printf(" < "), print(e->right), printf(")"); + break; + + case ek_lte: + printf("("), print(e->left), printf(" <= "), print(e->right), printf(")"); + break; + + case ek_gt: + printf("("), print(e->left), printf(" > "), print(e->right), printf(")"); + break; + + case ek_gte: + printf("("), print(e->left), printf(" >= "), print(e->right), printf(")"); + break; + case ek_ternary: printf("("), print(e->cond), printf(" ? "), print(e->left), printf(" : "), print(e->right), printf(")"); @@ -445,6 +476,11 @@ void calculate_simplifications(void) #define XOR(a, b) (( a) ^ (b)) #define NXOR(a, b) ~( (a) ^ (b)) + #define LT(a, b) ((~a) & (b)) + #define LTE(a, b) ((~a) | (b)) + #define GT(a, b) (( a) & ~(b)) + #define GTE(a, b) (( a) | ~(b)) + if (use_operators.or) { BINARY_OPERATOR(ek_or, OR); @@ -485,6 +521,26 @@ void calculate_simplifications(void) BINARY_OPERATOR(ek_nxor, NXOR); } + if (use_operators.lt) + { + BINARY_OPERATOR(ek_lt, LT); + } + + if (use_operators.lte) + { + BINARY_OPERATOR(ek_lte, LTE); + } + + if (use_operators.gt) + { + BINARY_OPERATOR(ek_gt, GT); + } + + if (use_operators.gte) + { + BINARY_OPERATOR(ek_gte, GTE); + } + if (use_operators.ternary) { for (int i = 0; i < N; i++) @@ -562,6 +618,18 @@ void get_simplifications(void) if (use_operators.nxor) strcat(path, "-nxor"); + if (use_operators.lt) + strcat(path, "-lt"); + + if (use_operators.lte) + strcat(path, "-lte"); + + if (use_operators.gt) + strcat(path, "-gt"); + + if (use_operators.gte) + strcat(path, "-gte"); + if (use_operators.ternary) strcat(path, "-ternary");