aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-03-10 21:37:11 +0000
committerYann Herklotz <ymherklotz@gmail.com>2018-03-10 21:37:11 +0000
commit2e124e11be8b88458f4fe8b8eb1ec0ff66a34eb7 (patch)
tree07e423b897ec6914dd27496528b21b93dcd883a3
parente3f93f203a1b47a31fef21219955335476857d90 (diff)
downloadCompiler-2e124e11be8b88458f4fe8b8eb1ec0ff66a34eb7.tar.gz
Compiler-2e124e11be8b88458f4fe8b8eb1ec0ff66a34eb7.zip
Improving documentation
-rw-r--r--README.md (renamed from 3-compiler-documentation.md)91
-rw-r--r--doc/.gitignore0
-rw-r--r--readme.md50
-rw-r--r--res/my-ast.png (renamed from my-ast.png)bin62299 -> 62299 bytes
-rw-r--r--test.c10
-rw-r--r--testing/ref_compiler.sh3
-rw-r--r--testing/testcases/test_ADD.c4
-rw-r--r--testing/testcases/test_ADD_driver.c8
8 files changed, 15 insertions, 151 deletions
diff --git a/3-compiler-documentation.md b/README.md
index da75e1d..b12c461 100644
--- a/3-compiler-documentation.md
+++ b/README.md
@@ -14,8 +14,7 @@ AST
Overview Diagram
----------------
-_Add a diagram of your AST, which is designed to *usefully* communicate
-the *important* properties of the AST._
+Overview of the ast that is built by the compiler.
![my-ast.png](my-ast.png)
@@ -23,8 +22,7 @@ the *important* properties of the AST._
Description
-----------
-_Describe the structure and organisation of your AST in 200 words
-or fewer_.
+### Description of the structure
I used a pure abstract Node class as an entry point to the AST.
I then had a TranslationUnit class which contained the external declarations and function
@@ -44,17 +42,11 @@ them.
Strengths
---------
-_Give two strengths or capabilities of your AST, using 50 words or less for each one_.
-
-### Strength 1
-
The class hierarchy and structure is very logical as it closely matches the grammar.
This also that it was easy to know what member variables a class needed and the
inheritance was very logical too. All the member functions are well separated
and only appear where they are actually used.
-### Strength 2
-
All the general base classes, that are mostly abstract as well, are in the bison union,
which means that I can use and assign all of those classes directly, and be more
specific in the member variables of those classes so that they only contain the types I need.
@@ -62,17 +54,11 @@ specific in the member variables of those classes so that they only contain the
Limitations
-----------
-_Give two limitations of your AST, using 50 words or less for each one_.
-
-### Limitation 1
-
The Type class is not very useful as it does not capture arrays correctly and store
all their information when using a multidimensional array for example. It also does not
enable me to extract this information correctly as it will only give me the primitive type of
the array.
-### Limitation 2
-
As I did not want all the classes to contain functions that they do not need, classes like
UnaryOperator have member functions. To access these I have to use dynamic casts and with my
linked lists, I always have to check for nullptr before doing anything with it.
@@ -84,10 +70,6 @@ Variable binding
General approach
----------------
-_Describe your overall approach to mapping variable, parameters, etc.
-into registers or memory locations at execution time, using 200 words
-or less_.
-
I did not use many registers because they are a limited resource, and instead I decided
only to use registers $2 and $3 for performing operations and rarely use registers $t0 and $t1
when loading the address of a value, for example for pointers. I also used registers $4, $5, $6, $7
@@ -105,16 +87,10 @@ variable shadowing.
Strengths
---------
-_Give two strengths or capabilities of your binding approach, using 50 words or less for each one_.
-
-### Strength 1
-
The Bindings class stores the type of the identifier so that I can look
it up and perform the right operation in the Expression class. Storing the type, however, also
means that I do not have to store the type of an Expression, but can just deduce it.
-### Strength 2
-
By only using two registers for operations, I do not have to worry about having no more
registers available, and which registers will not be overwritten after a function call.
The temporary expression result will always be in the current frame of the function even after
@@ -123,16 +99,10 @@ a function call.
Limitations
-----------
-_Give two limitations of your binding approach, using 50 words or less for each one_.
-
-### Limitation 1
-
As I am only using two registers to perform operations, I have to include loads and
stores to access the temporary results of the operations. I also store results of an operation
when I do not need the result anymore. This means that the code will run much slower.
-### Limitation 2
-
When counting the variables that are being assigned in the current function, I assume that
they are all integers. I also always store the return value $31 even when there is no function
call. This means that the frame is always much larger than it needs to be.
@@ -144,18 +114,11 @@ Reflection
Strengths
---------
-_What two aspects of your compiler do you think work well (beyond
-those identified in the AST and binding parts)?_
-
-### Strength 1
-
The Type class was not structured well for handling arrays, however, it does work well
with the other types and makes it easy to store and load variables using the
right operations. It also made it easy to identify pointers for pointer arithmatic and store
values in arrays without padding.
-### Strength 2
-
Function calls work well as they follow the MIPS ABI, and leave enough space for the called
function to store the parameters in the previous frame. The return address is also always stored,
which make recursive calls possible. Function declarations also work because they do not have
@@ -164,58 +127,34 @@ to emit assembly.
Scope for Improvement
---------------------
-_What parts of your compiler do you think could be improved?_
-
-### Improvement 1
-
I would like to work on multidimensional arrays as they do not fully work. To do
that I would have to add information such as the initial array in the type so that I can assign
arrays inside the array to a pointer and perform the right pointer arithmetic.
-### Improvement 2
-
I would also like to reduce the number of dynamic and static casts by adding more
intermediate classes. This would also make the whole AST design more extensible and it would
be easier to possibly add structures in the future. This would also make classes more specialized
and maintainable.
-Functionality (not assessed)
-============================
+Functionality
+=============
Which of these features does your compiler support (insert
an `x` to check a box):
-1 - [x] Local variables
-2 - [x] Integer arithmetic
-3 - [x] While
-4 - [x] IfElse
-5 - [x] For
-6 - [x] Function calls
-7 - [x] Arrays
-8 - [x] Pointers
-9 - [x] Strings
-10 - [ ] Structures
-11 - [ ] Floating-point
+- [x] Local variables
+- [x] Integer arithmetic
+- [x] While
+- [x] IfElse
+- [x] For
+- [x] Function calls
+- [x] Arrays
+- [x] Pointers
+- [x] Strings
+- [ ] Structures
+- [ ] Floating-point
Note that all features will be tested, regardless of what
appears here. This is documentation of what you expect to work,
versus what doesn't work.
-
-
-Feedback (not assessed)
-=======================
-
-_What aspects of your compiler would you like feedback on.
-Be specific, as "what could I have done differently" is
-too general to answer._
-
-### Feedback 1
-
-I would like to know if the Type class could have been improved for dealing with arrays and
-pointers of pointers.
-
-### Feedback 2
-
-Is using static and dynamic casts to figure out the type of an object a viable method or is
-there a better way?
diff --git a/doc/.gitignore b/doc/.gitignore
deleted file mode 100644
index e69de29..0000000
--- a/doc/.gitignore
+++ /dev/null
diff --git a/readme.md b/readme.md
deleted file mode 100644
index 94aa8ce..0000000
--- a/readme.md
+++ /dev/null
@@ -1,50 +0,0 @@
-The module code deliverables come in three parts:
-
- Deliverable | Due | Weight | Notes
--------------------------------|-------------|--------|------------------------------------
-[1-lexer.md](1-lexer.md) | Tue 7th Feb | 10% | A C lexer that produces JSON output
-[2-parser.md](2-parser.md) | Tue 7th Mar | 10% | A (restricted) C parser that produces XML output
-[3-compiler.md](3-compiler.md) | Tue 28th Mar | 50% | The final C compiler
-
-You will all get a bare private repository. It is up to you
-if you want to clone the master specification, or to start from
-scratch. Both approaches just require the git operations already used
-in lab 1, and possibly looking at the documentation for the commands
-you have already used. Remember that you can always do `git ${CMD} --help`
-for any CMD such as `pull`, `push`, `commit`, `remote`.
-
-Starting from scratch
----------------------
-
-1 - Create a local git repository using `git init` in a directory of your choice.
-
-2 - Commit files to your local repository (as you would normally commit)
-
-3 - Add the URL of your private repository as the remote `origin` (similar
- to manually adding the `spec` remote in the lab).
-
-4 - You should now be able to push and pull commits to origin, which is
- your private repo.
-
-Cloning the spec
-----------------
-
-1 - Clone the master specification from the public URL. This will produce
- a directory called `langproc-2016-cw` by default.
-
-2 - Rename it to something more meaningful, e.g. `langproc-2016-cw-${LOGIN}`.
-
-3 - Use `git remote` to rename `origin` (which points at the public spec) to
- `spec`.
-
-4 - Use `git remote` to add a new remote called `origin` pointing at
- your private repository.
-
-5 - You should then be able to push and pull to `origin`, and pull from `spec`,
- as in the lab.
-
-Submissions
------------
-
-Submission will be via github (code) + blackboard (commit hash),
-as in the lab.
diff --git a/my-ast.png b/res/my-ast.png
index c7ad076..c7ad076 100644
--- a/my-ast.png
+++ b/res/my-ast.png
Binary files differ
diff --git a/test.c b/test.c
deleted file mode 100644
index 4bfc9da..0000000
--- a/test.c
+++ /dev/null
@@ -1,10 +0,0 @@
-int main()
-{
- int x[4][3] = {
- { 1, 2 },
- { 3, 4, 5},
- { 6, 7, 8 }
- };
-
- return x[2][1];
-}
diff --git a/testing/ref_compiler.sh b/testing/ref_compiler.sh
deleted file mode 100644
index b5425b0..0000000
--- a/testing/ref_compiler.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-mips-linux-gnu-gcc -c -S -x c - -o -
diff --git a/testing/testcases/test_ADD.c b/testing/testcases/test_ADD.c
deleted file mode 100644
index 327dc85..0000000
--- a/testing/testcases/test_ADD.c
+++ /dev/null
@@ -1,4 +0,0 @@
-int f(int a, int b)
-{
- return 1;
-}
diff --git a/testing/testcases/test_ADD_driver.c b/testing/testcases/test_ADD_driver.c
deleted file mode 100644
index 9e74f32..0000000
--- a/testing/testcases/test_ADD_driver.c
+++ /dev/null
@@ -1,8 +0,0 @@
-int f(int a, int b);
-
-int main()
-{
- int r=f(10,11);
-
- return r == 21;
-}