_mesa_realloc_instructions(prog->Instructions,
prog->NumInstructions,
emitInfo->MaxInstructions);
+ if (!prog->Instructions) {
+ return NULL;
+ }
}
inst = prog->Instructions + prog->NumInstructions;
gl_register_file file, GLint index, GLuint swizzle)
{
struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_ARL);
- inst->SrcReg[0].File = file;
- inst->SrcReg[0].Index = index;
- inst->SrcReg[0].Swizzle = fix_swizzle(swizzle);
- inst->DstReg.File = PROGRAM_ADDRESS;
- inst->DstReg.Index = 0;
- inst->DstReg.WriteMask = WRITEMASK_X;
+ if (inst) {
+ inst->SrcReg[0].File = file;
+ inst->SrcReg[0].Index = index;
+ inst->SrcReg[0].Swizzle = fix_swizzle(swizzle);
+ inst->DstReg.File = PROGRAM_ADDRESS;
+ inst->DstReg.Index = 0;
+ inst->DstReg.WriteMask = WRITEMASK_X;
+ }
return inst;
}
emit_comment(slang_emit_info *emitInfo, const char *comment)
{
struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_NOP);
- inst_comment(inst, comment);
+ if (inst) {
+ inst_comment(inst, comment);
+ }
return inst;
}
* really just a NOP to attach the label to.
*/
inst = new_instruction(emitInfo, OPCODE_BGNSUB);
+ if (!inst) {
+ return NULL;
+ }
inst_comment(inst, n->Label->Name);
}
inst = prev_instruction(emitInfo);
if (inst && inst->Opcode != OPCODE_RET) {
inst = new_instruction(emitInfo, OPCODE_RET);
+ if (!inst) {
+ return NULL;
+ }
}
if (emitInfo->EmitBeginEndSub) {
inst = new_instruction(emitInfo, OPCODE_ENDSUB);
+ if (!inst) {
+ return NULL;
+ }
inst_comment(inst, n->Label->Name);
}
/* emit the function call */
inst = new_instruction(emitInfo, OPCODE_CAL);
+ if (!inst) {
+ return NULL;
+ }
/* The branch target is just the subroutine number (changed later) */
inst->BranchTarget = subroutineId;
inst_comment(inst, n->Label->Name);
* Note that ARB-KILL depends on sign of vector operand.
*/
inst = new_instruction(emitInfo, OPCODE_KIL_NV);
+ if (!inst) {
+ return NULL;
+ }
inst->DstReg.CondMask = COND_TR; /* always kill */
assert(emitInfo->prog->Target == GL_FRAGMENT_PROGRAM_ARB);
if (emitInfo->EmitHighLevelInstructions) {
if (emitInfo->EmitCondCodes) {
/* IF condcode THEN ... */
- struct prog_instruction *ifInst;
- ifInst = new_instruction(emitInfo, OPCODE_IF);
+ struct prog_instruction *ifInst = new_instruction(emitInfo, OPCODE_IF);
+ if (!ifInst) {
+ return NULL;
+ }
ifInst->DstReg.CondMask = COND_NE; /* if cond is non-zero */
/* only test the cond code (1 of 4) that was updated by the
* previous instruction.
else {
/* conditional jump to else, or endif */
struct prog_instruction *ifInst = new_instruction(emitInfo, OPCODE_BRA);
+ if (!ifInst) {
+ return NULL;
+ }
ifInst->DstReg.CondMask = COND_EQ; /* BRA if cond is zero */
inst_comment(ifInst, "if zero");
ifInst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
/* have else body */
elseInstLoc = prog->NumInstructions;
if (emitInfo->EmitHighLevelInstructions) {
- (void) new_instruction(emitInfo, OPCODE_ELSE);
+ struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_ELSE);
+ if (!inst) {
+ return NULL;
+ }
}
else {
/* jump to endif instruction */
- struct prog_instruction *inst;
- inst = new_instruction(emitInfo, OPCODE_BRA);
+ struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_BRA);
+ if (!inst) {
+ return NULL;
+ }
inst_comment(inst, "else");
inst->DstReg.CondMask = COND_TR; /* always branch */
}
}
if (emitInfo->EmitHighLevelInstructions) {
- (void) new_instruction(emitInfo, OPCODE_ENDIF);
+ struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_ENDIF);
+ if (!inst) {
+ return NULL;
+ }
}
if (n->Children[2]) {
/* emit OPCODE_BGNLOOP */
beginInstLoc = prog->NumInstructions;
if (emitInfo->EmitHighLevelInstructions) {
- (void) new_instruction(emitInfo, OPCODE_BGNLOOP);
+ struct prog_instruction *inst = new_instruction(emitInfo, OPCODE_BGNLOOP);
+ if (!inst) {
+ return NULL;
+ }
}
/* body */
if (emitInfo->EmitHighLevelInstructions) {
/* emit OPCODE_ENDLOOP */
endInst = new_instruction(emitInfo, OPCODE_ENDLOOP);
+ if (!endInst) {
+ return NULL;
+ }
}
else {
/* emit unconditional BRA-nch */
endInst = new_instruction(emitInfo, OPCODE_BRA);
+ if (!endInst) {
+ return NULL;
+ }
endInst->DstReg.CondMask = COND_TR; /* always true */
}
/* ENDLOOP's BranchTarget points to the BGNLOOP inst */
}
n->InstLocation = emitInfo->prog->NumInstructions;
inst = new_instruction(emitInfo, opcode);
- inst->DstReg.CondMask = COND_TR; /* always true */
+ if (inst) {
+ inst->DstReg.CondMask = COND_TR; /* always true */
+ }
return inst;
}
*/
const GLuint condWritemask = inst->DstReg.WriteMask;
inst = new_instruction(emitInfo, opcode);
- inst->DstReg.CondMask = COND_NE;
- inst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
+ if (inst) {
+ inst->DstReg.CondMask = COND_NE;
+ inst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
+ }
return inst;
}
else {
n->InstLocation = emitInfo->prog->NumInstructions;
inst = new_instruction(emitInfo, opcode);
+ if (!inst) {
+ return NULL;
+ }
inst = new_instruction(emitInfo, OPCODE_ENDIF);
+ if (!inst) {
+ return NULL;
+ }
emitInfo->prog->Instructions[ifInstLoc].BranchTarget
= emitInfo->prog->NumInstructions;
const GLuint condWritemask = inst->DstReg.WriteMask;
assert(emitInfo->EmitCondCodes);
inst = new_instruction(emitInfo, OPCODE_BRA);
- inst->DstReg.CondMask = COND_NE;
- inst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
+ if (inst) {
+ inst->DstReg.CondMask = COND_NE;
+ inst->DstReg.CondSwizzle = writemask_to_swizzle(condWritemask);
+ }
return inst;
}
}
if (n->Comment) {
inst = new_instruction(emitInfo, OPCODE_NOP);
- inst->Comment = _mesa_strdup(n->Comment);
+ if (inst) {
+ inst->Comment = _mesa_strdup(n->Comment);
+ }
inst = NULL;
}
if (withEnd) {
struct prog_instruction *inst;
inst = new_instruction(&emitInfo, OPCODE_END);
+ if (!inst) {
+ return GL_FALSE;
+ }
}
_slang_resolve_subroutines(&emitInfo);