m1_block * block( ARGIN_NOTNULL( M1_compiler *comp ) ) { m1_block *block; block = (m1_block *)m1_malloc(sizeof(m1_block)); init_symtab(&block->locals); return block; }
int calc_parser::init (char* Inputname, FILE* Outputdesc, int max_symb, int max_node) { inputname = Inputname; // Move name into parser object. outputdesc = Outputdesc; // Move desc into parser object. if (!init_symtab (max_symb)) return (0); // Initialize the symbol table. if (!init_ast (max_node)) return (0); // Initialize the AST. token.start = ""; // Make a blank symbol. token.end = token.start + 1; add_symbol (0, token.start, token.end); // Add it to the symbol table. n_errors = 0; // Set number of errors. max_errs = 10; // Set max number of errors. return (1); // Return OK. }
/************************************************************************** mcell_new_viz_output_block: Build a new VIZ output block, containing parameters for an output set for visualization. **************************************************************************/ void mcell_new_viz_output_block(struct viz_output_block *vizblk) { vizblk->frame_data_head = NULL; memset(&vizblk->viz_state_info, 0, sizeof(vizblk->viz_state_info)); vizblk->viz_mode = -1; vizblk->file_prefix_name = NULL; vizblk->viz_output_flag = 0; vizblk->species_viz_states = NULL; vizblk->dreamm_object_info = NULL; vizblk->dreamm_objects = NULL; vizblk->n_dreamm_objects = 0; vizblk->viz_children = init_symtab(1024); if (pointer_hash_init(&vizblk->parser_species_viz_states, 32)) mcell_allocfailed("Failed to initialize viz species states table."); }
PUBLIC int main(int argc, char **argv) { init_lex(); init_symtab(); init_type(); init_lib(); if (argc != 2) filename = "standard input"; else { filename = argv[1]; if ((yyin = fopen(filename, "r")) == NULL) { perror(filename); exit(1); } } yyparse(); return (err_count == 0 ? 0 : 1); }
/* * Decode the specified CTF buffer and optional symbol table and create a new * CTF container representing the symbolic debugging information. This code * can be used directly by the debugger, or it can be used as the engine for * ctf_fdopen() or ctf_open(), below. */ ctf_file_t * ctf_bufopen(const ctf_sect_t *ctfsect, const ctf_sect_t *symsect, const ctf_sect_t *strsect, int *errp) { const ctf_preamble_t *pp; ctf_header_t hp; ctf_file_t *fp; void *buf, *base; size_t size, hdrsz; int err; if (ctfsect == NULL || ((symsect == NULL) != (strsect == NULL))) return (ctf_set_open_errno(errp, EINVAL)); if (symsect != NULL && symsect->cts_entsize != sizeof (struct nlist) && symsect->cts_entsize != sizeof (struct nlist_64)) return (ctf_set_open_errno(errp, ECTF_SYMTAB)); if (symsect != NULL && symsect->cts_data == NULL) return (ctf_set_open_errno(errp, ECTF_SYMBAD)); if (strsect != NULL && strsect->cts_data == NULL) return (ctf_set_open_errno(errp, ECTF_STRBAD)); if (ctfsect->cts_size < sizeof (ctf_preamble_t)) return (ctf_set_open_errno(errp, ECTF_NOCTFBUF)); pp = (const ctf_preamble_t *)ctfsect->cts_data; ctf_dprintf("ctf_bufopen: magic=0x%x version=%u\n", pp->ctp_magic, pp->ctp_version); /* * Validate each part of the CTF header (either V1 or V2). * First, we validate the preamble (common to all versions). At that * point, we know specific header version, and can validate the * version-specific parts including section offsets and alignments. */ if (pp->ctp_magic != CTF_MAGIC) return (ctf_set_open_errno(errp, ECTF_NOCTFBUF)); if (pp->ctp_version == CTF_VERSION_2) { if (ctfsect->cts_size < sizeof (ctf_header_t)) return (ctf_set_open_errno(errp, ECTF_NOCTFBUF)); bcopy(ctfsect->cts_data, &hp, sizeof (hp)); hdrsz = sizeof (ctf_header_t); } else if (pp->ctp_version == CTF_VERSION_1) { const ctf_header_v1_t *h1p = (const ctf_header_v1_t *)ctfsect->cts_data; if (ctfsect->cts_size < sizeof (ctf_header_v1_t)) return (ctf_set_open_errno(errp, ECTF_NOCTFBUF)); bzero(&hp, sizeof (hp)); hp.cth_preamble = h1p->cth_preamble; hp.cth_objtoff = h1p->cth_objtoff; hp.cth_funcoff = h1p->cth_funcoff; hp.cth_typeoff = h1p->cth_typeoff; hp.cth_stroff = h1p->cth_stroff; hp.cth_strlen = h1p->cth_strlen; hdrsz = sizeof (ctf_header_v1_t); } else return (ctf_set_open_errno(errp, ECTF_CTFVERS)); size = hp.cth_stroff + hp.cth_strlen; ctf_dprintf("ctf_bufopen: uncompressed size=%lu\n", (ulong_t)size); if (hp.cth_lbloff > size || hp.cth_objtoff > size || hp.cth_funcoff > size || hp.cth_typeoff > size || hp.cth_stroff > size) return (ctf_set_open_errno(errp, ECTF_CORRUPT)); if (hp.cth_lbloff > hp.cth_objtoff || hp.cth_objtoff > hp.cth_funcoff || hp.cth_funcoff > hp.cth_typeoff || hp.cth_typeoff > hp.cth_stroff) return (ctf_set_open_errno(errp, ECTF_CORRUPT)); if ((hp.cth_lbloff & 3) || (hp.cth_objtoff & 1) || (hp.cth_funcoff & 1) || (hp.cth_typeoff & 3)) return (ctf_set_open_errno(errp, ECTF_CORRUPT)); /* * Once everything is determined to be valid, attempt to decompress * the CTF data buffer if it is compressed. Otherwise we just put * the data section's buffer pointer into ctf_buf, below. */ if (hp.cth_flags & CTF_F_COMPRESS) { size_t srclen, dstlen; const void *src; int rc = Z_OK; if (ctf_zopen(errp) == NULL) return (NULL); /* errp is set for us */ if ((base = ctf_data_alloc(size + hdrsz)) == MAP_FAILED) return (ctf_set_open_errno(errp, ECTF_ZALLOC)); bcopy(ctfsect->cts_data, base, hdrsz); ((ctf_preamble_t *)base)->ctp_flags &= ~CTF_F_COMPRESS; buf = (uchar_t *)base + hdrsz; src = (uchar_t *)ctfsect->cts_data + hdrsz; srclen = ctfsect->cts_size - hdrsz; dstlen = size; if ((rc = z_uncompress(buf, &dstlen, src, srclen)) != Z_OK) { ctf_dprintf("zlib inflate err: %s\n", z_strerror(rc)); ctf_data_free(base, size + hdrsz); return (ctf_set_open_errno(errp, ECTF_DECOMPRESS)); } if (dstlen != size) { ctf_dprintf("zlib inflate short -- got %lu of %lu " "bytes\n", (ulong_t)dstlen, (ulong_t)size); ctf_data_free(base, size + hdrsz); return (ctf_set_open_errno(errp, ECTF_CORRUPT)); } ctf_data_protect(base, size + hdrsz); } else { base = (void *)ctfsect->cts_data; buf = (uchar_t *)base + hdrsz; } /* * Once we have uncompressed and validated the CTF data buffer, we can * proceed with allocating a ctf_file_t and initializing it. */ if ((fp = ctf_alloc(sizeof (ctf_file_t))) == NULL) return (ctf_set_open_errno(errp, EAGAIN)); bzero(fp, sizeof (ctf_file_t)); fp->ctf_version = hp.cth_version; fp->ctf_fileops = &ctf_fileops[hp.cth_version]; bcopy(ctfsect, &fp->ctf_data, sizeof (ctf_sect_t)); if (symsect != NULL) { bcopy(symsect, &fp->ctf_symtab, sizeof (ctf_sect_t)); bcopy(strsect, &fp->ctf_strtab, sizeof (ctf_sect_t)); } if (fp->ctf_data.cts_name != NULL) fp->ctf_data.cts_name = ctf_strdup(fp->ctf_data.cts_name); if (fp->ctf_symtab.cts_name != NULL) fp->ctf_symtab.cts_name = ctf_strdup(fp->ctf_symtab.cts_name); if (fp->ctf_strtab.cts_name != NULL) fp->ctf_strtab.cts_name = ctf_strdup(fp->ctf_strtab.cts_name); if (fp->ctf_data.cts_name == NULL) fp->ctf_data.cts_name = _CTF_NULLSTR; if (fp->ctf_symtab.cts_name == NULL) fp->ctf_symtab.cts_name = _CTF_NULLSTR; if (fp->ctf_strtab.cts_name == NULL) fp->ctf_strtab.cts_name = _CTF_NULLSTR; fp->ctf_str[CTF_STRTAB_0].cts_strs = (const char *)buf + hp.cth_stroff; fp->ctf_str[CTF_STRTAB_0].cts_len = hp.cth_strlen; if (strsect != NULL) { fp->ctf_str[CTF_STRTAB_1].cts_strs = strsect->cts_data; fp->ctf_str[CTF_STRTAB_1].cts_len = strsect->cts_size; } fp->ctf_base = base; fp->ctf_buf = buf; fp->ctf_size = size + hdrsz; /* * If we have a parent container name and label, store the relocated * string pointers in the CTF container for easy access later. */ if (hp.cth_parlabel != 0) fp->ctf_parlabel = ctf_strptr(fp, hp.cth_parlabel); if (hp.cth_parname != 0) fp->ctf_parname = ctf_strptr(fp, hp.cth_parname); ctf_dprintf("ctf_bufopen: parent name %s (label %s)\n", fp->ctf_parname ? fp->ctf_parname : "<NULL>", fp->ctf_parlabel ? fp->ctf_parlabel : "<NULL>"); /* * If we have a symbol table section, allocate and initialize * the symtab translation table, pointed to by ctf_sxlate. */ if (symsect != NULL) { fp->ctf_nsyms = symsect->cts_size / symsect->cts_entsize; fp->ctf_sxlate = ctf_alloc(fp->ctf_nsyms * sizeof (uint_t)); if (fp->ctf_sxlate == NULL) { (void) ctf_set_open_errno(errp, EAGAIN); goto bad; } if ((err = init_symtab(fp, &hp, symsect, strsect)) != 0) { (void) ctf_set_open_errno(errp, err); goto bad; } } if ((err = init_types(fp, &hp)) != 0) { (void) ctf_set_open_errno(errp, err); goto bad; } /* * Initialize the ctf_lookup_by_name top-level dictionary. We keep an * array of type name prefixes and the corresponding ctf_hash to use. * NOTE: This code must be kept in sync with the code in ctf_update(). */ fp->ctf_lookups[0].ctl_prefix = "struct"; fp->ctf_lookups[0].ctl_len = strlen(fp->ctf_lookups[0].ctl_prefix); fp->ctf_lookups[0].ctl_hash = &fp->ctf_structs; fp->ctf_lookups[1].ctl_prefix = "union"; fp->ctf_lookups[1].ctl_len = strlen(fp->ctf_lookups[1].ctl_prefix); fp->ctf_lookups[1].ctl_hash = &fp->ctf_unions; fp->ctf_lookups[2].ctl_prefix = "enum"; fp->ctf_lookups[2].ctl_len = strlen(fp->ctf_lookups[2].ctl_prefix); fp->ctf_lookups[2].ctl_hash = &fp->ctf_enums; fp->ctf_lookups[3].ctl_prefix = _CTF_NULLSTR; fp->ctf_lookups[3].ctl_len = strlen(fp->ctf_lookups[3].ctl_prefix); fp->ctf_lookups[3].ctl_hash = &fp->ctf_names; fp->ctf_lookups[4].ctl_prefix = NULL; fp->ctf_lookups[4].ctl_len = 0; fp->ctf_lookups[4].ctl_hash = NULL; if (symsect != NULL) { if (symsect->cts_entsize == sizeof (struct nlist_64)) (void) ctf_setmodel(fp, CTF_MODEL_LP64); else if (symsect->cts_entsize == sizeof (struct nlist)) (void) ctf_setmodel(fp, CTF_MODEL_ILP32); else if (symsect->cts_entsize == sizeof (Elf64_Sym)) (void) ctf_setmodel(fp, CTF_MODEL_LP64); else (void) ctf_setmodel(fp, CTF_MODEL_ILP32); } else (void) ctf_setmodel(fp, CTF_MODEL_NATIVE); fp->ctf_refcnt = 1; return (fp); bad: ctf_close(fp); return (NULL); }
int main(int argc,char *argv[]) { if(argc!=2) { printf("Usage: %s <input file>\n",argv[0]); exit(1); } /* Load Optab */ char ***optab=NULL; int num_ops; if( (optab=load_optab("opfile",&num_ops)) == NULL) { printf("Optab generation failed\n"); exit(2); } /* Now let us load and initialize the symtab */ sym_tab *symtab=NULL; if( (symtab=init_symtab())==NULL ) { printf("Failed to initiate symtab\n"); free_optab(optab,num_ops); exit(3); } FILE *inp_file=NULL; if( (inp_file=fopen(argv[1],"r")) == NULL ) { printf("Failed to open input file\n"); free_optab(optab,num_ops); free_symtab(symtab); exit(4); } FILE *out_file=NULL; char *int_filename=NULL; if( (int_filename=(char *)malloc(strlen(argv[1])+5)) == NULL ) { printf("Out of memory\n"); free_optab(optab,num_ops); free_symtab(symtab); exit(5); } strcpy(int_filename,argv[1]); strcat(int_filename,"_INT"); FILE *int_file=NULL; if( (int_file=fopen(int_filename,"w+")) == NULL ) { printf("Failed to open intermediate file\n"); free_optab(optab,num_ops); free_symtab(symtab); free(int_filename); fclose(inp_file); exit(6); } /* And Here We Go */ long int LOCCTR=0; long int start_addr; char *read_line=NULL; size_t to_read = 0; ssize_t read_len; char *work_string=NULL; char *work_string2=NULL; char *prog_name=NULL; char *search_space=NULL; int start_loop=0; while( (read_len=getline(&read_line,&to_read,inp_file)) != -1 ) { if( (search_space=(char *)malloc(read_len+1)) == NULL ) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); free_optab(optab,num_ops); free_symtab(symtab); exit(10); } strcpy(search_space,""); sscanf(read_line,"%s",search_space); if(((*search_space)=='\0')||((*search_space)==';')) { free(search_space); search_space=NULL; free(read_line); read_line=NULL; continue; } free(search_space); search_space=NULL; if( (prog_name=malloc(read_len+1)) == NULL ) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(7); } if( (work_string=malloc( (read_len-strlen(prog_name)) +1) ) == NULL) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(prog_name); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(7); } sscanf(read_line,"%s%s",prog_name,work_string); if(!strcmp(work_string,"START")) { if( (work_string2=malloc((read_len-strlen(work_string))+1)) == NULL ) { free(work_string); free(prog_name); fclose(inp_file); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); printf("Out of memory\n"); exit(8); } char *searched=strstr(read_line,work_string); sscanf(searched+strlen(work_string),"%s",work_string2); if((*work_string2)=='\0') { printf("START directive requires an argument\n"); free(work_string); free(prog_name); free(work_string2); fclose(inp_file); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(9); } char *waste; LOCCTR=strtol(work_string2,&waste,16); if(waste == work_string2) { printf("Bad Assembly coding...\n"); printf("No suitable value for operand for START directive\n"); free(work_string); free(prog_name); free(work_string2); fclose(inp_file); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(9); } start_addr=LOCCTR; fprintf(int_file,"%lX\t%s\t%s\t%lX\n",LOCCTR,prog_name,work_string,start_addr); free(work_string2); free(prog_name); prog_name=NULL; free(work_string); work_string=NULL; free(read_line); read_line=NULL; to_read=0; while( (read_len=getline(&read_line,&to_read,inp_file)) != -1) { if( (search_space=(char *)malloc(read_len+1)) == NULL ) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); free_optab(optab,num_ops); free_symtab(symtab); exit(10); } strcpy(search_space,""); sscanf(read_line,"%s",search_space); if(((*search_space)=='\0')||((*search_space)==';')) { free(search_space); search_space=NULL; free(read_line); read_line=NULL; continue; } free(search_space); search_space=NULL; break; } start_loop=1; } else { LOCCTR=start_addr=0; start_loop=1; } if(start_loop) break; } // Check if the loop exited becuase the EOF was reached. If so exit... if(read_len == -1) { if(read_line) free(read_line); fclose(inp_file); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(0); } if( (work_string=malloc(read_len+1)) == NULL ) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); free_optab(optab,num_ops); free_symtab(symtab); exit(11); } char *label=NULL; char *pneumonic=NULL; char *operand=NULL; decode(read_line,read_len,&label,&pneumonic,&operand,int_filename,inp_file,int_file,NULL,optab,num_ops,symtab,LOCCTR,NULL); if(label) label[strlen(label)-1]='\0'; while(strcmp(pneumonic,"END")) { if(label) fprintf(int_file,"%lX\t%s\t%s\t%s\n",LOCCTR,label,pneumonic,operand); else { if(operand) fprintf(int_file,"%lX\t%s\t%s\n",LOCCTR,pneumonic,operand); else fprintf(int_file,"%lX\t%s\n",LOCCTR,pneumonic); } if(label) { label[strlen(label)-1]='\0'; if(search_symtab(symtab,label)>0) { printf("Duplicate symbol at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(12); } else { if(insert_symtab(label,symtab,LOCCTR)!=0) { printf("Failed to insert into symtab\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(13); } } } char *opcode,*waste; if( (opcode=search_optab(optab,pneumonic,num_ops)) != NULL) { LOCCTR+=3; } else if(!strcmp(pneumonic,"WORD")) { LOCCTR+=3; } else if(!strcmp(pneumonic,"RESW")) { if(operand == NULL) { printf("Bad assembly coding...\n"); printf("No value given for operand near RESW directive at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(23); } else { LOCCTR+=(3*strtol(operand,&waste,10)); if(waste == operand) { printf("Bad assembly coding...\n"); printf("No suitable value was found for allocating memory for RESW directive at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(21); } } } else if(!strcmp(pneumonic,"RESB")) { if(operand == NULL) { printf("Bad assembly coding...\n"); printf("No value given for operand near RESB directive at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(23); } else { LOCCTR+=(strtol(operand,&waste,10)); if(waste == operand) { printf("Bad assembly coding...\n"); printf("No suitable value was found for allocating memory for RESB directive at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(22); } } } else if(!strcmp(pneumonic,"BYTE")) { long int old_locctr=LOCCTR; if(!operand) { printf("Bad assembly coding...\n"); printf("No operand corresponding to BYTE directive at %lX\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(52); } if( ((*operand)=='c')|| ((*operand)=='C')) LOCCTR+=(strlen(operand)-3); else if( ((*operand)=='x')|| ((*operand)=='X')) { LOCCTR+=(strlen(operand)-3)/2; if( (strlen(operand)-3)%2) LOCCTR+=1; } else { printf("Bad assembly coding...\n"); printf("Wrong format for constant\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(14); } if( (LOCCTR-old_locctr)>MC_SIZE ) { printf("Constant value too long...\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(50); } if( !( (strlen(operand)>=4)&&(operand[1]=='\'')&&(operand[strlen(operand)-1]=='\'') ) ) { printf("Format for constant is convoluted at %lX...\n",old_locctr); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(51); } } else { printf("Opcode not found at %lX...\n",LOCCTR); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); free_optab(optab,num_ops); free_symtab(symtab); exit(15); } if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); read_line=NULL; to_read=0; while( (read_len=getline(&read_line,&to_read,inp_file)) != -1) { if( (search_space=(char *)malloc(read_len+1)) == NULL ) { printf("Out of memory\n"); fclose(inp_file); fclose(int_file); free(int_filename); free(read_line); free_optab(optab,num_ops); free_symtab(symtab); exit(10); } strcpy(search_space,""); sscanf(read_line,"%s",search_space); if(((*search_space)=='\0')||((*search_space)==';')) { free(search_space); search_space=NULL; free(read_line); read_line=NULL; continue; } free(search_space); search_space=NULL; break; } if(read_len == -1) { printf("Bad assembly coding...\n"); printf("End of file was reached before END directive\n"); fclose(int_file); fclose(inp_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(16); } label=NULL; pneumonic=NULL; operand=NULL; decode(read_line,read_len,&label,&pneumonic,&operand,int_filename,inp_file,int_file,NULL,optab,num_ops,symtab,LOCCTR,NULL); } //First Pass finished... Beginning second pass if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); fprintf(int_file,"%lX\t%s",LOCCTR,read_line); free(read_line); label=NULL; operand=NULL; pneumonic=NULL; read_line=NULL; fclose(inp_file); out_file=fopen("a.out","w+"); if( out_file == NULL) { printf("Failed to open output file...\n"); fclose(int_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(30); } //Write out the intermediate file and re-open it for second pass fclose(int_file); int_file=fopen(int_filename,"r"); if( int_file == NULL) { printf("Failed to open intermediate file...\n"); fclose(out_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(31); } int_file=fopen(int_filename,"r"); if( int_file == NULL) { printf("Failed to open intermediate file...\n"); fclose(out_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); exit(31); } char *read_raw_line=NULL; char string_loc[35]; while( (read_len=getline(&read_raw_line,&to_read,int_file)) != -1) { read_raw_line[strlen(read_raw_line)-1]='\0'; fprintf(out_file,"%s",read_raw_line); read_raw_line[strlen(read_raw_line)]='\n'; memset(mc,0,MC_SIZE); //We dont have to worry about about newlines spaces etc sscanf(read_raw_line,"%s",string_loc); read_line=read_raw_line+strlen(string_loc)+1; decode(read_line,read_len,&label,&pneumonic,&operand,int_filename,NULL,int_file,out_file,optab,num_ops,symtab,LOCCTR,read_raw_line); if(!label) fprintf(out_file,"\t"); if(!operand) fprintf(out_file,"\t"); char *opcode; long int add; if( (opcode=search_optab(optab,pneumonic,num_ops)) != NULL ) { sprintf(mc,"%s",opcode); if(operand) { if( (add=search_symtab(symtab,operand)) > 0 ) { sprintf(mc+strlen(mc),"%lX",add); } else { printf("Operand not available in symbol table\n"); fclose(int_file); fclose(out_file); free(int_filename); free(read_raw_line); free_optab(optab,num_ops); free_symtab(symtab); exit(35); } } } else if(!strcmp(pneumonic,"BYTE")) { convert_const(&operand); } read_raw_line[strlen(read_raw_line)-1]='\0'; fprintf(out_file,"\t\t%s\n",mc); if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); label=pneumonic=operand=NULL; free(read_raw_line); read_raw_line=NULL; } if(label) free(label); if(operand) free(operand); if(pneumonic) free(pneumonic); fclose(int_file); fclose(out_file); free(int_filename); free_optab(optab,num_ops); free_symtab(symtab); return 0; }