void gencode_main (tree * n) { gensymtab(n->left); gencode(n->right); print_st(); }
int main( int argc, char *argv[] ) { FILE *source, *target; Program program; SymbolTable symtab; HashTable Htable;//new if( argc == 3){ source = fopen(argv[1], "r"); target = fopen(argv[2], "w"); if( !source ){ printf("can't open the source file\n"); exit(2); } else if( !target ){ printf("can't open the target file\n"); exit(2); } else{ program = parser(source); fclose(source); InitHashName(&Htable);//new symtab = build(program,&Htable);//changed check(&program, &symtab,&Htable);//changed gencode(program, target,&Htable);//changed } } else{ printf("Usage: %s source_file target_file\n", argv[0]); } return 0; }
int main( int argc, char *argv[] ) { FILE *source, *target; // source -> .ac file target -> .dc file Program program; // root of the Syntax Tree SymbolTable symtab; // SymbolTable if( argc == 3){ source = fopen(argv[1], "r"); target = fopen(argv[2], "w"); if( !source ){ printf("can't open the source file\n"); exit(2); } else if( !target ){ printf("can't open the target file\n"); exit(2); } else{ program = parser(source); fclose(source); symtab = build(program); check(&program, &symtab); //check type float or int gencode(program, target,&symtab); } } else{ printf("Usage: %s source_file target_file\n", argv[0]); } return 0; }
void function(sSymbol_t f, sSymbol_t caller[], sSymbol_t callee[], int ncalls) { int i; localsize=offset=tmpsize=nbregs=0; funame=f->x.name; for (i=8;i<32;i++) temp[i]->x.name="******"; for (i = 0; caller[i] && callee[i]; i++) { caller[i]->x.name=stringf("(ap),%d",offset); caller[i]->x.adrmode='A'; offset+=caller[i]->type->size; if (optimizelevel>1 && callee[i]->sclass==REGISTER && allocreg(callee[i])) ; /* allocreg ok */ else { callee[i]->x.adrmode=caller[i]->x.adrmode; callee[i]->x.name=caller[i]->x.name; callee[i]->sclass=AUTO; } } busy=localsize=0; offset=6; gencode(caller,callee); omit_frame=(i==0 && localsize==6); print("%s\n",funame); if (optimizelevel>1 && omit_frame && nbregs==0) ; else print("\tENTER(%d,%d)\n",nbregs,localsize); if (isstruct(freturn(f->type))) print("\tMOVW_DI(op1,(fp),6)\n"); emitcode(); }
int main(int argc, char *argv[]) { #define CHECK(expr,cod) if(!(expr)) \ {code=(cod); goto abort;} enum ArchonErrors { AE_SUCCESS,AE_FORMAT,AE_MEMORY, AE_INT,AE_SOURCE,AE_DEST,AE_NULL }; int code = 0; FILE *ff=NULL; #ifdef VERBOSE clock_t t0 = clock(); static char *errors[AE_NULL] = { NULL, "Usage: archon4r0 [e|d] <source> <dest>", "Memory allocation error!", "Internal program error - sorry!", "Source has no read permission!", "Dest has no write permission!" }; #endif //VERBOSE setbuf(stdout,NULL); printf("%s\n",IDENT); CHECK(argc>=4,AE_FORMAT); ff = fopen(argv[2],"rb"); CHECK(ff,AE_SOURCE); fseek(ff,0,SEEK_END); CHECK(geninit(ff),AE_MEMORY); fclose(ff); ff = fopen(argv[argc-1],"wb"); CHECK(ff,AE_DEST); if(argv[1][0] == 'e') { clock_t t1; CHECK(gencode(),AE_MEMORY); printf("memory: %d meg\n",memory>>20); printf("Processing...\t"); //Suffix Array Construction t1 = clock(); CHECK(compute()>=0,AE_INT); printime("SAC",t1); #ifdef VERIFY printf("Verifying...\t"); t1 = verify(); printf("\nresult: %s\n",t1?"bad":"good"); #endif //VERIFY CHECK(encode(ff)>=0,AE_INT); genprint(); }else if(argv[1][0] == 'd') {
int main (int argc, char **argv) { find_formats (); genlegend (); if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h') genheader (); else gencode (); if (ferror (stdout) || fflush (stdout) || fclose (stdout)) return FATAL_EXIT_CODE; return SUCCESS_EXIT_CODE; }
int main(int argc, char *argv[]) { FILE *fp; yyscan_t yyscanner; M1_compiler comp; if (argc <= 1) { fprintf(stderr, "Usage: m1 <file>\n"); exit(EXIT_FAILURE); } fp = fopen(argv[1], "r"); if (fp == NULL) { fprintf(stderr, "Could not open file\n"); exit(EXIT_FAILURE); } /* set up compiler */ init_compiler(&comp); /* set up lexer and parser */ yylex_init(&yyscanner); yyset_extra(&comp, yyscanner); yyset_in(fp, yyscanner); comp.yyscanner = yyscanner; /* yyscanner has a pointer to comp, and vice versa. */ yyparse(yyscanner, &comp); fprintf(stderr, "parsing done\n"); if (comp.errors == 0) { assert(intstack_isempty(comp.breakstack) != 0); assert(intstack_isempty(comp.continuestack) != 0); check(&comp, comp.ast); /* need to finish */ //if (comp.errors == 0) { fprintf(stderr, "generating code...\n"); gencode(&comp, comp.ast); } } fclose(fp); fprintf(stderr, "compilation done\n"); return 0; }
int main (int argc, char **argv) { /* BEGIN GCC-XML MODIFICATIONS (2007/10/31 15:07:06) */ gccxml_fix_printf(); /* END GCC-XML MODIFICATIONS (2007/10/31 15:07:06) */ find_formats (); genlegend (); if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'h') genheader (); else gencode (); if (ferror (stdout) || fflush (stdout) || fclose (stdout)) return FATAL_EXIT_CODE; return SUCCESS_EXIT_CODE; }
static void function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { int i, size, varargs; Symbol* p; for (p = caller; *p; p++) (*p)->x.type = get_type((*p)->type, 0); for (p = callee; *p; p++) (*p)->x.type = get_type((*p)->type, 0); for (i = 0; callee[i]; i++) { Symbol p = callee[i]; Symbol q = caller[i]; gvmt_local(p); q->sclass = p->sclass = REGISTER; q->x.name = p->x.name; q->x.type = p->x.type; } // print("Function %s \\\n", f->x.name); //params = stackParameters(caller, callee); gencode(caller, callee); // framesize = roundup(offset, 4); emitcode(); }
static void asdl_function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { list_ty codelist = Seq_new(0), save, calleelist = Seq_new(0), callerlist = Seq_new(0); int i; dopending(f); for (i = 0; caller[i] != NULL; i++) { asdl_local(caller[i]); Seq_addhi(callerlist, to_generic_int(symboluid(caller[i]))); } for (i = 0; callee[i] != NULL; i++) { asdl_local(callee[i]); Seq_addhi(calleelist, to_generic_int(symboluid(callee[i]))); } save = interfaces; interfaces = codelist; gencode(caller, callee); asdl_segment(CODE); emitcode(); interfaces = save; put(rcc_Function(symboluid(f), callerlist, calleelist, ncalls, codelist)); }
/* * Generate code statements. */ void docode(char *fname, int lineno) { static int codedone = 0; struct table *tp; /* * Make sure we only execute once... */ if (codedone) return; codedone = 1; /* * Call the code-specific generator for each table. */ if (lineno > 0) linesync(fname, lineno, fofp); tp = getnexttable(NULL); while (tp != NULL) { gencode(tp, fofp); tp = getnexttable(tp); } }
int main( int argc, char *argv[] ) { FILE *source, *target; Program program; SymbolTable symtab; if( argc == 3){ source = fopen(argv[1], "r"); // test_parser(source); // printf("\n"); // return 0; target = fopen(argv[2], "w"); if( !source ){ printf("can't open the source file\n"); exit(2); } else if( !target ){ printf("can't open the target file\n"); exit(2); } else{ program = parser(source); fclose(source); symtab = build(program); check(&program, &symtab); gencode(program, target); } } else{ printf("Usage: %s source_file target_file\n", argv[0]); } return 0; }
void dfw_gencode(dfwork_t *dfw) { int id, id1, length; dfvm_insn_t *insn, *insn1, *prev; dfvm_value_t *arg1; dfw->insns = g_ptr_array_new(); dfw->consts = g_ptr_array_new(); dfw->loaded_fields = g_hash_table_new(g_direct_hash, g_direct_equal); dfw->interesting_fields = g_hash_table_new(g_direct_hash, g_direct_equal); gencode(dfw, dfw->st_root); dfw_append_insn(dfw, dfvm_insn_new(RETURN)); /* fixup goto */ length = dfw->insns->len; for (id = 0, prev = NULL; id < length; prev = insn, id++) { insn = (dfvm_insn_t *)g_ptr_array_index(dfw->insns, id); arg1 = insn->arg1; if (insn->op == IF_TRUE_GOTO || insn->op == IF_FALSE_GOTO) { dfvm_opcode_t revert = (insn->op == IF_FALSE_GOTO)?IF_TRUE_GOTO:IF_FALSE_GOTO; id1 = arg1->value.numeric; do { insn1 = (dfvm_insn_t*)g_ptr_array_index(dfw->insns, id1); if (insn1->op == revert) { /* this one is always false and the branch is not taken*/ id1 = id1 +1; continue; } else if (insn1->op == READ_TREE && prev && prev->op == READ_TREE && prev->arg2->value.numeric == insn1->arg2->value.numeric) { /* hack if it's the same register it's the same field * and it returns the same value */ id1 = id1 +1; continue; } else if (insn1->op != insn->op) { /* bail out */ arg1 = insn->arg1; arg1->value.numeric = id1; break; } arg1 = insn1->arg1; id1 = arg1->value.numeric; } while (1); } } /* move constants after registers*/ if (dfw->first_constant == -1) { /* NONE */ dfw->first_constant = dfw->next_register; return; } id = -dfw->first_constant -1; dfw->first_constant = dfw->next_register; dfw->next_register += id; length = dfw->consts->len; for (id = 0; id < length; id++) { insn = (dfvm_insn_t *)g_ptr_array_index(dfw->consts, id); if (insn->arg2 && insn->arg2->type == REGISTER && (int)insn->arg2->value.numeric < 0 ) insn->arg2->value.numeric = dfw->first_constant - insn->arg2->value.numeric -1; } length = dfw->insns->len; for (id = 0; id < length; id++) { insn = (dfvm_insn_t *)g_ptr_array_index(dfw->insns, id); if (insn->arg1 && insn->arg1->type == REGISTER && (int)insn->arg1->value.numeric < 0 ) insn->arg1->value.numeric = dfw->first_constant - insn->arg1->value.numeric -1; if (insn->arg2 && insn->arg2->type == REGISTER && (int)insn->arg2->value.numeric < 0 ) insn->arg2->value.numeric = dfw->first_constant - insn->arg2->value.numeric -1; if (insn->arg3 && insn->arg3->type == REGISTER && (int)insn->arg3->value.numeric < 0 ) insn->arg3->value.numeric = dfw->first_constant - insn->arg3->value.numeric -1; if (insn->arg4 && insn->arg4->type == REGISTER && (int)insn->arg4->value.numeric < 0 ) insn->arg4->value.numeric = dfw->first_constant - insn->arg4->value.numeric -1; } }
static void gen_test(dfwork_t *dfw, stnode_t *st_node) { test_op_t st_op; stnode_t *st_arg1, *st_arg2; dfvm_value_t *val1; dfvm_insn_t *insn; header_field_info *hfinfo; sttype_test_get(st_node, &st_op, &st_arg1, &st_arg2); switch (st_op) { case TEST_OP_UNINITIALIZED: g_assert_not_reached(); break; case TEST_OP_EXISTS: val1 = dfvm_value_new(HFINFO); hfinfo = (header_field_info*)stnode_data(st_arg1); /* Rewind to find the first field of this name. */ while (hfinfo->same_name_prev) { hfinfo = hfinfo->same_name_prev; } val1->value.hfinfo = hfinfo; insn = dfvm_insn_new(CHECK_EXISTS); insn->arg1 = val1; dfw_append_insn(dfw, insn); /* Record the FIELD_ID in hash of interesting fields. */ while (hfinfo) { g_hash_table_insert(dfw->interesting_fields, GINT_TO_POINTER(hfinfo->id), GUINT_TO_POINTER(TRUE)); hfinfo = hfinfo->same_name_next; } break; case TEST_OP_NOT: gencode(dfw, st_arg1); insn = dfvm_insn_new(NOT); dfw_append_insn(dfw, insn); break; case TEST_OP_AND: gencode(dfw, st_arg1); insn = dfvm_insn_new(IF_FALSE_GOTO); val1 = dfvm_value_new(INSN_NUMBER); insn->arg1 = val1; dfw_append_insn(dfw, insn); gencode(dfw, st_arg2); val1->value.numeric = dfw->next_insn_id; break; case TEST_OP_OR: gencode(dfw, st_arg1); insn = dfvm_insn_new(IF_TRUE_GOTO); val1 = dfvm_value_new(INSN_NUMBER); insn->arg1 = val1; dfw_append_insn(dfw, insn); gencode(dfw, st_arg2); val1->value.numeric = dfw->next_insn_id; break; case TEST_OP_EQ: gen_relation(dfw, ANY_EQ, st_arg1, st_arg2); break; case TEST_OP_NE: gen_relation(dfw, ANY_NE, st_arg1, st_arg2); break; case TEST_OP_GT: gen_relation(dfw, ANY_GT, st_arg1, st_arg2); break; case TEST_OP_GE: gen_relation(dfw, ANY_GE, st_arg1, st_arg2); break; case TEST_OP_LT: gen_relation(dfw, ANY_LT, st_arg1, st_arg2); break; case TEST_OP_LE: gen_relation(dfw, ANY_LE, st_arg1, st_arg2); break; case TEST_OP_BITWISE_AND: gen_relation(dfw, ANY_BITWISE_AND, st_arg1, st_arg2); break; case TEST_OP_CONTAINS: gen_relation(dfw, ANY_CONTAINS, st_arg1, st_arg2); break; case TEST_OP_MATCHES: gen_relation(dfw, ANY_MATCHES, st_arg1, st_arg2); break; } }
void gencode (tree * n) { // custion : only value that are not used after calling another gencode // cuz these values are not re-entrent static int param_count = 0; // ok struct SymbolTable *st; char *t1, *t2, new_tmp[MAX_VAR_NAME]; if (n == NULL) return; if (isleaf (n)) { checktype(n); if(istemp(name(n))) push_temp(name(n)); else push(name(n)); return; } switch(n->type) { case t_assign: if(isleaf(n->right)) { fprintf(out, "%s\t:=\t%s\n", name(n->left), name(n->right)); break; } gencode(n->right->left); gencode(n->right->right); fprintf(out, "%s\t:=\t%s\t%s\t%s\n", name(n->left), pop(), operation(n->right), pop()); break; case t_op: gencode(n->right); gencode(n->left); if(top()->temp) { t1 = pop(); t2 = pop(); fprintf(out, "%s\t:=\t%s\t%s\t%s\n", t1, t1, operation(n), t2); push_temp(t1); break; } t1 = pop(); t2 = pop(); sprintf(new_tmp, "_t%d", last_temp++); fprintf(out, "%s\t:=\t%s\t%s\t%s\n", new_tmp, t1, operation(n), t2); push_temp(new_tmp); break; case t_goto: st = lookup(name(n->left)); if(st && (gettype(name(n->left)) == LABEL)) fprintf(out, "%s\t%s\n", operation(n), name(n->left)); else { add(name(n->left), LABEL); st = lookup(name(n->left)); st->ok = 0; // waitting to see label defination fprintf(stderr, "Warning: waitting to see label(%s)\n", name(n->left)); } break; case t_while: { int Lbegin = newlabel(); int Lend = newlabel(); fprintf(out, "_l%d\t:\n", Lbegin); if(isleaf(n->left)) { fprintf(out, "if\t%s\t=\t0\tgoto\t_l%d\n", name(n->left), Lend); } else { /* TODO : it SHLULD be relop but we dont check */ gencode(n->left->left); gencode(n->left->right); fprintf(out, "if\t%s\t%s\t%s\tgoto\t_l%d\n", pop(), neg_operation(n->left), pop(), Lend); } gencode(n->right); fprintf(out, "goto\t_l%d\n", Lbegin); fprintf(out, "_l%d\t:\n", Lend); break; } case t_for: fprintf(stderr, "No impl for FOR yet!\n"); break; case t_sub: gencode(n->right); fprintf(out, "call\t%s\t%d\n", n->left->value.idval, param_count); param_count = 0; break; case t_param: gencode(n->left); fprintf(out, "param\t%s\n", pop()); param_count++; if(n->right) gencode(n->right); break; case t_if: { int L = newlabel(); if(isleaf(n->left)) { fprintf(out, "if\t%s\t=\t0\tgoto\t_l%d\n", name(n->left), L); } else { /* TODO : it SHLULD be relop but we dont check */ gencode(n->left->left); gencode(n->left->right); fprintf(out, "if\t%s\t%s\t%s\tgoto\t_l%d\n", pop(), operation(n->left), pop(), L); } gencode(n->right->left); // else if(n->right->right != NULL) { int L2 = newlabel(); fprintf(out, "goto\t_l%d\n", L2); fprintf(out, "_l%d\t:\n", L); gencode(n->right->right); fprintf(out, "_l%d\t:\n", L2); } else { fprintf(out, "_l%d\t:\n", L); } break; } case t_join: if(n->op == LABEL_JOIN) { add(n->left->value.idval, LABEL); fprintf(out, "%s\t:\n", n->left->value.idval); } else gencode(n->left); gencode(n->right); break; case t_block: gencode(n->left); break; } // switch }
/* initialize sdr channel struct ----------------------------------------------- * set value to sdr channel struct * args : int chno I channel number (1,2,...) * int sys I system type (SYS_***) * int prn I PRN number * int ctype I code type (CTYPE_***) * int dtype I data type (DTYPEI or DTYPEIQ) * int ftype I front end type (FTYPE1 or FTYPE2) * double f_cf I center (carrier) frequency (Hz) * double f_sf I sampling frequency (Hz) * double f_if I intermidiate frequency (Hz) * sdrch_t *sdr I/0 sdr channel struct * return : int 0:okay -1:error *-----------------------------------------------------------------------------*/ extern int initsdrch(int chno, int sys, int prn, int ctype, int dtype, int ftype, double f_cf, double f_sf, double f_if, sdrch_t *sdr) { int i; short *rcode; sdr->no=chno; sdr->sys=sys; sdr->prn=prn; sdr->sat=satno(sys,prn); sdr->ctype=ctype; sdr->dtype=dtype; sdr->ftype=ftype; sdr->f_sf=f_sf; sdr->f_if=f_if; sdr->ti=1/f_sf; /* code generation */ if (!(sdr->code=gencode(prn,ctype,&sdr->clen,&sdr->crate))) { SDRPRINTF("error: gencode\n"); return -1; } sdr->ci=sdr->ti*sdr->crate; sdr->ctime=sdr->clen/sdr->crate; sdr->nsamp=(int)(f_sf*sdr->ctime); sdr->nsampchip=(int)(sdr->nsamp/sdr->clen); satno2id(sdr->sat,sdr->satstr); /* set carrier frequency */ if (ctype==CTYPE_G1) { sprintf(sdr->satstr,"R%d",prn); /* frequency number instead of PRN */ sdr->f_cf=FREQ1_GLO+DFRQ1_GLO*prn; /* FDMA */ sdr->foffset=DFRQ1_GLO*prn; /* FDMA */ } else if (sdrini.fend==FEND_FRTLSDR) { sdr->foffset=f_cf*sdrini.rtlsdrppmerr*1e-6; } else { sdr->f_cf=f_cf; /* carrier frequency */ sdr->foffset=0.0; /* frequency offset */ } /* for BeiDou B1I */ if (ctype==CTYPE_B1I) sdr->nsampchip*=2; /* for BOC code */ /* acqisition struct */ initacqstruct(sys,ctype,prn,&sdr->acq); sdr->acq.nfft=2*sdr->nsamp;//calcfftnum(2*sdr->nsamp,0); /* memory allocation */ if (!(sdr->acq.freq=(double*)malloc(sizeof(double)*sdr->acq.nfreq))) { SDRPRINTF("error: initsdrch memory alocation\n"); return -1; } /* doppler search frequency */ for (i=0;i<sdr->acq.nfreq;i++) sdr->acq.freq[i]=sdr->f_if+((i-(sdr->acq.nfreq-1)/2)*sdr->acq.step) +sdr->foffset; /* tracking struct */ if (inittrkstruct(sdr->sat,ctype,sdr->ctime,&sdr->trk)<0) return -1; /* navigation struct */ if (initnavstruct(sys,ctype,prn,&sdr->nav)<0) { return -1; } /* memory allocation */ if (!(rcode=(short *)sdrmalloc(sizeof(short)*sdr->acq.nfft)) || !(sdr->xcode=cpxmalloc(sdr->acq.nfft))) { SDRPRINTF("error: initsdrch memory alocation\n"); return -1; } /* other code generation */ for (i=0;i<sdr->acq.nfft;i++) rcode[i]=0; /* zero padding */ rescode(sdr->code,sdr->clen,0,0,sdr->ci,sdr->nsamp,rcode); /* resampling */ cpxcpx(rcode,NULL,1.0,sdr->acq.nfft,sdr->xcode); /* FFT for acquisition */ cpxfft(NULL,sdr->xcode,sdr->acq.nfft); sdrfree(rcode); return 0; }
/* initialize navigation struct ------------------------------------------------ * set value to navigation struct * args : int sys I system type (SYS_GPS...) * int ctype I code type (CTYPE_L1CA...) * int prn I PRN (or SV) number * sdrnav_t *nav I/0 navigation struct * return : int 0:okay -1:error *-----------------------------------------------------------------------------*/ extern int initnavstruct(int sys, int ctype, int prn, sdrnav_t *nav) { int i; int pre_l1ca[8]= { 1,-1,-1,-1, 1,-1, 1, 1}; /* L1CA preamble*/ int pre_e1b[10]= { 1,-1, 1,-1,-1, 1, 1, 1, 1, 1}; /* E1B preamble */ int pre_g1[30]= {-1,-1,-1,-1,-1, 1, 1, 1,-1,-1, 1,-1,-1,-1, 1,-1, 1,-1, 1, 1, 1, 1,-1, 1, 1,-1, 1,-1,-1, 1}; /* G1 preamble */ int pre_b1i[11]= {-1,-1,-1, 1, 1, 1,-1, 1, 1,-1, 1}; /* B1I preamble */ int pre_sbs[24]= { 1,-1, 1,-1, 1, 1,-1,-1,-1, 1, 1,-1,-1, 1,-1, 1,-1,-1, 1, 1, 1 -1,-1, 1}; /* SBAS L1/QZS L1SAIF preamble */ int poly[2]={V27POLYA,V27POLYB}; nav->ctype=ctype; nav->sdreph.ctype=ctype; nav->sdreph.prn=prn; nav->sdreph.eph.iodc=-1; /* GPS/QZS L1CA */ if (ctype==CTYPE_L1CA) { nav->rate=NAVRATE_L1CA; nav->flen=NAVFLEN_L1CA; nav->addflen=NAVADDFLEN_L1CA; nav->prelen=NAVPRELEN_L1CA; nav->sdreph.cntth=NAVEPHCNT_L1CA; nav->update=(int)(nav->flen*nav->rate); memcpy(nav->prebits,pre_l1ca,sizeof(int)*nav->prelen); /* overlay code (all 1) */ nav->ocode=(short *)calloc(nav->rate,sizeof(short)); for (i=0;i<nav->rate;i++) nav->ocode[i]=1; } /* SBAS/QZS L1SAIF */ if (ctype==CTYPE_L1SAIF||ctype==CTYPE_L1SBAS) { nav->rate=NAVRATE_SBAS; nav->flen=NAVFLEN_SBAS; nav->addflen=NAVADDFLEN_SBAS; nav->prelen=NAVPRELEN_SBAS; nav->sdreph.cntth=NAVEPHCNT_SBAS; nav->update=(int)(nav->flen/3*nav->rate); memcpy(nav->prebits,pre_sbs,sizeof(int)*nav->prelen); /* create fec */ if((nav->fec=create_viterbi27_port(NAVFLEN_SBAS/2))==NULL) { SDRPRINTF("error: create_viterbi27 failed\n"); return -1; } /* set polynomial */ set_viterbi27_polynomial_port(poly); /* overlay code (all 1) */ nav->ocode=(short *)calloc(nav->rate,sizeof(short)); for (i=0;i<nav->rate;i++) nav->ocode[i]=1; } /* GLONASS G1 */ if (ctype==CTYPE_G1) { nav->rate=NAVRATE_G1; nav->flen=NAVFLEN_G1; nav->addflen=NAVADDFLEN_G1; nav->prelen=NAVPRELEN_G1; nav->sdreph.cntth=NAVEPHCNT_G1; nav->update=(int)(nav->flen*nav->rate); memcpy(nav->prebits,pre_g1,sizeof(int)*nav->prelen); nav->sdreph.geph.frq=prn; /* glonass frequency number */ /* overlay code (all 1) */ nav->ocode=(short *)calloc(nav->rate,sizeof(short)); for (i=0;i<nav->rate;i++) nav->ocode[i]=1; } /* Galileo E1B */ if (ctype==CTYPE_E1B) { nav->rate=NAVRATE_E1B; nav->flen=NAVFLEN_E1B; nav->addflen=NAVADDFLEN_E1B; nav->prelen=NAVPRELEN_E1B; nav->sdreph.cntth=NAVEPHCNT_E1B; nav->update=(int)(nav->flen*nav->rate); memcpy(nav->prebits,pre_e1b,sizeof(int)*nav->prelen); /* create fec */ if((nav->fec=create_viterbi27_port(120))==NULL) { SDRPRINTF("error: create_viterbi27 failed\n"); return -1; } /* set polynomial */ set_viterbi27_polynomial_port(poly); /* overlay code (all 1) */ nav->ocode=(short *)calloc(nav->rate,sizeof(short)); for (i=0;i<nav->rate;i++) nav->ocode[i]=1; } /* BeiDou B1I */ if (ctype==CTYPE_B1I) { /* MEO/IGSO (D1 NAV) */ if (prn>5) { nav->rate=NAVRATE_B1I; nav->flen=NAVFLEN_B1I; nav->addflen=NAVADDFLEN_B1I; nav->prelen=NAVPRELEN_B1I; nav->sdreph.cntth=NAVEPHCNT_B1I; nav->update=(int)(nav->flen*nav->rate); memcpy(nav->prebits,pre_b1i,sizeof(int)*nav->prelen); /* secondary code generation */ nav->ocode=gencode(-1,CTYPE_NH20,NULL,NULL); /* GEO (D2 NAV) */ } else { nav->rate=NAVRATE_B1IG; nav->flen=NAVFLEN_B1IG; nav->addflen=NAVADDFLEN_B1IG; nav->prelen=NAVPRELEN_B1IG; nav->sdreph.cntth=NAVEPHCNT_B1IG; nav->update=(int)(nav->flen*nav->rate); memcpy(nav->prebits,pre_b1i,sizeof(int)*nav->prelen); /* overlay code (all 1) */ nav->ocode=(short *)calloc(nav->rate,sizeof(short)); for (i=0;i<nav->rate;i++) nav->ocode[i]=1; } } if (!(nav->bitsync= (int *)calloc(nav->rate,sizeof(int))) || !(nav->fbits= (int *)calloc(nav->flen+nav->addflen,sizeof(int))) || !(nav->fbitsdec=(int *)calloc(nav->flen+nav->addflen,sizeof(int)))) { SDRPRINTF("error: initnavstruct memory alocation\n"); return -1; } return 0; }
char* eval(struct ast* a) { char *val, *rval, *lval, tempo, temp_variable[10]; //char tmpname[4], tmpstr[4]; switch (a->nodetype) { case 'K': return ((struct numval *) a)->number; // Leaf node case 'F': return ((struct floatval *) a)->number; // Leaf node reading_ident_list = 1; break; case 'Z': return ((struct stringval *) a)->number; // Leaf node case 'R': identqueuehead = NULL; reading_ident_list = 1; reading_integer_list = 0; reading_float_list = 0; reading_string_list = 0; break; case '$': case 'N': identqueuehead = NULL; reading_integer_list = 1; reading_ident_list = 0; //integer_ident_list = 0; reading_float_list = 0; reading_string_list = 0; break; case ';': case 'D': identqueuehead = NULL; reading_float_list = 1; reading_ident_list = 0; reading_integer_list = 0; //float_ident_list = 0; reading_string_list = 0; break; case '#': case 'L': identqueuehead = NULL; reading_string_list = 1; reading_ident_list = 0; reading_integer_list = 0; reading_float_list = 0; //string_ident_list = 0; break; case 'S': if (reading_integer_list == 1) { add_ident_to_queue(((struct identval *) a)->ident); if(in_main==0) { procedure_add_to_table(((struct identval *) a)->ident); } } if (reading_float_list == 1) { add_ident_to_queue(((struct identval *) a)->ident); if(in_main==0) { procedure_add_to_table(((struct identval *) a)->ident); } } if (reading_string_list == 1) { add_ident_to_queue(((struct identval *) a)->ident); if(in_main==0) { procedure_add_to_table(((struct identval *) a)->ident); } } if (reading_ident_list == 1) { is_valid_rvalue( ((struct identval *) a)->ident ); if(in_main == 0) procedure_is_valid_rvalue(((struct identval *) a)->ident ); add_ident_to_queue(((struct identval *) a)->ident); } //remove this //add_ident_to_queue(((struct identval *) a)->ident); return((struct identval *) a)->ident; // Leaf node case 'W': break; case 'J': count++; break; case 'A': if (para_write==1) { para_write=0; fprintf(fp_out,") \n"); } { int a =0 ; if(name!=0){ for(a=name-1;a>-1;a--) { fprintf(fp_out,"Line %d: %s = param\n",lineno++, param_name[a]); } }} name = 0; break; case '+': case '-': case '*': case '/': case '%': case '&': case '|': case '!': case 'B': case 'C': case 'G': case 'H': case '<': case '>': break; case '=':break; case 'I': break; case 'T': break; case 'Q': parent = 1; break; case 'O': case 'Y': break; case 'P': printf("This is a primary symbol\n"); break; case 'E': break; case '1': in_method=1; in_main = 0; procedure[proccount] = (struct sym_table*) malloc(sizeof(struct sym_table)); procedure[proccount]->size=0; procedure[proccount]->max_size=32; procedure[proccount]->entries = (struct sym_table_entry*) malloc(procedure[proccount]->max_size*sizeof(struct sym_table_entry)); proccount++; break; case '2': in_main = 0; procedure[proccount] = (struct sym_table*) malloc(sizeof(struct sym_table)); procedure[proccount]->size=0; procedure[proccount]->max_size=32; procedure[proccount]->entries = (struct sym_table_entry*) malloc(procedure[proccount]->max_size*sizeof(struct sym_table_entry)); proccount++; break; case '3': in_main = 0; procedure[proccount] = (struct sym_table*) malloc(sizeof(struct sym_table)); procedure[proccount]->size=0; procedure[proccount]->max_size=32; procedure[proccount]->entries = (struct sym_table_entry*) malloc(procedure[proccount]->max_size*sizeof(struct sym_table_entry)); proccount++; break; case '4': in_main = 0; procedure[proccount] = (struct sym_table*) malloc(sizeof(struct sym_table)); procedure[proccount]->size=0; procedure[proccount]->max_size=32; procedure[proccount]->entries = (struct sym_table_entry*) malloc(procedure[proccount]->max_size*sizeof(struct sym_table_entry)); proccount++; break; case '5': break; case '6': break; case '7': break; case '8': fprintf(fp_out,"Line %d: return \n", lineno++); break; case 'V': proc_used=1; break; case '@': break; case '^': break; case '~': para_write=1; break; case '[': para_write=1; break; case '(': para_write=1; break; case ')': para_write=1; break; case '_': break; case ']': break; case '9': break; case ':': procp_used = 1; break; case '.': break; case ',': break; case '?': funcp_write = 1; break; case 'U': funcp_write = 0; count_para = 0; break; default: printf("Error: it's here at top Unknown node type: %c\n", a->nodetype); return; } if (a->l) { lval = eval(a->l); switch (a->nodetype) { case 'R': reading_ident_list = 0; reading_integer_list = 0; reading_float_list = 0; reading_string_list = 0; break; case 'W': if (a->l->nodetype == '+' || a->l->nodetype == '-' || a->l->nodetype == '*' || a->l->nodetype == '/') { CPRINT(lineno, tempvars[tempvarindex], lval); fprintf(fp_out,"Line %d: %s = %s\n", lineno++, tempvars[tempvarindex], lval); sprintf(lval,"%s", tempvars[tempvarindex++]); } break; case '=': is_valid_rvalue(lval); if(in_main==0) procedure_is_valid_rvalue(lval); strcat(lval, " = "); break; case '+': case '-': case '*': case '/': case '%': case '&': case '|': case '!': case 'B': case 'C': case 'G': case 'H': case '<': case '>': break; case 'A': case 'I': case 'P': break; case 'J': fprintf(fp_out,"Line %d: Label %d:\n",lineno++, label++); gencode(lval); fprintf(fp_out,"Line %d: condition = %s\n",lineno++, tempvars[tempvarindex-1]); fprintf(fp_out,"Line %d: if(condition) goto Label %d:\n",lineno++, label++); fprintf(fp_out,"Line %d: goto Label %d:\n",lineno++,label++); break; case '$': strcpy(pointer_variables[number++],lval); //printf("%s\n",lval); case 'N': reading_ident_list = 0; reading_integer_list = 0; reading_float_list = 0; reading_string_list = 0; break; case ';': strcpy(pointer_variables[number++],lval); case 'D': reading_ident_list = 0; reading_integer_list = 0; reading_float_list = 0; reading_string_list = 0; break; case '#': strcpy(pointer_variables[number++],lval); case 'L': reading_ident_list = 0; reading_integer_list = 0; reading_float_list = 0; reading_string_list = 0; break; case 'T': break; case 'Q': break; case 'O': fprintf(fp_out,"Line %d: condition = %s\n",lineno++, lval); fprintf(fp_out,"Line %d: if !(condition) then goto Label 1 \n",lineno++); break; case 'Y': fprintf(fp_out,"Line %d: Label 3: \n",lineno++); break; case 'E': if (a->l->nodetype == '+' || a->l->nodetype == '-') { CPRINT(lineno, tempvars[tempvarindex], lval); fprintf(fp_out,"Line %d: %s = %s\n", lineno++, tempvars[tempvarindex], lval); sprintf(lval,"%s", tempvars[tempvarindex++]); } break; case 'S': return lval; break; case '1': return_type = 1; fprintf(fp_out,"Line %d: procedure int %s ()\n", lineno++, lval); proctype[procindex] = 1; strcat(procname[procindex++],lval); break; case '2': return_type = 2; fprintf(fp_out,"Line %d: procedure float %s ()\n", lineno++, lval); proctype[procindex]=2; strcat(procname[procindex++],lval); break; case '3': return_type = 3; fprintf(fp_out,"Line %d: procedure string %s ()\n", lineno++, lval); proctype[procindex]=3; strcat(procname[procindex++],lval); break; case '4': fprintf(fp_out,"Line %d: procedure void %s ()\n", lineno++, lval); strcat(procname[procindex++],lval); break; case '5': fprintf(fp_out,"Line %d: Call %s(), 0 \n", lineno++, lval); break; case '6': if(procp_used == 1) { if(number != 0) { int i = 0; for(i = 0; i<number; i++) fprintf(fp_out,"Line %d: param = %s\n", lineno++, pointer_variables[i]); number = 0; } fprintf(fp_out,"Line %d: return %s \n", lineno++, lval); } else { in_method=0; procedure_is_valid_rvalue(lval); int loc = procedure_check_table(lval); if(procedure[proccount-1]->entries[loc].type != return_type) yyerror(" return type do not match\n"); fprintf(fp_out,"Line %d: return %s \n", lineno++, lval); } break; case '8': fprintf(fp_out,"Line %d: return \n", lineno++); break; case '7': strcat(lval, " = "); break; case 'V': case '@': break; case '^': break; case '~': fprintf(fp_out,"Line %d: procedure int %s (", lineno++, lval); strcpy(procedure_names[procp_number++],lval); break; case '[': fprintf(fp_out,"Line %d: procedure float %s (", lineno++, lval); break; case '(': fprintf(fp_out,"Line %d: procedure string %s (", lineno++, lval); break; case ')': fprintf(fp_out,"Line %d: procedure void %s (", lineno++, lval); break; case '_': break; case ']': break; case '9': break; case ':': break; case '.': break; case ',': break; case '?': //printf("%s, ", lval); strcpy(procedure_compare[procp_compare_number++],lval); //printf("%s\n",lval); strcat(fcall, lval); break; case 'U': sprintf(fcall,"Line %d: %s = Call ", lineno++, lval); break; default: printf("Error: it's here at the left section Unknown node type: %c\n", a->nodetype); break; } } if (a->r) { if(a->nodetype=='J') { fprintf(fp_out,"Line %d: Label %d:\n",lineno++, label-2); } if(a->nodetype == 'V') { in_main = 0; procedure[proccount] = (struct sym_table*) malloc(sizeof(struct sym_table)); procedure[proccount]->size=0; procedure[proccount]->max_size=32; procedure[proccount]->entries = (struct sym_table_entry*) malloc(procedure[proccount]->max_size*sizeof(struct sym_table_entry)); proccount++; } rval = eval(a->r); switch (a->nodetype) { case '=': gencode(rval); if (a->r->nodetype=='S') { is_valid_rvalue(rval); if(in_main==0) procedure_is_valid_rvalue(rval); } if(a->r->nodetype == 'S' || a->r->nodetype == 'K' || a->r->nodetype == 'F' || a->r->nodetype == 'Z' ) strcat(lval, rval); else strcat(lval, tempvars[tempvarindex-1]); val = lval; break; case '+': case '-': case '*': case '/': case '%': case '&': case '|': case '!': case '<': case '>': case 'B': case 'C': case 'G': case 'H': if(a->r->nodetype == 'S') { is_valid_rvalue(rval); if(in_main==0) procedure_is_valid_rvalue(rval); } strcat(lval,rval); sprintf(tmpstr,"%c", a->nodetype); strcat(lval,tmpstr); return lval; break; case 'I': case 'A': case 'P': break; case 'T': break; case 'Q': break; case 'O': if (parent == 1) fprintf(fp_out,"Line %d: goto Label 3: \n",lineno++); parent = 0; fprintf(fp_out,"Line %d: Label 1:\n",lineno++); break; case 'Y': break; case 'J': fprintf(fp_out,"Line %d: Label %d:\n",lineno++, count*3); count--; break; case 'E': CPRINT_WR(lineno, rval); if(funcp_write == 1) { fprintf(fp_out,"Line %d: param = %s \n",lineno++, rval); //********INCOMLETE***********SYMBOL TABLE CHANGING MAY CAUSE TROUBLE LATER WHEN CODING int x = check_table(rval); sprintf(temp_variable, "%d", st->entries[x].type ); strcat(procedure_compare[procp_compare_number-1],temp_variable); count_para++; } else fprintf(fp_out,"Line %d: write %s\n",lineno++, rval); return; // return so we don't print an extra "write" statement case '1': break; case '2': case '3': case '4': case '5': case '6': break; case '7': is_valid_procname(rval); strcat(lval, "Call "); strcat(lval, rval); strcat(lval, "(), 0"); val = lval; break; case 'V': case '@': break; case '^': break; case '~': break; case '[': break; case '(': break; case ')': break; case '_': break; case ']': break; case '9': break; case ':': break; case '.': break; case ',': break; case ';': break; case '$': break; case '#': break; case '?': funcp_write = 1; fprintf(fp_out,"%s",fcall); fprintf(fp_out,", %d\n",count_para); funcp_write = 0; break; case 'U': { int i; int result = -1; for(i=0;i<procp_number;i++) { if (strcmp(procedure_compare[procp_compare_number-1], procedure_names[i]) == 0) {result = 0; break; } } if(result !=0) yyerror("Function Call do not match\n"); } break; default: printf("Error: it's here at the right section Unknown node type: %c\n", a->nodetype); break; } } // Only for non-literal or non-identifier nodes switch (a->nodetype) { case 'R': lineno = print_read_input_idents(lineno); break; case '$': case 'N': lineno = print_read_integer_idents(lineno); break; case ';': case 'D': lineno = print_read_float_idents(lineno); break; case '#': case 'L': lineno = print_read_string_idents(lineno); break; case 'W': break; case '=': CPRINT_ASSIGN(lineno, val); if(funcp_write == 1) count_para++; fprintf(fp_out,"Line %d: %s\n",lineno++, val); break; case 'A': case 'P': break; case '+': case '-': case '*': case '/': case '%': case '|': case '&': case '!': case 'B': case 'C': case 'G': case 'H': case '<': case '>': case 'J': break; case 'T': case 'Q': case 'O': case 'Y': break; case 'I': break; case 'E': CPRINT_WR(lineno, lval); if(funcp_write == 1) { int x = check_table(lval); sprintf(temp_variable, "%d", st->entries[x].type ); strcat(procedure_compare[procp_compare_number-1],temp_variable); //sprintf(procedure_compare[procp_compare_number-1], "%d", st->entries[x].type ); count_para++; fprintf(fp_out,"Line %d: param = %s \n",lineno++, lval); } else fprintf(fp_out,"Line %d: write %s\n",lineno++, lval); return lval; case '1': case '2': case '3': case '4': case '5': case '6': break; case '7': CPRINT_ASSIGN(lineno, val); fprintf(fp_out,"Line %d: %s\n",lineno++, val); break; case '8': break; case 'V': case '@': break; case '^': break; case '~': break; case '[': break; case '(': break; case ')': break; case '_': break; case ']': break; case '9': break; case ':': break; case '.': break; case ',': break; case '?': break; case 'U': break; default: printf("Error: it's here at the last section Unknown node type: %c\n", a->nodetype); return; } }
//function(..) module saved jan 1 2013 as part of prep for scrt integration static void function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { int i, saved, sizefsave, sizeisave, varargs; Symbol r, argregs[NUM_ARG_REGS]; usedmask[0] = usedmask[1] = 0; freemask[0] = freemask[1] = ~(unsigned)0; offset = maxoffset = maxargoffset = 0; for (i = 0; callee[i]; i++) //find last argument ; varargs = variadic(f->type) //see if variable arguments by type or by name of final argument || i > 0 && strcmp(callee[i-1]->name, "va_alist") == 0; for (i = 0; callee[i]; i++) { //for each argument Symbol p = callee[i]; Symbol q = caller[i]; assert(q); offset = roundup(offset, q->type->align); //calculate the offset from the caller's sp p->x.offset = q->x.offset = offset; p->x.name = q->x.name = stringd(offset); r = argreg(i, offset, optype(ttob(q->type)), q->type->size, optype(ttob(caller[0]->type))); if (i < NUM_ARG_REGS) argregs[i] = r; offset = roundup(offset + q->type->size, 2); //i dunno if (varargs) p->sclass = AUTO; //variable args are always auto? else if (r && ncalls == 0 && //I dunno !isstruct(q->type) && !p->addressed && !(isfloat(q->type) && r->x.regnode->set == IREG)) { p->sclass = q->sclass = REGISTER; askregvar(p, r); assert(p->x.regnode && p->x.regnode->vbl == p); q->x = p->x; q->type = p->type; } else if (askregvar(p, rmap(ttob(p->type))) && r != NULL && (isint(p->type) || p->type == q->type)) { assert(q->sclass != REGISTER); p->sclass = q->sclass = REGISTER; q->type = p->type; } } assert(!caller[i]); //done with arguments, their individual offsets and maxargoffset have been set offset = 0; gencode(caller, callee); if (ncalls) //prepare to save return address if necessary(i.e. we do calls of our own) usedmask[IREG] |= ((unsigned)1)<<REG_RETADDR; usedmask[IREG] &= INT_CALLEE_SAVE; //limit saving to those we're responsible for usedmask[FREG] &= 0xfff00000; maxargoffset = roundup(maxargoffset, usedmask[FREG] ? 8 : 2); if (ncalls && maxargoffset < NUM_ARG_REGS*2) maxargoffset = NUM_ARG_REGS*2; sizefsave = 4*bitcount(usedmask[FREG]); //space needed to save the float regs sizeisave = 2*bitcount(usedmask[IREG]); //space needed to save the int regs framesize = roundup(maxargoffset + sizefsave //space for outgoing arguments, space for saving floats, + sizeisave + maxoffset, 2); //space for saving ints, space for locals //segment(CODE); //printf("\talign 16\n"); printf("%s:\n", f->x.name); i = maxargoffset + sizefsave - framesize; //I dunno but it's -v and it's never used! if (framesize > 0) print("\talu2I sp,sp,%d,smi,smbi\n", framesize); saved = maxargoffset; /space needed for outgoing arguments