4 * Functions for managing instruction labels.
5 * Basically, this is used to manage the problem of forward branches where
6 * we have a branch instruciton but don't know the target address yet.
10 #include "slang_label.h"
14 _slang_label_new(const char *name
)
16 slang_label
*l
= (slang_label
*) _mesa_calloc(sizeof(slang_label
));
18 l
->Name
= _mesa_strdup(name
);
25 _slang_label_delete(slang_label
*l
)
30 _mesa_free(l
->References
);
36 _slang_label_add_reference(slang_label
*l
, GLuint inst
)
38 const GLuint oldSize
= l
->NumReferences
* sizeof(GLuint
);
39 assert(l
->Location
< 0);
40 l
->References
= _mesa_realloc(l
->References
,
41 oldSize
, oldSize
+ sizeof(GLuint
));
43 l
->References
[l
->NumReferences
] = inst
;
50 _slang_label_get_location(const slang_label
*l
)
57 _slang_label_set_location(slang_label
*l
, GLint location
,
58 struct gl_program
*prog
)
62 assert(l
->Location
< 0);
63 assert(location
>= 0);
65 l
->Location
= location
;
67 /* for the instructions that were waiting to learn the label's location: */
68 for (i
= 0; i
< l
->NumReferences
; i
++) {
69 const GLuint j
= l
->References
[i
];
70 prog
->Instructions
[j
].BranchTarget
= location
;
74 _mesa_free(l
->References
);