MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / insert_code

Method insert_code

src/liboslcomp/codegen.cpp:87–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85
86
87int
88OSLCompilerImpl::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

Callers

nothing calls this directly

Calls 10

sourceMethod · 0.80
insertMethod · 0.80
jumpMethod · 0.80
symtypeMethod · 0.80
initbeginMethod · 0.80
initendMethod · 0.80
sizeMethod · 0.45
sourcefileMethod · 0.45
sourcelineMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected