ref: 2b05b5d52482e818baf747bc8b0619fd0d26ca02
parent: a6692449e11bf9f40d051e0b8eb566bca72946ca
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 4 03:54:49 EDT 2021
cc2/qbe: Add complex() The calculation of the complexity number can be factorized and reuse it in different places of the code.
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -98,6 +98,29 @@
}
static Node *
+complex(Node *np)
+{
+ Node *lp = np->left, *rp = np->right;
+
+ if (np->address > 10)
+ return np;
+ if (lp)
+ np->complex = lp->complex;
+ if (rp) {
+ int d = np->complex - rp->complex;
+
+ if (d == 0)
+ ++np->complex;
+ else if (d < 0)
+ np->complex = rp->complex;
+ }
+ if (np->complex == 0)
+ ++np->complex;
+
+ return np;
+}
+
+static Node *
load(Type *tp, Node *np, Node *new)
{
int op;
@@ -726,19 +749,5 @@
np->left = lp;
np->right = rp;
- if (np->address > 10)
- return np;
- if (lp)
- np->complex = lp->complex;
- if (rp) {
- int d = np->complex - rp->complex;
-
- if (d == 0)
- ++np->complex;
- else if (d < 0)
- np->complex = rp->complex;
- }
- if (np->complex == 0)
- ++np->complex;
- return np;
+ return complex(np);
}