DCPUTeam / DCPUToolchain

[ARCHIVED] The code repository for the DCPU-16 Toolchain.
http://dcputoolcha.in/
MIT License
96 stars 14 forks source link

Line numbers are off by one in the preprocessor #190

Closed jdiez17 closed 11 years ago

jdiez17 commented 11 years ago
╭─jdiez@hyperspace  ~/DCPUToolchain  ‹master*› 
╰─$ cat test.dasm                              
set a, 1
add b, 1
set pc, 0
╭─jdiez@hyperspace  ~/DCPUToolchain  ‹master*› 
╰─$ ./dtasm/dtasm test.dasm -o test.o -s test.s
warning: expressions will not be adjusted at link or relocation time. ensure labels are not used as part of expressions.
╭─jdiez@hyperspace  ~/DCPUToolchain  ‹master*› 
╰─$ ./dtdb/dtdb -s test.s -c "inspect symbols" 
Created VM. 
Loaded symbols from test.s.
3 symbols are loaded.
0x0000: [  line] test.dasm:2
0x0002: [  line] test.dasm:3
0x0004: [  line] test.dasm:4

I suspect this can be fixed by changing lines 649-652 in libdcpu-pp/ppimpl.c, but I'm not sure what that code does. @hach-que can you take a look at this?

hach-que commented 11 years ago

This is because of a way the preprocessor changed in marking lines (in order to be compliant with every other preprocessor).

Previously is used to do this:

line 1
# 2 "blah"
line 3
line 4

but now it does this:

line 2
# 3 "blah"
line 3
line 4

e.g. the preprocessor directive itself indicates the next line number, not the current line number. The assembler and compiler that read in these values via rparse need to be updated to subtract 1 from them (this can be done by modifying rparse.c in libdcpu).