コード例 #1
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau
code_ptr* create_code_assign(char* variable, code_ptr* child, symbol* vars, symbol * paras) {
	code_ptr* c = create_code(TT_ASSIGN, child, NULL);
	c->name = strdup(variable);

	// Look though vars symbol table
	while (vars != NULL) {
		if (strcmp(vars->name, variable)==0) {
			c->reg = vars->reg;
			return c;
		}
		vars = vars->next;
	}

	// Look through paras symbol table
	while (paras != NULL) {
		if (strcmp(paras->name, variable)==0) {
			c->reg = paras->reg;
			return c;
		}
		paras = paras->next;
	}
	
	printf("Variable %s not found in symbol table\n", variable);
	exit(3);
}
コード例 #2
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code* create_code_or (struct code *a, struct code *b)
{
	struct code *c;
	c = create_code (TT_OR, a, b);
	c->val = get_control_label_id ();
	return c;
}
コード例 #3
0
ファイル: imsub.c プロジェクト: deepakantony/miscellaneous
void huff(float prob[],int loc[],int num, unsigned int *code, char *length)
{
	NODE *tree; /* pointer to a node */
	int lgth;

	lgth=0;
	tree=(NODE *)create_list(prob,loc,num); /* create tree */
	create_code(tree,lgth,code,length); /* get code from tree */
}
コード例 #4
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code* create_code_if (struct code *condition)
{
	struct code *c;

	c = create_code (TT_IF, condition, NULL);
	c->val = get_control_label_id ();

	return c;
}
コード例 #5
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code* create_code_while (struct code *condition)
{
	struct code *c;

	c = create_code (TT_WHILE, condition, NULL);
	c->val = get_control_label_id ();

	return c;
}
コード例 #6
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code* create_code_definition (struct code *expr, struct symbol *s)
{
	struct code *c;

	c = create_code (TT_DEF, expr, NULL);
	c->reg = s->reg;

	return c;
}
コード例 #7
0
ファイル: tut02-square.c プロジェクト: AHelper/gcc
int
main (int argc, char **argv)
{
  gcc_jit_context *ctxt = NULL;
  gcc_jit_result *result = NULL;

  /* Get a "context" object for working with the library.  */
  ctxt = gcc_jit_context_acquire ();
  if (!ctxt)
    {
      fprintf (stderr, "NULL ctxt");
      goto error;
    }

  /* Set some options on the context.
     Let's see the code being generated, in assembler form.  */
  gcc_jit_context_set_bool_option (
    ctxt,
    GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
    0);

  /* Populate the context.  */
  create_code (ctxt);

  /* Compile the code.  */
  result = gcc_jit_context_compile (ctxt);
  if (!result)
    {
      fprintf (stderr, "NULL result");
      goto error;
    }

  /* We're done with the context; we can release it: */
  gcc_jit_context_release (ctxt);
  ctxt = NULL;

  /* Extract the generated code from "result".  */
  void *fn_ptr = gcc_jit_result_get_code (result, "square");
  if (!fn_ptr)
     {
       fprintf (stderr, "NULL fn_ptr");
       goto error;
     }

  typedef int (*fn_type) (int);
  fn_type square = (fn_type)fn_ptr;
  printf ("result: %d\n", square (5));

 error:
  if (ctxt)
    gcc_jit_context_release (ctxt);
  if (result)
    gcc_jit_result_release (result);
  return 0;
}
コード例 #8
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau
code_ptr* create_code_goto(char* func_name, char* label_name) {
	code_ptr* c = create_code(TT_GOTO, (code_ptr *)NULL, (code_ptr *)NULL);
	char* asm_lbl;

	asm_lbl = strdup(func_name);
	strcat(asm_lbl, "_");
	strcat(asm_lbl, label_name);

	c->name = asm_lbl;
	return c;		
}
コード例 #9
0
ファイル: tut03-sum-of-squares.c プロジェクト: AlexMioMio/gcc
int
main (int argc, char **argv)
{
  gcc_jit_context *ctxt = NULL;
  gcc_jit_result *result = NULL;

  /* Get a "context" object for working with the library.  */
  ctxt = gcc_jit_context_acquire ();
  if (!ctxt)
    {
      fprintf (stderr, "NULL ctxt");
      goto error;
    }

  /* Set some options on the context.
     Let's see the code being generated, in assembler form.  */
  gcc_jit_context_set_bool_option (
    ctxt,
    GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
    0);

  /* Populate the context.  */
  create_code (ctxt);

  /* Compile the code.  */
  result = gcc_jit_context_compile (ctxt);
  if (!result)
    {
      fprintf (stderr, "NULL result");
      goto error;
    }

  /* Extract the generated code from "result".  */
  typedef int (*loop_test_fn_type) (int);
  loop_test_fn_type loop_test =
    (loop_test_fn_type)gcc_jit_result_get_code (result, "loop_test");
  if (!loop_test)
    {
      fprintf (stderr, "NULL loop_test");
      goto error;
    }

  /* Run the generated code.  */
  int val = loop_test (10);
  printf("loop_test returned: %d\n", val);

 error:
  gcc_jit_context_release (ctxt);
  gcc_jit_result_release (result);
  return 0;
}
コード例 #10
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code* create_code_var (char *name, struct symbol *params, struct symbol *vars)
{
	struct code *c;
	struct symbol *s;

	check_variable (name, params, vars);

	s = table_find_symbol (name, vars);
	if (s != NULL) {
		c = create_code (TT_VARIABLE, NULL, NULL);
		c->name = strdup (name);
		c->reg = s->reg;
		return c;
	}

	s = table_find_symbol (name, params);
	assert (s != NULL);

	c = create_code (TT_VARIABLE, NULL, NULL);
	c->name = strdup (name);
	c->reg = s->reg;
	return c;
}
コード例 #11
0
ファイル: tut01-hello-world.c プロジェクト: AlexMioMio/gcc
int
main (int argc, char **argv)
{
  gcc_jit_context *ctxt;
  gcc_jit_result *result;

  /* Get a "context" object for working with the library.  */
  ctxt = gcc_jit_context_acquire ();
  if (!ctxt)
    {
      fprintf (stderr, "NULL ctxt");
      exit (1);
    }

  /* Set some options on the context.
     Let's see the code being generated, in assembler form.  */
  gcc_jit_context_set_bool_option (
    ctxt,
    GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
    0);

  /* Populate the context.  */
  create_code (ctxt);

  /* Compile the code.  */
  result = gcc_jit_context_compile (ctxt);
  if (!result)
    {
      fprintf (stderr, "NULL result");
      exit (1);
    }

  /* Extract the generated code from "result".  */
  typedef void (*fn_type) (const char *);
  fn_type greet =
    (fn_type)gcc_jit_result_get_code (result, "greet");
  if (!greet)
    {
      fprintf (stderr, "NULL greet");
      exit (1);
    }

  /* Now call the generated function: */
  greet ("world");
  fflush (stdout);

  gcc_jit_context_release (ctxt);
  gcc_jit_result_release (result);
  return 0;
}
コード例 #12
0
ファイル: imsub.c プロジェクト: deepakantony/miscellaneous
void create_code(NODE *root, int lgth, unsigned int *code, char *length)
{
	if (root -> left != NULL){ 

	  /* writes code for next node */
		root->left->code = root -> code;
		root -> left -> code=root->left->code << 01;

	  /* keep track of length of code */
		++lgth;	

	  /* call subroutine again but with next node left as root node */
		create_code(root->left,lgth,code,length);
		}
	if (root -> right != NULL){

          /* writes code for next node */
		root -> right -> code = root -> code;
		root -> right -> code = root -> right -> code << 01;

	  /* add one for step right */
		root -> right -> code += 1;

          /* call subroutine again but with next node right as root node */
		create_code(root->right,lgth,code,length);
		}
	if (root -> left == NULL && root -> right == NULL){

	  /* write code and length to arrays, 
	     code and length are written in the same order
	     in the code and length arrays as the probability
	     they go with before the probabilities were sorted */

		code[root->l] = root -> code; 
		length[root->l] = lgth;
	}
}
コード例 #13
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau
code_ptr* create_code_var(char* name, symbol* params, symbol* vars) {
	char* reg;
	code_ptr* c;

	check_variable(name, params, vars);

	// First look for params
	reg = tbl_find_reg(name, params);

	if (reg == NULL) {
		// 'name' not found @params, look @vars
		reg = tbl_find_reg(name, vars);
		if (reg == NULL) {
			printf("THIS SHOULD NEVER HAPPEN: create_code_var(%s)\n", name);
			tbl_print(params);
			tbl_print(vars);
			exit(3);
		}
	} 
	c = create_code(TT_VARIABLE, (code_ptr *)NULL, (code_ptr *)NULL);
	c->name = strdup(name);
	c->reg = reg;
	return c;	
}
コード例 #14
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau2
struct code *create_code_num (long number)
{
	struct code *c = create_code (TT_NUM, NULL, NULL);
	c->val = number;
	return c;
}
コード例 #15
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau
code_ptr *create_code_num(long number) {
	code_ptr *c = create_code(TT_NUM, (code_ptr *)NULL, (code_ptr *)NULL);
	c->val = number;
	return c;
}
コード例 #16
0
ファイル: geekcode.c プロジェクト: masterdriverz/geekcode
int main(int argc, char **argv)
{
	char *outfile=NULL;
	int read=0, write=0, output=0, list=0, c, index;
	const struct option long_options[] = {
		{"list",	no_argument,		NULL,	'l'},
		{"read",	no_argument,		NULL,	'r'},
		{"write",	no_argument,		NULL,	'w'},
		{"output",	required_argument,	NULL,	'o'},
		{"help",	no_argument,		NULL,	'h'},
		{"version",	no_argument,		NULL,	'v'},
		{NULL, 0, NULL, 0}
	};
	while ((c = getopt_long(argc, argv, "lrwho:", long_options, &index)) != -1) {
		switch (c) {
		case 'l':
			list = 1;
			break;
		case 'r':
			read = 1;
			break;
		case 'w':
			write = 1;
			break;
		case 'h':
			usage(stdout);
			return 0;
		case 'o':
			output = 1;
			outfile = optarg;
			break;
		case 'v':
			version();
			return 0;
		default:
			usage(stderr);
			return -1;
		}
	}
	if (write+read+list > 1) {
		fputs("Conflicting actions given simultaneously.\n", stderr);
		usage(stderr);
		return -1;
	} else if (!write+read+list) {
		write = 1;
	}
	if (output && !write) {
		fputs("It only makes sense to use --output with --write.\n", stderr);
		usage(stderr);
		return 1;
	}
	if (list) {
		list_sections();
	} else if (read) {
		FILE *f=NULL;
		for (index = optind; index < argc; index++) {
			f = open_file(argv[index], "r");
			run_code(argv[index], f);
			if (fclose(f))
				file_error(argv[index], "closing");
		}
		/* If we haven't opened anything, use stdin */
		if (!f)
			run_code("stdin", stdin);
	} else {
		FILE *f;
		if (outfile)
			f = open_file(outfile, "w");
		else
			f = stdout;
		if (optind < argc) {
			fputs("--write takes no arguments\n", stderr);
			usage(stderr);
			return -1;
		}
		create_code();
		output_code(f);
	}
	return 0;
}
コード例 #17
0
ファイル: code_gen.c プロジェクト: bountin/uebersetzerbau
code_ptr* create_code_if(code_ptr* expr, long id) {
	code_ptr* c = create_code(TT_IF, expr, NULL);
	
	c->val = id;
	return c;
}