commit 525d4db4ea4f7b1562f39863e174f025ccc59a0b
parent 8ef0e2d0278688473fefac726ddb96fe3cda25e1
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Thu, 22 Oct 2015 11:48:55 -0400
new function to add constants
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/lisc/lisc.h b/lisc/lisc.h
@@ -326,6 +326,7 @@ void *vnew(ulong, size_t);
void vgrow(void *, ulong);
Ref newtmp(char *, Fn *);
Ref getcon(int64_t, Fn *);
+void addcon(Con *, Con *);
/* parse.c */
extern OpDesc opdesc[NOp];
diff --git a/lisc/util.c b/lisc/util.c
@@ -192,3 +192,18 @@ getcon(int64_t val, Fn *fn)
fn->con[c] = (Con){.type = CNum, .val = val};
return CON(c);
}
+
+void
+addcon(Con *c0, Con *c1)
+{
+ if (c0->type == CUndef)
+ *c0 = *c1;
+ else {
+ if (c1->type == CAddr) {
+ if (c0->type == CAddr)
+ diag("addcon: adding two addresses");
+ strcpy(c0->label, c1->label);
+ }
+ c0->val += c1->val;
+ }
+}