File: testmacro.c

package info (click to toggle)
sdcc 4.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100,120 kB
  • sloc: ansic: 935,524; cpp: 75,055; makefile: 57,615; sh: 30,106; asm: 14,243; perl: 12,136; yacc: 7,297; lisp: 1,672; python: 815; lex: 781; awk: 498; sed: 89
file content (84 lines) | stat: -rw-r--r-- 1,641 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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; 
}