public override void Visit(ParamDeclNode node) { Console.WriteLine(this.indentation + "Parameter <Identifier: " + node.identifier.name + ">"); indentation = indentation + " "; Console.WriteLine(this.indentation + "Type: " + node.type.toString()); indentation = indentation.Substring(0, indentation.Length - 3); }
public void genFunctions(Module module) { assembly.addLine(".section text"); foreach (FuncDefNode func in module.funcs) { CGFuncDefNode cgfunc = new CGFuncDefNode(func); assembly.addLine(".global " + func.name); uint paramofs = 8; for (int i = 0; i < func.paramList.Count; i++) { ParamDeclNode para = func.paramList[i]; CGParamDeclNode cgpara = new CGParamDeclNode(para); cgpara.addr = paramofs; paramofs += 4; } //for now, the only type we handle are ints, so each local var is 4 bytes on the stack cgfunc.stacksize = 0; for (int i = 0; i < func.locals.Count; i++) { VarDeclNode local = func.locals[i]; CGVarDeclNode cglocal = new CGVarDeclNode(local); cgfunc.stacksize += 4; cglocal.addr = cgfunc.stacksize; cglocal.type = CGVarDeclNode.VarType.LOCAL; } //func prolog assembly.addLine(func.name + ":"); assembly.addLine("push ebp"); assembly.addLine("mov ebp, esp"); assembly.addLine("sub esp, " + cgfunc.stacksize); foreach (StatementNode stmt in func.body) { genStatement(stmt); } //func epilog assembly.addLine("mov esp, ebp"); assembly.addLine("pop ebp"); assembly.addLine("ret"); } }
public void makeParamDeclarNode(DeclSpecNode declarspecs, DeclaratorNode declar) { ParamDeclNode pdecl = new ParamDeclNode(); pdecl.pType = declarspecs.baseType; DeclaratorNode dnode = declar; while (dnode != null) { if (dnode is IdentDeclaratorNode) { pdecl.name = ((IdentDeclaratorNode)dnode).ident; } dnode = dnode.next; } symbolTable.addSymbol(pdecl.name, pdecl); curParamList.paramList.Add(pdecl); }
public CGParamDeclNode(ParamDeclNode _paramdecl) { paramdecl = _paramdecl; paramdecl.cgnode = this; }
public override void Visit(ParamDeclNode node) { node.type.Accept(this); node.identifier.Accept(this); }
public override void Visit(ParamDeclNode node) { ParameterDefinition parameterDefinition = MethodBeingVisited.Parameters.Add(node.identifier.name); parameterDefinition.ParameterType = node.type.Type; }
public virtual void Visit(ParamDeclNode node) { node.type.Accept(this); node.identifier.Accept(this); }