source: liacs/coco/assignment3/DOCUMENTATION.TXT@ 291

Last change on this file since 291 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 3.7 KB
RevLine 
[2]1= INTRODUCTION =
2
3Welcome reader,
4
5You will find our solution on assignment 5 of Compiler Constructions 2008
6giving at LIACS University. First we will you a grand overview of the files
7altered, next we will bullet point the most important design decisions.
8
9And the grand finale will show the usage of the program.
10
11Enjoy!
12Johan and Rick <hvdzwet@liacs.nl>
13
14
15= FILES EDITED/ADDED =
16E ICGenerator.cc = Intermidiate code generator C++ source
17E ICGenerator.h = Intermidiate code generator C++ source
18E main.cc = Main program function, argument parsing
19
20= DESIGN DECISIONS =
21* Constants are evaluated upfront, also nested ones. Optimalisations are
22 included into the tree and generated on the fly
23
24* In order to keep the code readable human-readable tests are defined like
25 IsZero, IsConstant.
26
27* Made icode, symtab global to avoid calling the Treewalk with a whole lot of
28 arguments every time.
29
30* Recursive walking of Tree using Treewalk allowing us to generate code on the
31 fly on three different 'location' e.g. first encounter, midle pass, last visit.
32
33* Tried various optimatisations on PostProcess, by changing variable names,
34 removing assignments, but yet all led to race conditions.
35
36* Wrote some theoritical tests PostProcess which could be implemented.
37
38* Constants in multiple additions (e.g. 10 + a + 20 + b) will be simplified 30 + a + b
39
40* Constants in multiple combinations of additions and substractions will be
41 simplyfied (e.g. 10 + a - 20 + b) will be simplified -10 + a + b
42
43* In order to allow the full folding, NODE_ADD and NODE_SUB are evaluated
44 differently, Like first right child, then left child.
45
46* Full constant folding on NODE_MUL has not been implemented, but will goes
47 more and less the same as the code at NODE_ADD
48
49= SAMPLE GENERATED CODE =
50C01) program example;
51C02)
52C03) var x, y, z: integer;
53C04) function foo(a,b: integer): integer;
54C05) begin
55C06) foo := 1
56C07) end;
57C08)
58C09) begin
59C10) x := readinteger;
60C11) y := 20;
61C12) z := x + 20;
62C13) z := z + foo(0,0)
63C14) end.
64
65Program: example
66 # operator | operand1 | operand2 | result
67 ------------------+-------------------+-------------------+-------------------
68 0: CALL FUNC | sym: readinteger | | sym: t1
69 1: ASSIGN_I | sym: t1 | | sym: x
70 2: ASSIGN_I | int: 20 | | sym: y
71 3: ADD_I | sym: x | int: 20 | sym: t2
72 4: ASSIGN_I | sym: t2 | | sym: z
73 5: PARAM_I | int: 0 | |
74 6: PARAM_I | int: 0 | |
75 7: CALL FUNC | sym: foo | | sym: t3
76 8: ADD_I | sym: z | sym: t3 | sym: t4
77 9: ASSIGN_I | sym: t4 | | sym: z
78 10: RETURN | | |
79
80 11: SUBPROG | sym: foo | |
81 12: ASSIGN_I | int: 1 | | sym: foo
82 13: RETURN_I | sym: foo | |
83
84 ------------------+-------------------+-------------------+-------------------
85
86Line 0,1 will be line C10. Direct assignments like line C11 will only use one
87line 3. When calling functions (C13), first the parameters will be set on
88place at line 5,6 then the function itself will be caled at line 7.
89
90Some book keeping could be found at line 13 (return)
91
92= USAGE =
93# Compile
94$ make dirs
95$ make
96# Call without optimalisation
97$ ./comp -w -00 <testfile
98# Call with optimalisation
99$ ./comp -w -01 <testfile
Note: See TracBrowser for help on using the repository browser.