Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void functionToJVM(PrintWriter file, SymbolTable st, Node n)
- {
- //functionTable.setRegisters(function.name);
- SimpleNode function = (SimpleNode) n;
- SimpleNode args[] = null;
- SymbolTable function_table = null;
- String function_header;
- int children = function.jjtGetNumChildren();
- String name = function.getName()
- Symbol symbol = null;
- String return_symbol;
- //header
- for(int i = 0; i < children; i++)
- {
- if(function.jjtGetChild(i).toString().equals("Arg"))
- {
- args[i] = function.jjGetChild(i);
- }
- }
- file.print('\n' + ".method public static ");
- if(name.equals("Main"))
- {
- file.print("main([Ljava/lang/String;)V" + '\n');
- }
- else
- {
- function_table = this.st.get(name);
- function_header = name + '(';
- for (Map.Entry<String, Symbol> entry : function_table.getArgsList().entrySet()) {
- symbol = entry.getValue();
- if(symbol.getType().equals("int"))
- {
- function_header += "I";
- }
- else if(symbol.getType().equals("array"))
- {
- function_header += "[I";
- }
- }
- return_symbol = function_table.getReturnType();
- if(return_symbol == "void")
- {
- function_header += ")V";
- }
- else
- {
- if(return_symbol.equals("int"))
- {
- function_header += ")I";
- }
- else if(return_symbol.equals("boolean"))
- {
- function_header += ")Z";
- }
- else if (returnSymbol.equals("int[]"))
- {
- function_header += function_header + ")[I";
- }
- }
- file.print(function_header);
- }
- //limites
- file.println("locals_" + name);
- file.println("stack_" + name);
- //statements
- int children = function.jjtGetNumChildren();
- for(int i = 0; i < children; i++)
- {
- //statementToJVM
- }
- //return
- return_symbol = function_table.getReturnType();
- if(function_table.getReturnType().equals("void"))
- {
- file.println(" return");
- }
- else
- {
- //printFileLoadVariable(file, st, não sei como passar aqui o simbolo de retorno como node, "ID")
- if(return_symbol.equals("int") || return_symbol.equals("boolean"))
- {
- file.println(" ireturn");
- }
- else
- {
- file.println(" areturn");
- }
- }
- file.println(".end method\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement