Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7497695
New changes
nayan-1210 Apr 14, 2025
3d33ddb
changes
Rushit27 Apr 14, 2025
f8abff7
start of 4
nayan-1210 Apr 23, 2025
b82b4e1
Added scope pointer to each 3ac line
Rushit27 Apr 23, 2025
08ef907
addedd passes and stack
Ann18532 Apr 23, 2025
e530619
if statement
nayan-1210 Apr 23, 2025
4655704
Liveness analysis and register spill
nayan-1210 Apr 24, 2025
6eaadc5
basic function
nayan-1210 Apr 24, 2025
bdc774b
float function
nayan-1210 Apr 25, 2025
bde71d2
structural changes and fixed wrong function sizes
Rushit27 Apr 25, 2025
8034445
fixed wrong scope pointers
Rushit27 Apr 25, 2025
bacee74
added spill functionality
Rushit27 Apr 25, 2025
f29098a
function call with stack
nayan-1210 Apr 26, 2025
a47ff29
not working
nayan-1210 Apr 26, 2025
9750816
sort(all(func_params));
B1tB3ast Apr 26, 2025
8f7e2bd
Handled float params
B1tB3ast Apr 26, 2025
5a3e7fb
added pointers
Ann18532 Apr 27, 2025
b012008
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
Ann18532 Apr 27, 2025
a07c854
fixed scope pointer bugs
Rushit27 Apr 27, 2025
7186ea4
Merge branch 'fourth' of https://github.com/Project-Compiler-Design/C…
Rushit27 Apr 27, 2025
02fec48
fixed pointers
nayan-1210 Apr 27, 2025
d76f3d0
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
nayan-1210 Apr 27, 2025
568d404
float addition
nayan-1210 Apr 27, 2025
bde7dc5
double alloc
B1tB3ast Apr 27, 2025
f4c21d1
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
B1tB3ast Apr 27, 2025
bd5b75a
changes
B1tB3ast Apr 27, 2025
03889f5
float and double register spill
nayan-1210 Apr 27, 2025
af3ea9a
mixed op
B1tB3ast Apr 27, 2025
8c1b8d1
added struct
Ann18532 Apr 27, 2025
dc8f5e2
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
Ann18532 Apr 27, 2025
eaebb33
changes
Rushit27 Apr 28, 2025
b278b7b
Merge branch 'fourth' of https://github.com/Project-Compiler-Design/C…
Rushit27 Apr 28, 2025
50fc980
arrays working
Rushit27 Apr 28, 2025
7572821
printf
B1tB3ast Apr 28, 2025
6ff3126
changes
B1tB3ast Apr 28, 2025
3d92740
float,double array and pointer
nayan-1210 Apr 28, 2025
613820c
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
nayan-1210 Apr 28, 2025
13912a2
struct assignment
nayan-1210 Apr 28, 2025
7b24d4a
changes
nayan-1210 Apr 28, 2025
adfb9c2
printf/scanf
Ann18532 Apr 28, 2025
94afde9
static
B1tB3ast Apr 28, 2025
ec2c3b0
union
Ann18532 Apr 28, 2025
f03833a
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
Ann18532 Apr 28, 2025
6ccfb75
until loop
Ann18532 Apr 28, 2025
62abcc7
static var
nayan-1210 Apr 28, 2025
c45f54d
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
nayan-1210 Apr 28, 2025
d32693d
changes
nayan-1210 Apr 28, 2025
ba4fd1f
float errors fixed
nayan-1210 Apr 28, 2025
a12cede
recursive func call and return handling
Ann18532 Apr 28, 2025
955bc94
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
Ann18532 Apr 28, 2025
24bbada
float operation
B1tB3ast Apr 28, 2025
7ded009
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
B1tB3ast Apr 28, 2025
50f8803
multilevel ptr
Rushit27 Apr 28, 2025
7b8ef5b
Merge branch 'fourth' of https://github.com/Project-Compiler-Design/C…
Rushit27 Apr 28, 2025
9842420
print
B1tB3ast Apr 28, 2025
f33e370
Merge branch 'fourth' of github.com:Project-Compiler-Design/CSN-352-C…
B1tB3ast Apr 28, 2025
110a16d
cleaned
B1tB3ast Apr 29, 2025
791bbf5
change
B1tB3ast Apr 29, 2025
fa87fbe
cleaned + commented
Ann18532 Apr 29, 2025
e8be4dc
final
B1tB3ast Apr 29, 2025
1a28e3a
ch
B1tB3ast Apr 29, 2025
020558f
switch case bt fix
B1tB3ast Apr 30, 2025
0b7aa71
static, continue solved
B1tB3ast Apr 30, 2025
fbb60fc
single level pointer
B1tB3ast Apr 30, 2025
b06c42c
Final code
B1tB3ast May 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.associations": {
"random": "c"
"random": "c",
"iostream": "cpp"
}
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
79 changes: 64 additions & 15 deletions Assignment3/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,67 @@ bool startsWithPointerOrAddress(const string& line) {
}

// Function to clean Three-Address Code from input file and write to output file
// void cleanTAC(string input) {
// int lineno=1;
// string line="";
// int index=0;
// while(index<input.length()){
// line="";
// while(index<input.length()){
// if(input[index]!='\n'){
// line+=input[index];
// index++;
// }
// else{
// index++;
// break;
// }
// }

// // Trim leading and trailing spaces
// while (!line.empty() && isspace(line.front())) line.erase(line.begin());
// while (!line.empty() && isspace(line.back())) line.pop_back();

// // Skip empty lines and lines with only a single number
// if (line.empty() || isSingleNumber(line)) continue;

// // Skip lines with pointers or address-of expressions
// if (startsWithPointerOrAddress(line) && line.find('=') == string::npos) {
// continue;
// }

// // Check if the line is a label or function
// cerr<<lineno<<". ";
// if (!line.empty() && line.back() == ':' || !line.empty() && line.substr(0,4)=="FUNC") {
// cerr << line << endl; // Labels should not be indented
// } else {
// cerr << " " << line << endl; // Indent normal instructions
// }
// lineno++;
// }
// // cout << "Cleaning complete! Check " << endl;
// }
bool isOnlyStringLiteral(const string& line) {
// line must start and end with double quotes, and nothing else
return line.size() >= 2 && line.front() == '\"' && line.back() == '\"';
}

void cleanTAC(string input) {
int lineno=1;
string line="";
int index=0;
while(index<input.length()){
line="";
while(index<input.length()){
if(input[index]!='\n'){
line+=input[index];
int lineno = 1;
string line = "";
int index = 0;
while (index < input.length()) {
line = "";
while (index < input.length()) {
if (input[index] != '\n') {
line += input[index];
index++;
}
else{
} else {
index++;
break;
}
}

// Trim leading and trailing spaces
while (!line.empty() && isspace(line.front())) line.erase(line.begin());
while (!line.empty() && isspace(line.back())) line.pop_back();
Expand All @@ -163,18 +207,23 @@ void cleanTAC(string input) {
continue;
}

// ✅ Skip lines that contain only a string literal
if (isOnlyStringLiteral(line)) {
continue;
}

// Check if the line is a label or function
cerr<<lineno<<". ";
if (!line.empty() && line.back() == ':' || !line.empty() && line.substr(0,4)=="FUNC") {
cerr << lineno << ". ";
if (!line.empty() && line.back() == ':' || !line.empty() && line.substr(0, 4) == "FUNC") {
cerr << line << endl; // Labels should not be indented
} else {
cerr << " " << line << endl; // Indent normal instructions
}
}
lineno++;
}
// cout << "Cleaning complete! Check " << endl;
}


string replace_break_continue(string original_code,string end_label,string update_label,int i){
string new_code = original_code;
int flag=0;
Expand Down
2 changes: 1 addition & 1 deletion Assignment3/include/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct symbol_info {
int pointer_depth=0;
qid place;
std::string code;

bool is_static=false;
bool is_return=false;
std::string return_type="";
bool is_array_access=false;
Expand Down
11 changes: 2 additions & 9 deletions Assignment3/output/output1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,5 @@ Intermediate code generated successfully
4. *t0:= 10
5. t1:= a+4
6. *t1:= 10
7. c:= 4
8. p:= &c
9. q:= &p
10. t2:= *q
11. d:= *t3
12. t4:= *q
13. *t4:= 20
14. RETURN 0
15. FUNC_END main
7. RETURN 0
8. FUNC_END main
6 changes: 2 additions & 4 deletions Assignment3/output/output2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ Intermediate code generated successfully
======================================================================
1. FUNC_BEGIN main
2. b:= 3
3. c:= b
4. d:= 4
5. RETURN 0
6. FUNC_END main
3. RETURN 0
4. FUNC_END main
43 changes: 20 additions & 23 deletions Assignment3/output/output3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ Intermediate code generated successfully
======================================================================
1. FUNC_BEGIN main
2. sum:= 0
3. "Enter a positive integer: "
4. PARAM "Enter a positive integer: "
5. t0:= CALL printf,1
6. "%d"
7. PARAM "%d"
8. PARAM &num
9. t1:= CALL scanf,2
10. count:= 1
11. LABEL0:
12. t2:= count<=num
13. if(t2) goto LABEL2
14. goto LABEL1
15. LABEL2:
16. sum:= sum&count
17. count:= count+1
18. goto LABEL0
19. LABEL1:
20. "Sum = %d"
21. PARAM "Sum = %d"
22. PARAM sum
23. t3:= CALL printf,2
24. RETURN 0
25. FUNC_END main
3. PARAM "Enter a positive integer: "
4. t0:= CALL printf,1
5. PARAM "%d"
6. PARAM &num
7. t1:= CALL scanf,2
8. count:= 1
9. LABEL0:
10. t2:= count<=num
11. if(t2) goto LABEL2
12. goto LABEL1
13. LABEL2:
14. sum:= sum&count
15. count:= count+1
16. goto LABEL0
17. LABEL1:
18. PARAM "Sum = %d"
19. PARAM sum
20. t3:= CALL printf,2
21. RETURN 0
22. FUNC_END main
144 changes: 67 additions & 77 deletions Assignment3/output/output4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,70 @@ No Errors in the code
Intermediate code generated successfully
======================================================================
1. FUNC_BEGIN main
2. "Enter an operator (+, -, *, /): "
3. PARAM "Enter an operator (+, -, *, /): "
4. t0:= CALL printf,1
5. "%c"
6. PARAM "%c"
7. PARAM &operation
8. t1:= CALL scanf,2
9. "Enter two operands: "
10. PARAM "Enter two operands: "
11. t2:= CALL printf,1
12. "%lf %lf"
13. PARAM "%lf %lf"
14. PARAM &n1
15. PARAM &n2
16. t3:= CALL scanf,3
17. r:= 0
18. if(operation=='+') goto LABEL0
19. if(operation=='-') goto LABEL5
20. if(operation=='*') goto LABEL6
21. if(operation=='/') goto LABEL7
22. goto LABEL8
23. LABEL0:
24. "%.1lf + %.1lf = %.1lf"
25. t4:= n1+n2
26. PARAM "%.1lf + %.1lf = %.1lf"
27. PARAM n1
28. PARAM n2
29. PARAM t4
30. t5:= CALL printf,4
31. goto LABEL9
32. LABEL5:
33. if(b==1) goto LABEL1
34. if(b==2) goto LABEL2
35. goto LABEL3
36. LABEL1:
37. goto LABEL4
38. LABEL2:
39. r:= r-1
40. "%.1lf - %.1lf = %.1lf"
41. t6:= n1-n2
42. PARAM "%.1lf - %.1lf = %.1lf"
43. PARAM n1
44. PARAM n2
45. PARAM t6
46. t7:= CALL printf,4
47. goto LABEL4
48. LABEL3:
49. "Error! operator is not correct"
50. PARAM "Error! operator is not correct"
51. t8:= CALL printf,1
52. goto LABEL4
53. LABEL4:
54. goto LABEL9
55. LABEL6:
56. "%.1lf * %.1lf = %.1lf"
57. t9:= n1*n2
58. PARAM "%.1lf * %.1lf = %.1lf"
59. PARAM n1
60. PARAM n2
61. PARAM t9
62. t10:= CALL printf,4
63. LABEL7:
64. "%.1lf / %.1lf = %.1lf"
65. t11:= n1/n2
66. PARAM "%.1lf / %.1lf = %.1lf"
67. PARAM n1
68. PARAM n2
69. PARAM t11
70. t12:= CALL printf,4
71. goto LABEL9
72. LABEL8:
73. "Error! operator is not correct"
74. PARAM "Error! operator is not correct"
75. t13:= CALL printf,1
76. LABEL9:
77. RETURN 0
78. FUNC_END main
2. PARAM "Enter an operator (+, -, *, /): "
3. t0:= CALL printf,1
4. PARAM "%c"
5. PARAM &operation
6. t1:= CALL scanf,2
7. PARAM "Enter two operands: "
8. t2:= CALL printf,1
9. PARAM "%lf %lf"
10. PARAM &n1
11. PARAM &n2
12. t3:= CALL scanf,3
13. r:= 0
14. if(operation=='+') goto LABEL0
15. if(operation=='-') goto LABEL5
16. if(operation=='*') goto LABEL6
17. if(operation=='/') goto LABEL7
18. goto LABEL8
19. LABEL0:
20. t4:= n1+n2
21. PARAM "%.1lf + %.1lf = %.1lf"
22. PARAM n1
23. PARAM n2
24. PARAM t4
25. t5:= CALL printf,4
26. goto LABEL9
27. LABEL5:
28. if(b==1) goto LABEL1
29. if(b==2) goto LABEL2
30. goto LABEL3
31. LABEL1:
32. goto LABEL4
33. LABEL2:
34. r:= r-1
35. t6:= n1-n2
36. PARAM "%.1lf - %.1lf = %.1lf"
37. PARAM n1
38. PARAM n2
39. PARAM t6
40. t7:= CALL printf,4
41. goto LABEL4
42. LABEL3:
43. PARAM "Error! operator is not correct"
44. t8:= CALL printf,1
45. goto LABEL4
46. LABEL4:
47. goto LABEL9
48. LABEL6:
49. t9:= n1*n2
50. PARAM "%.1lf * %.1lf = %.1lf"
51. PARAM n1
52. PARAM n2
53. PARAM t9
54. t10:= CALL printf,4
55. LABEL7:
56. t11:= n1/n2
57. PARAM "%.1lf / %.1lf = %.1lf"
58. PARAM n1
59. PARAM n2
60. PARAM t11
61. t12:= CALL printf,4
62. goto LABEL9
63. LABEL8:
64. PARAM "Error! operator is not correct"
65. t13:= CALL printf,1
66. LABEL9:
67. RETURN 0
68. FUNC_END main
Loading