+#define CUSTOM_COLOR_BASE 100
+static const char *color_names[ird_color_count];
+static const char *color_rgb[ird_color_count];
+static struct obstack color_obst;
+
+/** define a custom color. */
+static void custom_color(int num, const char *rgb_def)
+{
+ assert(num < ird_color_count);
+ obstack_printf(&color_obst, "%d", CUSTOM_COLOR_BASE + num);
+ obstack_1grow(&color_obst, '\0');
+
+ color_rgb[num] = rgb_def;
+ color_names[num] = obstack_finish(&color_obst);
+}
+
+/** Define a named color. */
+static void named_color(int num, const char *name)
+{
+ assert(num < ird_color_count);
+ color_rgb[num] = NULL;
+ color_names[num] = name;
+}
+
+/** Initializes the used colors. */
+static void init_colors(void)
+{
+ static int initialized = 0;
+ if (initialized)
+ return;
+
+ obstack_init(&color_obst);
+
+ custom_color(ird_color_prog_background, "204 204 204");
+ custom_color(ird_color_block_background, "255 255 0");
+ custom_color(ird_color_dead_block_background, "190 150 150");
+ named_color(ird_color_block_inout, "lightblue");
+ named_color(ird_color_default_node, "white");
+ custom_color(ird_color_memory, "153 153 255");
+ custom_color(ird_color_controlflow, "255 153 153");
+ custom_color(ird_color_const, "204 255 255");
+ custom_color(ird_color_proj, "255 255 153");
+ custom_color(ird_color_uses_memory, "153 153 255");
+ custom_color(ird_color_phi, "105 255 105");
+ custom_color(ird_color_anchor, "100 100 255");
+ named_color(ird_color_error, "red");
+ custom_color(ird_color_entity, "204 204 255");
+
+ initialized = 1;
+}
+