コード例 #1
0
ファイル: DebugVMCompiler.java プロジェクト: higuchi-y/nez
 public boolean optimizeCharSet(Pchoice p) {
   boolean[] map = Cset.newMap(false);
   for (int i = 0; i < p.size(); i++) {
     Expression e = p.get(i);
     if (e instanceof Cbyte) {
       map[((Cbyte) e).byteChar] = true;
     } else if (e instanceof Cset) {
       Cset bmap = (Cset) e;
       for (int j = 0; j < bmap.byteMap.length; j++) {
         if (bmap.byteMap[j]) {
           map[j] = true;
         }
       }
     } else {
       return false;
     }
   }
   this.builder.createIcharclass(p, this.builder.jumpFailureJump(), map);
   return true;
 }
コード例 #2
0
ファイル: DebugVMCompiler.java プロジェクト: higuchi-y/nez
 @Override
 public Instruction encodePchoice(Pchoice p, Instruction next, Instruction failjump) {
   if (!optimizeCharSet(p)) {
     BasicBlock fbb = null;
     BasicBlock mergebb = new BasicBlock();
     this.builder.createIaltstart(p);
     this.builder.createIpush(p.get(0));
     for (int i = 0; i < p.size(); i++) {
       fbb = new BasicBlock();
       this.builder.pushFailureJumpPoint(fbb);
       this.altInstructionMap.put(p.get(i), this.builder.createIalt(p));
       p.get(i).encode(this, next, failjump);
       if (i == p.size() - 1) {
         this.builder.createIaltend(p, true, i);
       } else {
         this.builder.createIaltend(p, false, i);
       }
       this.builder.createIpop(p.get(i));
       this.builder.createIjump(p.get(i), mergebb);
       this.builder.setInsertPoint(this.builder.popFailureJumpPoint());
       if (i != p.size() - 1) {
         this.builder.createIsucc(p.get(i + 1));
         this.builder.createIpeek(p.get(i + 1));
       } else {
         this.builder.createIpop(p.get(i));
         this.builder.createIaltfin(p);
       }
     }
     this.builder.createIjump(p.get(p.size() - 1), this.builder.jumpFailureJump());
     this.builder.setInsertPoint(mergebb);
     this.builder.createIaltfin(p);
   }
   return null;
 }