#include #include #include "raichu_fpu.c" #define BUFSIZE 1024 char buf[BUFSIZE]; char *read_space(char *str){ while(((*str) == ' ') || ((*str) == '\t')); return str; } int read_line(FILE *fpr, unsigned int *op1p, unsigned int *op2p){ char *fgisok; fgisok = fgets(buf, BUFSIZE, fpr); if(fgisok){ int i; char *str; if(buf[strlen(buf) - 1] != '\n'){ fprintf(stderr, "line too long\n"); return -1; } (*op1p) = 0; str = read_space(buf); for(i = 0; i < 32; i++, str++){ unsigned int bit; bit = (unsigned int)(*str - '0'); if(bit < 2) (*op1p) = ((*op1p) << 1) + bit; else{ fprintf(stderr, "file input error\n"); return -1; } } (*op2p) = 0; str = read_space(str); for(i = 0; i < 32; i++, str++){ unsigned int bit; bit = (unsigned int)(*str - '0'); if(bit < 2) (*op2p) = ((*op2p) << 1) + bit; else{ fprintf(stderr, "file input error\n"); return -1; } } } else if(ferror(fpr)){ fprintf(stderr, "file read error\n"); return -1; } return 0; } void write_line(unsigned int val){ unsigned int i; for(i = 31; i < 32; i--) printf("%d", ((val >> i) & 1)); } unsigned int call_fpufunc(unsigned int op1, unsigned int op2){ return fpu_fadd(op1, op2); } int main(int argc, char *argv[]){ FILE *fpr; if(argc < 2){ fprintf(stderr, "usage: fpucheck [input file]\n"); return 1; } if((fpr = fopen(argv[1], "r"))){ unsigned int op1, op2; while((read_line(fpr, &op1, &op2)) > 0){ write_line(call_fpufunc(op1, op2)); } fclose(fpr); } else{ fprintf(fpr, "file %s not found\n", argv[1]); return 1; } return 0; }