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 "main/mtypes.h"
11 #include "program/prog_instruction.h"
12 #include "slang_label.h"
13 #include "slang_mem.h"
18 _slang_label_new(const char *name
)
20 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
22 l
->Name
= _slang_strdup(name
);
29 * As above, but suffix the name with a unique number.
32 _slang_label_new_unique(const char *name
)
35 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
37 l
->Name
= (char *) _slang_alloc(strlen(name
) + 10);
42 _mesa_snprintf(l
->Name
, strlen(name
) + 10, "%s_%d", name
, id
);
50 _slang_label_delete(slang_label
*l
)
57 _slang_free(l
->References
);
65 _slang_label_add_reference(slang_label
*l
, GLuint inst
)
67 const GLuint oldSize
= l
->NumReferences
* sizeof(GLuint
);
68 assert(l
->Location
< 0);
69 l
->References
= _slang_realloc(l
->References
,
70 oldSize
, oldSize
+ sizeof(GLuint
));
72 l
->References
[l
->NumReferences
] = inst
;
79 _slang_label_get_location(const slang_label
*l
)
86 _slang_label_set_location(slang_label
*l
, GLint location
,
87 struct gl_program
*prog
)
91 assert(l
->Location
< 0);
92 assert(location
>= 0);
94 l
->Location
= location
;
96 /* for the instructions that were waiting to learn the label's location: */
97 for (i
= 0; i
< l
->NumReferences
; i
++) {
98 const GLuint j
= l
->References
[i
];
99 prog
->Instructions
[j
].BranchTarget
= location
;
103 _slang_free(l
->References
);
104 l
->References
= NULL
;