Example #1
0
/**
 * Print the given basic block.
 * 
 * @param block  the basic block
 */
void JVMWriter::printBasicBlock(const BasicBlock *block) {
    printLabel(getLabelName(block));
    if (trace) {
        if (block->hasName()) {
            std::string n = block->getName();
            printTrc(n + ":");
        }
    }
    for(BasicBlock::const_iterator i = block->begin(), e = block->end();
        i != e; i++) {
        instNum++;
        
        if (trace)
            printSimpleInstruction(".line", utostr(trcLineNum+1));
        else if(debug >= 1)
            printSimpleInstruction(".line", utostr(instNum));
            
        if(debug >= 3 || trace) {
            // print current instruction as comment
            // note that this block of code significantly increases
            // code generation time
            std::string str;
            raw_string_ostream ss(str); ss << *i;
            ss.flush();
            if (trace)
                printTrc(str);
            if (debug >= 3) {
                std::string::size_type pos = 0;
                while((pos = str.find("\n", pos)) != std::string::npos)
                    str.replace(pos++, 1, "\n;");
                out << ';' << str << '\n';
            }
        }
        
        if(i->getOpcode() == Instruction::PHI)
            // don't handle phi instruction in current block
            continue;
        printInstruction(i);
        if(i->getType() != Type::getVoidTy(block->getContext())
        && i->getOpcode() != Instruction::Invoke)
            // instruction doesn't return anything, or is an invoke instruction
            // which handles storing the return value itself
            printValueStore(i);
    }
}