Company asking me to resign in my 8th month of pregnancy

Dear Seniors, I have joined my Organisation in Jan 2016 as Asst.Mgr - HR. I got pregnant in May 2016 and on 11 July 2016 I told my Boss i.e Director of Co. that I am pregnant. On 16 July 2016, my director told me that you are not performing and gave a Performance Improvement plan. All the points mentioned in the letter were activities of a Head HR not Assistant Manager - HR. During my joining I was not told that I will have to Head HR activities also.The letter stated they will check my performance till 31 July 2016 and will take a call. Then my company hired a Head HR on July 25 2016, who was supposed to check my performance. But my company asked the Head HR to resign due to his performance on Oct 10,2016. Now I am in my 8th month of pregnancy, my company has made me work all these months and now they are asking me to resign on immediate basis. i.e 31 December 2016 again stating performance. Till July 2016, I had never received any performance related issues.They are forcing me to resign after he came to know that I am pregnant. This is to save the 3 months paid maternity leave which I will get in case I stay in the company. The company has a good maternity policy on papers but is forcing to resign in order to save money. Please let me know what can I do. I would like to go legal on this. Kindly guide me as I feel cheated and insulted for making me work till 8th month and now that I am ready for my maternity leave, they are forcing me to resign. Regards, Deepthi