summaryrefslogtreecommitdiff
path: root/support/tests/internal/testmacro.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/tests/internal/testmacro.c
downloadsdcc-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/testmacro.c')
-rw-r--r--support/tests/internal/testmacro.c84
1 files changed, 84 insertions, 0 deletions
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;
+}