Skip to content

Commit

Permalink
re-add PASM output to imcc, re-add imcpasm tests
Browse files Browse the repository at this point in the history
one new IMCCompiler api method: set_to_pasm
remove static output in imcc/instructions.c
detect .pasm -o outfile extension
add and fix old t/compilers/imcc/imcpasm/*.t tests and the pir_2*_
  Parrot::Test methods
change Parrot::Test pir_2_pasm method to use -d1000, which is equivalent
  to pasm output, just to stderr.
use new LIKELY/UNLIKELY macros
  • Loading branch information
Reini Urban committed Jan 10, 2015
1 parent d204948 commit bc8496b
Show file tree
Hide file tree
Showing 24 changed files with 2,325 additions and 220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -396,6 +396,7 @@ winxed-c.html
/t/compilers/data_json/*.pir
/t/compilers/data_json/*_pbcexe
/t/compilers/imcc/*.pbc
/t/compilers/imcc/imcpasm/*.pir
/t/compilers/imcc/reg/*.pasm
/t/compilers/imcc/reg/*.pbc
/t/compilers/imcc/reg/*.pir
Expand Down
30 changes: 23 additions & 7 deletions compilers/imcc/debug.c
Expand Up @@ -259,12 +259,28 @@ IMCC_debug_ins(ARGMOD(imc_info_t *imcc), int level, ARGIN(const Instruction *ins
{
ASSERT_ARGS(IMCC_debug_ins)
PIOHANDLE pstderr;
if (!(level & imcc->debug))
if (!((level & imcc->debug) || imcc->write_pasm))
return;
pstderr = Parrot_io_internal_std_os_handle(imcc->interp, PIO_STDERR_FILENO);
Parrot_io_pprintf(imcc->interp, pstderr, "0x%lx %s ", PTR2ULONG(ins), ins->opname);
ins_print(imcc, pstderr, ins);
Parrot_io_pprintf(imcc->interp, pstderr, "\n");
if (level & imcc->debug) {
PIOHANDLE pstderr;
pstderr = Parrot_io_internal_std_os_handle(imcc->interp, PIO_STDERR_FILENO);
if (imcc->verbose)
Parrot_io_eprintf(imcc->interp, "0x%x ", ins);
Parrot_io_eprintf(imcc->interp, "%s ", ins->opname);
ins_print(imcc, pstderr, ins);
Parrot_io_eprintf(imcc->interp, "\n");
}
#if 0
if (imcc->write_pasm) {
Parrot_io_pprintf(imcc->interp, imcc->write_pasm, "%s ", ins->opname);
ins_print(imcc, imcc->write_pasm, ins);
Parrot_io_pprintf(imcc->interp, imcc->write_pasm, "\n");
}
#endif
}

/*
Expand All @@ -283,14 +299,14 @@ dump_instructions(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
ASSERT_ARGS(dump_instructions)
const Instruction *ins;
int pc;
const PIOHANDLE pstderr =
const PIOHANDLE pstderr =
Parrot_io_internal_std_os_handle(imcc->interp, PIO_STDERR_FILENO);

Parrot_io_eprintf(imcc->interp,
"\nDumping the instructions status:"
"\n-------------------------------\n");
Parrot_io_eprintf(imcc->interp,
"nins line blck deep flags\t type opnr size pc X ins\n");
"nins line blck deep flags\t type opnr size pc X ins\n");

for (pc = 0, ins = unit->instructions; ins; ins = ins->next) {
const Basic_block * const bb = unit->bb_list[ins->bbindex];
Expand All @@ -303,11 +319,11 @@ dump_instructions(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit))
ins->opsize, pc);
}
else {
Parrot_io_eprintf(imcc->interp, "\t");
Parrot_io_eprintf(imcc->interp, " \t \t ");
}

Parrot_io_eprintf(imcc->interp, "%s\n", ins->opname);
ins_print(imcc, pstderr, ins);
IMCC_debug_ins(imcc, 0xffff, ins);
//Parrot_io_eprintf(imcc->interp, "%s\n", ins->opname);
//ins_print(imcc, pstderr, ins);
pc += ins->opsize;
}

Expand Down
2 changes: 1 addition & 1 deletion compilers/imcc/imc.c
Expand Up @@ -79,7 +79,7 @@ imc_compile_all_units(ARGMOD(imc_info_t * imcc))
}
#endif

emit_close(imcc, NULL);
emit_close(imcc);

/* All done with compilation, now free all memory allocated
* for instructions and other structures. */
Expand Down
2 changes: 1 addition & 1 deletion compilers/imcc/imc.h
Expand Up @@ -461,12 +461,12 @@ struct _imc_info_t {
AsmState asm_state;
SymHash ghash;
jmp_buf jump_buf; /* The jump for error handling */
PIOHANDLE write_pasm;
int cnr;
int debug;
int dont_optimize;
int emitter;
int error_code; /* The Error code. */
int expect_pasm;
int imcc_warn;
int in_pod;
int ins_line;
Expand Down
16 changes: 9 additions & 7 deletions compilers/imcc/imcc.l
Expand Up @@ -64,6 +64,8 @@ static void include_file(ARGMOD(imc_info_t *imcc), ARGIN(STRING *file_name), ARG

static int handle_identifier(ARGMOD(imc_info_t *imcc), YYSTYPE *valp, ARGIN(const char *id));

PIOHANDLE determine_input_file_type(ARGMOD(imc_info_t * imcc), ARGIN(STRING *sourcefile));

#define YY_DECL int yylex(YYSTYPE *valp, yyscan_t yyscanner, ARGMOD(imc_info_t *imcc))

#define YYCHOP() (yytext[--yyleng] = '\0')
Expand Down Expand Up @@ -132,8 +134,8 @@ SP [ ]

%%
/* for emacs "*/
if (imcc->expect_pasm == 1 && !imcc->in_pod) {
imcc->expect_pasm = 2;
if (imcc->write_pasm == 1 && !imcc->in_pod) {
imcc->write_pasm = 2;
BEGIN(emit);
}

Expand Down Expand Up @@ -235,10 +237,10 @@ SP [ ]
}

<INITIAL,emit>{EOL} {
if (imcc->expect_pasm == 2)
if (imcc->write_pasm == 2)
BEGIN(INITIAL);

imcc->expect_pasm = 0;
imcc->write_pasm = 0;

return '\n';
}
Expand All @@ -248,12 +250,12 @@ SP [ ]
}

<cmt5>.*{EOL} {
if (imcc->expect_pasm == 2)
if (imcc->write_pasm == 2)
BEGIN(INITIAL);
else
yy_pop_state(yyscanner);

imcc->expect_pasm = 0;
imcc->write_pasm = 0;

return '\n';
}
Expand Down Expand Up @@ -1364,7 +1366,7 @@ imcc_compile_buffer_safe(ARGMOD(imc_info_t *imcc), yyscan_t yyscanner,
buffer = YY_CURRENT_BUFFER;

file = imcc_setup_input(imcc, yyscanner, source, source_c, is_file);
emit_open(imcc);
emit_open(imcc, source);
success = imcc_run_compilation(imcc, yyscanner);
imcc_cleanup_input(imcc, file, source_c, is_file);

Expand Down

0 comments on commit bc8496b

Please sign in to comment.