Example #1
0
        internal static CTFITypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            if (!tp.Match(Token.EnumId.ENUM))
            {
                return(null);
            }

            tp.MustBe(Token.EnumId.COLON);

            List <CTFTypeSpecifier> cds = ParseList(scope, tp);

            tp.MustBe(Token.EnumId.LCURL);

            List <CTFEnumElem> list = new List <CTFEnumElem>();

            do
            {
                CTFEnumElem ce = CTFEnumElem.Parse(tp);
                list.Add(ce);
            }while (tp.Match(Token.EnumId.SEPARATOR));

            tp.MustBe(Token.EnumId.RCURL);

            return(new CTFEnumSpecifier(Token.EnumId.ENUM, cds, list));
        }
        private static CTFAssignmentExpression Parse(CTFScope scope, TokParser tp)
        {
            CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);

            if (cue != null)
            {
                if (tp.Match(Token.EnumId.ASSIGNMENT))
                {
                    CTFUnaryExpression cue2 = CTFUnaryExpression.Parse(tp);
                    if (cue2 == null)
                    {
                        throw new CTFException();
                    }

                    return(new CTFAssignmentExpression(cue, cue2));
                }

                if (tp.Match(Token.EnumId.TYPE_ASSIGNMENT))
                {
                    CTFTypeSpecifier cs = CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                    if (cs == null)
                    {
                        throw new CTFException();
                    }

                    return(new CTFAssignmentExpression(cue, cs));
                }
            }

            return(null);
        }
Example #3
0
        private CTFFile Parse(TokParser tp)
        {
            for (;;)
            {
                switch (tp.Token.Id)
                {
                case Token.EnumId.CLOCK:
                    Clock = new CTFTClock(ParseAEList(tp));
                    break;

                case Token.EnumId.EVENT:
                    CTFTEvent ce = new CTFTEvent(scope, ParseAEList(tp));
                    Events.Add(ce.Id, ce);
                    break;

                case Token.EnumId.STREAM:
                    stream = new CTFTStream(scope, ParseAEList(tp));
                    break;

                case Token.EnumId.ENV:
                    env = new CTFTEnv(ParseAEList(tp));
                    break;

                case Token.EnumId.TRACE:
                    trace = new CTFTTrace(scope, ParseAEList(tp));
                    break;

                case Token.EnumId.TYPEALIAS:
                    tp.Next();
                    List <CTFTypeSpecifier> cds = CTFITypeSpecifier.ParseList(scope, tp);
                    if (cds == null)
                    {
                        throw new CTFException();
                    }

                    tp.MustBe(Token.EnumId.TYPE_ASSIGNMENT);
                    List <CTFTypeSpecifier> cds2 = CTFITypeSpecifier.ParseList(scope, tp);
                    CTFDeclarator           cd   = CTFDeclarator.Parse(tp);
                    CTFType.AddType(scope, cds, cds2, cd);
                    break;

                case Token.EnumId.STRUCT:
                    CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                    break;

                case Token.EnumId.EOF:
                    return(this);

                case Token.EnumId.TERM:
                    tp.Next();     // Skip it
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
Example #4
0
        internal static CTFTypeSpecifier ParseTypeSpecifier(CTFScope scope, TokParser tp)
        {
            Token.EnumId id = tp.Token.Id;
            switch (id)
            {
            case Token.EnumId.VOID:
            case Token.EnumId.CHAR:
            case Token.EnumId.SHORT:
            case Token.EnumId.INT:
            case Token.EnumId.FLOAT:
            case Token.EnumId.DOUBLE:
            case Token.EnumId.SIGNED:
            case Token.EnumId.BOOL:
            case Token.EnumId.COMPLEX:
            case Token.EnumId.IMAGINARY:
                throw new CTFException();     // unsupported

            case Token.EnumId.LONG:
            case Token.EnumId.UNSIGNED:
                tp.Next();
                return(Get(id));

            case Token.EnumId.STRUCT:
                return(CTFStructSpecifier.Parse(scope, tp));

            case Token.EnumId.VARIANT:
                return(CTFVaraintSpecifier.Parse(scope, tp));

            case Token.EnumId.ENUM:
                return(CTFEnumSpecifier.Parse(scope, tp));

            // ctf-type-specifier
            case Token.EnumId.FLOATING_POINT:
            case Token.EnumId.INTEGER:
                tp.Next();
                tp.MustBe(Token.EnumId.LCURL);
                List <CTFAssignmentExpression> cael = CTFAssignmentExpression.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
                return(new CTFATypeSpecifier(id, cael));

            case Token.EnumId.STRING:
                tp.Next();
                return(Get(Token.EnumId.STRING));

            case Token.EnumId.IDEN:     // must be a type in a scope
                CTFTypeSpecifier ct = CTFNTypeSpecifier.Get(scope, tp.Token.Buffer);
                if (ct == null)
                {
                    return(null);
                }

                tp.Next();
                return(ct);
            }

            return(null);
        }
Example #5
0
        private List <CTFAssignmentExpression> ParseAEList(TokParser tp)
        {
            tp.Next();
            tp.MustBe(Token.EnumId.LCURL);
            List <CTFAssignmentExpression> lcae = CTFAssignmentExpression.ParseList(scope, tp);

            if (lcae == null)
            {
                throw new CTFException();
            }

            tp.MustBe(Token.EnumId.RCURL);
            return(lcae);
        }
Example #6
0
        //public List<CTFERecord> readTrace(string metafile)
        public List <CTFThread> ReadTrace(string metafile)
        {
            List <CTFThread> threads = new List <CTFThread>();
            TokParser        p       = null;

            try
            {
                p = new TokParser(metafile);
                ParseFile(p);

                // Try to find all stream files
                int n = metafile.LastIndexOf(Path.DirectorySeparatorChar);
                if (n >= 0)
                {
                    CTFStreamReader cr = GetStreamReader();

                    string dir      = Path.GetDirectoryName(metafile);
                    var    files    = Directory.GetFiles(dir);
                    var    ctffiles = Array.FindAll(files, s => s.Contains("channel0_"));

                    foreach (string cfile in ctffiles)
                    {
                        cr.Open(cfile);
                        for (CTFERecord cer; (cer = cr.GetEvent()) != null;)
                        {
                            CTFThread thread = CTFThread.FirstOrCreateCTFThreadById(Convert.ToUInt64(cer.Vpid),
                                                                                    Convert.ToUInt64(cer.Vtid), threads);
                            thread.Records.Add(cer);
                            if (cr.IsEvDiscarded == true)
                            {
                                thread.LostRecords.Add(cr.EvDiscarded);
                                cr.IsEvDiscarded = false;
                            }
                        }

                        cr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Print("Error {0}\n", ex.Message);
            }
            finally
            {
                p?.Close();
            }

            return(threads);
        }
Example #7
0
        internal static CTFEnumElem Parse(TokParser tp)
        {
            string name = tp.GetIden();

            tp.MustBe(Token.EnumId.ASSIGNMENT);
            CTFUnaryExpression first = CTFUnaryExpression.Parse(tp);
            CTFEnumElem        ce    = new CTFEnumElem(name, first.Calculate());

            if (tp.Match(Token.EnumId.ELIPSES))
            {
                ce.Second = CTFUnaryExpression.Parse(tp).Calculate();
            }

            return(ce);
        }
        internal static CTFTypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            tp.MustBe(Token.EnumId.VARIANT);
            tp.MustBe(Token.EnumId.LT);
            CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);

            if (cue == null)
            {
                throw new CTFException();
            }

            tp.MustBe(Token.EnumId.GT);
            tp.MustBe(Token.EnumId.LCURL);
            List <CTFStructOrVariantDeclaration> list = CTFStructOrVariantDeclaration.ParseList(scope, tp);

            tp.MustBe(Token.EnumId.RCURL);
            return(new CTFVaraintSpecifier(Token.EnumId.VARIANT, cue, list));
        }
        internal static CTFPrimaryExpression Parse(TokParser tp)
        {
            Token t = tp.Token;

            switch (tp.Token.Id)
            {   // All this values can be used in expression
            case Token.EnumId.IDEN:
            case Token.EnumId.ALIGN:
            case Token.EnumId.SIGNED:
            case Token.EnumId.CLOCK:
            case Token.EnumId.EVENT:
            case Token.EnumId.INT_LITERAL:
            case Token.EnumId.STR_LITERAL:
                tp.Next();
                return(new CTFPrimaryExpression(t));
            }

            return(null);
        }
Example #10
0
        internal static List <CTFTypeSpecifier> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFTypeSpecifier> specifiers = new List <CTFTypeSpecifier>();

            for (;;)
            {
                CTFTypeSpecifier cts = ParseTypeSpecifier(scope, tp);
                if (cts == null)
                {
                    break;
                }

                specifiers.Add(cts);
            }

            if (specifiers.Count == 0)
            {
                return(null);
            }

            return(specifiers);
        }
        internal static List <CTFAssignmentExpression> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFAssignmentExpression> cael = new List <CTFAssignmentExpression>();

            while (true)
            {
                CTFAssignmentExpression cae = Parse(scope, tp);
                if (cae == null)
                {
                    break;
                }

                tp.MustBe(Token.EnumId.TERM);
                cael.Add(cae);
            }

            if (cael.Count == 0)
            {
                return(null);
            }

            return(cael);
        }
Example #12
0
        private static CTFStructOrVariantDeclaration Parse(CTFScope scope, TokParser tp)
        {
            List <CTFTypeSpecifier> list = new List <CTFTypeSpecifier>();

            for (;;)
            {
                CTFTypeSpecifier s = CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                if (s == null)
                {
                    break;
                }

                list.Add(s);
            }

            if (list.Count == 0)
            {
                return(null);
            }

            CTFDeclarator cd = CTFDeclarator.Parse(tp);

            return(new CTFStructOrVariantDeclaration(list, cd));
        }
Example #13
0
        internal static CTFTypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            string name = null;
            List <CTFStructOrVariantDeclaration> list = null;

            if (!tp.Match(Token.EnumId.STRUCT))
            {
                return(null);
            }

            if (tp.Token.Id == Token.EnumId.IDEN)
            {
                name = tp.Token.Buffer;
                tp.Next();
            }

            if (tp.Match(Token.EnumId.LCURL))
            {
                list = CTFStructOrVariantDeclaration.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
            }

            int align = 0;

            if (tp.Match(Token.EnumId.ALIGN))
            {
                tp.MustBe(Token.EnumId.LPAREN);
                CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);
                tp.MustBe(Token.EnumId.RPAREN);
                align = cue.Calculate();
            }

            CTFType ct = CTFType.GetStructType(scope, name, list, align);

            return(new CTFStructSpecifier(ct));
        }
Example #14
0
        internal static List <CTFStructOrVariantDeclaration> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFStructOrVariantDeclaration> list = new List <CTFStructOrVariantDeclaration>();

            for (;;)
            {
                CTFStructOrVariantDeclaration item = Parse(scope, tp);
                if (item == null)
                {
                    break;
                }

                tp.MustBe(Token.EnumId.TERM);
                list.Add(item);
            }

            if (list.Count == 0)
            {
                return(null);
            }

            return(list);
        }
Example #15
0
 public CTFFile ParseFile(TokParser tp)
 {
     return(Parse(tp));
 }