예제 #1
0
파일: linux_vm86.c 프로젝트: aosm/X11
static int
do_vm86(xf86Int10InfoPtr pInt)
{
    int retval, signo;

    xf86InterceptSignals(&signo);
    retval = vm86_rep(VM86S);
    xf86InterceptSignals(NULL);

    if (signo >= 0) {
	xf86DrvMsg(pInt->scrnIndex, X_ERROR,
	    "vm86() syscall generated signal %d.\n", signo);
	dump_registers(pInt);
	dump_code(pInt);
	stack_trace(pInt);
	return 0;
    }

    switch (VM86_TYPE(retval)) {
    case VM86_UNKNOWN:
	if (!vm86_GP_fault(pInt)) return 0;
	break;
    case VM86_STI:
	xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n");
	dump_registers(pInt);
	dump_code(pInt);
	stack_trace(pInt);
	return 0;
    case VM86_INTx:
	pInt->num = VM86_ARG(retval);
	if (!int_handler(pInt)) {
	    xf86DrvMsg(pInt->scrnIndex, X_ERROR,
		"Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval));
	    dump_registers(pInt);
	    dump_code(pInt);
	    stack_trace(pInt);
	    return 0;
	}
	/* I'm not sure yet what to do if we can handle ints */
	break;
    case VM86_SIGNAL:
	return 1;
	/*
	 * we used to warn here and bail out - but now the sigio stuff
	 * always fires signals at us. So we just ignore them for now.
	 */
	xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n");
	return 0;
    default:
	xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n",
		VM86_ARG(retval), VM86_TYPE(retval));
	dump_registers(pInt);
	dump_code(pInt);
	stack_trace(pInt);
	return 0;
    }

    return 1;
}
예제 #2
0
void po_dump_codebuf(Poco_cb *pcb, Code_buf *cbuf)
/*****************************************************************************
 * disassmble ops to stdout on the fly during compile; for debugging.
 ****************************************************************************/
{
	dump_code(pcb, stdout, cbuf->code_buf, (cbuf->code_pt - cbuf->code_buf));
}
예제 #3
0
HRESULT compile_subscript_stat(parser_ctx_t *parser, statement_t *stat, BOOL from_eval, unsigned *ret_off)
{
    unsigned off;
    HRESULT hres;

    TRACE("\n");

    hres = init_compiler(parser);
    if(FAILED(hres))
        return hres;

    off = parser->compiler->code_off;
    if(stat->next)
        hres = compile_block_statement(parser->compiler, stat);
    else
        hres = compile_statement(parser->compiler, NULL, stat);
    if(FAILED(hres))
        return hres;

    resolve_labels(parser->compiler, off);

    if(!from_eval && !push_instr(parser->compiler, OP_pop))
        return E_OUTOFMEMORY;
    if(!push_instr(parser->compiler, OP_ret))
        return E_OUTOFMEMORY;

    if(TRACE_ON(jscript_disas))
        dump_code(parser->compiler, off);

    *ret_off = off;
    return S_OK;
}
예제 #4
0
파일: xen_debug.c 프로젝트: MarginC/kame
void
do_coprocessor_error(struct pt_regs *regs, long error_code)
{

	printk("Copro error\n");
	dump_regs(regs);
	dump_code(regs->eip);
	do_exit();
}
예제 #5
0
파일: xen_debug.c 프로젝트: MarginC/kame
void
do_general_protection(struct pt_regs *regs, long error_code)
{

	HYPERVISOR_shared_info->events_mask = 0;
	printk("GPF\n");
	printk("Error Code: 0x%lx", error_code);
	dump_regs(regs);
	dump_code(regs->eip);
	do_exit();
}
예제 #6
0
파일: xen_debug.c 프로젝트: MarginC/kame
static void inline
do_trap(int trapnr, char *str, struct pt_regs *regs, long error_code)
{

	printk("FATAL:  Unhandled Trap (see mini-os:traps.c)");
	printf("%d %s", trapnr, str);
	dump_regs(regs);
	dump_code(regs->eip);

	do_exit();
}
예제 #7
0
파일: main.c 프로젝트: archiecobbs/jcvm
static void
dump_attr(_jc_env *env, int indent, _jc_classfile *cf,
	_jc_cf_attr *attrs, int num)
{
	int i;

	for (i = 0; i < num; i++) {
		_jc_cf_attr *const attr = &attrs[i];

		if (indent)
			printf("\t");
		printf("[%2d]\t\%s: ", i, attr->name);
		if (strcmp(attr->name, "ConstantValue") == 0) {
			dump_const(attr->u.ConstantValue);
			printf("\n");
		} else if (strcmp(attr->name, "SourceFile") == 0)
			printf("\"%s\"\n", attr->u.SourceFile);
		else if (strcmp(attr->name, "Exceptions") == 0) {
			const int num = attr->u.Exceptions.num_exceptions;
			int j;

			for (j = 0; j < num; j++) {
				printf("%s%s", attr->u.Exceptions.exceptions[j],
				    j == num - 1 ? "\n" : ", ");
			}
		} else if (strcmp(attr->name, "InnerClasses") == 0) {
			const int num = attr->u.InnerClasses.num_classes;
			int j;

			printf("%d classes\n", num);
			for (j = 0; j < num; j++) {
				_jc_cf_inner_class *const inner
				    = &attr->u.InnerClasses.classes[j];

				printf("\t[%2d]\tInner: %s\n", j,
				    inner->inner != NULL ?
				      inner->inner : "none");
				printf("\t\tOuter: %s\n",
				    inner->outer != NULL ?
				      inner->outer : "none");
				printf("\t\t Name: %s\n",
				    inner->name != NULL ? inner->name : "none");
				printf("\t\tFlags: 0x%04x\n",
				    inner->access_flags);
			}
		} else if (strcmp(attr->name, "Code") == 0)
			dump_code(env, cf, &attr->u.Code);
		else
			printf("length %d\n", attr->length);
	}
}
예제 #8
0
파일: ar.c 프로젝트: meesokim/z88dk
void dump_object( FILE *fp, char *filename )
{
    long obj_start = ftell(fp) - 8;		/* before signature */
    int org = -1;
    long fp_modname, fp_expr, fp_names, fp_extern, fp_code;

    if ( file_version >= 8 )
        ; /* no object ORG - ORG is now per section */
    else if ( file_version >= 5 )
        org		= (int) xfread_long( fp, filename );
    else
        org		= xfread_word( fp, filename );

    fp_modname	= xfread_long( fp, filename );
    fp_expr		= xfread_long( fp, filename );
    fp_names	= xfread_long( fp, filename );
    fp_extern	= xfread_long( fp, filename );
    fp_code		= xfread_long( fp, filename );

    /* module name */
    fseek( fp, obj_start + fp_modname, SEEK_SET );
    printf("  Name: %s\n", xfread_string( fp, filename ) );

    /* org */
    if ( org >= 0 )
        printf("  Org:  $%04X\n", org );

    /* names */
    if ( fp_names >= 0 )
        dump_names( fp, filename,
                    obj_start + fp_names,
                    obj_start + END( fp_extern, fp_modname ) );

    /* extern */
    if ( fp_extern >= 0 )
        dump_extern( fp, filename,
                     obj_start + fp_extern,
                     obj_start + fp_modname );

    /* expressions */
    if ( fp_expr >= 0 && opt_showexpr )
        dump_expr( fp, filename,
                   obj_start + fp_expr,
                   obj_start + END( fp_names, END( fp_extern, fp_modname ) ) );

    /* code */
    if ( fp_code >= 0 && opt_dump_code )
        dump_code( fp, filename, obj_start + fp_code );
}
예제 #9
0
//------------------------------------------------------------------------------
// Name: show_menu()
// Desc:
//------------------------------------------------------------------------------
void DumpState::show_menu() {

    State state;
    edb::v1::debugger_core->get_state(state);

    std::cout << "------------------------------------------------------------------------------\n";
    dump_registers(state);
    std::cout << "[" << hex_string<quint16>(*state["ss"]) << ":" << hex_string(state.stack_pointer()) << "]---------------------------------------------------------[stack]\n";
    dump_stack(state);

    const edb::address_t data_address = edb::v1::current_data_view_address();
    std::cout << "[" << hex_string<quint16>(*state["ds"]) << ":" << hex_string(data_address) << "]---------------------------------------------------------[ data]\n";
    dump_data(data_address);
    std::cout << "[" << hex_string<quint16>(*state["cs"]) << ":" << hex_string(state.instruction_pointer()) << "]---------------------------------------------------------[ code]\n";
    dump_code(state);
    std::cout << "------------------------------------------------------------------------------\n";
}
예제 #10
0
파일: dump.c 프로젝트: ahaym/trumpify
static int dump_node(pNode node)
{
  switch(node->type) {
  case literal: printf("\"%s\"", node->data); break;
  case symbol: 
    printf("{%s", node->data); 
    if(node->params) { printf("("); dump_atoms(node->params); printf(")"); };
    printf("}"); 
    break;
  case mapping: dump_node(node->params); printf(" > %s", node->data); break;
  case deref: printf("DEREF("); dump_node(node->params); printf(")"); break;
  case var_conddef: printf("%s << ", node->data); dump_node(node->params); 
      break;
  case var_def: printf("%s = ", node->data); dump_node(node->params); break;
  case code: printf("code:"); dump_code(node->data); break;
    break;
  };
};
예제 #11
0
void po_dump_file(Poco_cb *pcb)
/*****************************************************************************
 * disassemble an entire poco program.
 ****************************************************************************/
{
Func_frame *ff;
FILE *file;

if (( file = pcb->po_dump_file) == NULL)
	return;
ff = pcb->run.fff;
while (ff != NULL)
	{
	fprintf(file, ".......%s..%ld......\n", ff->name,
		ff->code_size);
	dump_code(pcb, file, ff->code_pt, ff->code_size);
	ff = ff->next;
	}
}
예제 #12
0
파일: bytecode.c 프로젝트: 40a/jq
void dump_disassembly(int indent, struct bytecode* bc) {
  if (bc->nclosures > 0) {
    printf("%*s[params: ", indent, "");
    jv params = jv_object_get(jv_copy(bc->debuginfo), jv_string("params"));
    for (int i=0; i<bc->nclosures; i++) {
      if (i) printf(", ");
      jv name = jv_array_get(jv_copy(params), i);
      printf("%s", jv_string_value(name));
      jv_free(name);
    }
    jv_free(params);
    printf("]\n");
  }
  dump_code(indent, bc);
  for (int i=0; i<bc->nsubfunctions; i++) {
    struct bytecode* subfn = bc->subfunctions[i];
    jv name = jv_object_get(jv_copy(subfn->debuginfo), jv_string("name"));
    printf("%*s%s:%d:\n", indent, "", jv_string_value(name), i);
    jv_free(name);
    dump_disassembly(indent+2, subfn);
  }
}
예제 #13
0
int main(int argc, char* argv[]) {

  bool all = false;
  bool string = false;
  bool stringdata = false;
  bool type = false;
  bool proto = false;
  bool field = false;
  bool meth = false;
  bool clsdef = false;
  bool clsdata = false;
  bool code = false;
  bool enarr = false;
  bool anno = false;
  bool debug = false;
  uint32_t ddebug_offset = 0;

  char c;
  static const struct option options[] = {
    { "all", no_argument, nullptr, 'a' },
    { "string", no_argument, nullptr, 's' },
    { "stringdata", no_argument, nullptr, 'S' },
    { "type", no_argument, nullptr, 't' },
    { "proto", no_argument, nullptr, 'p' },
    { "field", no_argument, nullptr, 'f' },
    { "meth", no_argument, nullptr, 'm' },
    { "clsdef", no_argument, nullptr, 'c' },
    { "clsdata", no_argument, nullptr, 'C' },
    { "code", no_argument, nullptr, 'x' },
    { "enarr", no_argument, nullptr, 'e' },
    { "anno", no_argument, nullptr, 'A' },
    { "debug", no_argument, nullptr, 'd' },
    { "ddebug", required_argument, nullptr, 'D' },
    { "clean", no_argument, (int*)&clean, 1 },
    { "help", no_argument, nullptr, 'h' },
    { nullptr, 0, nullptr, 0 },
  };

  while ((c = getopt_long(
            argc,
            argv,
            "asStpfmcCxeAdDh",
            &options[0],
            nullptr)) != -1) {
    switch (c) {
      case 'a':
        all = true;
        break;
      case 's':
        string = true;
        break;
      case 'S':
        stringdata = true;
        break;
      case 't':
        type = true;
        break;
      case 'p':
        proto = true;
        break;
      case 'f':
        field = true;
        break;
      case 'm':
        meth = true;
        break;
      case 'c':
        clsdef = true;
        break;
      case 'C':
        clsdata = true;
        break;
      case 'x':
        code = true;
        break;
      case 'e':
        enarr = true;
        break;
      case 'A':
        anno = true;
        break;
      case 'd':
        debug = true;
        break;
      case 'D':
        sscanf(optarg, "%x", &ddebug_offset);
        break;
      case 'h':
        puts(ddump_usage_string);
        return 0;
      case '?':
        return 1; // getopt_long has printed an error
      case 0:
        // we're handling a long-only option
        break;
      default:
        abort();
    }
  }

  if (optind == argc) {
    fprintf(stderr, "%s: no dex files given; use -h for help\n", argv[0]);
    return 1;
  }

  while (optind < argc) {
    const char* dexfile = argv[optind++];
    ddump_data rd;
    open_dex_file(dexfile, &rd);
    redump(format_map(&rd).c_str());
    if (string || all) {
      dump_strings(&rd);
    }
    if (stringdata || all) {
      dump_stringdata(&rd);
    }
    if (type || all) {
      dump_types(&rd);
    }
    if (proto || all) {
      dump_protos(&rd);
    }
    if (field || all) {
      dump_fields(&rd);
    }
    if (meth || all) {
      dump_methods(&rd);
    }
    if (clsdef || all) {
      dump_clsdefs(&rd);
    }
    if (clsdata || all) {
      dump_clsdata(&rd);
    }
    if (code || all) {
      dump_code(&rd);
    }
    if (enarr || all) {
      dump_enarr(&rd);
    }
    if (anno || all) {
      dump_anno(&rd);
    }
    if (debug || all) {
      dump_debug(&rd);
    }
    if (ddebug_offset != 0) {
      disassemble_debug(&rd, ddebug_offset);
    }
    fprintf(stdout, "\n");
    fflush(stdout);
  }

  return 0;
}
예제 #14
0
파일: dump.c 프로젝트: jasonlarkin/disorder
static void dump_ns(g95_namespace *ns) {
g95_symbol *sym, *result;
g95_namespace *p, *save;
g95_locus *where;
g95_annot *a;
int m, rank;

    save = g95_current_ns; 
    g95_current_ns = ns;
  
    where = &ns->declared_at;
    sym = ns->proc_name;

    switch(ns->state) {
    case COMP_PROGRAM:
	if (ns->unit_name == NULL)
	    dumpf("program(None, %L)\n", where);
	else
	    dumpf("program(%S,%L)\n", ns->unit_name, where);

	break;

    case COMP_MODULE:
	dumpf("module(%S,%L,%L)\n", sym->name, where,
	      &ns->proc_name->declared_at);
	break;

    case COMP_SUBROUTINE:
	dumpf("subroutine(%S,%S,%L,", sym->name, sym->module,
	      &ns->proc_name->declared_at);
	dump_formal(ns->proc_name);
	dumpf(")\n");
	break;

    case COMP_FUNCTION:
	result = sym->result;
	rank = (result->as == NULL) ? 0 : result->as->rank;

	dumpf("function(%S,%S,%L,%S,%d,%d,", sym->name, sym->module,
	      &ns->proc_name->declared_at, g95_typename(&result->ts), rank,
	      result->attr.pointer);

	dump_formal(ns->proc_name);
	dumpf(")\n");
	break;

    case COMP_BLOCK_DATA:
	if (ns->proc_name->name == NULL)
	    dumpf("block_data(None,%L)\n", where);
	else
	    dumpf("block_data(%S,%L)\n", sym->name, where);

	break;

    case COMP_NONE:
	return;

    default:
	g95_internal_error("dump_ns(): Bad state");
    }

    g95_traverse_symtree(ns, g95_clear_sym_mark);
    g95_traverse_symtree(ns, dump_symtree);

    dump_common(ns->common_root);

    for(a=ns->annotation; a; a=a->next)
	switch(a->type) {
	case ANNOT_PARAMETER:
	    dumpf("parameter_use(%p,%L)\n", a->u.sym, &a->where);
	    break;

	case ANNOT_DERIVED:
	    dumpf("derived_use(%p,%L)\n", a->u.sym, &a->where);
	    break;

	case ANNOT_LABEL:
	    dumpf("label_use(%p,%L)\n", a->u.sym, &a->where);
	    break;

	case ANNOT_OPERATOR:
	    dumpf("operator_use(%p,%L)\n", a->u.sym, &a->where);
	    break;

	default:
	    g95_internal_error("init_dump(): Bad type");
	}

    m = dump_code(ns->code);
    dumpf("add_code(%C)\n", m);

    if (m != 0)
	dumpf("del %C\n", m);

    for(p=ns->contained; p; p=p->sibling)
	dump_ns(p);

    dumpf("end()\n");
    g95_current_ns = save;
}
예제 #15
0
파일: linux_vm86.c 프로젝트: aosm/X11
/* vm86 fault handling */
static Bool
vm86_GP_fault(xf86Int10InfoPtr pInt)
{
    unsigned char *csp, *lina;
    CARD32 org_eip;
    int pref_seg;
    int done, is_rep, prefix66, prefix67;

    csp = lina = SEG_ADR((unsigned char *), X86_CS, IP);

    is_rep = 0;
    prefix66 = prefix67 = 0;
    pref_seg = -1;

    /* eat up prefixes */
    done = 0;
    do {
	switch (MEM_RB(pInt, (int)csp++)) {
	case 0x66:      /* operand prefix */  prefix66=1; break;
	case 0x67:      /* address prefix */  prefix67=1; break;
	case 0x2e:      /* CS */              pref_seg=X86_CS; break;
	case 0x3e:      /* DS */              pref_seg=X86_DS; break;
	case 0x26:      /* ES */              pref_seg=X86_ES; break;
	case 0x36:      /* SS */              pref_seg=X86_SS; break;
	case 0x65:      /* GS */              pref_seg=X86_GS; break;
	case 0x64:      /* FS */              pref_seg=X86_FS; break;
	case 0xf0:      /* lock */            break;
	case 0xf2:      /* repnz */
	case 0xf3:      /* rep */             is_rep=1; break;
	default: done=1;
	}
    } while (!done);
    csp--;   /* oops one too many */
    org_eip = X86_EIP;
    X86_IP += (csp - lina);

    switch (MEM_RB(pInt, (int)csp)) {
    case 0x6c:                    /* insb */
	/* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx
	 * but is anyone using extended regs in real mode? */
	/* WARNING: no test for DI wrapping! */
	X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI),
				X86_FLAGS & DF, is_rep ? LWECX : 1);
	if (is_rep) LWECX_ZERO;
	X86_IP++;
	break;

    case 0x6d:                  /* (rep) insw / insd */
	/* NOTE: ES can't be overwritten */
	/* WARNING: no test for _DI wrapping! */
	if (prefix66) {
	    X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI),
				   X86_EFLAGS & DF, is_rep ? LWECX : 1);
	}
	else {
	    X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI),
				   X86_FLAGS & DF, is_rep ? LWECX : 1);
	}
	if (is_rep) LWECX_ZERO;
	X86_IP++;
	break;

    case 0x6e:                  /* (rep) outsb */
	if (pref_seg < 0) pref_seg = X86_DS;
	/* WARNING: no test for _SI wrapping! */
	X86_SI += port_rep_outb(pInt, X86_DX, (CARD32)LIN_PREF_SI,
			        X86_FLAGS & DF, is_rep ? LWECX : 1);
	if (is_rep) LWECX_ZERO;
	X86_IP++;
	break;

    case 0x6f:                  /* (rep) outsw / outsd */
	if (pref_seg < 0) pref_seg = X86_DS;
	/* WARNING: no test for _SI wrapping! */
	if (prefix66) {
	    X86_SI += port_rep_outl(pInt, X86_DX, (CARD32)LIN_PREF_SI,
				    X86_EFLAGS & DF, is_rep ? LWECX : 1);
	}
	else {
	    X86_SI += port_rep_outw(pInt, X86_DX, (CARD32)LIN_PREF_SI,
				    X86_FLAGS & DF, is_rep ? LWECX : 1);
	}
	if (is_rep) LWECX_ZERO;
	X86_IP++;
	break;

    case 0xe5:                  /* inw xx, inl xx */
	if (prefix66) X86_EAX = x_inl(csp[1]);
	else X86_AX = x_inw(csp[1]);
	X86_IP += 2;
	break;

    case 0xe4:                  /* inb xx */
	X86_AL = x_inb(csp[1]);
	X86_IP += 2;
	break;

    case 0xed:                  /* inw dx, inl dx */
	if (prefix66) X86_EAX = x_inl(X86_DX);
	else X86_AX = x_inw(X86_DX);
	X86_IP += 1;
	break;

    case 0xec:                  /* inb dx */
	X86_AL = x_inb(X86_DX);
	X86_IP += 1;
	break;

    case 0xe7:                  /* outw xx */
	if (prefix66) x_outl(csp[1], X86_EAX);
	else x_outw(csp[1], X86_AX);
	X86_IP += 2;
	break;

    case 0xe6:                  /* outb xx */
	x_outb(csp[1], X86_AL);
	X86_IP += 2;
	break;

    case 0xef:                  /* outw dx */
	if (prefix66) x_outl(X86_DX, X86_EAX);
	else x_outw(X86_DX, X86_AX);
	X86_IP += 1;
	break;

    case 0xee:                  /* outb dx */
	x_outb(X86_DX, X86_AL);
	X86_IP += 1;
	break;

    case 0xf4:
#ifdef DEBUG
	ErrorF("hlt at %p\n", lina);
#endif
	return FALSE;

    case 0x0f:
	xf86DrvMsg(pInt->scrnIndex, X_ERROR,
	    "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, X86_EIP);
	goto op0ferr;

    default:
	xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n");

    op0ferr:
	dump_registers(pInt);
	stack_trace(pInt);
	dump_code(pInt);
	xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n");
	return FALSE;
    }                           /* end of switch() */
    return TRUE;
}
예제 #16
0
int
main(int argc, char *argv[])
{
  int c;
  gp_boolean usage = false;
  int display_flags;

  char temp_buf[12];
  char *processor_name;
  const struct px *processor_info;
  proc_class_t processor_class;

  gp_init();

#define DISPLAY_NOTHING 0
#define DISPLAY_DIR     1
#define DISPLAY_SYM     2
#define DISPLAY_ROM     4
#define DISPLAY_SRC     8
#define DISPLAY_MESS    16
#define DISPLAY_ALL     0xff

  display_flags = DISPLAY_NOTHING;
  while ((c = getopt_long(argc, argv, GET_OPTIONS, longopts, NULL)) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = true;
      break;

    case 'a':
      display_flags = DISPLAY_ALL;
      break;

    case 'd':
      display_flags |= DISPLAY_DIR;
      break;

    case 's':
      display_flags |= DISPLAY_SYM;
      break;

    case 'r':
      display_flags |= DISPLAY_ROM;
      break;

    case 'l':
      display_flags |= DISPLAY_SRC;
      break;

    case 'm':
      display_flags |= DISPLAY_MESS;
      break;

    case 'v':
      fprintf(stderr, "%s\n", GPVC_VERSION_STRING);
      exit(0);
    }

    if (usage) {
      break;
    }
  }

  if ((optind + 1) == argc) {
    strncpy(filename, argv[optind], sizeof(filename));
  }
  else {
    usage = 1;
  }

  if (display_flags == DISPLAY_NOTHING) {
    display_flags = DISPLAY_ALL;
  }

  if (usage) {
    show_usage();
  }

  codefile = fopen(filename,"rb");
  if (codefile == NULL) {
    perror(filename);
    exit(1);
  }

  /* Start off by reading the directory block */
  main_dir = read_directory();

  /* Determine if byte address and org are different */
  processor_name = substr(temp_buf,
                          sizeof(temp_buf),
                          &main_dir->dir[COD_DIR_PROCESSOR],
                          8);

  processor_info = gp_find_processor(processor_name);
  processor_class = gp_processor_class(processor_info);

  if (display_flags & DISPLAY_DIR) {
    dump_directory_blocks();
  }

  if (display_flags & DISPLAY_ROM) {
    dump_code(processor_class);
  }

  if (display_flags & DISPLAY_SYM) {
    dump_symbols();
    dump_lsymbols();
    dump_local_vars(processor_class);
  }

  dump_source_files();

  if (display_flags & DISPLAY_SRC) {
    dump_line_symbols();
  }

  if (display_flags & DISPLAY_MESS) {
    dump_message_area();
  }

  return EXIT_SUCCESS;
}
예제 #17
0
파일: main.c 프로젝트: swansontec/outline2c
/**
 * Program entry point. Constructs and launches the main program object.
 */
int main(int argc, char *argv[])
{
    Pool pool = pool_init(0x10000); /* 64K block size */
    Options opt = options_init();
    Source *in;
    Scope *scope = scope_new(&pool, 0);
    ListBuilder code = list_builder_init(&pool);

    /* Read the options: */
    if (!options_parse(&opt, argc, argv)) {
        options_usage(argv[0]);
        goto error;
    }

    /* Determine output file name: */
    if (!string_size(opt.name_out)) {
        if (string_rmatch(opt.name_in, string_from_k(".ol")) != 3) {
            fprintf(stderr, "error: If no output file is specified, the input file name must end with \".ol\".\n");
            goto error;
        }
        opt.name_out = string(opt.name_in.p, opt.name_in.end - 3);
    }

    /* Input stream: */
    in = source_load(&pool, opt.name_in);
    if (!in) {
        fprintf(stderr, "error: Could not open source file \"%s\"\n", opt.name_in.p);
        goto error;
    }

    /* Keywords: */
    scope_add(scope, &pool, string_from_k("macro"), dynamic(type_keyword,
              keyword_new(&pool, parse_macro)));
    scope_add(scope, &pool, string_from_k("outline"), dynamic(type_keyword,
              keyword_new(&pool, parse_outline)));
    scope_add(scope, &pool, string_from_k("union"), dynamic(type_keyword,
              keyword_new(&pool, parse_union)));
    scope_add(scope, &pool, string_from_k("map"), dynamic(type_keyword,
              keyword_new(&pool, parse_map)));
    scope_add(scope, &pool, string_from_k("for"), dynamic(type_keyword,
              keyword_new(&pool, parse_for)));
    scope_add(scope, &pool, string_from_k("include"), dynamic(type_keyword,
              keyword_new(&pool, parse_include)));

    /* Do outline2c stuff: */
    if (!parse_code(&pool, in, scope, out_list_builder(&code))) goto error;
    if (opt.debug) {
        printf("--- AST: ---\n");
        dump_code(code.first, 0);
        printf("\n");
    }
    if (!main_generate(&pool, code.first, &opt)) goto error;

    /* Clean up: */
    pool_free(&pool);
    return 0;

error:
    pool_free(&pool);
    return 1;
}
예제 #18
0
파일: dump.c 프로젝트: jasonlarkin/disorder
static int dump_code(g95_code *c) {
int m, n, list_size, *list, node[2];
g95_forall_iterator *f;
g95_filepos *filepos;
g95_inquire *inquire;
g95_close *close;
g95_flush *flush;
g95_alloc *alloc;
g95_open *open;
g95_wait *wait;
g95_case *sel;
g95_code *d;
g95_dt *dt;

    if (c == NULL)
	return 0;

    n = st_n++;
    list = NULL;
    list_size = 0;

    dumpf("%C = []\n", n);

    for(; c; c=c->next) {
	switch(c->type) {
	case EXEC_CONTINUE:
	case EXEC_NOP:
	case EXEC_DT_END:
	    dumpf("%C.append(st_nop(%L", n, &c->where);
	    break;

	case EXEC_ASSIGN:
	    dumpf("%C.append(st_assign(%L,", n, &c->where);
	    dump_expr(c->expr);
	    dump_char(',');
	    dump_expr(c->expr2);
	    break;

	case EXEC_POINTER_ASSIGN:
	    dumpf("%C.append(st_ptr_assign(%L,", n, &c->where);
	    dump_expr(c->expr);
	    dump_char(',');
	    dump_expr(c->expr2);
	    break;

	case EXEC_GOTO:
	    dumpf("%C.append(st_goto(%L, %d", n, &c->where, c->label->value);
	    break;

	case EXEC_PAUSE:
	    dumpf("%C.append(st_pause(%L", n, &c->where);
	    break;

	case EXEC_STOP:
	    dumpf("%C.append(st_stop(%L", n, &c->where);
	    break;

	case EXEC_RETURN:
	    dumpf("%C.append(st_return(%L", n, &c->where);
	    if (c->expr != NULL) {
		dumpf(",rc=");
		dump_expr(c->expr);
	    }

	    break;

	case EXEC_IF:
	    node[0] = dump_code(c->block);
	    node[1] = dump_code(c->ext.block);
	    list = node;
	    list_size = 2;

	    dumpf("%C.append(st_if(%L,", n, &c->where);
	    dump_expr(c->expr);
	    dumpf(",%C,%C", node[0], node[1]);
	    break;

	case EXEC_DO_WHILE:
	    node[0] = dump_code(c->block);
	    list = node;
	    list_size = 1;

	    dumpf("%C.append(st_do_while(%L,", n, &c->where, node[0]);
	    dump_expr(c->expr);

	    dumpf(",%C", node[0]);

	    if (c->sym != NULL)
		dumpf(",label='%s'", c->sym->name);

	    break;

	case EXEC_DO:
	    node[0] = dump_code(c->block);
	    list = node;
	    list_size = 1;

	    dumpf("%C.append(st_do(%L, ", n, &c->where);
	    dump_expr(c->ext.iterator->var);

	    dump_char(',');
	    dump_expr(c->ext.iterator->start);

	    dump_char(',');
	    dump_expr(c->ext.iterator->end);

	    dump_char(',');
	    dump_expr(c->ext.iterator->step);

	    dumpf(",%C", node[0]);

	    if (c->sym != NULL)
		dumpf(",label='%s'", c->sym->name);

	    break;

	case EXEC_OPEN:
	    open = c->ext.open;
	    dumpf("%C.append(st_open(%L", n, &c->where);

	    if (open->unit != NULL) {
		dumpf(",unit=");
		dump_expr(open->unit);
	    }

	    if (open->file != NULL) {
		dumpf(",file=");
		dump_expr(open->file);
	    }

	    if (open->status != NULL) {
		dumpf(",status=");
		dump_expr(open->status);
	    }

	    if (open->access != NULL) {
		dumpf(",access=");
		dump_expr(open->access);
	    }

	    if (open->form != NULL) {
		dumpf(",form=");
		dump_expr(open->form);
	    }

	    if (open->recl != NULL) {
		dumpf(",recl=");
		dump_expr(open->recl);
	    }

	    if (open->decimal != NULL) {
		dumpf(",decimal=");
		dump_expr(open->decimal);
	    }

	    if (open->blank != NULL) {
		dumpf(",blank=");
		dump_expr(open->position);
	    }

	    if (open->position != NULL) {
		dumpf(",position=");
		dump_expr(open->position);
	    }

	    if (open->action != NULL) {
		dumpf(",action=");
		dump_expr(open->action);
	    }

	    if (open->delim != NULL) {
		dumpf(",delim=");
		dump_expr(open->delim);
	    }

	    if (open->pad != NULL) {
		dumpf(",pad=");
		dump_expr(open->pad);
	    }

	    if (open->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(open->iostat);
	    }

	    if (open->err != NULL)
		dumpf(",err=%d", open->err->value);

	    break;

	case EXEC_CLOSE:
	    close = c->ext.close;
	    dumpf("%C.append(st_close(%L", n, &c->where);

	    if (close->unit != NULL) {
		dumpf(",unit=");
		dump_expr(close->unit);
	    }

	    if (close->status != NULL) {
		dumpf(",status=");
		dump_expr(close->status);
	    }

	    if (close->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(close->iostat);
	    }

	    if (close->err != NULL)
		dumpf(",err=%d", close->err->value);

	    break;

	case EXEC_BACKSPACE:
	    dumpf("%C.append(st_backspace(%L", n, &c->where);
	    goto show_filepos;

	case EXEC_ENDFILE:
	    dumpf("%C.append(st_endfile(%L", n, &c->where);
	    goto show_filepos;

	case EXEC_REWIND:
	    dumpf("%C.append(st_rewind(%L", n, &c->where);

	show_filepos:
	    filepos = c->ext.filepos;

	    if (filepos->unit != NULL) {
		dumpf(",unit=");
		dump_expr(filepos->unit);
	    }

	    if (filepos->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(filepos->iostat);
	    }

	    if (filepos->err != NULL)
		dumpf(",err=%d", filepos->err->value);

	    break;

	case EXEC_INQUIRE:
	    dumpf("%C.append(st_inquire(%L", n, &c->where);

	    inquire = c->ext.inquire;

	    if (inquire->unit != NULL) {
		dumpf(",unit=");
		dump_expr(inquire->unit);
	    }

	    if (inquire->file != NULL) {
		dumpf(",file=");
		dump_expr(inquire->file);
	    }

	    if (inquire->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(inquire->iostat);
	    }

	    if (inquire->exist != NULL) {
		dumpf(",exist=");
		dump_expr(inquire->exist);
	    }

	    if (inquire->opened != NULL) {
		dumpf(",opened=");
		dump_expr(inquire->opened);
	    }

	    if (inquire->number != NULL) {
		dumpf(",number=");
		dump_expr(inquire->number);
	    }

	    if (inquire->named != NULL) {
		dumpf(",named=");
		dump_expr(inquire->named);
	    }

	    if (inquire->name != NULL) {
		dumpf(",name=");
		dump_expr(inquire->name);
	    }

	    if (inquire->access != NULL) {
		dumpf(",access=");
		dump_expr(inquire->access);
	    }

	    if (inquire->sequential != NULL) {
		dumpf(",sequential=");
		dump_expr(inquire->sequential);
	    }

	    if (inquire->direct != NULL) {
		dumpf(",direct=");
		dump_expr(inquire->direct);
	    }

	    if (inquire->form != NULL) {
		dumpf(",form=");
		dump_expr(inquire->form);
	    }

	    if (inquire->formatted != NULL) {
		dumpf(",formatted=");
		dump_expr(inquire->formatted);
	    }

	    if (inquire->unformatted != NULL) {
		dumpf(",unformatted=");
		dump_expr(inquire->unformatted);
	    }

	    if (inquire->recl != NULL) {
		dumpf(",recl=");
		dump_expr(inquire->recl);
	    }

	    if (inquire->nextrec != NULL) {
		dumpf(",nextrec=");
		dump_expr(inquire->nextrec);
	    }

	    if (inquire->blank != NULL) {
		dumpf(",blank=");
		dump_expr(inquire->blank);
	    }

	    if (inquire->position != NULL) {
		dumpf(",position=");
		dump_expr(inquire->position);
	    }

	    if (inquire->action != NULL) {
		dumpf(",action=");
		dump_expr(inquire->action);
	    }

	    if (inquire->read != NULL) {
		dumpf(",read=");
		dump_expr(inquire->read);
	    }

	    if (inquire->write != NULL) {
		dumpf(",write=");
		dump_expr(inquire->write);
	    }

	    if (inquire->readwrite != NULL) {
		dumpf(",readwrite=");
		dump_expr(inquire->readwrite);
	    }

	    if (inquire->delim != NULL) {
		dumpf(",delim=");
		dump_expr(inquire->delim);
	    }

	    if (inquire->pad != NULL) {
		dumpf(",pad=");
		dump_expr(inquire->pad);
	    }

	    if (inquire->pos != NULL) {
		dumpf(",pos=");
		dump_expr(inquire->pos);
	    }

	    if (inquire->iolength != NULL) {
		dumpf(",iolength=");
		dump_expr(inquire->iolength);
	    }

	    if (inquire->size != NULL) {
		dumpf(",size=");
		dump_expr(inquire->size);
	    }

	    if (inquire->err != NULL)
		dumpf(",err=%d", inquire->err->value);

	    break;

	case EXEC_FLUSH:
	    dumpf("%C.append(st_flush(%L", n, &c->where);

	    flush = c->ext.flush;

	    if (flush->unit != NULL) {
		dumpf(",unit=");
		dump_expr(flush->unit);
	    }

	    if (flush->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(flush->iostat);
	    }

	    if (flush->iomsg != NULL) {
		dumpf(",iomsg=");
		dump_expr(flush->iomsg);
	    }

	    if (flush->err != NULL)
		dumpf(",err=%d", flush->err->value);

	    break;

	case EXEC_WAIT:
	    dumpf("%C.append(st_wait(%L", n, &c->where);

	    wait = c->ext.wait;

	    if (wait->unit != NULL) {
		dumpf(",unit=");
		dump_expr(wait->unit);
	    }

	    if (wait->id != NULL) {
		dumpf(",id=");
		dump_expr(wait->id);
	    }

	    if (wait->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(wait->iostat);
	    }

	    if (wait->iomsg != NULL) {
		dumpf(",iomsg=");
		dump_expr(wait->iomsg);
	    }

	    if (wait->err != NULL)
		dumpf(",err=%d", wait->err->value);

	    if (wait->end != NULL)
		dumpf(",end=%d", wait->end->value);

	    if (wait->eor != NULL)
		dumpf(",eof=%d", wait->eor->value);

	    break;

	case EXEC_IOLENGTH:
	    dumpf("%C.append(st_iolength(%L,", n, &c->where);
	    dump_expr(c->expr);
	    break;

	case EXEC_WRITE:
	    dumpf("%C.append(st_write(%L", n, &c->where);
	    goto show_dt;

	case EXEC_READ:
	    dumpf("%C.append(st_read(%L", n, &c->where);

	show_dt:
	    dt = c->ext.dt;

	    if (dt->io_unit->ts.type == BT_INTEGER)
		dumpf(",unit=");

	    else
		dumpf(",internal_unit=");

	    dump_expr(dt->io_unit);

	    if (dt->format_expr != NULL) {
		dumpf(",format_expr=");
		dump_expr(dt->format_expr);
	    }

	    if (dt->rec != NULL) {
		dumpf(",rec=");
		dump_expr(dt->rec);
	    }

	    if (dt->advance != NULL) {
		dumpf(",advance=");
		dump_expr(dt->advance);
	    }

	    if (dt->iostat != NULL) {
		dumpf(",iostat=");
		dump_expr(dt->iostat);
	    }

	    if (dt->size != NULL) {
		dumpf(",size=");
		dump_expr(dt->size);
	    }

	    if (dt->pos != NULL) {
		dumpf(",pos=");
		dump_expr(dt->pos);
	    }

	    if (dt->decimal != NULL) {
		dumpf(",decimal=");
		dump_expr(dt->decimal);
	    }

	    if (dt->namelist != NULL)
		dumpf(",namelist=(%S,%L)", dt->namelist->name,
		      &dt->namelist_where);

	    if (dt->format_label != NULL)
		dumpf(",format_label=%d", dt->format_label->value);

	    if (dt->err != NULL)
		dumpf(",err=%d", dt->err->value);

	    if (dt->end != NULL)
		dumpf(",end=%d", dt->end->value);

	    if (dt->eor != NULL)
		dumpf(",eof=%d", dt->eor->value);

	    break;

	case EXEC_TRANSFER:
	    dumpf("%C.append(st_transfer(%L,%d,", n, &c->expr->where,
		  c->ext.transfer == M_READ);
	    dump_expr(c->expr);
	    break;

	case EXEC_ALLOCATE:
	    dumpf("%C.append(st_allocate(%L,", n, &c->where);
	    goto show_alloc;

	case EXEC_DEALLOCATE:
	    dumpf("%C.append(st_deallocate(%L,", n, &c->where);

	show_alloc:
	    dumpf("[");
	    alloc = c->ext.alloc_list;

	    while(alloc != NULL) {
		dump_expr(alloc->expr);
		
		if (alloc->next != NULL)
		    dump_char(',');

		alloc = alloc->next;
	    }

	    dumpf("]");

	    if (c->expr != NULL) {
		dumpf(",stat=");
		dump_expr(c->expr);
	    }

	    break;

	case EXEC_ARITHMETIC_IF:
	    dumpf("%C.append(st_arith_if(%L,", n, &c->where);
	    dump_expr(c->expr);
	    dumpf(", %d, %d, %d", c->label->value, c->label2->value,
		  c->label3->value);
	    break;

	case EXEC_LABEL_ASSIGN:
	    dumpf("%C.append(st_label_assign(%L,", n, &c->where);
	    dump_expr(c->expr);
	    dumpf(", %d", c->label->value);
	    break;

	case EXEC_SELECT:
	    for(d=c->block; d; d=d->block)
		list_size++;

	    list = g95_getmem(list_size * sizeof(int));
	    m = 0;

	    for(d=c->block; d; d=d->block)
		list[m++] = dump_code(d->next);

	    dumpf("%C.append(st_select(%L, ", n, &c->where);

	    dump_expr(c->expr);
	    dumpf(",[");

	    m = 0;

	    for(d=c->block; d; d=d->next) {
		dumpf("[");

		for(sel=d->ext.case_list; sel; sel=sel->next) {
		    dump_char('(');

		    if (sel->low == NULL)
			dumpf("None");
		    else
			dump_expr(sel->low);

		    dumpf(",");

		    if (sel->high == NULL)
			dumpf("None");
		    else
			dump_expr(sel->high);
		}

		dumpf("],%C,", list[m++]);
	    }

	    dump_char(']');
	    break;

	case EXEC_CYCLE:
	    dumpf("%C.append(st_cycle(%L", n, &c->where);

	    if (c->sym != NULL)
		dumpf(",label=%p", c->sym);

	    break;

	case EXEC_EXIT:
	    dumpf("%C.append(st_exit(%L", n, &c->where);

	    if (c->sym != NULL)
		dumpf(",label=%p", c->sym);

	    break;

	case EXEC_ENTRY:
	    dumpf("%C.append(st_entry(%L,'%s',", n, &c->where, c->sym->name);
	    dump_formal(c->sym);
	    break;

	case EXEC_WHERE:
	    for(d=c->block; d; d=d->block)
		list_size++;

	    list = g95_getmem(list_size * sizeof(int));

	    m = 0;
	    for(d=c->block; d; d=d->block)
		list[m++] = dump_code(d->next);

	    dumpf("%C.append(st_where(%L, [", n, &c->where);

	    m = 0;
	    for(d=c->block; d; d=d->block) {
		dump_char('(');

		if (d->expr == NULL)
		    dumpf("None");
		else
		    dump_expr(d->expr);

		dumpf(",%C),", list[m++]);
	    }

	    dump_char(']');
	    break;

	case EXEC_FORALL:
	    node[0] = dump_code(c->block);
	    list = node;
	    list_size = 1;

	    dumpf("%C.append(st_forall(%L, [", n, &c->where);

	    for(f=c->ext.forall_iterator; f; f=f->next) {
		dump_char('(');
		dump_expr(f->var);
		dump_char(',');
		dump_expr(f->start);
		dump_char(',');
		dump_expr(f->end);
		dump_char(',');
		dump_expr(f->stride);
		dump_char(')');

		if (f->next != NULL)
		    dump_char(',');
	    }

	    dumpf("], %C", node[0]);

	    if (c->expr != NULL) {
		dumpf(", mask=");
		dump_expr(c->expr);
	    }

	    break;

	case EXEC_CALL:
	    dumpf("%C.append(st_call(%L,", n, &c->where);
	    dump_name(c->sym, c->ext.sub.isym);
	    dump_char(',');
	    dump_actual(c->ext.sub.actual);
	    break;

	default:
	    g95_internal_error("dump_code(): Bad code");
	    break;
	}

	if (c->here != NULL)
	    dumpf(",here=%d", c->here->value);

	dumpf("))\n");

	for(m=0; m<list_size; m++)
	    if (list[m] != 0)
		dumpf("del %C\n", list[m]);

	list_size = 0;

	if (list != NULL && list != node)
	    g95_free(list);
    }

    return n;
}
예제 #19
0
int main(int argc, char *argv[])
{
  extern int optind;
  unsigned int buffer_size;
  int c,usage=0;
  int display_flags;
  Directory *dir;

  gp_init();

  byte_addr = 0;

#define DISPLAY_NOTHING 0
#define DISPLAY_DIR     1
#define DISPLAY_SYM     2
#define DISPLAY_ROM     4
#define DISPLAY_SRC     8
#define DISPLAY_MESS    16
#define DISPLAY_ALL     0xff

  display_flags = DISPLAY_NOTHING;
  while ((c = GETOPT_FUNC) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = 1;
      break;
    case 'a':
      display_flags = DISPLAY_ALL;
      break;
    case 'd':
      display_flags |= DISPLAY_DIR;
      break;
    case 's':
      display_flags |= DISPLAY_SYM;
      break;
    case 'r':
      display_flags |= DISPLAY_ROM;
      break;
    case 'l':
      display_flags |= DISPLAY_SRC;
      break;
    case 'm':
      display_flags |= DISPLAY_MESS;
      break;
    case 'v':
      fprintf(stderr, "%s\n", GPVC_VERSION_STRING);
      exit(0);
    }
    if (usage)
      break;
  }
  
  if ((optind + 1) == argc)
    strncpy(filename, argv[optind], sizeof(filename));
  else
    usage = 1;

  if(display_flags == DISPLAY_NOTHING)
    display_flags = DISPLAY_ALL;

  if (usage) {
    show_usage();
  }

  codefile = fopen(filename,"rb");
  if(codefile == NULL) {
    perror(filename);
    exit(1);
  }

  /* Start off by reading the directory block */
  read_directory();

  fseek(codefile, 0,SEEK_SET);
  buffer_size = fread(directory_block_data, 1, COD_BLOCK_SIZE, codefile);

  if(display_flags & DISPLAY_DIR)
    directory_block();

  dir = (Directory *)directory_block_data;

  if(display_flags & DISPLAY_ROM)
    dump_code();

  if(display_flags & DISPLAY_SYM) {
    dump_symbols();
    dump_lsymbols();
    dump_local_vars();
  }

  dump_source_files();

  if(display_flags & DISPLAY_SRC)
    dump_line_symbols();

  if(display_flags & DISPLAY_MESS)
    dump_message_area();

  return EXIT_SUCCESS;
}
예제 #20
0
/*
    @function main
*/
int main()
{
    /*test pq*/
    struct tnode* p=NULL;
    struct tnode* lc,*rc;
    float freq[]={0.01,0.04,0.05,0.11,0.19,0.20,0.4};
    int   NCHAR=7; /*number of characters*/
    int i=0;
    const char *CODE_FILE="code.txt";
    const char *OUT_FILE="encoded.txt";
    FILE* fout=NULL;
	/*zero out code*/
    memset(code,0,sizeof(code));

	/*testing queue*/
    pq_insert(talloc('a', 0.1));
    pq_insert(talloc('b', 0.2));
    pq_insert(talloc('c', 0.15));
    pq_insert(talloc('g', 0.3));
    pq_insert(talloc('x', 0.002));
    		
    /*making sure it pops in the right order*/
	puts("making sure it pops in the right order");
	while((p=pq_pop()))
    {
	printf("iam free \n");

	if(p != NULL)
	{
            free(p);
	}
	
    }
	
    qhead=NULL;
    /*initialize with freq*/
    for(i=0;i<NCHAR;i++)
    {
        pq_insert(talloc('a'+i,freq[i]));
    } 
    /*build tree*/
    for(i=0;i<NCHAR-1;i++)
    {
        lc=pq_pop();
        
        rc=pq_pop();
        
        /*create parent*/
        p=talloc(0,lc->freq+rc->freq);
        /*set parent link*/
        lc->parent=rc->parent=p;
        /*set child link*/
        p->right=rc; p->left=lc;
		/*make it non-leaf*/
		p->isleaf=0;
        /*add the new node to the queue*/
        pq_insert(p);
    }
    /*get root*/
     root=pq_pop();
	/*build code*/
	generate_code(root,0);
	/*output code*/
	puts("code:");
	fout=fopen(CODE_FILE,"w");
	dump_code(stdout);
	dump_code(fout);
	fclose(fout);

	/*encode a sample string*/
	puts("orginal:abba cafe bad");
	fout=fopen(OUT_FILE,"w");
	encode("abba cafe bad",stdout);
	encode("abba cafe bad",fout);
	fclose(fout);

	free(root);
	free(lc);
	free(rc);
	return 0;


}