#
#	File name: transformer.py
#
#	The transformer main functions in order to make all operations related with transforming source code or preparing transformation
#
#	Verion: 1.0
#	Date created: 11/09/2020
#
#	Author: Charalampos Marantos
#

import sys
import os
import collections
import itertools

from time_transformation import *
from energy_transformation import *

#-----------------------------------------
class Transformer():
	"""docstring for Transformer"""

	def __init__(self, code, tool):
		self.code = code
		self.tool = tool

	# Backup source file before applying transformation
	def _backup(self):
		os.system("cp "+self.code.source_file+" "+self.code.source_file+"_backup")

	# Backup source file before applying transformation
	def restore(self):
		os.system("cp "+self.code.source_file+"_backup "+self.code.source_file)

	# Prapare source file for transformation (insert annotations or pragmas that each tranform tool or compiler may need)
	def prepare(self, transformation, info):
		self._backup()
		globals()["insert_"+self.tool+"_pragmas"](self.code, transformation, info)

	#Show part of code that was transformed
	def show_transformed(self):
		globals()["print_"+self.tool+"_transformed"](self.code)
