Skip to content

Commit

Permalink
Akankshya (#10)
Browse files Browse the repository at this point in the history
* IC

* Finished

* Lab test
  • Loading branch information
akankshya107 authored Apr 20, 2019
1 parent 9b567cb commit 8ff62fa
Show file tree
Hide file tree
Showing 116 changed files with 1,295 additions and 181 deletions.
Binary file removed .vscode/ipch/1040019817a43567/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/15c3e3f0f42c5e33/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/1ff17bd5f4f3264a/key.ipch
Binary file not shown.
Binary file removed .vscode/ipch/1ff17bd5f4f3264a/mmap_address.bin
Binary file not shown.
Binary file modified .vscode/ipch/2e77a1999dead6f3/driver.ipch
Binary file not shown.
Binary file modified .vscode/ipch/2e77a1999dead6f3/mmap_address.bin
Binary file not shown.
Binary file added .vscode/ipch/3ae3cc5de1ab0aa9/codegen.ipch
Binary file not shown.
Binary file added .vscode/ipch/3ae3cc5de1ab0aa9/mmap_address.bin
Binary file not shown.
Binary file added .vscode/ipch/3ae3d15de1ab1328/codegen.ipch
Binary file not shown.
Binary file added .vscode/ipch/3ae3d15de1ab1328/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/5f455833527d977d/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/75654e5e946554f3/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/75654e5e946554f3/semanticDef.ipch
Binary file not shown.
Binary file removed .vscode/ipch/75d716a5cadcaae8/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/8492df9a5c720c1d/mmap_address.bin
Binary file not shown.
Binary file added .vscode/ipch/865bad59bd698257/i.ipch
Binary file not shown.
Binary file added .vscode/ipch/865bad59bd698257/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/9819ba4e5eb8f450/AST.ipch
Binary file not shown.
Binary file removed .vscode/ipch/9819ba4e5eb8f450/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/9819c54e5eb90701/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/9c3349a3d8645de0/mmap_address.bin
Binary file not shown.
Binary file modified .vscode/ipch/9c3354a3d8647091/mmap_address.bin
Binary file not shown.
Binary file modified .vscode/ipch/9c3354a3d8647091/semantic.ipch
Binary file not shown.
Binary file modified .vscode/ipch/9cf179b387589795/SymbolTable.ipch
Binary file not shown.
Binary file removed .vscode/ipch/b02ebb65a06be2cc/DFA.ipch
Binary file not shown.
Binary file removed .vscode/ipch/b02ebb65a06be2cc/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/b762fc130726fef/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/b7638c130727f3a/lexer.ipch
Binary file not shown.
Binary file removed .vscode/ipch/b7638c130727f3a/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/b8441f1db8053adf/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/b8441f1db8053adf/parser.ipch
Binary file not shown.
Binary file removed .vscode/ipch/b844281db8054a2a/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/bc47c219cdcb60/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/bc52c219cdde11/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/c1487d9c51588b0e/mmap_address.bin
Binary file not shown.
Binary file added .vscode/ipch/c59882860e1dfdd5/Intermediate.ipch
Binary file not shown.
Binary file added .vscode/ipch/c59882860e1dfdd5/mmap_address.bin
Binary file not shown.
Binary file modified .vscode/ipch/c59887860e1e0654/Intermediate.ipch
Binary file not shown.
Binary file removed .vscode/ipch/ed1622843dc7bdfe/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/f2d946fa2e4c0e65/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/f2d94bfa2e4c16e4/AST.ipch
Binary file not shown.
Binary file removed .vscode/ipch/f2d94bfa2e4c16e4/mmap_address.bin
Binary file not shown.
Binary file modified AST.h.gch
Binary file not shown.
Binary file modified AST.o
Binary file not shown.
Binary file modified ASTDef.h.gch
Binary file not shown.
Binary file added Coding proforma.pdf
Binary file not shown.
Binary file modified DFA.o
Binary file not shown.
522 changes: 500 additions & 22 deletions Intermediate.c

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Intermediate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "IntermediateDef.h"
TEMP newTemp();
LABEL newLabel();
result *newResult(int flag, TEMP t, LABEL l);
arg* newArg(int flag, hash_ele* h, TEMP t, LABEL L, int num, float rnum, int width);
op* newOp(int flag, TAG tag, TOKEN tkname);
label* returnLabel(int flag, LABEL l, char* dataDef);
quadruple* newQuad(arg *a1, arg *a2, op* op, LABEL *l, result *res);
quadruple* generateIntermediateCode(ASTNodeIt* root);
char* concat(const char *s1, const char *s2);
arg* getArg(ASTNodeIt* ast);
Binary file added Intermediate.h.gch
Binary file not shown.
Binary file added Intermediate.o
Binary file not shown.
17 changes: 15 additions & 2 deletions IntermediateDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
// KARABEE BATTA 2016A7PS0052P
// AASTHA KATARIA 2016A7PS0062P

#ifndef SYM_INCLUDED
#include "SymbolTable.h"
#define SYM_INCLUDED
#endif
typedef int LABEL;
typedef int TEMP;
typedef struct IntermediateDef IntermediateDef;

typedef struct label label;
typedef struct arg{
int flag;
union{
hash_ele* hElem;
TEMP t;
LABEL L; //TRUE is stored in arg1, FALSE in arg2
label *L; //TRUE is stored in arg1, FALSE in arg2
int num;
float rnum;
int width;
}u;
}arg;

Expand All @@ -36,11 +41,19 @@ typedef struct{
}u;
}result;

typedef struct label{
int flag;
union{
LABEL l;
char *dataDef;
}u;
}label;

typedef struct quadruple{
arg* a1;
arg* a2;
op* operand;
result *res;
LABEL l;
label *L;
struct quadruple* next;
}quadruple;
Binary file modified IntermediateDef.h.gch
Binary file not shown.
87 changes: 0 additions & 87 deletions README.md

This file was deleted.

2 changes: 1 addition & 1 deletion SymbolTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void populate_type(hash_ele* hashEle_identifier,ASTNodeIt* temp)
else if(temp->node->u.n->children->node->u.l->leaf_symbol->tokenName==TK_REAL)
{
hashEle_identifier->ele->u.g->u.t->is_record=0;
hashEle_identifier->ele->u.g->u.t->u.pri_type=false;
hashEle_identifier->ele->u.g->u.t->u.pri_type=true;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions SymbolTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// KARABEE BATTA 2016A7PS0052P
// AASTHA KATARIA 2016A7PS0062P
#include "SymbolTableDef.h"
#define SYM_INCLUDED
//hashtable functions
char *TypeString(int index);
int hashEle(char *str);
Expand Down
Binary file modified SymbolTable.h.gch
Binary file not shown.
Binary file modified SymbolTable.o
Binary file not shown.
2 changes: 1 addition & 1 deletion SymbolTableDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct globalTableElem{
bool is_record;
union{
type* t;
rec* rec_type_list;
rec* rec_type_list;
}u;
int offset;
}globalTableElem;
Expand Down
Binary file modified SymbolTableDef.h.gch
Binary file not shown.
Binary file removed asm_w/hello
Binary file not shown.
21 changes: 0 additions & 21 deletions asm_w/hello.asm

This file was deleted.

Binary file removed asm_w/hello.o
Binary file not shown.
58 changes: 58 additions & 0 deletions codegen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "Intermediate.h"

quadruple *writeDataDefs(quadruple *code, FILE *fp){
while(code->operand->flag==0 && code->operand->u.tag==TAG_DECLARE){
if(code->a1->u.width==2) fprintf(fp, "%s\tdw\tdup(?)", code->L->u.dataDef);
else fprintf(fp, "%s\tdd\tdup(?)", code->L->u.dataDef);
code=code->next;
}
return code;
}

void writeCode(quadruple *code, FILE *fp){
while(code!=NULL){
if(code->operand->flag==0 && code->operand->u.tag==TAG_READ){
fprintf(fp, "\tMOV\tEDX, %d", (code->a2->u.width==2)? 3:5);
fprintf(fp, "\tMOV\tECX, %s", code->a1->u.L->u.dataDef);
fprintf(fp, "\tMOV\tEAX, 3");
fprintf(fp, "\tMOV\tEBX, EAX");
fprintf(fp, "\tINT\t80H");
}
else if(code->operand->flag==0 && code->operand->u.tag==TAG_WRITE){
fprintf(fp, "\tMOV\tEDX, %d", (code->a2->u.width==2)? 3:5);
fprintf(fp, "\tMOV\tECX, %s", code->a1->u.L->u.dataDef);
fprintf(fp, "\tMOV\tEBX, 1");
fprintf(fp, "\tMOV\tEAX, 4");
fprintf(fp, "\tINT\t80H");
}
else if(code->operand->flag==1 && (code->operand->u.tkname==TK_PLUS || code->operand->u.tkname==TK_MINUS || code->operand->u.tkname==TK_DIV || code->operand->u.tkname==TK_MUL)){
if(code->operand->u.tkname==TK_PLUS){

}
else if(code->operand->u.tkname==TK_MINUS){

}
else if(code->operand->u.tkname==TK_DIV){

}
else if(code->operand->u.tkname==TK_MUL){

}
}
code = code->next;
}
fprintf(fp, "\tMOV\tEAX, 1");
fprintf(fp, "\tMOV\tEBX, 0");
fprintf(fp, "\tINT\t80H");
}

void generateCode(ASTNodeIt *ast, char *filename){
FILE *fp = fopen(filename, "w");
quadruple *fullcode = generateIntermediateCode(ast);
fprintf(fp,"SECTION .bss\n");
fprintf(fp,"\tlpBuffer: resb 18\n\tBuf_Len: equ $-lpBuffer\n");
fprintf(fp,"lft: RESW 8\nFOR_CTRL: RESW 8\nOUT: RESW 10\ntemp: RESW 1\nrgt: RESW 1\n");
quadruple *stmts = writeDataDefs(fullcode, fp);
fprintf(fp,"SECTION .text\nglobal _start\n\n_start:\n");
writeCode(stmts, fp);
}
5 changes: 5 additions & 0 deletions codegen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "Intermediate.h"

quadruple *writeDataDefs(quadruple *code, FILE *fp);
void writeCode(quadruple *code, FILE *fp);
void generateCode(ASTNodeIt *ast, char *filename);
Binary file added codegen.h.gch
Binary file not shown.
Binary file added codegen.o
Binary file not shown.
Binary file modified compiler
Binary file not shown.
Binary file added compiler_DFA_1.pdf
Binary file not shown.
23 changes: 11 additions & 12 deletions driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "parser.h"
#include "grammar.h"
#include "semantic.h"
#include "codegen.h"
extern parse_table T;
extern int semantic_correct;
// extern int parse_correct;
Expand Down Expand Up @@ -111,19 +112,17 @@ int main(int argc, char *argv[]){
int i;
printf("Please enter whether code is free of syntactic, semantic or type mismatch errors(0 for no, 1 for yes)\n");
printf("To check, use option=9 first\n");
scanf("%d\n", &i);
if(i){
treeNodeIt* t = parseInputSourceCode(argv[1]);
ASTNodeIt *ast;
if(parse_correct){
ast = semanticAnalyzer(t);
}
if(!semantic_correct){
printf("Code compiles successfully...\n");
}
else printf("\n");
// constructASMcode(ast, argv[2]);
treeNodeIt* t = parseInputSourceCode(argv[1]);
ASTNodeIt *ast;
if(parse_correct){
ast = semanticAnalyzer(t);
}
if(!semantic_correct){
printf("Code compiles successfully...\n");
continue;
}
else printf("\n");
generateCode(ast, argv[2]);
}
else{
printf("Enter correct option\n");
Expand Down
Binary file modified driver.o
Binary file not shown.
Binary file modified grammar.h.gch
Binary file not shown.
Binary file modified grammar.o
Binary file not shown.
Binary file modified grammarDef.h.gch
Binary file not shown.
5 changes: 0 additions & 5 deletions hello.c

This file was deleted.

26 changes: 0 additions & 26 deletions hello.s

This file was deleted.

Binary file modified key.h.gch
Binary file not shown.
Binary file modified key.o
Binary file not shown.
Binary file modified keyDef.h.gch
Binary file not shown.
Binary file modified lexer.h.gch
Binary file not shown.
Binary file modified lexer.o
Binary file not shown.
Binary file modified lexerDef.h.gch
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 12 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# // NARAPAREDDY BHAVANA 2016A7PS0034P
# // KARABEE BATTA 2016A7PS0052P
# // AASTHA KATARIA 2016A7PS0062P
compile: keyhead lexhead parshead stackhead grammarhead ASThead symbolTablehead semantichead SymbolTable.o semantic.o key.o DFA.o AST.o grammar.o stack.o lexer.o parser.o driver.o
gcc driver.o AST.o SymbolTable.o semantic.o DFA.o grammar.o stack.o lexer.o parser.o key.o -o compiler
compile: keyhead lexhead parshead stackhead grammarhead ASThead symbolTablehead semantichead inthead codehead Intermediate.o codegen.o SymbolTable.o semantic.o key.o DFA.o AST.o grammar.o stack.o lexer.o parser.o driver.o
gcc driver.o AST.o Intermediate.o codegen.o SymbolTable.o semantic.o DFA.o grammar.o stack.o lexer.o parser.o key.o -o compiler
driver.o: driver.c
gcc -c -g driver.c
AST.o: AST.c
gcc -c -g AST.c
Intermediate.o: Intermediate.c
gcc -c -g Intermediate.c
codegen.o: codegen.c
gcc -c -g codegen.c
SymbolTable.o: SymbolTable.c
gcc -c -g SymbolTable.c
semantic.o: semantic.c
Expand Down Expand Up @@ -47,4 +51,9 @@ symbolTablehead:
gcc SymbolTableDef.h
gcc SymbolTable.h
semantichead:
gcc semantic.h
gcc semantic.h
inthead:
gcc Intermediate.h
gcc IntermediateDef.h
codehead:
gcc codegen.h
6 changes: 5 additions & 1 deletion parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ treeNodeIt* parseInputSourceCode(char *testcaseFile){
printf("Line %d: The token %s for lexeme %.2f does not match with expected token %s\n", ti->line_no, TerminalString(ti->tokenName), ti->u.value_of_real, nonTerminalStringTable[e->elem.nonterminal]->nonterminal);
}
do{
if(ti->tokenName==EOS){
e_flag=1;
break;
}
ti = getNextToken(fp);
// printf("%s\n", TerminalString(ti->tokenName));
if((T[e->elem.nonterminal][ti->tokenName].is_error==0)){
Expand Down Expand Up @@ -468,4 +472,4 @@ size_t printParseTreeNodes(treeNodeIt *root){
}
temp = temp->next;
}
}
}
Binary file modified parser.h.gch
Binary file not shown.
Binary file modified parser.o
Binary file not shown.
Binary file modified parserDef.h.gch
Binary file not shown.
Loading

0 comments on commit 8ff62fa

Please sign in to comment.