summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-22 11:48:55 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-10-30 13:20:42 -0400
commit525d4db4ea4f7b1562f39863e174f025ccc59a0b (patch)
treebc435525480fda3003e16571071d782f4810abcb
parent8ef0e2d0278688473fefac726ddb96fe3cda25e1 (diff)
downloadroux-525d4db4ea4f7b1562f39863e174f025ccc59a0b.tar.gz
new function to add constants
-rw-r--r--lisc/lisc.h1
-rw-r--r--lisc/util.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 4903961..efae900 100644
--- 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
index 53aad55..90fa1bb 100644
--- 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;
+ }
+}