From bb3ed9c4d30727532a9499e0bb86f1d0cdca4361 Mon Sep 17 00:00:00 2001 From: vrokas Date: Sun, 6 Jun 2004 21:25:57 +0000 Subject: [PATCH] Cumulative patch for pic16 port * src/pic16/device.h (typedef PIC16_device) modified fields for defining microcontrollers, * src/pic16/device.c: added new info for all devices in Pics16 array, * src/pic16/gen.c (genPcall): fixed bug that caused the return label to be optimised out by the pCode optimiser, * src/pic16/glue.c (pic16emitRegularMap): treat implicit aggragates specially, bug reported by G.M. Gallant, * src/pic16/pcode.c (pic16_newpCodeLabelFORCE): NEW, marks a label as force'd so that cannot be optimised out by pCode optimiser, * src/pic16/pcode.c, * src/pic16/pcodepeeph.c, * src/pic16/pcoderegs.c: many modifications to re-enable peepholes, they are disabled by default, but can be enabled explicit with command argument --denable-peeps, for testing, * device/lib/pic16/startup/Makefile: added --no-peep,--pomit-config-words, --pomit-ivt in COMPILE_FLAGS git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3354 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 20 ++ device/lib/pic16/startup/Makefile | 1 + src/pic16/device.c | 506 ++++++++++++++++-------------- src/pic16/device.h | 24 +- src/pic16/gen.c | 27 +- src/pic16/glue.c | 19 +- src/pic16/main.c | 8 + src/pic16/pcode.c | 63 +++- src/pic16/pcode.h | 9 +- src/pic16/pcodepeep.c | 55 ++-- src/pic16/ralloc.c | 4 +- 11 files changed, 419 insertions(+), 317 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8010e55e..8cbd19d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-06-07 Vangelis Rokas + + Cumulative patch for pic16 port: + * src/pic16/device.h (typedef PIC16_device) modified fields for + defining microcontrollers, + * src/pic16/device.c: added new info for all devices in Pics16 array, + * src/pic16/gen.c (genPcall): fixed bug that caused the return label + to be optimised out by the pCode optimiser, + * src/pic16/glue.c (pic16emitRegularMap): treat implicit aggragates + specially, bug reported by G.M. Gallant, + * src/pic16/pcode.c (pic16_newpCodeLabelFORCE): NEW, marks a label + as force'd so that cannot be optimised out by pCode optimiser, + * src/pic16/pcode.c, + * src/pic16/pcodepeeph.c, + * src/pic16/pcoderegs.c: many modifications to re-enable peepholes, + they are disabled by default, but can be enabled explicit with + command argument --denable-peeps, for testing, + * device/lib/pic16/startup/Makefile: added --no-peep,--pomit-config-words, + --pomit-ivt in COMPILE_FLAGS + 2004-06-06 Maarten Brock * src/pic16/pcode.c (pic16_emitDB): removed double semicolon which fails diff --git a/device/lib/pic16/startup/Makefile b/device/lib/pic16/startup/Makefile index 1c2f2eb8..ba2b341b 100644 --- a/device/lib/pic16/startup/Makefile +++ b/device/lib/pic16/startup/Makefile @@ -22,6 +22,7 @@ SRCS = crt0 \ # add nostdinc and nostdlib for this device libraries +COMPILE_FLAGS += --no-peep --pomit-config-words --pomit-ivt COMPILE_FLAGS += $(MODELFLAGS) --nostdinc --nostdlib CFILES = $(patsubst %,%.c,$(SRCS)) diff --git a/src/pic16/device.c b/src/pic16/device.c index 2364bd9e..f63d5095 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -41,311 +41,330 @@ static PIC16_device Pics16[] = { +// { +// {"p18f242", "18f242", "pic18f242", "f242"}, // aliases +// 0, +// 0x300, // RAMsize +// 0, +// { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */ +// { +// /* PIC18F242 configuration words */ +// 0x300001, +// 0x30000d, +// { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , +// { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , +// { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , +// { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , +// { 0x40, 0, 0xff } /* d */ } +// } +// }, + { - {"p18f242", "18f242", "pic18f242", "f242"}, // aliases + {"p18f242", "18f242", "pic18f242", "f242"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x80, 0, - { - /* PIC18F242 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf80, 0xfff }, /* PIC18F242 range of SFR's */ + { + /* PIC18F242 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f248", "18f248", "pic18f248", "f248"}, // aliases + {"p18f248", "18f248", "pic18f248", "f248"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x60, 0, - { - /* PIC18F248 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf00, 0xfff }, /* PIC18F248 range of SFR's */ + { + /* PIC18F248 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f252", "18f252", "pic18f252", "f252"}, // aliases + {"p18f252", "18f252", "pic18f252", "f252"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x80, 0, - { - /* PIC18F252 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf80, 0xfff }, /* PIC18F252 range of SFR's */ + { + /* PIC18F252 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f258", "18f258", "pic18f258", "f258"}, // aliases + {"p18f258", "18f258", "pic18f258", "f258"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x60, 0, - { - /* PIC18F258 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf00, 0xfff }, /* PIC18F258 range of SFR's */ + { + /* PIC18F258 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f442", "18f442", "pic18f442", "f442"}, // aliases + {"p18f442", "18f442", "pic18f442", "f442"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x80, 0, - { - /* PIC18F442 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf80, 0xfff }, /* PIC18F442 range of SFR's */ + { + /* PIC18F442 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f448", "18f448", "pic18f448", "f448"}, // aliases + {"p18f448", "18f448", "pic18f448", "f448"}, 0, - 0x300, // bank mask - 0x300, // RAMsize + 0x300, /* 768 */ + 0x60, 0, - { - /* PIC18F448 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf00, 0xfff }, /* PIC18F448 range of SFR's */ + { + /* PIC18F448 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f452", "18f452", "pic18f452", "f452"}, // aliases + {"p18f452", "18f452", "pic18f452", "f452"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x80, 0, - { - /* PIC18F452 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf80, 0xfff }, /* PIC18F452 range of SFR's */ + { + /* PIC18F452 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f458", "18f458", "pic18f458", "f458"}, // aliases + {"p18f458", "18f458", "pic18f458", "f458"}, 0, - 0x600, // bank mask - 0x600, // RAMsize + 0x600, /* 1536 */ + 0x60, 0, - { - /* PIC18F458 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf00, 0xfff }, /* PIC18F458 range of SFR's */ + { + /* PIC18F458 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { -1, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f1220", "18f1220", "pic18f1220", "f1220"}, // aliases + {"p18f1220", "18f1220", "pic18f1220", "f1220"}, 0, - 0x200, - 0x200, + 0x100, /* 256 */ + 0x80, 0, - { - /* PIC18F1220 configuration words */ - 0x300001, - 0x30000d, - { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf80, 0xfff }, /* PIC18F1220 range of SFR's */ + { + /* PIC18F1220 configuration words */ + 0x300001, + 0x30000d, + { { 0xcf, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x80, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x03, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x03, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x03, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - - { - {"p18f6520", "18f6520", "pic18f6520", "f6520"}, // aliases + {"p18f6520", "18f6520", "pic18f6520", "f6520"}, 0, - 0x800, // bank mask - 0x800, // RAMsize - 1, - { - /* PIC18F6520 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0x800, /* 2048 */ + 0x60, + 0, + { 0xf6b, 0xfff }, /* PIC18F6520 range of SFR's */ + { + /* PIC18F6520 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { 0x80, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f6620", "18f6620", "pic18f6620", "f6620"}, // aliases + {"p18f6620", "18f6620", "pic18f6620", "f6620"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize - 1, - { - /* PIC18F6620 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf6b, 0xfff }, /* PIC18F6620 range of SFR's */ + { + /* PIC18F6620 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f6680", "18f6680", "pic18f6680", "f6680"}, // aliases + {"p18f6680", "18f6680", "pic18f6680", "f6680"}, 0, - 0xc00, // bank mask - 0xc00, // RAMsize - 1, - { - /* PIC18F6680 configuration words */ - 0x300001, - 0x30000d, - { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf00, 0xfff }, /* PIC18F6680 range of SFR's */ + { + /* PIC18F6680 configuration words */ + 0x300001, + 0x30000d, + { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f6720", "18f6720", "pic18f6720", "f6720"}, // aliases + {"p18f6720", "18f6720", "pic18f6720", "f6720"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize - 1, - { - /* PIC18F6720 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf6b, 0xfff }, /* PIC18F6720 range of SFR's */ + { + /* PIC18F6720 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { -1, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f8520", "18f8520", "pic18f8520", "f8520"}, // aliases + {"p18f8520", "18f8520", "pic18f8520", "f8520"}, 0, - 0x800, // bank mask - 0x800, // RAMsize + 0x800, /* 2048 */ + 0x60, 1, - { - /* PIC18F8520 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf6b, 0xfff }, /* PIC18F8520 range of SFR's */ + { + /* PIC18F8520 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { 0x83, 0, 0xff } /* 4 */ , { 0x88, 0, 0xff } /* 5 */ , { -1, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f8620", "18f8620", "pic18f8620", "f8620"}, // aliases + {"p18f8620", "18f8620", "pic18f8620", "f8620"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize + 0xf00, /* 3840 */ + 0x60, 1, - { - /* PIC18F8620 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + { 0xf6b, 0xfff }, /* PIC18F8620 range of SFR's */ + { + /* PIC18F8620 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, { - {"p18f8680", "18f8680", "pic18f8680", "f8680"}, // aliases + {"p18f8680", "18f8680", "pic18f8680", "f8680"}, 0, - 0xc00, // bank mask - 0x800, // RAMsize - 1, - { - /* PIC18F8680 configuration words */ - 0x300001, - 0x30000d, - { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } + 0xf00, /* 3840 */ + 0x60, + 0, + { 0xf00, 0xfff }, /* PIC18F8680 range of SFR's */ + { + /* PIC18F8680 configuration words */ + 0x300001, + 0x30000d, + { { 0x2f, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x1f, 0, 0xff } /* 3 */ , + { 0x83, 0, 0xff } /* 4 */ , { 0x83, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0x0f, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0x0f, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0x0f, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } }, - { - {"p18f8720", "18f8720", "pic18f8720", "f8720"}, // aliases + {"p18f8720", "18f8720", "pic18f8720", "f8720"}, 0, - 0xf00, // bank mask - 0xf00, // RAMsize + 0xf00, /* 3840 */ + 0x60, 1, - { - /* PIC18F8720 configuration words */ - 0x300001, - 0x30000d, - { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , - { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , - { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , - { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , - { 0x40, 0, 0xff } /* d */ } - } - } + { 0xf6b, 0xfff }, /* PIC18F8720 range of SFR's */ + { + /* PIC18F8720 configuration words */ + 0x300001, + 0x30000d, + { { 0x27, 0, 0xff } /* 1 */ , { 0x0f, 0, 0xff } /* 2 */ , { 0x0f, 0, 0xff } /* 3 */ , + { 0x83, 0, 0xff } /* 4 */ , { 0x01, 0, 0xff } /* 5 */ , { 0x85, 0, 0xff } /* 6 */ , + { -1, 0, 0xff } /* 7 */ , { 0xff, 0, 0xff } /* 8 */ , { 0xc0, 0, 0xff } /* 9 */ , + { 0xff, 0, 0xff } /* a */ , { 0xe0, 0, 0xff } /* b */ , { 0xff, 0, 0xff } /* c */ , + { 0x40, 0, 0xff } /* d */ } + } + }, }; @@ -1084,7 +1103,6 @@ void pic16_assignConfigWordValue(int address, int value) { int i; - for(i=0;icwInfo.confAddrEnd-pic16->cwInfo.confAddrStart+1;i++) { if((address == pic16->cwInfo.confAddrStart+i) && (pic16->cwInfo.crInfo[i].mask != -1)) { diff --git a/src/pic16/device.h b/src/pic16/device.h index f9bef221..88a90ab5 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -38,18 +38,23 @@ #define CONFIGURATION_WORDS 20 +typedef struct { + int sfrLoAddr; + int sfrHiAddr; +} sfrRangeInfo_t; + + typedef struct { int mask; int emit; int value; -} configRegInfo; +} configRegInfo_t; typedef struct { int confAddrStart; /* starting address */ int confAddrEnd; /* ending address */ - configRegInfo crInfo[ CONFIGURATION_WORDS ]; -} configWordsInfo; - + configRegInfo_t crInfo[ CONFIGURATION_WORDS ]; +} configWordsInfo_t; #define PROCESSOR_NAMES 4 @@ -57,11 +62,12 @@ typedef struct { typedef struct PIC16_device { char *name[PROCESSOR_NAMES];/* aliases for the processor name */ - int maxRAMaddress; /* maximum value for a data address */ - int bankMask; /* Bitmask that is ANDed with address to extract banking bits */ - int RAMsize; /* size of Data RAM - VR 031120 */ - int extMIface; /* device has external memory interface */ - configWordsInfo cwInfo; /* configuration words info */ + int maxRAMaddress; /* maximum value for a data address */ + int RAMsize; /* size of Data RAM - VR 031120 */ + int acsSplitOfs; /* access bank split offset */ + int extMIface; /* device has external memory interface */ + sfrRangeInfo_t sfrRange; /* SFR range */ + configWordsInfo_t cwInfo; /* configuration words info */ } PIC16_device; /* Given a pointer to a register, this macro returns the bank that it is in */ diff --git a/src/pic16/gen.c b/src/pic16/gen.c index c84e20e5..395abc91 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -273,6 +273,11 @@ void pic16_emitpLabel(int key) pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(NULL,key+100+labelOffset)); } +void pic16_emitpLabelFORCE(int key) +{ + pic16_addpCode2pBlock(pb,pic16_newpCodeLabelFORCE(NULL,key+100+labelOffset)); +} + void pic16_emitpcode(PIC_OPCODE poc, pCodeOp *pcop) { @@ -2963,9 +2968,7 @@ static void genPcall (iCode *ic) // push return address // push $ on return stack, then replace with retlbl - // Note: retlbl is supplied as dummy operand to PUSH - // This has the nice side effect of keeping the label from being optimized out :o) - pic16_emitpcode(POC_PUSH, pic16_popGetLabel(retlbl->key)); + pic16_emitpcodeNULLop(POC_PUSH); pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 0, 0)); pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosl)); @@ -2975,22 +2978,22 @@ static void genPcall (iCode *ic) pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosu)); /* make the call by writing the pointer into pc */ - // FIXME Disabled writes to PCLATU because of gpsim problems -#if 1 pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),2), pic16_popCopyReg(&pic16_pc_pclatu))); -#else - fprintf(stderr, -"WARNING: (%s:%d) PCLATU is not written because of gpsim problems\n\ -Correct this as soon as gpsim bug is fixed\n", __FILE__, __LINE__); -#endif - pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),1), pic16_popCopyReg(&pic16_pc_pclath))); + // note: MOVFF to PCL not allowed pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0)); pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl)); + +// pic16_emitpcode(POC_GOTO, pic16_popGetLabel(retlbl->key)); +// pic16_emitpcodeNULLop(POC_NOP); +// pic16_emitpcodeNULLop(POC_NOP); + /* return address is here: (X) */ - pic16_emitpLabel(retlbl->key); + pic16_emitpLabelFORCE(retlbl->key); + +// pic16_emitpcodeNULLop(POC_NOP); pic16_freeAsmop (IC_LEFT(ic),NULL,ic,TRUE); diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 211c3822..52e6d779 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -132,8 +132,9 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) for (sym = setFirstItem (map->syms); sym; sym = setNextItem (map->syms)) { #if 0 - fprintf(stderr, "\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\n", - map->sname, sym->name, sym->used, IS_EXTERN(sym->etype), IS_STATIC(sym->etype)); + fprintf(stderr, "\t%s: sym: %s\tused: %d\textern: %d\tstatic: %d\taggregate: %d\n", + map->sname, sym->name, sym->used, IS_EXTERN(sym->etype), IS_STATIC(sym->etype), + IS_AGGREGATE(sym->type)); printTypeChain( sym->type, stderr ); fprintf(stderr, "\n"); #endif @@ -168,7 +169,6 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) !IS_STATIC (sym->etype) && !IS_FUNC(sym->type)) { checkAddSym(&publics, sym); -// addSetHead(&publics, sym); } else if(IS_STATIC(sym->etype) && !(sym->ival && !sym->level) @@ -272,7 +272,11 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) sym->implicit = 1; // mark as implicit #endif if(!sym->ival) { - reg = pic16_allocDirReg( operandFromSymbol( sym ) ); + if(IS_AGGREGATE(sym->type)) { + reg=pic16_allocRegByName(sym->rname, getSize( sym->type ), NULL); + } else { + reg = pic16_allocDirReg( operandFromSymbol( sym ) ); + } if(checkAddReg(&pic16_rel_udata, reg)) { addSetHead(&publics, sym); } @@ -619,11 +623,10 @@ pic16emitStaticSeg (memmap * map) fprintf(stderr, "\n"); #endif - if(SPEC_ABSA(sym->etype) - && (SPEC_ABSA(sym->etype) && PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))) { + if(SPEC_ABSA(sym->etype) && PIC16_IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype))) { - pic16_assignConfigWordValue(SPEC_ADDR (sym->etype), - (int) floatFromVal(list2val( sym->ival ))); + pic16_assignConfigWordValue(SPEC_ADDR(sym->etype), + (int) floatFromVal(list2val(sym->ival))); continue; } diff --git a/src/pic16/main.c b/src/pic16/main.c index 3e4f9c7d..e26f3da7 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -208,6 +208,8 @@ extern int pic16_debug_verbose; extern int pic16_ralloc_debug; extern int pic16_pcode_verbose; +int pic16_enable_peeps=0; + OPTION pic16_optionsTable[]= { { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"}, { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"}, @@ -225,6 +227,8 @@ OPTION pic16_optionsTable[]= { { 0, ALT_ASM, NULL, "Use alternative assembler"}, { 0, ALT_LINK, NULL, "Use alternative linker"}, + { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"}, + { 0, NULL, NULL, NULL} }; @@ -333,6 +337,10 @@ _pic16_finaliseOptions (void) /* peepholes are disabled for the time being */ options.nopeep = 1; + /* explicit enable peepholes for testing */ + if(pic16_enable_peeps) + options.nopeep = 0; + options.all_callee_saves = 1; // always callee saves // options.float_rent = 1; // options.intlong_rent = 1; diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 9aa84272..206add78 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -3646,7 +3646,8 @@ pCode *pic16_newpCodeLabel(char *name, int key) pcl->pc.print = pCodePrintLabel; pcl->key = key; - + pcl->force = 0; + pcl->label = NULL; if(key>0) { sprintf(s,"_%05d_DS_",key); @@ -3664,6 +3665,15 @@ pCode *pic16_newpCodeLabel(char *name, int key) } +pCode *pic16_newpCodeLabelFORCE(char *name, int key) +{ + pCodeLabel *pcl = (pCodeLabel *)pic16_newpCodeLabel(name, key); + + pcl->force = 1; + + return ( (pCode *)pcl ); +} + /*-----------------------------------------------------------------*/ /* newpBlock - create and return a pointer to a new pBlock */ @@ -3843,6 +3853,8 @@ pCodeOp *pic16_newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype) PCOW(pcop)->subtype = subtype; PCOW(pcop)->matched = NULL; + PCOW(pcop)->pcop2 = NULL; + return pcop; } @@ -3854,23 +3866,41 @@ pCodeOp *pic16_newpCodeOpWild2(int id, int id2, pCodeWildBlock *pcwb, pCodeOp *s pCodeOp *pcop; - if(!pcwb || !subtype || !subtype2) { - fprintf(stderr, "Wild opcode declaration error: %s-%d\n",__FILE__,__LINE__); - exit(1); - } + if(!pcwb || !subtype || !subtype2) { + fprintf(stderr, "Wild opcode declaration error: %s-%d\n",__FILE__,__LINE__); + exit(1); + } - pcop = Safe_calloc(1,sizeof(pCodeOpWild)); - pcop->type = PO_WILD; - sprintf(s,"%%%d",id); - pcop->name = Safe_strdup(s); + pcop = Safe_calloc(1,sizeof(pCodeOpWild)); + pcop->type = PO_WILD; + sprintf(s,"%%%d",id); + pcop->name = Safe_strdup(s); - PCOW(pcop)->id = id; - PCOW(pcop)->pcwb = pcwb; - PCOW(pcop)->subtype = subtype; - PCOW(pcop)->matched = NULL; + PCOW(pcop)->id = id; + PCOW(pcop)->pcwb = pcwb; + PCOW(pcop)->subtype = subtype; + PCOW(pcop)->matched = NULL; + + PCOW(pcop)->pcop2 = Safe_calloc(1, sizeof(pCodeOpWild)); + + if(!subtype2->name) { + PCOW(pcop)->pcop2 = Safe_calloc(1, sizeof(pCodeOpWild)); + PCOW2(pcop)->pcop.type = PO_WILD; + sprintf(s, "%%%d", id2); + PCOW2(pcop)->pcop.name = Safe_strdup(s); + PCOW2(pcop)->id = id2; + PCOW2(pcop)->subtype = subtype2; + +// fprintf(stderr, "%s:%d %s [wild,wild] for name: %s (%d)\tname2: %s (%d)\n", __FILE__, __LINE__, __FUNCTION__, +// pcop->name, id, PCOW2(pcop)->pcop.name, id2); + } else { + PCOW2(pcop)->pcop2 = pic16_pCodeOpCopy( subtype2 ); + +// fprintf(stderr, "%s:%d %s [wild,str] for name: %s (%d)\tname2: %s (%d)\n", __FILE__, __LINE__, __FUNCTION__, +// pcop->name, id, PCOW2(pcop)->pcop.name, id2); + } + - PCOW(pcop)->id2 = id2; - PCOW(pcop)->subtype2 = subtype2; return pcop; } @@ -6175,7 +6205,8 @@ static void pBlockRemoveUnusedLabels(pBlock *pb) /* This pCode is a label, so search the pBlock to see if anyone * refers to it */ - if( (pcl->key>0) && (!findInstructionUsingLabel(pcl, pb->pcHead))) { + if( (pcl->key>0) && (!findInstructionUsingLabel(pcl, pb->pcHead)) + && (!pcl->force)) { //if( !findInstructionUsingLabel(pcl, pb->pcHead)) { /* Couldn't find an instruction that refers to this label * So, unlink the pCode label from it's pCode chain diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index 3f8a1da3..7c1bd2d5 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -439,9 +439,8 @@ typedef struct pCodeOpWild * card will be expanded */ pCodeOp *matched; /* When a wild matches, we'll store a pointer to the * opcode we matched */ - int id2; /* same as id but for second wild operand */ - pCodeOp *subtype2; /* Poiter to the second Operand type */ - pCodeOp *matched2; /* same as matched but for second wil operand */ + + pCodeOp *pcop2; /* second operand if exists */ } pCodeOpWild; @@ -648,6 +647,7 @@ typedef struct pCodeLabel char *label; int key; + int force; /* label cannot be optimized out */ } pCodeLabel; @@ -861,7 +861,7 @@ typedef struct peepCommand { #define PCOR2(x) ((pCodeOpReg2 *)(x)) #define PCORB(x) ((pCodeOpRegBit *)(x)) #define PCOW(x) ((pCodeOpWild *)(x)) - +#define PCOW2(x) (PCOW(PCOW(x)->pcop2)) #define PBR(x) ((pBranch *)(x)) #define PCWB(x) ((pCodeWildBlock *)(x)) @@ -900,6 +900,7 @@ pCode *pic16_newpCodeCharP(char *cP); // Create a new pCode given a pCode *pic16_newpCodeInlineP(char *cP); // Create a new pCode given a char * pCode *pic16_newpCodeFunction(char *g, char *f); // Create a new function pCode *pic16_newpCodeLabel(char *name,int key); // Create a new label given a key +pCode *pic16_newpCodeLabelFORCE(char *name, int key); // Same as newpCodeLabel but label cannot be optimized out pCode *pic16_newpCodeCSource(int ln, char *f, char *l); // Create a new symbol line pBlock *pic16_newpCodeChain(memmap *cm,char c, pCode *pc); // Create a new pBlock void pic16_printpBlock(FILE *of, pBlock *pb); // Write a pBlock to a file diff --git a/src/pic16/pcodepeep.c b/src/pic16/pcodepeep.c index 7a2409cf..b905e022 100644 --- a/src/pic16/pcodepeep.c +++ b/src/pic16/pcodepeep.c @@ -652,6 +652,14 @@ static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb) p[3].pct[0].tok.s, dest)); +#if 0 + fprintf(stderr,"altpat_mnem2a %s var %d destination %s(%d)\n", + p->pct[0].tok.s, + p[1].pct[1].tok.n, + p[3].pct[0].tok.s, + dest); +#endif + opcode = pic16_getpCode(p->pct[0].tok.s,dest); if(opcode < 0) { @@ -662,13 +670,14 @@ static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb) if(pic16Mnemonics[opcode]->isBitInst) { pcosubtype = pic16_newpCodeOp(NULL,PO_BIT); pcosubtype2 = NULL; - } else + } else { +#if 0 if(pic16Mnemonics[opcode]->is2MemOp) { - return NULL; /* support for movff instruction */ pcosubtype = pic16_newpCodeOp(NULL, PO_GPR_REGISTER); - pcosubtype2 = pic16_newpCodeOp(p[3].pct[0].tok.s, PO_GPR_REGISTER); + pcosubtype2 = pic16_newpCodeOp(p[3].pct[0].tok.s, PO_STR); } else { +#endif pcosubtype = pic16_newpCodeOp(NULL,PO_GPR_REGISTER); pcosubtype2 = NULL; } @@ -693,7 +702,6 @@ static void * cvt_altpat_mnem2a(void *pp,pCodeWildBlock *pcwb) } -#if 1 /*-----------------------------------------------------------------*/ /* cvt_altpat_mem2b - convert assembly line type to a pCode */ /* instruction with 2 wild operands */ @@ -761,7 +769,6 @@ static void * cvt_altpat_mnem2b(void *pp,pCodeWildBlock *pcwb) return pci; } -#endif /*-----------------------------------------------------------------*/ @@ -1738,7 +1745,7 @@ static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) return 0; #if 0 - fprintf(stderr," Comparing operands %s", + fprintf(stderr,"%s:%d Comparing operands %s", __FILE__, __LINE__, pic16_get_op( pcops,NULL,0)); fprintf(stderr," to %s\n", @@ -1764,14 +1771,14 @@ static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) n2 = pic16_get_op(pcopd,NULL,0); if( !n2 || strcmp(b,n2)) { - //fprintf(stderr," - fail - diff names: %s, len=%d, %s, len=%d\n",b,strlen(b), n2, strlen(n2) ); +// fprintf(stderr," - fail - diff names: %s, len=%d, %s, len=%d\n",b,strlen(b), n2, strlen(n2) ); return 0; // different names } switch(pcops->type) { case PO_DIR: if( PCOR(pcops)->instance != PCOR(pcopd)->instance) { - //fprintf(stderr, " - fail different instances\n"); +// fprintf(stderr, " - fail different instances\n"); return 0; } break; @@ -1911,6 +1918,7 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) #endif PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop; + havematch = -1; if(!peepBlock->target.wildpCodeOps[index]) { peepBlock->target.wildpCodeOps[index] = PCI(pcs)->pcop; @@ -1930,7 +1938,7 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) // return pCodeOpCompare(PCI(pcs)->pcop, peepBlock->target.wildpCodeOps[index]); } - if(!havematch && PCI(pcs)->pcop) { + if((havematch==-1) && PCI(pcs)->pcop) { char *n; switch(PCI(pcs)->pcop->type) { @@ -1953,13 +1961,13 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) // return 1; } } - + /* now check whether the second operand matches */ - if(PCI(pcd)->is2MemOp && (PCOR2(PCI(pcd)->pcop)->pcop2->type == PO_WILD)) { + if(PCOW2(PCI(pcd)->pcop) && (PCOR2(PCI(pcd)->pcop)->pcop2->type == PO_WILD)) { fprintf(stderr, "%s:%d %s second operand is wild\n", __FILE__, __LINE__, __FUNCTION__); - index = PCOW(PCI(pcd)->pcop)->id2; + index = PCOW2(PCI(pcd)->pcop)->id; //DFPRINTF((stderr,"destination is wild\n")); #ifdef DEBUG_PCODEPEEP if (index > peepBlock->nops) { @@ -1968,7 +1976,7 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) } #endif - PCOW(PCI(pcd)->pcop)->matched2 = PCOR2(PCI(pcs)->pcop)->pcop2; + PCOW2(PCI(pcd)->pcop)->matched = PCOR2(PCI(pcs)->pcop)->pcop2; if(!peepBlock->target.wildpCodeOps[index]) { peepBlock->target.wildpCodeOps[index] = PCOR2(PCI(pcs)->pcop)->pcop2; @@ -1984,7 +1992,7 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) ); */ - return (havematch && pCodeOpCompare(PCOR2(PCI(pcs)->pcop)->pcop2, + return ((havematch==1) && pCodeOpCompare(PCOR2(PCI(pcs)->pcop)->pcop2, peepBlock->target.wildpCodeOps[index])); } @@ -2006,7 +2014,7 @@ static int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd) else { DFPRINTF((stderr,"first time for a variable: %d, %s\n",index,n)); peepBlock->target.vars[index] = n; - return (havematch); //&& 1; + return (havematch==1); //&& 1; } } @@ -2322,6 +2330,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) pCodeCSource *pc_cline=NULL; _DLL *peeprules; int matched; + pCode *pcr; peeprules = (_DLL *)peepSnippets; @@ -2386,7 +2395,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) (pic16_pCodeSearchCondition(pcin,peepBlock->postFalseCond) > 0) ) matched = 0; - //fprintf(stderr," condition results = %d\n",pic16_pCodeSearchCondition(pcin,peepBlock->postFalseCond)); +// fprintf(stderr," condition results = %d\n",pic16_pCodeSearchCondition(pcin,peepBlock->postFalseCond)); //if(!matched) fprintf(stderr,"failed on conditions\n"); @@ -2395,7 +2404,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) if(matched) { pCode *pcprev; - pCode *pcr; +// pCode *pcr; /* We matched a rule! Now we have to go through and remove the @@ -2456,7 +2465,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) if(pcin) pCodeDeleteChain(pc,pcin); - fprintf(stderr, "%s:%d rule matched\n", __FILE__, __LINE__); +// fprintf(stderr, "%s:%d rule matched\n", __FILE__, __LINE__); /* Generate the replacement code */ pc = pcprev; @@ -2472,7 +2481,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) * Is it wild? */ if(PCI(pcr)->pcop->type == PO_WILD) { int index = PCOW(PCI(pcr)->pcop)->id; - fprintf(stderr, "%s:%d replacing index= %d\n", __FUNCTION__, __LINE__, index); +// fprintf(stderr, "%s:%d replacing index= %d\n", __FUNCTION__, __LINE__, index); //DFPRINTF((stderr,"copying wildopcode\n")); if(peepBlock->target.wildpCodeOps[index]) pcop = pic16_pCodeOpCopy(peepBlock->target.wildpCodeOps[index]); @@ -2485,10 +2494,10 @@ int pic16_pCodePeepMatchRule(pCode *pc) if(PCI(pcr)->is2MemOp && PCOR2(PCI(pcr)->pcop)->pcop2) { /* The replacing instruction has also a second operand. * Is it wild? */ - fprintf(stderr, "%s:%d pcop2= %p\n", __FILE__, __LINE__, PCOR2(PCI(pcr)->pcop)->pcop2); +// fprintf(stderr, "%s:%d pcop2= %p\n", __FILE__, __LINE__, PCOR2(PCI(pcr)->pcop)->pcop2); if(PCOR2(PCI(pcr)->pcop)->pcop2->type == PO_WILD) { - int index = PCOW(PCI(pcr)->pcop)->id2; - fprintf(stderr, "%s:%d replacing index= %d\n", __FUNCTION__, __LINE__, index); + int index = PCOW2(PCI(pcr)->pcop)->id; +// fprintf(stderr, "%s:%d replacing index= %d\n", __FUNCTION__, __LINE__, index); //DFPRINTF((stderr,"copying wildopcode\n")); if(peepBlock->target.wildpCodeOps[index]) pcop = pic16_popCombine2(pic16_pCodeOpCopy(pcop), @@ -2497,7 +2506,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) DFPRINTF((stderr,"error, wildopcode in replace but not source?\n")); } else pcop = pic16_popCombine2(pic16_pCodeOpCopy(pcop), - pic16_pCodeOpCopy(PCI(pcr)->pcop), 0); + pic16_pCodeOpCopy(PCOR2(PCI(pcr)->pcop)->pcop2), 0); } diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index b2833778..93cab98d 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -750,7 +750,9 @@ pic16_allocRegByName (char *name, int size, operand *op) /* Register wasn't found in hash, so let's create * a new one and put it in the hash table AND in the * dynDirectRegNames set */ - fprintf (stderr,"%s:%d symbol name %s\tregop= %p\n", __FUNCTION__, __LINE__, name, op); + +// fprintf (stderr,"%s:%d symbol name %s\tregop= %p\n", __FUNCTION__, __LINE__, name, op); + reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,size,0, op); debugLog ("%d -- added %s to hash, size = %d\n", __LINE__, name,reg->size); -- 2.30.2