let genSubroutine (id: ide) (pdeclist: dec list) (dlist: dec list) (dect: dec_table) (proct: proc_table) (c: cmd) (ic: intermediateCode) (r: return)=
    let localVarTable = jointable (genDecTable (dlist) (Hashtbl.create 0) ic true) (genParamTable (List.rev pdeclist) (Hashtbl.create 0)) in
    let updatedTable = jointable dect localVarTable in
    if (cmdsemantic c updatedTable proct) then (
        let oldinstr = ic#getInstructionClass and 
        newInstr = (new funUtils) in (
            ic#setInstructionClass newInstr;
            (genCommand c updatedTable proct ic);
            match r with
                Void        ->  (
                                 ic#addInstr(RETNullNullNull);
                                 let newInstr = ic#getInstructionClass in (
                                    ic#setInstructionClass oldinstr;
                                     Subroutine(r,pdeclist,localVarTable,newInstr);
                                 )
                                )
              | SRet(Int)   ->  (
                                 let (_,_,e) = (getVarDeclaration id localVarTable ) in 
                                 ic#addInstr(RET, e, NullNull);
                                 let newInstr = ic#getInstructionClass in (
                                    ic#setInstructionClass oldinstr;
                                    Subroutine(r,pdeclist,localVarTable,newInstr);
                                 )
                                )
              | SRet(Float->  (
                                 let (_,_,e) = (getVarDeclaration id localVarTable) in 
                                 ic#addInstr(RET, e, NullNull);
                                 let newInstr = ic#getInstructionClass in (
                                    ic#setInstructionClass oldinstr;
                                    Subroutine(r,pdeclist,localVarTable,newInstr);
                                 )
                                )
            )
    )else (
        raise (SEMANTIC_ERROR "Error while defining subroutine\n")
    )