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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
|
// ---------------------------------------------------------------------------
// - ccnf.cpp -
// - standard platform library - config file generator -
// ---------------------------------------------------------------------------
// - This program is free software; you can redistribute it and/or modify -
// - it provided that this copyright notice is kept intact. -
// - -
// - This program is distributed in the hope that it will be useful, but -
// - without any warranty; without even the implied warranty of -
// - merchantability or fitness for a particular purpose. In no event shall -
// - the copyright holder be liable for any direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software. -
// ---------------------------------------------------------------------------
// - author (c) 1999-2012 amaury darsch -
// - author (c) 2010-2012 nobuhiro iwamatsu superh processor -
// - author (c) 2011-2012 pino toscano hurd platform -
// ---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
// supported platforms
#define AFNIX_PLATFORM_UNKNOWN 0
#define AFNIX_PLATFORM_LINUX 1
#define AFNIX_PLATFORM_SOLARIS 2
#define AFNIX_PLATFORM_FREEBSD 3
#define AFNIX_PLATFORM_DARWIN 4
#define AFNIX_PLATFORM_GNUKBSD 5
#define AFNIX_PLATFORM_GNU 6
// recognized platform name
#define AFNIX_PLATNAME_LINUX "linux"
#define AFNIX_PLATNAME_SOLARIS "solaris"
#define AFNIX_PLATNAME_FREEBSD "freebsd"
#define AFNIX_PLATNAME_DARWIN "darwin"
#define AFNIX_PLATNAME_GNUKBSD "gnukbsd"
#define AFNIX_PLATNAME_GNU "gnu"
// supported processors
#define AFNIX_PROCTYPE_UNKNOWN 0
#define AFNIX_PROCTYPE_IA32 1
#define AFNIX_PROCTYPE_SPARC 2
#define AFNIX_PROCTYPE_ALPHA 3
#define AFNIX_PROCTYPE_ARM 4
#define AFNIX_PROCTYPE_PPC 5
#define AFNIX_PROCTYPE_M68K 6
#define AFNIX_PROCTYPE_MIPS 7
#define AFNIX_PROCTYPE_MIPSEL 8
#define AFNIX_PROCTYPE_PA64 9
#define AFNIX_PROCTYPE_IA64 10
#define AFNIX_PROCTYPE_S390 11
#define AFNIX_PROCTYPE_X64 12
#define AFNIX_PROCTYPE_SH 13
// recognized processor name
#define AFNIX_PROCNAME_UNKNOWN "unknown"
#define AFNIX_PROCNAME_IA32 "ia32"
#define AFNIX_PROCNAME_SPARC "sparc"
#define AFNIX_PROCNAME_ALPHA "alpha"
#define AFNIX_PROCNAME_ARM "arm"
#define AFNIX_PROCNAME_PPC "ppc"
#define AFNIX_PROCNAME_M68K "m68k"
#define AFNIX_PROCNAME_MIPS "mips"
#define AFNIX_PROCNAME_MIPSEL "mipsel"
#define AFNIX_PROCNAME_PA64 "pa64"
#define AFNIX_PROCNAME_IA64 "ia64"
#define AFNIX_PROCNAME_S390 "s390"
#define AFNIX_PROCNAME_X64 "x64"
#define AFNIX_PROCNAME_SH "sh"
// force size type with S390
#if defined(__s390__)
const bool AFNIX_FORCE_LONG = true;
#else
const bool AFNIX_FORCE_LONG = false;
#endif
// special darwin flag
#if defined(__APPLE__)
const bool AFNIX_FORCE_DARWIN = true;
#else
const bool AFNIX_FORCE_DARWIN = false;
#endif
// compute the platform id
static int get_platid (const char* plat) {
if (!plat || (strlen (plat) == 0)) return AFNIX_PLATFORM_UNKNOWN;
// linux
if (strcmp (plat, AFNIX_PLATNAME_LINUX) == 0)
return AFNIX_PLATFORM_LINUX;
// solaris
if (strcmp (plat, AFNIX_PLATNAME_SOLARIS) == 0)
return AFNIX_PLATFORM_SOLARIS;
// freebsd
if (strcmp (plat, AFNIX_PLATNAME_FREEBSD) == 0)
return AFNIX_PLATFORM_FREEBSD;
// darwin
if (strcmp (plat, AFNIX_PLATNAME_DARWIN) == 0)
return AFNIX_PLATFORM_DARWIN;
// gnu/freebsd
if (strcmp (plat, AFNIX_PLATNAME_GNUKBSD) == 0)
return AFNIX_PLATFORM_GNUKBSD;
// gnu/hurd
if (strcmp (plat, AFNIX_PLATNAME_GNU) == 0)
return AFNIX_PLATFORM_GNU;
// unknown
return AFNIX_PLATFORM_UNKNOWN;
}
// compute the processor id
static int get_procid (const char* proc) {
if (!proc || (strlen (proc) == 0)) return AFNIX_PROCTYPE_UNKNOWN;
// ia
if (strcmp (proc, AFNIX_PROCNAME_IA32) == 0)
return AFNIX_PROCTYPE_IA32;
// sparc
if (strcmp (proc, AFNIX_PROCNAME_SPARC) == 0)
return AFNIX_PROCTYPE_SPARC;
// alpha
if (strcmp (proc, AFNIX_PROCNAME_ALPHA) == 0)
return AFNIX_PROCTYPE_ALPHA;
// arm
if (strcmp (proc, AFNIX_PROCNAME_ARM) == 0)
return AFNIX_PROCTYPE_ARM;
// ppc
if (strcmp (proc, AFNIX_PROCNAME_PPC) == 0)
return AFNIX_PROCTYPE_PPC;
// m68k
if (strcmp (proc, AFNIX_PROCNAME_M68K) == 0)
return AFNIX_PROCTYPE_M68K;
// mips
if (strcmp (proc, AFNIX_PROCNAME_MIPS) == 0)
return AFNIX_PROCTYPE_MIPS;
// mipsel
if (strcmp (proc, AFNIX_PROCNAME_MIPSEL) == 0)
return AFNIX_PROCTYPE_MIPSEL;
// pa64
if (strcmp (proc, AFNIX_PROCNAME_PA64) == 0)
return AFNIX_PROCTYPE_PA64;
// ia64
if (strcmp (proc, AFNIX_PROCNAME_IA64) == 0)
return AFNIX_PROCTYPE_IA64;
// s390
if (strcmp (proc, AFNIX_PROCNAME_S390) == 0)
return AFNIX_PROCTYPE_S390;
// x86-64
if (strcmp (proc, AFNIX_PROCNAME_X64) == 0) {
switch (sizeof(void*)) {
case 4:
return AFNIX_PROCTYPE_IA32;
case 8:
return AFNIX_PROCTYPE_X64;
default:
return AFNIX_PROCTYPE_UNKNOWN;
}
}
// SuperH
if (strcmp (proc, AFNIX_PROCNAME_SH) == 0)
return AFNIX_PROCTYPE_SH;
// unknown
return AFNIX_PROCTYPE_UNKNOWN;
}
// get the processor name by id - this is needed as the procid
// can remap the processor
static const char* get_procnm (const int id) {
if (id == AFNIX_PROCTYPE_IA32) return AFNIX_PROCNAME_IA32;
if (id == AFNIX_PROCTYPE_SPARC) return AFNIX_PROCNAME_SPARC;
if (id == AFNIX_PROCTYPE_ALPHA) return AFNIX_PROCNAME_ALPHA;
if (id == AFNIX_PROCTYPE_ARM) return AFNIX_PROCNAME_ARM;
if (id == AFNIX_PROCTYPE_PPC) return AFNIX_PROCNAME_PPC;
if (id == AFNIX_PROCTYPE_M68K) return AFNIX_PROCNAME_M68K;
if (id == AFNIX_PROCTYPE_MIPS) return AFNIX_PROCNAME_MIPS;
if (id == AFNIX_PROCTYPE_MIPSEL) return AFNIX_PROCNAME_MIPSEL;
if (id == AFNIX_PROCTYPE_PA64) return AFNIX_PROCNAME_PA64;
if (id == AFNIX_PROCTYPE_IA64) return AFNIX_PROCNAME_IA64;
if (id == AFNIX_PROCTYPE_S390) return AFNIX_PROCNAME_S390;
if (id == AFNIX_PROCTYPE_X64) return AFNIX_PROCNAME_X64;
if (id == AFNIX_PROCTYPE_SH) return AFNIX_PROCNAME_SH;
return AFNIX_PROCNAME_UNKNOWN;
}
// the ccnf header
static const char* header =
"// ------------------------------------------------------------------------\n"
"// - ccnf.hpp -\n"
"// - standard platform library - base type configuration -\n"
"// ------------------------------------------------------------------------\n"
"// - This program is free software; you can redistribute it and/or modify -\n"
"// - it provided that this copyright notice is kept intact. -\n"
"// - -\n"
"// - This program is distributed in the hope that it will be useful, but -\n"
"// - without any warranty; without even the implied warranty of -\n"
"// - merchantability or fitness for a particular purpose. In no event -\n"
"// - shall the copyright holder be liable for any direct, indirect, -\n"
"// - incidental or special damages arising in any way out of the use of -\n"
"// - this software. -\n"
"// - -\n"
"// - This file was automatically generated by ccnf -\n"
"// ------------------------------------------------------------------------\n"
"// - copyright (c) 1999-2012 amaury darsch -\n"
"// ------------------------------------------------------------------------";
static const char* nilptr =
"// the base nilp pointer definition\n"
"#ifndef nilp\n"
"#define nilp 0\n"
"#endif\n";
static const char* darwindefs =
"// special darwin definitions\n"
"#if defined (__APPLE__)\n"
"#if defined (__ppc__)\n"
"#define AFNIX_DARWIN_PROCID AFNIX_PROCTYPE_PPC\n"
"#define AFNIX_DARWIN_PROC AFNIX_PROCNAME_PPC\n"
"#elif defined (__ppc64__)\n"
"#define AFNIX_DARWIN_PROCID AFNIX_PROCTYPE_PPC\n"
"#define AFNIX_DARWIN_PROC AFNIX_PROCNAME_PPC\n"
"#elif defined (__i386__)\n"
"#define AFNIX_DARWIN_PROCID AFNIX_PROCTYPE_IA32\n"
"#define AFNIX_DARWIN_PROC AFNIX_PROCNAME_IA32\n"
"#else\n"
"#error \"unsupported darwin architecture\"\n"
"#endif\n"
"#endif\n";
static const char* types =
" // fundamental types of the afnix system\n"
" typedef unsigned char t_byte;\n"
" typedef unsigned short t_word;\n"
" typedef unsigned int t_quad;\n"
" typedef unsigned long long t_octa;\n"
" typedef long long t_long;\n"
" typedef double t_real;\n";
static const char* constants =
" // fundamental characters of the afnix system\n"
" const char nilc = 0x00; // nil character\n"
" const char sohc = 0x01; // start of heading\n"
" const char stxc = 0x02; // start of text\n"
" const char etxc = 0x03; // end of text\n"
" const char eosc = 0x04; // end of stream\n"
" const char bspc = 0x08; // backspace\n"
" const char delc = 0x7f; // delete\n"
" const char eolc = 0x0a; // end of line\n"
" const char crlc = 0x0d; // carriage return\n"
" const char blkc = 0x20; // blank\n"
" const char tabc = 0x09; // tab\n"
"\n"
" // fundamental quads of the afnix system\n"
" const t_quad nilq = 0x00000000; // nil quad\n"
" const t_quad sohq = 0x00000001; // start of heading\n"
" const t_quad stxq = 0x00000002; // start of text\n"
" const t_quad etxq = 0x00000003; // end of text\n"
" const t_quad eosq = 0x00000004; // end of stream\n"
" const t_quad bspq = 0x00000008; // backspace\n"
" const t_quad delq = 0x0000007f; // delete\n"
" const t_quad eolq = 0x0000000a; // end of line\n"
" const t_quad crlq = 0x0000000d; // carriage return\n"
" const t_quad blkq = 0x00000020; // blank\n"
" const t_quad tabq = 0x00000009; // tab\n";
int main (int, char**) {
// print the header
fprintf (stdout, "%s\n\n", header);
// install the control header
fprintf (stdout, "#ifndef AFNIX_CCNF_HPP\n");
fprintf (stdout, "#define AFNIX_CCNF_HPP\n\n");
// define current revision
fprintf (stdout, "// afnix revision\n");
fprintf (stdout, "#define AFNIX_VERSION_MAJOR %s\n", PLTMAJOR);
fprintf (stdout, "#define AFNIX_VERSION_MINOR %s\n", PLTMINOR);
fprintf (stdout, "#define AFNIX_VERSION_PATCH %s\n", PLTPATCH);
fprintf (stdout, "#define AFNIX_VERSION_TOTAL \"%s.%s.%s\"\n",
PLTMAJOR, PLTMINOR, PLTPATCH);
fprintf (stdout, "\n");
// define the platform list
fprintf (stdout, "// supported platforms\n");
fprintf (stdout, "#define AFNIX_PLATFORM_UNKNOWN %d\n",
AFNIX_PLATFORM_UNKNOWN);
fprintf (stdout, "#define AFNIX_PLATFORM_LINUX %d\n",
AFNIX_PLATFORM_LINUX);
fprintf (stdout, "#define AFNIX_PLATFORM_SOLARIS %d\n",
AFNIX_PLATFORM_SOLARIS);
fprintf (stdout, "#define AFNIX_PLATFORM_FREEBSD %d\n",
AFNIX_PLATFORM_FREEBSD);
fprintf (stdout, "#define AFNIX_PLATFORM_DARWIN %d\n",
AFNIX_PLATFORM_DARWIN);
fprintf (stdout, "#define AFNIX_PLATFORM_GNUKBSD %d\n",
AFNIX_PLATFORM_GNUKBSD);
fprintf (stdout, "#define AFNIX_PLATFORM_GNU %d\n",
AFNIX_PLATFORM_GNU);
fprintf (stdout, "\n");
// define the processor list
fprintf (stdout, "// supported processors\n");
fprintf (stdout, "#define AFNIX_PROCTYPE_UNKNOWN %d\n",
AFNIX_PROCTYPE_UNKNOWN);
fprintf (stdout, "#define AFNIX_PROCTYPE_IA32 %d\n",
AFNIX_PROCTYPE_IA32);
fprintf (stdout, "#define AFNIX_PROCTYPE_SPARC %d\n",
AFNIX_PROCTYPE_SPARC);
fprintf (stdout, "#define AFNIX_PROCTYPE_ALPHA %d\n",
AFNIX_PROCTYPE_ALPHA);
fprintf (stdout, "#define AFNIX_PROCTYPE_ARM %d\n",
AFNIX_PROCTYPE_ARM);
fprintf (stdout, "#define AFNIX_PROCTYPE_PPC %d\n",
AFNIX_PROCTYPE_PPC);
fprintf (stdout, "#define AFNIX_PROCTYPE_M68K %d\n",
AFNIX_PROCTYPE_M68K);
fprintf (stdout, "#define AFNIX_PROCTYPE_MIPS %d\n",
AFNIX_PROCTYPE_MIPS);
fprintf (stdout, "#define AFNIX_PROCTYPE_MIPSEL %d\n",
AFNIX_PROCTYPE_MIPSEL);
fprintf (stdout, "#define AFNIX_PROCTYPE_PA64 %d\n",
AFNIX_PROCTYPE_PA64);
fprintf (stdout, "#define AFNIX_PROCTYPE_IA64 %d\n",
AFNIX_PROCTYPE_IA64);
fprintf (stdout, "#define AFNIX_PROCTYPE_S390 %d\n",
AFNIX_PROCTYPE_S390);
fprintf (stdout, "#define AFNIX_PROCTYPE_X64 %d\n",
AFNIX_PROCTYPE_X64);
fprintf (stdout, "#define AFNIX_PROCTYPE_SH %d\n",
AFNIX_PROCTYPE_SH);
fprintf (stdout, "\n");
// recognized processor names
fprintf (stdout, "// recognized processor names\n");
fprintf (stdout, "#define AFNIX_PROCNAME_UNKNOWN \"%s\"\n",
AFNIX_PROCNAME_UNKNOWN);
fprintf (stdout, "#define AFNIX_PROCNAME_IA32 \"%s\"\n",
AFNIX_PROCNAME_IA32);
fprintf (stdout, "#define AFNIX_PROCNAME_SPARC \"%s\"\n",
AFNIX_PROCNAME_SPARC);
fprintf (stdout, "#define AFNIX_PROCNAME_ALPHA \"%s\"\n",
AFNIX_PROCNAME_ALPHA);
fprintf (stdout, "#define AFNIX_PROCNAME_ARM \"%s\"\n",
AFNIX_PROCNAME_ARM);
fprintf (stdout, "#define AFNIX_PROCNAME_PPC \"%s\"\n",
AFNIX_PROCNAME_PPC);
fprintf (stdout, "#define AFNIX_PROCNAME_M68K \"%s\"\n",
AFNIX_PROCNAME_M68K);
fprintf (stdout, "#define AFNIX_PROCNAME_MIPS \"%s\"\n",
AFNIX_PROCNAME_MIPS);
fprintf (stdout, "#define AFNIX_PROCNAME_MIPSEL \"%s\"\n",
AFNIX_PROCNAME_MIPSEL);
fprintf (stdout, "#define AFNIX_PROCNAME_PA64 \"%s\"\n",
AFNIX_PROCNAME_PA64);
fprintf (stdout, "#define AFNIX_PROCNAME_IA64 \"%s\"\n",
AFNIX_PROCNAME_IA64);
fprintf (stdout, "#define AFNIX_PROCNAME_S390 \"%s\"\n",
AFNIX_PROCNAME_S390);
fprintf (stdout, "#define AFNIX_PROCNAME_X64 \"%s\"\n",
AFNIX_PROCNAME_X64);
fprintf (stdout, "#define AFNIX_PROCNAME_SH \"%s\"\n",
AFNIX_PROCNAME_SH);
fprintf (stdout, "\n");
// install the darwin definition
if (AFNIX_FORCE_DARWIN == true) {
fprintf (stdout, "%s", darwindefs);
fprintf (stdout, "\n");
}
// compute id and name
const int platid = get_platid (PLATNAME);
const int procid = get_procid (PROCNAME);
const char* procnm = get_procnm (procid);
// install the config names
fprintf (stdout, "// platform definitions\n");
fprintf (stdout, "#define AFNIX_PLATFORM_PLATID %d\n", platid);
fprintf (stdout, "#define AFNIX_PLATFORM_VERSION %s\n", PLATVERS);
fprintf (stdout, "#define AFNIX_PLATFORM_MAJOR %s\n", PLATVMAJ);
fprintf (stdout, "#define AFNIX_PLATFORM_MINOR %s\n", PLATVMIN);
fprintf (stdout, "#define AFNIX_PLATFORM_NAME \"%s\"\n", PLATNAME);
fprintf (stdout, "#define AFNIX_PLATFORM_VINFO \"%s\"\n", PLATVERS);
// special case for darwin
if (AFNIX_FORCE_DARWIN == true) {
fprintf (stdout, "#define AFNIX_PLATFORM_PROCID AFNIX_DARWIN_PROCID\n");
fprintf (stdout, "#define AFNIX_PLATFORM_PROC AFNIX_DARWIN_PROC\n");
} else {
fprintf (stdout, "#define AFNIX_PLATFORM_PROCID %d\n", procid);
fprintf (stdout, "#define AFNIX_PLATFORM_PROC \"%s\"\n", procnm);
}
fprintf (stdout, "#define AFNIX_PLATFORM_PTYPE \"%s\"\n", PROCTYPE);
fprintf (stdout, "\n");
// install installation onfiguration
fprintf (stdout, "// configuration definitions\n");
if (strcmp (LINKTYPE, "static") == 0) {
fprintf (stdout, "#define AFNIX_REGISTER_STATIC\n");
fprintf (stdout, "#define AFNIX_LINKTYPE_STATIC true\n");
} else {
fprintf (stdout, "#define AFNIX_LINKTYPE_STATIC false\n");
}
fprintf (stdout, "\n");
// add the nil pointer definition
fprintf (stdout, "%s", nilptr);
fprintf (stdout, "\n");
// start the namespace
fprintf (stdout, "namespace afnix {\n");
// install the base types
fprintf (stdout, "%s", types);
fprintf (stdout, "\n");
// install the size type
fprintf (stdout, " // pointer size type\n");
if (platid == AFNIX_PLATFORM_DARWIN)
fprintf (stdout, " typedef unsigned long int t_size;\n");
else if (AFNIX_FORCE_LONG == true)
fprintf (stdout, " typedef unsigned long t_size;\n");
else if (sizeof (void*) == 8 )
fprintf (stdout, " typedef unsigned long t_size;\n");
else
fprintf (stdout, " typedef unsigned int t_size;\n");
fprintf (stdout, "\n");
// install the constants
fprintf (stdout, "%s", constants);
// install the footer
fprintf (stdout, "}\n\n");
fprintf (stdout, "#endif\n");
return 0;
}
|