Ejemplo n.º 1
0
        public SymbolEntry AddRecord(SymbolEntry t)
        {
            if (_entries.TryGetValue(t.Id, out var e))
            {
                ErrorReporter.GetInstance().Add($"{t.Id} already exists in scope", ErrorCode.SymbolRedefinition);
                return(null);
            }

            //TODO Better alignment
            var dblk   = _offset % _blockSize;
            var tWidth = t.Width == 0 ? (uint)CliOptions.Arch.MAX_BUS_WIDTH : t.Width;

            if (tWidth > dblk)
            {
                _offset += dblk;
            }

            _stackWidth += tWidth;
            _offset     += tWidth;

            t.SetScope(this);
            t.Offset = _offset;
            _entries.Add(t.Id, t);

            return(t);
        }
Ejemplo n.º 2
0
 public PreProcessor()
 {
     _dependencyManager = new DependencyManager();
     _reporter          = ErrorReporter.GetInstance();
     _distro            = PageDistro.GetInstance();
     queue = new Queue <string>();
 }
Ejemplo n.º 3
0
        public SymbolEntry AddRecord(string id, string type)
        {
            var t = _typeTable.GetPrimitive(type);

            if (t == null)
            {
                ErrorReporter.GetInstance().Add($"Type {type} not found", ErrorCode.SymbolUndefined);
                return(null);
            }

            return(AddRecord(new SymbolEntry(id, t.Width, t)));
        }
Ejemplo n.º 4
0
        public IDatumTable <SymbolEntry> AddTable(string id, string type)
        {
            var dt = _typeTable.GetPrimitive(type);

            if (dt == null)
            {
                ErrorReporter.GetInstance().Add($"Type {type} not found", ErrorCode.SymbolUndefined);
                return(null);
            }

            var e = new SymbolEntry(id, 0, dt);
            var s = new SymbolAddrTable(id, this, _blockSize);

            e.Target = s;
            AddRecord(e);

            return(s);
        }
Ejemplo n.º 5
0
        private static int Main(string[] args)
        {
            KCCEnv.Init();

            //Parse CLI options
            var cliOptions = CliOptions.GetInstance();

            cliOptions.ParseCli(args);
            cliOptions.ReadHelpFile();

            //Initialize
            Debug.Init(cliOptions.EnableDebugMessages);
            var errorReporter = ErrorReporter.GetInstance();
            var pageDistro    = PageDistro.GetInstance();

            errorReporter.ValidateAndFlush();

            //TODO replace with ErrorReporter.FatalError?
            if (!cliOptions.IsValid())
            {
                ColorIO.WriteLineError("Fatal Errors Found: Cannot Continue");
                return(-1);
            }

            if (cliOptions.Src == null)
            {
                ColorIO.WriteLineError("Source file is either unspecified or unable to be read");
                return(-1);
            }

            var preProcessor = new PreProcessor.PreProcessor();

            preProcessor.PreCompileProject(cliOptions.Src);

            var translator = new Translator();

            PageInfo pageInfo;

            while ((pageInfo = pageDistro.GetNextPage()) != null)
            {
                translator.Translate(pageInfo.ToString());
            }


            if (errorReporter.ValidateAndFlush())
            {
                ColorIO.WriteLineError("Fatal Errors Found: Cannot Continue");
                return(-1);
            }

            var converter = new Converter();

            converter.LogInternalTranslation();

            if (errorReporter.ValidateAndFlush())
            {
                ColorIO.WriteLineError("Fatal Errors Found: Cannot Continue");
                return(-1);
            }

            converter.Build();

            return(0);
        }
Ejemplo n.º 6
0
        public void ParseCli(IReadOnlyList <string> args)
        {
            var argSize  = args.Count;
            var reporter = ErrorReporter.GetInstance();

            for (var i = 0; i < argSize; ++i)
            {
                var arg = args[i];

                if (arg[1] != '-')
                {
                    for (var j = 1; j < arg.Length; ++j)
                    {
                        switch (arg[j])
                        {
                        case 'h':
                            ReadHelpDoc = true;
                            break;

                        case 'v':
                            var val = DetectOptionValue(arg, j);
                            if (val == null)
                            {
                                VerboseLevel = Verbosity.Detailed;
                            }
                            else
                            {
                                switch (val)
                                {
                                case "none":
                                case "silent":
                                    VerboseLevel = Verbosity.None;
                                    break;

                                case "basic":
                                    VerboseLevel = Verbosity.Basic;
                                    break;

                                case "detailed":
                                case "loud":
                                    VerboseLevel = Verbosity.Detailed;
                                    break;

                                default:
                                    reporter.Add("Unknown verbose level", ErrorCode.Error);
                                    break;
                                }

                                j = arg.Length;
                            }
                            break;

                        case 'd':
                            EnableDebugMessages = true;
                            break;


                        default:
                            reporter.Add("Unrecognized option '" + arg[j] + "'", ErrorCode.Error);
                            break;
                        }
                    }
                }
                else
                {
                    var value     = DetectOptionValue(arg, 0);
                    var statement = arg;

                    if (value != null)
                    {
                        statement = statement.Substring(0, statement.Length - value.Length - 1);
                    }

                    switch (statement)
                    {
                    case "--exe":
                        if (value == null)
                        {
                            reporter.Add(statement + ": Must supply a value", ErrorCode.Error);
                            _canContinue = false;
                            break;
                        }
                        OutputName = value;
                        break;

                    case "--intdbg":
                        EnableDebugMessages = true;
                        break;

                    case "--src":
                        if (value == null)
                        {
                            reporter.Add(statement + ": Must supply a value", ErrorCode.Error);
                            _canContinue = false;
                            break;
                        }
                        else if (Src != null)
                        {
                            reporter.Add("Previous source file " + Src + " will be ignored", ErrorCode.FileRedundant);
                        }

                        var ext = Path.GetExtension(value);
                        if (ext.ToLower() != ".kcc")
                        {
                            reporter.Add($"Warning: {value} may not be a recognized file", ErrorCode.BadFileExtension);
                        }

                        Src        = value;
                        OutputName = $@"{Path.ChangeExtension(Src, "")}";
                        OutputName = OutputName.Remove(OutputName.Length - 1, 1);

                        break;

                    case "--pintern":
                        OutputInternals = true;
                        break;

                    default:
                        _canContinue = false;
                        reporter.Add("Unrecognized option '" + statement + "'", ErrorCode.Error);
                        break;
                    }
                }
            }
        }