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"
11 #include "slang_mem.h"
16 _slang_label_new(const char *name
)
19 slang_label
*l
= (slang_label
*) _mesa_calloc(sizeof(slang_label
));
21 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
25 l
->Name
= _mesa_strdup(name
);
27 l
->Name
= _slang_strdup(name
);
35 * As above, but suffix the name with a unique number.
38 _slang_label_new_unique(const char *name
)
42 slang_label
*l
= (slang_label
*) _mesa_calloc(sizeof(slang_label
));
44 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
48 l
->Name
= (char *) _mesa_malloc(_mesa_strlen(name
) + 10);
50 l
->Name
= (char *) _slang_alloc(_mesa_strlen(name
) + 10);
56 _mesa_sprintf(l
->Name
, "%s_%d", name
, id
);
64 _slang_label_delete(slang_label
*l
)
70 _mesa_free(l
->References
);
77 _slang_label_add_reference(slang_label
*l
, GLuint inst
)
79 const GLuint oldSize
= l
->NumReferences
* sizeof(GLuint
);
80 assert(l
->Location
< 0);
82 l
->References
= _mesa_realloc(l
->References
,
83 oldSize
, oldSize
+ sizeof(GLuint
));
85 l
->References
= _slang_realloc(l
->References
,
86 oldSize
, oldSize
+ sizeof(GLuint
));
89 l
->References
[l
->NumReferences
] = inst
;
96 _slang_label_get_location(const slang_label
*l
)
103 _slang_label_set_location(slang_label
*l
, GLint location
,
104 struct gl_program
*prog
)
108 assert(l
->Location
< 0);
109 assert(location
>= 0);
111 l
->Location
= location
;
113 /* for the instructions that were waiting to learn the label's location: */
114 for (i
= 0; i
< l
->NumReferences
; i
++) {
115 const GLuint j
= l
->References
[i
];
116 prog
->Instructions
[j
].BranchTarget
= location
;
121 _mesa_free(l
->References
);
123 l
->References
= NULL
;