this
This commit is contained in:
@ -744,7 +744,7 @@ int generateFunctionStart(Instruction *inst) {
|
||||
fprintf(cg_flag, "%s:\n", getName(funDecTN));
|
||||
fprintf(cg_flag, "\tpushq\t%%rbp\n");
|
||||
fprintf(cg_flag, "\tmovq\t%%rsp, %%rbp\n");
|
||||
fprintf(cg_flag, "\tsubq\t$%d, %%rsp\n", 128); // [CHANGE ME] 128 is a placeholder for the stack size
|
||||
fprintf(cg_flag, "\tsubq\t$%d, %%rsp\n", getStackSize());
|
||||
|
||||
//now we need to add the CGs of nodes to the CG list by doing assign from the
|
||||
// have function declararation node
|
||||
|
@ -68,6 +68,7 @@ int generateFunctionStart(Instruction *instruction);
|
||||
extern int label_count;
|
||||
extern Instruction *begin;
|
||||
extern Instruction *current;
|
||||
extern SymbolTable *top;
|
||||
|
||||
extern int offset;
|
||||
extern int currentsp;
|
||||
|
@ -1739,3 +1739,28 @@ TableNode *printTableNode(TableNode *tn) {
|
||||
|
||||
return tn;
|
||||
}
|
||||
|
||||
int getStackSize() {
|
||||
int i = 0;
|
||||
TableNode *tn = getFirstEntry(top);
|
||||
while (tn != NULL) {
|
||||
i++;
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
|
||||
ListOfTable *lt = getChildren(top);
|
||||
while (lt != NULL) {
|
||||
TableNode *first = lt->table->entries;
|
||||
while (first != NULL) {
|
||||
i++;
|
||||
first = getNextEntry(first);
|
||||
}
|
||||
|
||||
lt = lt->next;
|
||||
}
|
||||
|
||||
i= i * 8;
|
||||
if (i % 16 != 0) i += 8;
|
||||
|
||||
return i;
|
||||
}
|
@ -163,12 +163,14 @@ TableNode *getNextEntry(TableNode *tn);
|
||||
TableNode *printTableNode(TableNode *tn);
|
||||
int getElementOffset(TableNode *rec, char* id);
|
||||
int getRecPosition(TableNode* rec, char* id);
|
||||
int getStackSize();
|
||||
|
||||
extern int yylex(void);
|
||||
extern char *yytext;
|
||||
extern int yyleng;
|
||||
extern int yychar;
|
||||
extern SymbolTable *cur;
|
||||
extern SymbolTable *top;
|
||||
extern int line_number;
|
||||
extern int column_number;
|
||||
extern FILE *yyin;
|
||||
|
@ -5,8 +5,6 @@ function entry: string2integer
|
||||
entry (arg) := {
|
||||
[integer: x; string: s; character: c; integer: result]
|
||||
|
||||
result := printS("hello world");
|
||||
|
||||
s := inS(1);
|
||||
result := printS(s);
|
||||
|
||||
|
Reference in New Issue
Block a user