//- expressions ------------------------------------------------------------- public IdentExprNode getExprIdentNode(String id) { OILNode idsym = symbolTable.findSymbol(id); IdentExprNode node = new IdentExprNode(idsym); return(node); }
// switch (node.nodetype) // { // case NodeType.VarDeclar: // codeGen.evalVarDeclaration(node); // break; // case NodeType.PrimaryId: // codeGen.evalPrimaryId(node); // break; // case NodeType.PrimaryConst: // codeGen.evalPrimaryConst(node); // break; // case NodeType.AddExpr: // codeGen.evalAddExpression(node); // break; public void genIdentExpression(IdentExprNode expr) { OILNode lsym = expr.idsym; switch (lsym.type) { case OILType.ParamDecl: uint pofs = ((CGParamDeclNode)(lsym.cgnode)).addr; assembly.addLine("mov eax, [ebp+" + pofs + "]"); break; case OILType.VarDecl: uint vofs = ((CGVarDeclNode)(lsym.cgnode)).addr; assembly.addLine("mov eax, [ebp-" + vofs + "]"); break; default: break; } assembly.addLine("push eax"); //var value --> top of stack }
//only supporting simple assignments (=) now, not compound assignments (ie +=, *= etc) public void genAssignmentExpression(AssignExprNode expr) { genExpression(expr.rhs); assembly.addLine("pop eax"); //rhs --> eax IdentExprNode lvar = (IdentExprNode)expr.lhs; OILNode lsym = lvar.idsym; switch (lsym.type) { case OILType.ParamDecl: uint pofs = ((CGParamDeclNode)(lsym.cgnode)).addr; assembly.addLine("mov [ebp+" + pofs + "],eax"); break; case OILType.VarDecl: uint vofs = ((CGVarDeclNode)(lsym.cgnode)).addr; assembly.addLine("mov [ebp-" + vofs + "],eax"); break; default: break; } }