douggilliland / R32V2020

My 32-bit RISC CPU for smallish FPGAs
GNU General Public License v3.0
14 stars 3 forks source link

#define would be really helpful #58

Closed douggilliland closed 4 years ago

douggilliland commented 5 years ago

@mjgpy3 Something like #define could be very helpful for keeping tracks of constants - like the ports in the memory map.

Would be something like the C version:

define _SERIAL_PORT_BASE 0x1000

Then it could be used with something like:

lix r9,_SERIAL_PORT_BASE.lower

mjgpy3 commented 5 years ago

@douggilliland would #DEFINE work like a standard c-style precompiler directive?

E.g. #define SOME_A SOME_B basically means replace every occurrence of SOME_A with SOME_B in the file? Should it span files or only work in the file containing the #define?

douggilliland commented 5 years ago

@mjgpy3 Yep, just like C. Doesn't probably matter if it is local to the file or persists into the include files.

mjgpy3 commented 5 years ago

Is it okay to require that #define comes before usage of the term it defines? I shouldn't need another pass if this is acceptable.

mjgpy3 commented 5 years ago

Also, I'm going to restrict the definable terms to alphanumeric plus _ if that's okay.

mjgpy3 commented 5 years ago

I know C let's one do some pretty crazy stuff with these :)

mjgpy3 commented 5 years ago

Also I'm going to make this replace at the token level. In other words crazy things like the following aren't allowed.

#DEFINE dr di
addr r10, r11, 42

To try to get

addi r10, r11, 42