示例#1
0
/**
 * decrement the primary register by one if char, INTSIZE if int
 */
void gen_decrement_primary_reg(LVALUE *lval) {
    output_line("dcx \th");
    switch (lval->ptr_type) {
        case CINT:
        case UINT:
            output_line("dcx \th");
            break;
        case STRUCT:
            gen_immediate2();
            output_number(lval->tagsym->size - 1);
            newline();
            // two's complement
            output_line("mov  \ta,d");
            output_line("cma");
            output_line("mov  \td,a");
            output_line("mov  \ta,e");
            output_line("cma");
            output_line("mov \te,a");
            output_line("inx \td");
            // substract
            output_line("dad \td");
            break ;
        default:
            break;
    }
}
示例#2
0
/**
 * print all assembler info before any code is generated
 */
void header (void) {
    output_string ("; Small C Debug\n;\tCoder (ac0)\n;");
    frontend_version();
    newline ();
    output_line ("\t;program area SMALLC_GENERATED is RELOCATABLE");
    output_line ("\t.module SMALLC_GENERATED");
}
示例#3
0
int main()
{
	double /* **U, **Unew,err=0.0,*/ sta = 1.0/8.0, stb=1.0/128.0;
	int sa = 9, sb = 129, i/*,j*/;
	FILE *outs;
	init(&U,sa,sa);
	init(&Unew,sa,sa);
	init(&Ub,sb,sb);
	
	init_cond(&U, sa, sa, sta,sta);
	
	memcpy(&Unew,&U,sizeof(Unew));
	for(i = 0; i<1000 /*&& (err>0.001 || err == 0.0)*/; i++)
	{
		//err = 0.0;
		iteration(&U,&Unew, sa,sa, sta,sta);
		memcpy(&U,&Unew,sizeof(Unew));
	}
	
	outs = fopen("../output/out1.dat", "w");
	output_line(U, sa,sa, sta,sta, outs);
	fclose(outs);
	
	//init_cond(&Ub, sb, sb, stb,stb);
	interpol(&Ub, sb, sb, stb, stb, 	&U, sa-1, sa-1, sta, sta);
	init_cond(&Ub, sb, sb, stb, stb);
	
	outs = fopen("../output/out2.dat", "w");
	output_line(Ub, sb,sb, stb,stb, outs);
	fclose(outs);
	
	freeArr(&Unew, sa);
	//output_line(U, sa,sa, sta,sta);
	//output_line(Ub, sb,sb, stb,stb);
	//freeArr(&U, sa);
	init(&Unew,sb,sb);
	init_cond(&Unew, sb, sb, stb, stb);
	memcpy(&Unew,&Ub,sizeof(Ub));
	//err = 0.0;
	for(i = 0; i<1000 /*&& (err>0.0005 || err == 0.0)*/ ; i++)
	{
		iteration(&Ub,&Unew, sb,sb, stb,stb);
		memcpy(&Ub,&Unew,sizeof(Unew));
	}
	
	outs = fopen("../output/out3.dat", "w");
	output_line(Ub, sb,sb, stb,stb, outs);
	fclose(outs);
	
	
	outs = fopen("../output/out3_mstk.dat", "w");
	opt_mstk_line(Ub, sb,sb, stb,stb, outs);
	fclose(outs);
	//output_line(U, size,size, step,step);

	//printf("%f %f %f\n", step*5, step*5, err);
	return 0;
}
示例#4
0
/**
 * push the primary register onto the stack
 */
void gen_push(int reg) {
    if (reg & DE_REG) {
        output_line ("push\td");
        stkp = stkp - INTSIZE;
    } else {
        output_line ("push\th");
        stkp = stkp - INTSIZE;
    }
}
示例#5
0
/**
 * store the specified object type in the primary register
 * at the address in secondary register (on the top of the stack)
 * @param typeobj
 */
void gen_put_indirect(char typeobj) {
    if (typeobj & CCHAR) {
        //gen_call("ccpchar");
        output_line("popstoreb r1 (r2)");
    } else {
        output_line("popstore r1 (r2)");
    }
    stkp = stkp + INTSIZE;
}
示例#6
0
/**
 * print all assembler info before any code is generated
 */
void header (void) {
    output_string ("; Small C 8080\n;\tCoder (2.4,84/11/27)\n;");
    frontend_version();
    newline ();
    output_line ("\t;program area SMALLC_GENERATED is RELOCATABLE");
    output_line ("\t.module SMALLC_GENERATED");
    output_line ("\t.list   (err, loc, bin, eqt, cyc, lin, src, lst, md)");
    output_line ("\t.nlist  (pag)");
}
示例#7
0
/**
 * test the primary register and jump if false to label
 * @param label the label
 * @param ft if true jnz is generated, jz otherwise
 */
void gen_test_jump(int label, int ft)
{
    output_line ("mov \ta,h");
    output_line ("ora \tl");
    if (ft)
        output_with_tab ("jnz \t");
    else
        output_with_tab ("jz  \t");
    print_label (label);
    newline ();
}
示例#8
0
static void
do_report(const char *filename, unsigned line_no, const char *severity,
          const char *fmt, va_list args)
{
    char buf[128];
    vsnprintf(buf, sizeof(buf), fmt, args);
    buf[sizeof(buf) - 1] = 0;
    if (filename != NULL)
        output_line(0, "%s:%d: %s: %s",
                    filename, line_no, severity, buf);
    else
        output_line(0, "%s: %s", severity, buf);
}
示例#9
0
/**
 * store the specified object type in the primary register
 * at the address in secondary register (on the top of the stack)
 * @param typeobj
 */
void gen_put_indirect(char typeobj) {
    gen_pop ();
    if (typeobj & CCHAR) {
        //gen_call("ccpchar");
        output_line("mov \ta,l");
        output_line("stax\td");
    } else {
        if (uflag) {
            output_line("shlx");
        } else {
            gen_call("ccpint");
        }
    }
}
示例#10
0
/**
 * decrement the primary register by one if char, INTSIZE if int
 */
void gen_decrement_primary_reg(LVALUE *lval) {
    switch (lval->ptr_type) {
        case CINT:
        case UINT:
            output_line("sub r1 2");
            break;
        case STRUCT:
            output_with_tab("sub r1 ");
            output_number(lval->tagsym->size - 1);
            newline();
            break ;
        default:
            output_line("sub r1 1");
            break;
    }
}
示例#11
0
/**
 * fetch the specified object type indirect through the primary
 * register into the primary register
 * @param typeobj object type
 */
void gen_get_indirect(char typeobj, int reg) {
    if (typeobj == CCHAR) {
        if (reg & DE_REG) {
            gen_swap();
        }
        output_line("loadsb r1 (r1)");
    } else if (typeobj == UCHAR) {
        if (reg & DE_REG) {
            gen_swap();
        }
        //gen_call("cguchar");
        output_line("loadub r1 (r1)");
    } else { // int
         output_line("load r1 (r1)");
    }
}
示例#12
0
int main()
{
    char token[MAXL];
    char repeat[MAXL];

    if(access("token.txt",0))
        printf("You don't have token, please set it:");
    else
    {
        printf("You have a token, will you change it (y/n):");
        if(getchar()!='y') {
            printf("bye~\n");
            return 0;
        }
        printf("Please set it:");
    }

    while(1)
    {
        input_token(token);
        printf("Repeat it:");
        input_token(repeat);
        if(strcmp(token,repeat)) {
            printf("they are not same, please set it again:");
            continue;
        }
        break;
    }

    FILE *out=fopen("token.txt","w");
    output_line(out,token);
    fclose(out);

    return 0;
}
示例#13
0
/**
 * increment the primary register by 1 if char, INTSIZE if int
 */
void gen_increment_primary_reg(LVALUE *lval) {
    switch (lval->ptr_type) {
        case STRUCT:
            gen_immediate2();
            output_number(lval->tagsym->size);
            newline();
            output_line("dad \td");
            break ;
        case CINT:
        case UINT:
            output_line("inx \th");
        default:
            output_line("inx \th");
            break;
    }
}
示例#14
0
文件: fileio.c 项目: dschwen/jszip
int playback_line( int buflen, char *buffer, int *read_size )
{
   char *cp;

   if ( recording == ON || replaying == OFF )
   {
      return ( -1 );
   }

   if ( fgets( buffer, buflen, rfp ) == NULL )
   {
      close_record(  );
      return ( -1 );
   }
   else
   {
      cp = strrchr( buffer, '\n' );
      if ( cp != NULL )
      {
         *cp = '\0';
      }
      *read_size = strlen( buffer );
      output_line( buffer );
   }

   return ( '\n' );

}                               /* playback_line */
示例#15
0
int main(int argc, char **argv)
{
  const char *label;
  unsigned pos;
  
  switch (argc)
  {
  case 1:
    label = "";
    break;
  case 2:
    if (is_help_option(argv[1]))
    {
      usage();
      return EXIT_SUCCESS;
    }
    else label = argv[1];
    break;
  default:
    usage();
    return EXIT_FAILURE;
  }

  for (pos = 0;;)
  {
    unsigned char buf[LINE];

    unsigned left = LINE - (pos % LINE);
    int res;
    
    /* Try reading the rest of the current line. */
    res = do_read(STDIN_FILENO, buf, left);
    if (!res)
      /* EOF */
      return EXIT_SUCCESS;

    else if (res < 0)
      {
	fprintf(stderr, "%s: read error: %s\n", label, strerror(errno));
	return EXIT_FAILURE;
      }

    /* Dump it */
    if (output_line(STDERR_FILENO, label, pos, buf, res) <= 0)
      {
	fprintf(stderr, "%s: write error on stderr: %s\n", label, strerror(errno));
	return EXIT_FAILURE;
      }
    
    /* And pass it on */
    if (do_write(STDOUT_FILENO, buf, res) < 0)
      {
	fprintf(stderr, "%s: write error: %s\n", label, strerror(errno));
	return EXIT_FAILURE;
      }

    pos += res;
  }
}
示例#16
0
/**
 * perform subroutine call to value on top of stack
 */
void callstk(void) {
    gen_immediate ();
    output_string ("#.+5");
    newline ();
    gen_swap_stack ();
    output_line ("pchl");
    stkp = stkp + INTSIZE;
}
示例#17
0
/**
 * fetch a static memory cell into the primary register
 * @param sym
 */
void gen_get_memory(SYMBOL *sym) {
    if ((sym->identity != POINTER) && (sym->type == CCHAR)) {
        output_with_tab ("lda\t");
        output_string (sym->name);
        newline ();
        gen_call ("ccsxt");
    } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) {
        output_with_tab("lda\t");
        output_string(sym->name);
        newline();
        output_line("mov \tl,a");
        output_line("mvi \th,#0");
    } else {
        output_with_tab ("lhld\t");
        output_string (sym->name);
        newline ();
    }
}
示例#18
0
/**
 * add the primary and secondary registers
 * if lval2 is int pointer and lval is not, scale lval
 * @param lval
 * @param lval2
 */
void gen_add(LVALUE *lval, LVALUE *lval2) {
    if (dbltest (lval2, lval)) {
        gen_swap ();
        gen_multiply_by_two();
        gen_swap ();
    }
    output_line ("popadd r1 r2");
    stkp = stkp + INTSIZE;
}
示例#19
0
static void
handle_exit_signal(Event *event) {
	debug(DEBUG_FUNCTION, "handle_exit_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
	if (event->proc->state != STATE_IGNORED) {
		output_line(event->proc, "+++ killed by %s +++",
				shortsignal(event->proc, event->e_un.signum));
	}
	remove_process(event->proc);
}
示例#20
0
static void
handle_exit(Event *event) {
	debug(DEBUG_FUNCTION, "handle_exit(pid=%d, status=%d)", event->proc->pid, event->e_un.ret_val);
	if (event->proc->state != STATE_IGNORED) {
		output_line(event->proc, "+++ exited (status %d) +++",
				event->e_un.ret_val);
	}
	remove_process(event->proc);
}
示例#21
0
/**
 * add the primary and secondary registers
 * if lval2 is int pointer and lval is not, scale lval
 * @param lval
 * @param lval2
 */
void gen_add(LVALUE *lval, LVALUE *lval2) {
    gen_pop ();
    if (dbltest (lval2, lval)) {
        gen_swap ();
        gen_multiply_by_two ();
        gen_swap ();
    }
    output_line ("dad \td");
}
示例#22
0
static void
handle_signal(Event *event) {
	debug(DEBUG_FUNCTION, "handle_signal(pid=%d, signum=%d)", event->proc->pid, event->e_un.signum);
	if (event->proc->state != STATE_IGNORED && !options.no_signals) {
		output_line(event->proc, "--- %s (%s) ---",
				shortsignal(event->proc, event->e_un.signum),
				strsignal(event->e_un.signum));
	}
	continue_after_signal(event->proc->pid, event->e_un.signum);
}
示例#23
0
/**
 * test the primary register and jump if false to label
 * @param label the label
 * @param ft if true jnz is generated, jz otherwise
 */
void gen_test_jump(int label, int ft)
{
    output_line ("test r1");
    if (ft)
        output_with_tab ("jumpnz ");
    else
        output_with_tab ("jumpz ");
    print_label (label);
    newline ();
}
示例#24
0
/**
 * asm - store the primary register into the specified static memory cell
 * @param sym
 */
void gen_put_memory(SYMBOL *sym) {
    if ((sym->identity != POINTER) && (sym->type & CCHAR)) {
        output_line ("mov \ta,l");
        output_with_tab ("sta \t");
    } else {
        output_with_tab ("shld\t");
    }
    output_string (sym->name);
    newline ();
}
示例#25
0
文件: fileio.c 项目: dschwen/jszip
void z_input_stream( int arg )
{
   char new_record_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1];

   UNUSEDVAR( arg );

   /* If recording or replaying is already on then complain */

   if ( recording == ON || replaying == ON )
   {
      output_line( "Recording or replaying is already active." );
   }
   else
   {                            /* Get recording file name */

      if ( get_file_name( new_record_name, record_name, GAME_PLAYBACK ) == 0 )
      {
         /* Open recording file */
         rfp = fopen( new_record_name, "r" );

         /* Turn on recording if open succeeded */
         if ( rfp != NULL )
         {
#if defined BUFFER_FILES        
            setbuf( rfp, rfpbuffer ); 
#endif 
            /* Make file name the default name */
            strcpy( record_name, new_record_name );

            /* Set replaying on */
            replaying = ON;
         }
         else
         {
            output_line( "Record file open failed" );
         }
      }
   }

}                               /* z_input_stream */
示例#26
0
文件: debug.c 项目: KapJlcoH/ltrace
void
debug_(int level, const char *file, int line, const char *fmt, ...) {
	char buf[1024];
	va_list args;

	if (!(options.debug & level)) {
		return;
	}
	va_start(args, fmt);
	vsnprintf(buf, 1024, fmt, args);
	va_end(args);

	output_line(NULL, "DEBUG: %s:%d: %s", file, line, buf);
}
示例#27
0
static void
normal_exit(void) {
	output_line(0, 0);
	if (options.summary) {
		show_summary();
	}
	if (options.output) {
		fclose(options.output);
		options.output = NULL;
	}
#ifdef HAVE_PYTHON
	Py_Finalize();
#endif
}
示例#28
0
文件: fileio.c 项目: dschwen/jszip
void open_record( void )
{
   char new_record_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1];

   /* If recording or playback is already on then complain */

   if ( recording == ON || replaying == ON )
   {
      output_line( "Recording or playback are already active." );
   }
   else
   {                            /* Get recording file name */
      if ( get_file_name( new_record_name, record_name, GAME_RECORD ) == 0 )
      {
         /* Open recording file */
         rfp = fopen( new_record_name, "w" );

         /* Turn on recording if open succeeded */
         if ( rfp != NULL )
         {
#if defined BUFFER_FILES        
            setbuf( rfp, rfpbuffer ); 
#endif 
            /* Make file name the default name */
            strcpy( record_name, new_record_name );

            /* Set recording on */
            recording = ON;
         }
         else
         {
            output_line( "Record file create failed" );
         }
      }
   }

}                               /* open_record */
示例#29
0
		void push(int_type ch) {
			if (ch == '\r' || ch == '\n') {
				if (_lastc != ch && (_lastc == '\r' || _lastc == '\n')) ch = 0;
				else {
					if (!_linebuffer.empty()) {
						std::lock_guard<std::mutex> lock(s_mutex);
						output_line(_linebuffer);
						_linebuffer.clear();
					}
				}
			}
			else 
				_linebuffer.push_back(ch);
			_lastc = ch;
		}
示例#30
0
/**
 * fetch the specified object type indirect through the primary
 * register into the primary register
 * @param typeobj object type
 */
void gen_get_indirect(char typeobj, int reg) {
    if (typeobj == CCHAR) {
        if (reg & DE_REG) {
            gen_swap();
        }
        gen_call("ccgchar");
    } else if (typeobj == UCHAR) {
        if (reg & DE_REG) {
            gen_swap();
        }
        //gen_call("cguchar");
        output_line("mov \tl,m");
        output_line("mvi \th,0");
    } else { // int
        if (uflag) {
            if (reg & HL_REG) {
                gen_swap();
            }
            output_line("lhlx");
        } else {
            gen_call("ccgint");
        }
    }
}