Exemplo n.º 1
0
        /// <summary>
        /// Extract all the <see cref="GBaseBlock"/>s from the given GIMPLE source.
        /// </summary>
        /// <param name="gimple">GIMPLE source file content.</param>
        /// <returns>
        /// <see cref="List{T}"/> of <see cref="GBaseBlock"/> containing all the Base Blocks.
        /// </returns>
        public static List <GBaseBlock> getBaseBlocks(List <string> gimple)
        {
            Block        block        = new Block( );
            List <Block> blocks       = new List <Block> ( );
            bool         readingBlock = false;

            foreach (var line in gimple)
            {
                if (GBBStmt.matches(line))
                {
                    readingBlock = true;
                }
                if (line.Length == 0)
                {
                    if (readingBlock)
                    {
                        blocks.Add(block);
                    }
                    readingBlock = false;
                    block        = new Block( );
                }
                if (readingBlock)
                {
                    block.Add(line.Trim( ));
                }
            }

            List <GBaseBlock> baseBlocks = new List <GBaseBlock> ( );

            foreach (var b in blocks)
            {
                baseBlocks.Add(new GBaseBlock(b));
            }
            return(baseBlocks);
        }
Exemplo n.º 2
0
 private void getVarsDecl(List <string> gimple)
 {
     gVarsDecl.Clear( );
     foreach (var line in gimple)
     {
         if (line == "" || GBBStmt.matches(line))
         {
             break;
         }
         string declPattern = @"\s*(?<type>.*) (?<name>\S*);";
         var    match       = Regex.Match(line, declPattern);
         var    gVar        = new GVar
         {
             name = match.Groups["name"].Value,
             type = match.Groups["type"].Value
         };
         gVarsDecl.Add(gVar);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create a <see cref="GBaseBlock"/> from the GIMPLE source containing content of the current Base Block.
        /// </summary>
        /// <param name="block">GIMPLE source for current block.</param>
        public GBaseBlock(List <string> block)
        {
            if (block.Count == 0)
            {
                throw new ArgumentOutOfRangeException( );
            }
            var gBlockDecl = new GBBStmt(block[0]);

            number = gBlockDecl.number;
            int line = 1;

            foreach (var stmt in block)
            {
                var gStmt = toGimpleStmt(stmt);
                if (gStmt != null)
                {
                    gStmt.linenum = line;
                    gStatements.Add(gStmt);
                    vars.UnionWith(gStmt.vars);
                }
                ++line;
            }
        }