Exemple #1
0
GLboolean
_slang_preprocess_version (const char *text, GLuint *version, GLuint *eaten, slang_info_log *log)
{
   grammar id;
   byte *prod, *I;
   unsigned int size;

   id = grammar_load_from_text ((const byte *) (slang_pp_version_syn));
   if (id == 0) {
      grammar_error_to_log (log);
      return GL_FALSE;
   }

   if (!grammar_fast_check (id, (const byte *) (text), &prod, &size, 8)) {
      grammar_error_to_log (log);
      grammar_destroy (id);
      return GL_FALSE;
   }

   /* there can be multiple #version directives - grab the last one */
   I = &prod[size - 6];
   *version = (GLuint) (I[0]) + (GLuint) (I[1]) * 100;
   *eaten = (GLuint) (I[2]) + ((GLuint) (I[3]) << 8) + ((GLuint) (I[4]) << 16) + ((GLuint) (I[5]) << 24);

   grammar_destroy (id);
   grammar_alloc_free (prod);
   return GL_TRUE;
}
Exemple #2
0
/**
 * Run preprocessor on source code.
 * \param extensions  indicates which GL extensions are enabled
 * \param output  the post-process results
 * \param input  the input text
 * \param elog  log to record warnings, errors
 * \return GL_TRUE for success, GL_FALSE for error
 */
GLboolean
_slang_preprocess_directives(slang_string *output,
                             const char *input,
                             slang_info_log *elog,
                             const struct gl_extensions *extensions,
                             struct gl_sl_pragmas *pragmas)
{
   grammar pid, eid;
   GLboolean success;
   slang_string without_backslashes;

   pid = grammar_load_from_text ((const byte *) (slang_pp_directives_syn));
   if (pid == 0) {
      grammar_error_to_log (elog);
      return GL_FALSE;
   }
   eid = grammar_load_from_text ((const byte *) (slang_pp_expression_syn));
   if (eid == 0) {
      grammar_error_to_log (elog);
      grammar_destroy (pid);
      return GL_FALSE;
   }

   slang_string_init(&without_backslashes);
   success = _slang_preprocess_backslashes(&without_backslashes, input);

   if (0) {
      _mesa_printf("Pre-processed shader:\n");
      _mesa_printf("%s", slang_string_cstr(&without_backslashes));
      _mesa_printf("----------------------\n");
   }

   if (success) {
      success = preprocess_source(output,
                                  slang_string_cstr(&without_backslashes),
                                  pid,
                                  eid,
                                  elog,
                                  extensions,
                                  pragmas);
   }

   slang_string_free(&without_backslashes);
   grammar_destroy (eid);
   grammar_destroy (pid);

   if (0) {
      _mesa_printf("Post-processed shader:\n");
      _mesa_printf("%s", slang_string_cstr(output));
      _mesa_printf("----------------------\n");
   }

   return success;
}
Exemple #3
0
int _slang_preprocess_version (const char *text, unsigned int *version, unsigned int *eaten,
	slang_info_log *log)
{
	grammar id;
	byte *prod, *I;
	unsigned int size;

	id = grammar_load_from_text ((const byte *) slang_version_syn);
	if (id == 0)
	{
		char buf[1024];
		unsigned int pos;
		grammar_get_last_error ( (unsigned char*) buf, 1024, (int*) &pos);
		slang_info_log_error (log, buf);
		return 0;
	}

	if (!grammar_fast_check (id, (const byte *) text, &prod, &size, 8))
	{
		char buf[1024];
		unsigned int pos;
		grammar_get_last_error ( (unsigned char*) buf, 1024, (int*) &pos);
		slang_info_log_error (log, buf);
		grammar_destroy (id);
		return 0;
	}

	grammar_destroy (id);

	/* there can be multiple #version directives - grab the last one */
	I = prod;
	while (I < prod + size)
	{
		*version =
			(unsigned int) I[0] +
			(unsigned int) I[1] * 100;
		*eaten =
			((unsigned int) I[2]) +
			((unsigned int) I[3] << 8) +
			((unsigned int) I[4] << 16) +
			((unsigned int) I[5] << 24);
		I += 6;
	}

	grammar_alloc_free (prod);
	return 1;
}