diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/tests/internal | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/tests/internal')
| -rw-r--r-- | support/tests/internal/Makefile | 21 | ||||
| -rw-r--r-- | support/tests/internal/stubs.c | 5 | ||||
| -rw-r--r-- | support/tests/internal/testmacro.c | 84 |
3 files changed, 110 insertions, 0 deletions
diff --git a/support/tests/internal/Makefile b/support/tests/internal/Makefile new file mode 100644 index 0000000..94c103a --- /dev/null +++ b/support/tests/internal/Makefile @@ -0,0 +1,21 @@ +TOPDIR = ../../.. + +LIBSOURCE = \ + $(TOPDIR)/src/SDCCutil.c \ + $(TOPDIR)/src/SDCChasht.c \ + $(TOPDIR)/support/util/NewAlloc.c \ + $(TOPDIR)/support/util/SDCCerr.c \ + $(TOPDIR)/src/SDCCmacro.c \ + stubs.c + +SOURCES = testpaths.c $(LIBSOURCE) + +include $(TOPDIR)/Makefile.common + +CFLAGS += -I$(TOPDIR)/src -I$(TOPDIR)/support/util -I$(TOPDIR) + +all: all-tests + +all-tests: $(OBJ) + $(CC) -o $@ $(OBJ) + diff --git a/support/tests/internal/stubs.c b/support/tests/internal/stubs.c new file mode 100644 index 0000000..ee5e809 --- /dev/null +++ b/support/tests/internal/stubs.c @@ -0,0 +1,5 @@ +int fatalError; +int lineno; +char *filename = "tests"; +char buffer[4096]; +char scratchFileName[4096]; diff --git a/support/tests/internal/testmacro.c b/support/tests/internal/testmacro.c new file mode 100644 index 0000000..d25eecf --- /dev/null +++ b/support/tests/internal/testmacro.c @@ -0,0 +1,84 @@ +#include <SDCCmacro.h> +#include <stdio.h> + +static const char *_maps[] = + { + "immedzero", "#0", + "immedvala", "#0x%02X", + "stra", "%s", + "port", "z80", + "stdlibpath", "{basepath}/lib/{port}", + "stdlibname", "{port}.lib", + "portouttypeflag", "-i", + "srcfilename", "fish", + "portoutext", ".ihx", + "crt0name", "{stdlibpath}/crt0{portobjext}", + "portobjext", ".o", + "otherobjfiles", "none", + "basepath", "/home/michaelh/sdcc", + NULL + }; + +static hTab * +_populateHash(const char **pin) +{ + hTab *pret = NULL; + + while (*pin) + { + printf("Adding %s -> %s\n", pin[0], pin[1]); + shash_add (&pret, pin[0], pin[1]); + pin += 2; + + } + + return pret; +} + +static void +_testEval(hTab *ph, const char *pin, const char *pexpect, ...) +{ + va_list ap; + char *pgot; + + va_start(ap, pexpect); + + pgot = mvsprintf(ph, pin, ap); + + if (strcmp(pgot, pexpect) != 0) + { + printf("Fail: expected: %s, got %s\n", pexpect, pgot); + } + else + { + printf("%s -> %s\n", pin, pgot); + } + + va_end(ap); +} + +void +testMacros(void) +{ + hTab *ph = _populateHash(_maps); + + _testEval(ph, "{immedzero}", "#0"); + _testEval(ph, "{immedvala}", "#0x23", 0x23); + _testEval(ph, "{stra}", "#0", "{immedzero}"); + + printf("Link command:\n%s\n", + msprintf(ph, + "link-{port} -n -c -- -b_CODE=0x%04X -b_DATA=0x%04X" + " -m -j -k{stdlibpath} -l{stdlibname} {portouttypeflag}" + " {srcfilename}{portoutext} {crt0name} {srcfilename}{portobjext} {otherobjfiles}", + 0x1234, 0x3456)); + +} + +int +main(void) +{ + testMacros(); + + return 0; +} |
