package compiler;

/*
 Verificar operacao unaria negacao valor em laco
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import API.Api;
import API.BuildParams;
import API.CodeProcessor;
import API.Target;
import IntermediaryCode.IRGenerator;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Eugenio
 */
public class IVANNOSYS {

    protected static IvannosysCompiler COM;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {

        try {
            String cmd = "", file = "";

            if (args.length
                    > 0) {
                cmd = args[0];
            }
            switch (cmd) {
                case "create":
                    break;
                default:

                    COM = new IvannosysCompiler(
                            "UTF-8",
                            IvannosysCompiler.INPUT_FILE)
                            .include(".\\src\\samples")
                            // Especifica a classe de geração de codigo de tres enderecos
                            .IRGenerator(new IRGenerator())
                            // Extensao dos arquivos 
                            .setExtensionLibrary(".go");

                    // Inicializa a api do compilador
                    Api.Init(COM);

                    // Parametros de compilação
                    BuildParams.Add("display.ERROS", "true");
                    BuildParams.Add("display.IR", "true");
                    BuildParams.Add("display.AST", "true");
                    BuildParams.Add("mode", "developement");

                    // Especifica a classe de geração de codigo alvo mips
                    Target.Add("mips", new targets.mips.Gen());
                    Target.Add("mipsjun", new targets.mips.jun.Gen());

                    // Registra os processadores para o alvo mips
                    // Executa alocacao de registradores antes de traduzir cada bloco
                    CodeProcessor.On("mips,mipsjun", "BeforeTranslateBlock", "mips.register.alloc");
                    CodeProcessor.On("mips,mipsjun", "AfterTranslateBlock", "mips.o.L1,mips.copy.dep");
                    // Atualiza os enderecos
                    CodeProcessor.On("mips,mipsjun", "AfterTranslate", "mips.update.address");

                    // String file = "src\\samples\\program.go",
                    // String file = "src\\samples\\program.go",
                    // String file = "src\\samples\\program_mult_manycore.go",
                    // String file = "src\\samples\\program_mult_jon.go",
                    // String file = "src\\samples\\program_mult.go",
                    file = "src\\samples\\program_jun_bit_count.go";
                    COM.Compile(file);
            }

        } catch (Exception ex) {
            Logger.getLogger(IVANNOSYS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
