aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-25 14:27:05 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-25 14:27:05 +0000
commit42342b2a58c2a9189ac0ef657c766c8632782bc7 (patch)
tree1eac2cad4370966a59b78bb3a3a8687618ac7fb5
parentf8d552b35e4897b18cc01777bb9725c59a3d5340 (diff)
downloadCompiler-42342b2a58c2a9189ac0ef657c766c8632782bc7.tar.gz
Compiler-42342b2a58c2a9189ac0ef657c766c8632782bc7.zip
Work on types and do everything correctly
-rw-r--r--c_compiler/src/expression.cpp7
-rw-r--r--test_deliverable/testcases/test_ARRAY2.c9
-rw-r--r--test_deliverable/testcases/test_ARRAY2_driver.c6
3 files changed, 19 insertions, 3 deletions
diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp
index fd78799..e65d2f7 100644
--- a/c_compiler/src/expression.cpp
+++ b/c_compiler/src/expression.cpp
@@ -689,12 +689,13 @@ VariableStackBindings AssignmentExpression::printAsm(VariableStackBindings bindi
// evaluate rhs and get the result back at the stack position I assigned
// don't have to change the stack position as there is no lhs to evaluate
rhs_->printAsm(bindings, label_count);
-
- // now the result of the rhs will be in that stack position, so we can load it into $2
- printf("\tlw\t$2,%d($fp)\n", expression_stack_position);
+ bindings.nextExpressionStackPosition();
// we are assigning so we don't have to evaluate the lhs as it will be overwritten anyways
lhs_postfix->stackPosition(bindings, label_count);
+
+ // now the result of the rhs will be in that stack position, so we can load it into $2
+ printf("\tlw\t$2,%d($fp)\n", expression_stack_position);
printf("\tsw\t$2,0($t0)\n");
return bindings;
}
diff --git a/test_deliverable/testcases/test_ARRAY2.c b/test_deliverable/testcases/test_ARRAY2.c
new file mode 100644
index 0000000..9bb22f9
--- /dev/null
+++ b/test_deliverable/testcases/test_ARRAY2.c
@@ -0,0 +1,9 @@
+int array2(int a, int b)
+{
+ int c[50] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16};
+
+ c[39] = a * b;
+ c[40] = c[39] + c[2];
+ return c[40];
+}
diff --git a/test_deliverable/testcases/test_ARRAY2_driver.c b/test_deliverable/testcases/test_ARRAY2_driver.c
new file mode 100644
index 0000000..5d4ae3d
--- /dev/null
+++ b/test_deliverable/testcases/test_ARRAY2_driver.c
@@ -0,0 +1,6 @@
+int array2(int a, int b);
+
+int main()
+{
+ return !( 29*49+3 == array2(29, 49) );
+}