Permalink
Browse files

fix main class allocation

  • Loading branch information...
andrewrk committed Dec 7, 2010
1 parent bc62931 commit f734f509f1f082279966c12ab77ea74ae4e101c7
View
@@ -640,12 +640,9 @@ void generate_code(Program * program, SymbolTable * symbol_table, bool debug, bo
asm_out << "main:" << std::endl;
asm_out << "la $fp, heap_start" << std::endl;
- // create instance of main class and run the constructor
- asm_out << "sw $fp, -4($sp)" << std::endl;
- asm_out << "addi $fp, $fp, " << get_class_size_in_bytes(program->identifier->text, symbol_table) << std::endl;
- asm_out << "jal " << Utils::to_lower(program->identifier->text) << "_"
- << Utils::to_lower(program->identifier->text) << std::endl;
+ asm_out << "jal _entrypoint__entrypoint" << std::endl;
+ asm_out << std::endl << "# quit" << std::endl;
asm_out << "li $v0, 10" << std::endl;
asm_out << "syscall" << std::endl;
for (ClassList * class_list_node = program->class_list; class_list_node != NULL; class_list_node = class_list_node->next) {
View
@@ -1,4 +1,3 @@
-
#include "parser.h"
#include "symbol_table.h"
#include "semantic_checker.h"
@@ -7,6 +6,7 @@
#include <string>
void print_usage(std::string exe_name);
+void add_entry_point(Program * program);
int main(int argc, char * argv[]) {
char * filename = NULL;
@@ -38,6 +38,9 @@ int main(int argc, char * argv[]) {
Program * program = parse_input(filename);
+ add_entry_point(program);
+
+
SymbolTable * symbol_table = build_symbol_table(program);
if (symbol_table == NULL)
return 1;
@@ -53,6 +56,18 @@ int main(int argc, char * argv[]) {
return 0;
}
+void add_entry_point(Program * program) {
+ VariableDeclarationList * main_instance = new VariableDeclarationList(new VariableDeclaration(new IdentifierList(new Identifier("_instance", -1), NULL), new TypeDenoter(program->identifier)), NULL);
+ FunctionDeclaration * main_function = new FunctionDeclaration(new Identifier("_entrypoint", -1), NULL, NULL, new FunctionBlock(main_instance, new StatementList(
+ new Statement(new AssignmentStatement(new VariableAccess(new Identifier("_instance", -1)),
+ new Expression(new AdditiveExpression(new MultiplicativeExpression(new NegatableExpression(
+ new PrimaryExpression(new ObjectInstantiation(program->identifier)))))))), NULL)));
+ ClassDeclaration * class_declaration = new ClassDeclaration(new Identifier("_entrypoint", -1), NULL,
+ new ClassBlock(NULL, new FunctionDeclarationList(main_function, NULL)));
+
+ program->class_list = new ClassList(class_declaration, program->class_list);
+}
+
void print_usage(std::string exe_name) {
std::cerr << "Usage: \n\n";
@@ -0,0 +1,2 @@
+100
+200
@@ -20,7 +20,9 @@ BEGIN
counter := counter + 1
END;
- PRINT global[95][5]
+ PRINT global[95][4];
+ PRINT global[95][5];
+ PRINT global[95][6];
END
END
@@ -0,0 +1,4 @@
+88
+2
+88
+2

0 comments on commit f734f50

Please sign in to comment.