/* -------------------------------------------------------------- */ /* * TCC - Tiny C Compiler * * tcctools.c - extra tools and and -m32/64 support * */ /* -------------------------------------------------------------- */ /* * This program is for making libtcc1.a without ar * tiny_libmaker - tiny elf lib maker * usage: tiny_libmaker [lib] files... * Copyright (c) 2007 Timppa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "tcc.h" //#define ARMAG "!\n" #define ARFMAG "`\n" typedef struct { char ar_name[16]; char ar_date[12]; char ar_uid[6]; char ar_gid[6]; char ar_mode[8]; char ar_size[10]; char ar_fmag[2]; } ArHdr; static unsigned long le2belong(unsigned long ul) { return ((ul & 0xFF0000)>>8)+((ul & 0xFF000000)>>24) + ((ul & 0xFF)<<24)+((ul & 0xFF00)<<8); } /* Returns 1 if s contains any of the chars of list, else 0 */ static int contains_any(const char *s, const char *list) { const char *l; for (; *s; s++) { for (l = list; *l; l++) { if (*s == *l) return 1; } } return 0; } static int ar_usage(int ret) { fprintf(stderr, "usage: tcc -ar [rcsv] lib file...\n"); fprintf(stderr, "create library ([abdioptxN] not supported).\n"); return ret; } ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv) { static ArHdr arhdr = { "/ ", " ", "0 ", "0 ", "0 ", " ", ARFMAG }; static ArHdr arhdro = { " ", " ", "0 ", "0 ", "0 ", " ", ARFMAG }; FILE *fi, *fh = NULL, *fo = NULL; ElfW(Ehdr) *ehdr; ElfW(Shdr) *shdr; ElfW(Sym) *sym; int i, fsize, i_lib, i_obj; char *buf, *shstr, *symtab = NULL, *strtab = NULL; int symtabsize = 0;//, strtabsize = 0; char *anames = NULL; int *afpos = NULL; int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs; char tfile[260], stmp[20]; char *file, *name; int ret = 2; const char *ops_conflict = "habdioptxN"; // unsupported but destructive if ignored. int verbose = 0; i_lib = 0; i_obj = 0; // will hold the index of the lib and first obj for (i = 1; i < argc; i++) { const char *a = argv[i]; if (*a == '-' && strstr(a, ".")) ret = 1; // -x.y is always invalid (same as gnu ar) if ((*a == '-') || (i == 1 && !strstr(a, "."))) { // options argument if (contains_any(a, ops_conflict)) ret = 1; if (strstr(a, "v")) verbose = 1; } else { // lib or obj files: don't abort - keep validating all args. if (!i_lib) // first file is the lib i_lib = i; else if (!i_obj) // second file is the first obj i_obj = i; } } if (!i_obj) // i_obj implies also i_lib. we require both. ret = 1; if (ret == 1) return ar_usage(ret); if ((fh = fopen(argv[i_lib], "wb")) == NULL) { fprintf(stderr, "tcc: ar: can't open file %s \n", argv[i_lib]); goto the_end; } sprintf(tfile, "%s.tmp", argv[i_lib]
discard """
  cmd: "nim cpp $file"
  output: '''int
float'''
"""

import typetraits

# bug #4625
type
  Vector {.importcpp: "std::vector<'0 >", header: "vector".} [T] = object

proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.}

proc doSomething[T](v: var Vector[T]) =
  echo T.name

var v = initVector[int]()
v.doSomething()

var vf = initVector[float]()
vf.doSomething() # Nim uses doSomething[int] here in C++
d/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* re-execute the i386/x86_64 cross-compilers with tcc -m32/-m64: */ #if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64 ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option) { tcc_error("-m%d not implemented.", option); } #else #ifdef _WIN32 #include static char *str_replace(const char *str, const char *p, const char *r) { const char *s, *s0; char *d, *d0; int sl, pl, rl; sl = strlen(str); pl = strlen(p); rl = strlen(r); for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) { for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) { if (d) { memcpy(d, s0, sl = s - s0), d += sl; memcpy(d, r, rl), d += rl; } else sl += rl - pl; } if (d) { strcpy(d, s0); return d0; } } } static int execvp_win32(const char *prog, char **argv) { int ret; char **p; /* replace all " by \" */ for (p = argv; *p; ++p) if (strchr(*p, '"')) *p = str_replace(*p, "\"", "\\\""); ret = _spawnvp(P_NOWAIT, prog, (const char *const*)argv); if (-1 == ret) return ret; _cwait(&ret, ret, WAIT_CHILD); exit(ret); } #define execvp execvp_win32 #endif /* _WIN32 */ ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int target) { char program[4096]; char *a0 = argv[0]; int prefix = tcc_basename(a0) - a0; snprintf(program, sizeof program, "%.*s%s" #ifdef TCC_TARGET_PE "-win32" #endif "-tcc" #ifdef _WIN32 ".exe" #endif , prefix, a0, target == 64 ? "x86_64" : "i386"); if (strcmp(a0, program)) execvp(argv[0] = program, argv); tcc_error("could not run '%s'", program); } #endif /* TCC_TARGET_I386 && TCC_TARGET_X86_64 */ /* -------------------------------------------------------------- */ /* enable commandline wildcard expansion (tcc -o x.exe *.c) */ #ifdef _WIN32 int _CRT_glob = 1; #ifndef _CRT_glob int _dowildcard = 1; #endif #endif /* -------------------------------------------------------------- */ /* generate xxx.d file */ ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename) { FILE *depout; char buf[1024]; int i; if (!filename) { /* compute filename automatically: dir/file.o -> dir/file.d */ snprintf(buf, sizeof buf, "%.*s.d", (int)(tcc_fileextension(target) - target), target); filename = buf; } if (s->verbose) printf("<- %s\n", filename); /* XXX return err codes instead of error() ? */ depout = fopen(filename, "w"); if (!depout) tcc_error("could not open '%s'", filename); fprintf(depout, "%s: \\\n", target); for (i=0; inb_target_deps; ++i) fprintf(depout, " %s \\\n", s->target_deps[i]); fprintf(depout, "\n"); fclose(depout); } /* -------------------------------------------------------------- */