Esempio n. 1
0
 public GamaTopLevelCompiler(GamaGlobalContext ctx, GamaNamespace parent)
 {
     GlobalContext    = ctx;
     NamespaceContext = new GamaNamespaceContext(this, parent);
 }
Esempio n. 2
0
 public GamaNamespaceCompiler(GamaGlobalContext ctx)
 {
     GlobalContext = ctx;
 }
Esempio n. 3
0
            public static int Process(Compile args)
            {
                if (args.Files.Count() == 0)
                {
                    Console.WriteLine("Error: No input files provided");
                    return(1);
                }

                string file = args.Files.First();

                if (!File.Exists(file))
                {
                    Console.WriteLine($"File does not exists: { file }");
                    return(1);
                }

                var ctx = new GamaGlobalContext($"[module/{ file }]");

                InstanceTypes.Initialize();
                ctx.Root.Types.AddRange(InstanceTypes.All);

                var sw = new Stopwatch();

                sw.Start();

                var inputtxt = File.ReadAllText(file);
                var input    = new AntlrInputStream(inputtxt);
                var lexer    = new GamaLexer(input);
                var tokens   = new CommonTokenStream(lexer);
                var parser   = new GamaParser(tokens);
                var program  = parser.program();

                if (parser.NumberOfSyntaxErrors > 0)
                {
                    Console.WriteLine("Code contains syntax errors, aborting compilation.");
                    return(2);
                }
                var unit = new GamaNamespaceCompiler(ctx);

                unit.Visit(program);

                sw.Stop();

                if (!ctx.Module.TryVerify(LLVMVerifierFailureAction.LLVMPrintMessageAction, out string err))
                {
                    ctx.Module.Dump();
                    if (ctx.ErrorList.Count > 0)
                    {
                        foreach (var e in ctx.ErrorList)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    return(3);
                }
                else
                {
                    if (ctx.ErrorList.Count > 0)
                    {
                        foreach (var e in ctx.ErrorList)
                        {
                            Console.WriteLine(e.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine(ctx.Module.PrintToString());
                        Console.WriteLine($"Compilation took { sw.Elapsed.Seconds } sec, { sw.Elapsed.Milliseconds } ms");
                        ctx.Module.WriteBitcodeToFile(args.Output);
                        if (args.Link)
                        {
                        }
                    }
                }
                return(0);
            }