Source mapping

We do not just want the function name, we often also want to know the line numbers. Let's implement this.

Interface

class scanner
{
public:
    int get_token_begin_line();
    int get_token_begin_column();
    int get_token_end_line();
    int get_token_end_column();
}

struct parse_node
{
    source_span source_span;
};

struct source_location
{
    int line;
    int column;
};

struct source_span
{
    source_location begin;
    source_location end;
};

struct statement_symbol
{
    source_span source_span;
    int start_address;
};

struct symbols
{
    vector<statement_symbol> statements;
};

class debugger
{
public:
    source_span get_source_span();
};

Interface explained

Since only the scanner know the actual file, the source location information must be tracked from the scanner and passes all the way to the code generator generating the symbols.

When get_source_span() is called, find the next statement on or after the current instruction.

if conditions, return, calls are all considered statements.

Implementation

Again, this is a long exercise. Building the statement label will bring us a long way though. Now we can make sense of line numbers in the debugger.

results matching ""

    No results matching ""