| 85 | |
| 86 | |
| 87 | int |
| 88 | OSLCompilerImpl::insert_code (int opnum, const char *opname, |
| 89 | size_t nargs, Symbol **args, ASTNode *node) |
| 90 | { |
| 91 | Opcode op (ustring (opname), m_codegenmethod, m_opargs.size(), nargs); |
| 92 | if (node) |
| 93 | op.source (node->sourcefile(), node->sourceline()); |
| 94 | m_ircode.insert (m_ircode.begin()+opnum, op); |
| 95 | add_op_args (nargs, args); |
| 96 | |
| 97 | // Unless we were inserting at the end, we may need to adjust |
| 98 | // the jump addresses of other ops and the param init ranges. |
| 99 | if (opnum < (int)m_ircode.size()-1) { |
| 100 | // Adjust jump offsets |
| 101 | for (auto& c : m_ircode) { |
| 102 | for (int j = 0; j < (int)Opcode::max_jumps && c.jump(j) >= 0; ++j) { |
| 103 | if (c.jump(j) > opnum) { |
| 104 | c.jump(j) = c.jump(j) + 1; |
| 105 | // std::cerr << "Adjusting jump target at op " << n << "\n"; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | // Adjust param init ranges |
| 110 | for (auto&& s : symtab()) { |
| 111 | if (s->symtype() == SymTypeParam || |
| 112 | s->symtype() == SymTypeOutputParam) { |
| 113 | if (s->initbegin() > opnum) |
| 114 | s->initbegin (s->initbegin()+1); |
| 115 | if (s->initend() > opnum) |
| 116 | s->initend (s->initend()+1); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return opnum; |
| 122 | } |
| 123 | |
| 124 | |
| 125 |
nothing calls this directly
no test coverage detected