summary refs log tree commit diff stats
path: root/compiler/passaux.nim
Commit message (Expand)AuthorAgeFilesLines
* test removing dollar for objects out of system (#20242)metagn2022-08-241-0/+2
* improvements to hint:processing: show import stack, distinguish nims, show in...Timothee Cour2021-06-301-9/+4
* even lighter version of #17938: fix most issues with UnusedImport, XDeclaredB...Timothee Cour2021-06-261-1/+1
* add `--processing:dots|filenames|off` to customize `hintProcessing` (#17817)Timothee Cour2021-04-231-3/+4
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-4/+4
* properly handle note override logic/verbosity/config/cmdline using modifiedyN...Timothee Cour2020-02-271-2/+2
* [refactoring] remove unused imports in the compiler and in some stdlib modulesAraq2019-07-181-1/+1
* styleCheck: make the compiler and large parts of the stdlib compatible with -...Araq2019-07-101-1/+1
* Make the registered passes local to the ModuleGraph (#9259)LemonBoy2018-10-091-2/+2
* incremental compilation: implemented basic replay logicAndreas Rumpf2018-06-021-1/+1
* remove more global variables in the Nim compilerAndreas Rumpf2018-05-271-1/+1
* options.nim: no global variables anymoreAndreas Rumpf2018-05-131-1/+1
* the remaining passes all compile againAndreas Rumpf2018-05-131-6/+10
* big compiler refactoring; avoid globals for multi method dispatcher generationAndreas Rumpf2017-02-221-18/+0
* new dependency tracking for nimsuggestAraq2016-11-051-1/+3
* refactoring complete: explicit ident cacheAraq2016-10-311-2/+2
* C code generation now deterministic; fixes #4364Andreas Rumpf2016-06-221-1/+1
* compiler: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-041-12/+12
* Introduce NotesVerbosity defining verbosity levelsAdam Strzelecki2015-07-031-1/+1
* Nimrod renamed to NimAraq2014-08-281-1/+1
* 'nil' as a statement is deprecated, use an empty 'discard' insteadAraq2014-01-191-1/+1
* case consistency part 4Araq2013-12-271-3/+3
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
* CaaS in-memory cachingZahary Karadjov2012-11-281-2/+2
* caas is now drivable through stdinZahary Karadjov2012-11-281-8/+3
* docgen2 improvementsAraq2012-06-231-1/+1
* year 2012 for most copyright headersAraq2012-01-021-1/+1
* lazy loading of body ast implementedAraq2011-10-301-1/+1
* much more efficient rod file generationAraq2011-10-181-2/+2
* big repo cleanupAraq2011-04-121-0/+52
v class='alt'>
040c57f0a ^
e8657c710 ^
d68181246 ^
e8657c710 ^

d68181246 ^
040c57f0a ^

93cd98dd1 ^
e8657c710 ^
93cd98dd1 ^



040c57f0a ^
93cd98dd1 ^


d68181246 ^
93cd98dd1 ^

040c57f0a ^

2133fbfcc ^

040c57f0a ^
93cd98dd1 ^

040c57f0a ^



d68181246 ^
93cd98dd1 ^


7e747d11c ^
040c57f0a ^
93cd98dd1 ^
040c57f0a ^
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

 
                            
                                         





                                                   
                                                         
 








                                                                            
 
                                                                  
                                       

                               






                                              
                                
                                        
                                                  
 
                       

                                           
                     
                                         


                                          



                                         
 
                                          
                        

                                                                         
                        

                                       
                                                              
                                                             



                                                  
 


                                                  
 

                                                   

                                             

                                                                
 

                                                    



                                      
 


                                                                                                
                                                                                   
                      
                                          
 
#
#
#           The Nim Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

import
  os, strutils, options, msgs, tinyc, lineinfos, sequtils

const tinyPrefix = "dist/nim-tinyc-archive".unixToNativePath
const nimRoot = currentSourcePath.parentDir.parentDir
const tinycRoot = nimRoot / tinyPrefix
when not dirExists(tinycRoot):
  static: doAssert false, $(tinycRoot, "requires: ./koch installdeps tinyc")
{.compile: tinycRoot / "tinyc/libtcc.c".}

var
  gConf: ConfigRef # ugly but can be cleaned up if this is revived

proc tinyCErrorHandler(closure: pointer, msg: cstring) {.cdecl.} =
  rawMessage(gConf, errGenerated, $msg)

proc initTinyCState: PccState =
  result = openCCState()
  setErrorFunc(result, nil, tinyCErrorHandler)

var
  gTinyC = initTinyCState()
  libIncluded = false

proc addFile(filename: string) =
  if addFile(gTinyC, filename) != 0'i32:
    rawMessage(gConf, errCannotOpenFile, filename)

proc setupEnvironment =
  when defined(amd64):
    defineSymbol(gTinyC, "__x86_64__", nil)
  elif defined(i386):
    defineSymbol(gTinyC, "__i386__", nil)
  when defined(linux):
    defineSymbol(gTinyC, "__linux__", nil)
    defineSymbol(gTinyC, "__linux", nil)

  var nimDir = getPrefixDir(gConf).string
  var tinycRoot = nimDir / tinyPrefix
  let libpath = nimDir / "lib"

  addIncludePath(gTinyC, cstring(libpath))
  when defined(windows):
    addSysincludePath(gTinyC, cstring(tinycRoot / "tinyc/win32/include"))
  addSysincludePath(gTinyC, cstring(tinycRoot / "tinyc/include"))
  when defined(windows):
    defineSymbol(gTinyC, "_WIN32", nil)
    # we need Mingw's headers too:
    var gccbin = getConfigVar("gcc.path") % ["nim", tinycRoot]
    addSysincludePath(gTinyC, cstring(gccbin /../ "include"))
    #addFile(tinycRoot / r"tinyc\win32\wincrt1.o")
    addFile(tinycRoot / r"tinyc\win32\alloca86.o")
    addFile(tinycRoot / r"tinyc\win32\chkstk.o")
    #addFile(tinycRoot / r"tinyc\win32\crt1.o")

    #addFile(tinycRoot / r"tinyc\win32\dllcrt1.o")
    #addFile(tinycRoot / r"tinyc\win32\dllmain.o")
    addFile(tinycRoot / r"tinyc\win32\libtcc1.o")

    #addFile(tinycRoot / r"tinyc\win32\lib\crt1.c")
    #addFile(tinycRoot / r"tinyc\lib\libtcc1.c")
  else:
    addSysincludePath(gTinyC, "/usr/include")
    when defined(amd64):
      addSysincludePath(gTinyC, "/usr/include/x86_64-linux-gnu")

proc compileCCode*(ccode: string, conf: ConfigRef) =
  gConf = conf
  if not libIncluded:
    libIncluded = true
    setupEnvironment()
  discard compileString(gTinyC, ccode)

proc run*(conf: ConfigRef, args: string) =
  doAssert gConf == conf
  var s = @[cstring(conf.projectName)] & map(split(args), proc(x: string): cstring = cstring(x))
  var err = tinyc.run(gTinyC, cint(s.len), cast[cstringArray](addr(s[0]))) != 0'i32
  closeCCState(gTinyC)
  if err: rawMessage(conf, errUnknown, "")