Exemplo n.º 1
0
        public static void TypeCheck(SymTable SymbolTable, StartNode node)
        {
            Stopwatch TypeCheckTimer = new Stopwatch();

            TypeCheckTimer.Start();
            AstTypeCheckerVisitor TypeChecker = new AstTypeCheckerVisitor(SymbolTable);

            TypeChecker.VisitRoot(node);
            TypeCheckTimer.Stop();
            PrintCompilerMessage("Type checking took: " + TypeCheckTimer.ElapsedMilliseconds + "ms");
            ErrorChecker(SymbolTable.errorOccured, 2, "TypeChecker");
        }
Exemplo n.º 2
0
        public SymFunc(string name, List <SymVar> parameters, SymTable localVariables, StatementNode body, SymType returnType)
        {
            Name           = name;
            Parameters     = parameters;
            LocalVariables = localVariables;
            Body           = body;

            if (returnType == null)
            {
                ReturnType = new SymVoid();
            }
            else
            {
                ReturnType = returnType;
            }

            //predefined
            if (localVariables == null)
            {
                return;
            }

            foreach (var localSymbol in LocalVariables.Reverse())
            {
                var lvar = localSymbol as SymVar;
                Debug.Assert(lvar != null);

                if (lvar.LocType != SymVar.SymLocTypeEnum.Local)
                {
                    continue;
                }
                LocalVariableBsize += lvar.Type.BSize;
                LocalVarOffsetTable.Add(lvar.Name, LocalVariableBsize);
            }
            // align
            LocalVariableBsize += LocalVariableBsize % 8 > 0 ? 8 - LocalVariableBsize % 8 : 0;

            var paramOffset = 16;

            foreach (var param in parameters)
            {
                ParamsOffsetTable.Add(param.Name, paramOffset);
                var paramSize = param.Type.BSize;
                //  parameters will be aligned on stack
                paramSize   += paramSize % 8 > 0 ? 8 - paramSize % 8  : 0;
                paramOffset += paramSize;
            }

            ParamsSizeB = paramOffset;
        }
Exemplo n.º 3
0
        public SymRecord(string name, SymTable fields)
        {
            Name   = name;
            Fields = fields;

            foreach (var field in Fields)
            {
                if (field is SymVar symVar)
                {
                    OffsetTable.Add(field.Name, BSize);
                    BSize += symVar.Type.BSize;
                }
                else
                {
                    Debug.Assert(false);
                }

                //todo: align?
            }
        }
Exemplo n.º 4
0
        public static void Compile()
        {
            Stopwatch TotalTimer = new Stopwatch();

            TotalTimer.Start();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Giraph Compiler 1.0.1");
            Console.ForegroundColor = ConsoleColor.Red;

            GiraphParser.StartContext CST = BuildCST("kode.giraph");
            ErrorChecker(_error, 9999, "Code error!");
            AbstractNode AST         = BuildAST(CST);
            SymTable     SymbolTable = BuildSymbolTable(AST as StartNode);

            TypeCheck(SymbolTable, AST as StartNode);
            //PrettyPrint(AST as StartNode);
            WriteCodeToFiles(AST as StartNode);
            TotalTimer.Stop();
            PrintCompilerMessage($"Total compile timer: {TotalTimer.ElapsedMilliseconds}ms");
            CompileGeneratedCode();             // Compile the C# code.
        }
Exemplo n.º 5
0
 protected PredefinedSymFunc(string name, List <SymVar> parameters, SymTable localVariables, StatementNode body, SymType returnType)
     : base(name, parameters, localVariables, body, returnType)
 {
 }