@Override public int genLLCode(BasicBlock block) { Function func = block.getFunc(); HashMap funcSymbolTable = func.getTable(); HashMap globalSymbolTable = func.getGlobalHash(); if (funcSymbolTable.containsKey(id)) { return (int) funcSymbolTable.get(id); } else if (globalSymbolTable.containsKey(id)) { return (int) globalSymbolTable.get(id); } else { throw new lowlevel.LowLevelException("Var " + id + " is not defined"); } }
/** * This method makes low level code for return statements * * @param func */ public void genLLCode(Function func) { BasicBlock currBlock = func.getCurrBlock(); BasicBlock returnBlock = func.getReturnBlock(); if (expression != null) { expression.genLLCode(func); Operation setReturn = new Operation(Operation.OperationType.ASSIGN, currBlock); Operand retSrc = new Operand(Operand.OperandType.REGISTER, expression.getRegisterNum()); Operand retDest = new Operand(Operand.OperandType.MACRO, "RetReg"); setReturn.setSrcOperand(0, retSrc); setReturn.setDestOperand(0, retDest); currBlock.appendOper(setReturn); } Operation newOper = new Operation(OperationType.JMP, currBlock); Operand src = new Operand(Operand.OperandType.BLOCK, returnBlock.getBlockNum()); newOper.setSrcOperand(0, src); currBlock.appendOper(newOper); }