mirror of
https://github.com/janet-lang/janet
synced 2025-07-21 11:22:53 +00:00
Add source mapping to emitted C.
This commit is contained in:
parent
4d7baef89e
commit
7cc176f0c0
@ -21,13 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
* - pointer math, pointer types
|
* [ ] pointer math, pointer types
|
||||||
* - callk - allow linking to other named functions
|
* [ ] callk - allow linking to other named functions
|
||||||
* - composite types - support for load, store, move, and function args.
|
* [ ] composite types - support for load, store, move, and function args.
|
||||||
* Have some mechanism for field access (dest = src.offset)
|
* [ ] Have some mechanism for field access (dest = src.offset)
|
||||||
* - support for stack allocation of arrays
|
* [ ] Related, move type creation as opcodes like in SPIRV - have separate virtual "type slots" and value slots for this.
|
||||||
* - more math intrinsics
|
* [ ] support for stack allocation of arrays
|
||||||
* - better C interface for building up IR
|
* [ ] more math intrinsics
|
||||||
|
* [ ] source mapping (using built in Janet source mapping metadata on tuples)
|
||||||
|
* [ ] better C interface for building up IR
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef JANET_AMALG
|
#ifndef JANET_AMALG
|
||||||
@ -226,6 +228,8 @@ typedef struct {
|
|||||||
uint32_t constant;
|
uint32_t constant;
|
||||||
} constant;
|
} constant;
|
||||||
};
|
};
|
||||||
|
int32_t line;
|
||||||
|
int32_t column;
|
||||||
} JanetSysInstruction;
|
} JanetSysInstruction;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -415,6 +419,8 @@ static void janet_sysir_init_instructions(JanetSysIR *out, JanetView instruction
|
|||||||
if (janet_tuple_length(tuple) < 1) {
|
if (janet_tuple_length(tuple) < 1) {
|
||||||
janet_panic("invalid instruction, no opcode");
|
janet_panic("invalid instruction, no opcode");
|
||||||
}
|
}
|
||||||
|
int32_t line = janet_tuple_sm_line(tuple);
|
||||||
|
int32_t column = janet_tuple_sm_column(tuple);
|
||||||
Janet opvalue = tuple[0];
|
Janet opvalue = tuple[0];
|
||||||
if (!janet_checktype(opvalue, JANET_SYMBOL)) {
|
if (!janet_checktype(opvalue, JANET_SYMBOL)) {
|
||||||
janet_panicf("expected opcode symbol, found %V", opvalue);
|
janet_panicf("expected opcode symbol, found %V", opvalue);
|
||||||
@ -482,6 +488,8 @@ static void janet_sysir_init_instructions(JanetSysIR *out, JanetView instruction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_instruction_well_formed(instruction, x, out);
|
check_instruction_well_formed(instruction, x, out);
|
||||||
|
instruction.line = line;
|
||||||
|
instruction.column = column;
|
||||||
ir[cursor++] = instruction;
|
ir[cursor++] = instruction;
|
||||||
}
|
}
|
||||||
/* Check last instruction is jump or return */
|
/* Check last instruction is jump or return */
|
||||||
@ -583,6 +591,9 @@ void janet_sys_ir_lower_to_c(JanetSysIR *ir, JanetBuffer *buffer) {
|
|||||||
for (uint32_t i = 0; i < ir->instruction_count; i++) {
|
for (uint32_t i = 0; i < ir->instruction_count; i++) {
|
||||||
janet_formatb(buffer, "_i%u:\n ", i);
|
janet_formatb(buffer, "_i%u:\n ", i);
|
||||||
JanetSysInstruction instruction = ir->instructions[i];
|
JanetSysInstruction instruction = ir->instructions[i];
|
||||||
|
if (instruction.line > 0) {
|
||||||
|
janet_formatb(buffer, "#line %d\n ", instruction.line);
|
||||||
|
}
|
||||||
switch (instruction.opcode) {
|
switch (instruction.opcode) {
|
||||||
case JANET_SYSOP_CONSTANT: {
|
case JANET_SYSOP_CONSTANT: {
|
||||||
const char *cast = c_prim_names[ir->types[instruction.two.dest]];
|
const char *cast = c_prim_names[ir->types[instruction.two.dest]];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user