Skip to content

Commit

Permalink
add op "getcodelocation"; gets file and line of a MVMCode
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Apr 9, 2015
1 parent 45861b3 commit 42e3d2e
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 127 deletions.
164 changes: 85 additions & 79 deletions lib/MAST/Ops.nqp
Expand Up @@ -663,50 +663,51 @@ BEGIN {
1598,
1601,
1603,
1603,
1605,
1605,
1607,
1610,
1613,
1609,
1612,
1615,
1617,
1619,
1621,
1623,
1626,
1629,
1632,
1635,
1636,
1625,
1628,
1631,
1634,
1637,
1638,
1642,
1645,
1648,
1651,
1654,
1657,
1660,
1663,
1666,
1669,
1672,
1676,
1680,
1683,
1686,
1689,
1692,
1695,
1698,
1701,
1702,
1640,
1644,
1647,
1650,
1653,
1656,
1659,
1662,
1665,
1668,
1671,
1674,
1678,
1682,
1685,
1688,
1691,
1694,
1697,
1700,
1703,
1704,
1706,
1708,
1708,
1708,
1709,
1709);
1710,
1710,
1710,
1711,
1711);
MAST::Ops.WHO<@counts> := nqp::list_i(0,
2,
2,
Expand Down Expand Up @@ -1366,6 +1367,7 @@ BEGIN {
2,
3,
2,
2,
0,
2,
2,
Expand Down Expand Up @@ -3012,6 +3014,8 @@ BEGIN {
57,
33,
65,
66,
65,
65,
128,
65,
Expand Down Expand Up @@ -3779,52 +3783,53 @@ BEGIN {
'normalizecodes', 655,
'strfromcodes', 656,
'strtocodes', 657,
'sp_log', 658,
'sp_osrfinalize', 659,
'sp_guardconc', 660,
'sp_guardtype', 661,
'sp_guardcontconc', 662,
'sp_guardconttype', 663,
'sp_getarg_o', 664,
'sp_getarg_i', 665,
'sp_getarg_n', 666,
'sp_getarg_s', 667,
'sp_fastinvoke_v', 668,
'sp_fastinvoke_i', 669,
'sp_fastinvoke_n', 670,
'sp_fastinvoke_s', 671,
'sp_fastinvoke_o', 672,
'sp_namedarg_used', 673,
'sp_getspeshslot', 674,
'sp_findmeth', 675,
'sp_fastcreate', 676,
'sp_get_o', 677,
'sp_get_i', 678,
'sp_get_n', 679,
'sp_get_s', 680,
'sp_bind_o', 681,
'sp_bind_i', 682,
'sp_bind_n', 683,
'sp_bind_s', 684,
'sp_p6oget_o', 685,
'sp_p6ogetvt_o', 686,
'sp_p6ogetvc_o', 687,
'sp_p6oget_i', 688,
'sp_p6oget_n', 689,
'sp_p6oget_s', 690,
'sp_p6obind_o', 691,
'sp_p6obind_i', 692,
'sp_p6obind_n', 693,
'sp_p6obind_s', 694,
'sp_jit_enter', 695,
'sp_boolify_iter', 696,
'sp_boolify_iter_arr', 697,
'sp_boolify_iter_hash', 698,
'prof_enter', 699,
'prof_enterspesh', 700,
'prof_enterinline', 701,
'prof_exit', 702,
'prof_allocated', 703);
'getcodelocation', 658,
'sp_log', 659,
'sp_osrfinalize', 660,
'sp_guardconc', 661,
'sp_guardtype', 662,
'sp_guardcontconc', 663,
'sp_guardconttype', 664,
'sp_getarg_o', 665,
'sp_getarg_i', 666,
'sp_getarg_n', 667,
'sp_getarg_s', 668,
'sp_fastinvoke_v', 669,
'sp_fastinvoke_i', 670,
'sp_fastinvoke_n', 671,
'sp_fastinvoke_s', 672,
'sp_fastinvoke_o', 673,
'sp_namedarg_used', 674,
'sp_getspeshslot', 675,
'sp_findmeth', 676,
'sp_fastcreate', 677,
'sp_get_o', 678,
'sp_get_i', 679,
'sp_get_n', 680,
'sp_get_s', 681,
'sp_bind_o', 682,
'sp_bind_i', 683,
'sp_bind_n', 684,
'sp_bind_s', 685,
'sp_p6oget_o', 686,
'sp_p6ogetvt_o', 687,
'sp_p6ogetvc_o', 688,
'sp_p6oget_i', 689,
'sp_p6oget_n', 690,
'sp_p6oget_s', 691,
'sp_p6obind_o', 692,
'sp_p6obind_i', 693,
'sp_p6obind_n', 694,
'sp_p6obind_s', 695,
'sp_jit_enter', 696,
'sp_boolify_iter', 697,
'sp_boolify_iter_arr', 698,
'sp_boolify_iter_hash', 699,
'prof_enter', 700,
'prof_enterspesh', 701,
'prof_enterinline', 702,
'prof_exit', 703,
'prof_allocated', 704);
MAST::Ops.WHO<@names> := nqp::list('no_op',
'const_i8',
'const_i16',
Expand Down Expand Up @@ -4483,6 +4488,7 @@ BEGIN {
'normalizecodes',
'strfromcodes',
'strtocodes',
'getcodelocation',
'sp_log',
'sp_osrfinalize',
'sp_guardconc',
Expand Down
41 changes: 41 additions & 0 deletions src/6model/reprs/MVMCode.c
Expand Up @@ -125,3 +125,44 @@ static const MVMREPROps this_repr = {
MVM_REPR_ID_MVMCode,
1, /* refs_frames */
};

MVM_PUBLIC MVMObject * MVM_code_location(MVMThreadContext *tc, MVMObject *code) {
MVMObject *BOOTHash = tc->instance->boot_types.BOOTHash;
MVMCodeBody *body = &((MVMCode*)code)->body;

if (REPR(code)->ID != MVM_REPR_ID_MVMCode) {
MVM_exception_throw_adhoc(tc, "getcodelocation needs an object of MVMCode REPR, got %s instead", REPR(code)->name);
} else {
MVMObject * result = REPR(BOOTHash)->allocate(tc, STABLE(BOOTHash));
MVMBytecodeAnnotation *ann = MVM_bytecode_resolve_annotation(tc, &body->sf->body, 0);
MVMCompUnit *cu = body->sf->body.cu;
MVMint32 str_idx = ann ? ann->filename_string_heap_index : 0;
MVMint32 line_nr = ann ? ann->line_number : 1;
MVMString *filename = cu->body.filename;

MVMROOT(tc, result, {
MVMString *filename_key = MVM_string_ascii_decode_nt(tc, tc->instance->VMString, "file");
MVMROOT(tc, filename_key, {
MVMString *linenumber_key = MVM_string_ascii_decode_nt(tc, tc->instance->VMString, "line");

if (ann && str_idx < cu->body.num_strings) {
filename = cu->body.strings[str_idx];
}

MVMROOT(tc, linenumber_key, {
MVM_repr_bind_key_o(tc, result, filename_key,
MVM_repr_box_str(tc, tc->instance->boot_types.BOOTStr, filename)
);

MVM_repr_bind_key_o(tc, result, linenumber_key,
MVM_repr_box_int(tc, tc->instance->boot_types.BOOTInt, line_nr)
);
});
});
});

return result;
}

return NULL;
}
2 changes: 2 additions & 0 deletions src/6model/reprs/MVMCode.h
Expand Up @@ -16,3 +16,5 @@ struct MVMCode {

/* Function for REPR setup. */
const MVMREPROps * MVMCode_initialize(MVMThreadContext *tc);

MVM_PUBLIC MVMObject * MVM_code_location(MVMThreadContext *tc, MVMObject *code);
4 changes: 4 additions & 0 deletions src/core/interp.c
Expand Up @@ -4507,6 +4507,10 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
OP(strfromcodes):
OP(strtocodes):
MVM_exception_throw_adhoc(tc, "NYI");
OP(getcodelocation):
GET_REG(cur_op, 0).o = MVM_code_location(tc, GET_REG(cur_op, 2).o);
cur_op += 4;
goto NEXT;
OP(sp_log):
if (tc->cur_frame->spesh_log_idx >= 0) {
MVM_ASSIGN_REF(tc, &(tc->cur_frame->static_info->common.header),
Expand Down
2 changes: 1 addition & 1 deletion src/core/oplabels.h
Expand Up @@ -659,6 +659,7 @@ static const void * const LABELS[] = {
&&OP_normalizecodes,
&&OP_strfromcodes,
&&OP_strtocodes,
&&OP_getcodelocation,
&&OP_sp_log,
&&OP_sp_osrfinalize,
&&OP_sp_guardconc,
Expand Down Expand Up @@ -1024,7 +1025,6 @@ static const void * const LABELS[] = {
NULL,
NULL,
NULL,
NULL,
&&OP_CALL_EXTOP,
&&OP_CALL_EXTOP,
&&OP_CALL_EXTOP,
Expand Down
2 changes: 2 additions & 0 deletions src/core/oplist
Expand Up @@ -695,6 +695,8 @@ encodenorm r(str) r(str) r(int64) r(obj)
normalizecodes r(obj) r(int64) r(obj)
strfromcodes w(str) r(obj)
strtocodes r(str) r(int64) r(obj)
getcodelocation w(obj) r(obj) :pure


# Spesh ops. Naming convention: start with sp_. Must all be marked .s, which
# is how the validator knows to exclude them.
Expand Down
13 changes: 12 additions & 1 deletion src/core/ops.c
Expand Up @@ -7231,6 +7231,17 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
{ MVM_operand_read_reg | MVM_operand_str, MVM_operand_read_reg | MVM_operand_int64, MVM_operand_read_reg | MVM_operand_obj }
},
{
MVM_OP_getcodelocation,
"getcodelocation",
" ",
2,
1,
0,
0,
0,
{ MVM_operand_write_reg | MVM_operand_obj, MVM_operand_read_reg | MVM_operand_obj }
},
{
MVM_OP_sp_log,
"sp_log",
Expand Down Expand Up @@ -7735,7 +7746,7 @@ static const MVMOpInfo MVM_op_infos[] = {
},
};

static const unsigned short MVM_op_counts = 704;
static const unsigned short MVM_op_counts = 705;

MVM_PUBLIC const MVMOpInfo * MVM_op_get_op(unsigned short op) {
if (op >= MVM_op_counts)
Expand Down

0 comments on commit 42e3d2e

Please sign in to comment.