|
1 |
| -## Instructions of running |
2 |
| -- run using ``python3 parser.py Inputfile OutputFile SymbolTableFile`` |
3 |
| - |
4 |
| -## SymbolTable : |
5 |
| -- This is a list of symbol Tables; One for global and one each for functions and classes |
6 |
| -- each local and temp varible contain base address, offset and size |
7 |
| -- All entries for activation record are in function entry of symbol table |
8 |
| - |
9 |
| - |
10 |
| -## 3AC : |
11 |
| -### BeginFunc |
12 |
| -``` |
13 |
| - push %rbp |
14 |
| - mov %rsp %rbp |
15 |
| - sub <local_var_space> %rsp |
16 |
| - push <callee saved registers> |
17 |
| -``` |
18 |
| - |
19 |
| -### EndFunc |
20 |
| -``` |
21 |
| - pop <callee saved registers> |
22 |
| - mov %rbp %rsp |
23 |
| - pop %rbp |
24 |
| - ret |
25 |
| -``` |
26 |
| -### Some Specific Points: |
27 |
| - - We currently generate 2 3AC code file(code.crux, code2.crux), one contains names of variable, while other contain address, relative to stack or heap |
28 |
| - - load_address a , b :: a = &b :: put address of b in variable a |
29 |
| - - load a, b :: a = *b; |
30 |
| - - eq a, b :: *a = b |
31 |
| - - eqconst a, b :: a = b |
32 |
| - |
33 |
| -## Features : |
34 |
| -- if,if-else |
35 |
| -- break,continue |
36 |
| -- for,while,do-while |
37 |
| -- Functions, Function Overloading |
38 |
| -- Classes |
39 |
| -- new , delete |
40 |
| -- Vanilla C features |
41 |
| - |
42 |
| -Following are the differences from vanilla implementation of the above[^1] |
43 |
| -## Miscelaneous |
44 |
| -- Variable sized arrays cannot be declared : |
45 |
| - ``` |
46 |
| - int a[5]; //allowed |
47 |
| - int a[c]; //not allowed |
48 |
| - ``` |
49 |
| -## Branches |
50 |
| - - Same as vanilla C++ except following changes |
51 |
| - - We have no else if clause so you have to write if-else as : |
52 |
| - ``` |
53 |
| - if(i==0){ |
54 |
| - y=1; |
55 |
| - }else{ |
56 |
| - if(i==1){ |
57 |
| - y=2; |
58 |
| - } |
59 |
| - } |
60 |
| - ``` |
61 |
| - - You have to use curly braces for all loops,branches,etc... single lines not allowed |
62 |
| - ``` |
63 |
| - if(i==0) y=1; //not allowed |
64 |
| - if(i==0){ y=1; } //allowed |
65 |
| - ``` |
66 |
| -## Loops |
67 |
| -- All 3 for, while and do-while loops are allowed and same as vanilla C++ except for the compulsory use of braces |
68 |
| - ``` |
69 |
| - for(;;)int i=0; //not allowed |
70 |
| - for(;;){;} //allowed |
71 |
| - ``` |
72 |
| -- break gets attached to nearest switch-case/\{for,while,do-while\}loop, while continue gets attached to nearest \{for,while,do-while\}loop. See tests/34.cpp. |
73 |
| - |
74 |
| -## Classes |
75 |
| -- Class variables are accessed only by ``this``. |
76 |
| -- Class function can be prototyped inside class declaration itself |
77 |
| -- Class function should be defined outside of class as in given example, it does not needs to prototyped for definition. |
78 |
| -- No Constructor and Destructor, we have to call them excplicitly. |
79 |
| -- Class functions can be prototyped inside class and can be added later using "::" operator. |
80 |
| - ``` |
81 |
| - class x{ |
82 |
| - int a; |
83 |
| - int f(int b); |
84 |
| - }; |
85 |
| - class x:: int f(int y){ |
86 |
| - if(this->a > y){ |
87 |
| - return 0; |
88 |
| - }else{ |
89 |
| - return 1; |
90 |
| - } |
91 |
| - } |
92 |
| - ``` |
93 |
| - |
94 |
| -## Functions |
95 |
| -- Function overloading allowed. |
96 |
| - - 2 Functions are same only if thier name are same, and order of type of arguments are exactly same. |
97 |
| - - Class Functions can also be overloaded. |
98 |
| - - return type overloading is not allowed. E.g. |
99 |
| - ``` |
100 |
| - void func(int b, int c){;} //1,2,3,4 are all different |
101 |
| - void func(int b, float c){;} |
102 |
| - void func(int b){;} |
103 |
| - void func1(int b, int c){;} |
104 |
| - int func(int a, int h){return 1;} //same as 1 |
105 |
| - ``` |
106 |
| -- Function code is generated as follows: |
107 |
| - - offset of all local variables except parameters are calculated during function definition. |
108 |
| - - offset of parameters is calculated during function call. |
109 |
| - - Stack space is increased using offset calculated earlier using BeginFunc and EndFunc reverts to original space |
110 |
| -
|
111 |
| -## Include |
112 |
| -- Presently you can only include std.cpp, it contains function for new and delete. And include statement(if used) should be at the top of the file. |
113 |
| -
|
114 |
| -## Allocation/Deallocation |
115 |
| -- new keyword is used for allocation and is used as ```new (int)[c]``` round brackets are compulsory and square braces are optional and if mentioned returns array of allocated objects. Here variable sized arrays are possible. |
116 |
| -- to delete a variable previously allocated, use ``delete id`` and for array use ``delete [] id``. Currently the id should be an identifier only. |
117 |
| -
|
118 |
| -[^1]: Reference for 3AC : [Stanford 3AC Examples](https://web.stanford.edu/class/archive/cs/cs143/cs143.1128/handouts/240%20TAC%20Examples.pdf ) |
| 1 | +## Compile and Run |
| 2 | +- ```./compile_and_run.sh <file_name>``` |
119 | 3 |
|
| 4 | +## Compile and Run seperately |
| 5 | +- ```./compile.sh <file_name>``` |
| 6 | +- ```./m.out``` |
120 | 7 |
|
| 8 | +## clean temp generated files |
| 9 | +- ```./clean.sh``` |
0 commit comments