summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-10-27 21:03:53 +0200
committerAraq <rumpf_a@web.de>2011-10-27 21:03:53 +0200
commit5e5e4abfeee16bcacf659d35745d456586cb37e5 (patch)
treeb6f613094501c7e260be84821670c26d57969d75
parentabe9dfafe84015d275d9fed3cb81c97666daf298 (diff)
downloadNim-5e5e4abfeee16bcacf659d35745d456586cb37e5.tar.gz
new compiler option tlsEmulation
-rwxr-xr-xcompiler/ccgstmts.nim6
-rwxr-xr-xcompiler/ccgthreadvars.nim4
-rwxr-xr-xcompiler/commands.nim9
-rwxr-xr-xcompiler/condsyms.nim3
-rwxr-xr-xcompiler/msgs.nim11
-rwxr-xr-xcompiler/options.nim3
-rwxr-xr-xcompiler/platform.nim10
-rwxr-xr-xdoc/advopt.txt1
-rwxr-xr-xlib/system/threads.nim2
-rwxr-xr-xtodo.txt5
-rwxr-xr-xweb/news.txt2
11 files changed, 28 insertions, 28 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index bf3d6aea1..346f86737 100755
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -655,9 +655,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
     asgnFieldDiscriminant(p, e)
 
 proc genStmts(p: BProc, t: PNode) = 
-  var 
-    a: TLoc
-    prc: PSym
+  var a: TLoc
   case t.kind
   of nkEmpty: 
     nil
@@ -697,7 +695,7 @@ proc genStmts(p: BProc, t: PNode) =
   of nkPragma: genPragma(p, t)
   of nkProcDef, nkMethodDef, nkConverterDef: 
     if (t.sons[genericParamsPos].kind == nkEmpty): 
-      prc = t.sons[namePos].sym
+      var prc = t.sons[namePos].sym
       if (optDeadCodeElim notin gGlobalOptions and
           sfDeadCodeElim notin getModule(prc).flags) or
           ({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
diff --git a/compiler/ccgthreadvars.nim b/compiler/ccgthreadvars.nim
index 0f3661010..d11b6f06a 100755
--- a/compiler/ccgthreadvars.nim
+++ b/compiler/ccgthreadvars.nim
@@ -11,9 +11,7 @@
 ## thread local storage. (**Thank you Mac OS X!**)
 
 proc emulatedThreadVars(): bool {.inline.} =
-  result = optThreads in gGlobalOptions
-  # NOW: Use the work-around everywhere, because it should be faster anyway.
-  #platform.OS[targetOS].props.contains(ospLacksThreadVars)
+  result = {optThreads, optTlsEmulation} <= gGlobalOptions
 
 proc AccessThreadLocalVar(p: BProc, s: PSym) =
   if emulatedThreadVars() and not p.ThreadVarAccessed:
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 3a2c0d6cb..cf172111a 100755
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -34,8 +34,8 @@ const
   AdvancedUsage = slurp"doc/advopt.txt".replace("//", "")
 
 proc getCommandLineDesc(): string = 
-  result = `%`(HelpMessage, [VersionAsString, platform.os[platform.hostOS].name, 
-                             cpu[platform.hostCPU].name]) & Usage
+  result = (HelpMessage % [VersionAsString, platform.os[platform.hostOS].name, 
+                           cpu[platform.hostCPU].name]) & Usage
 
 var 
   helpWritten: bool           # BUGFIX 19
@@ -191,6 +191,7 @@ proc testCompileOption*(switch: string, info: TLineInfo): bool =
   of "genscript": result = contains(gGlobalOptions, optGenScript)
   of "threads": result = contains(gGlobalOptions, optThreads)
   of "taintmode": result = contains(gGlobalOptions, optTaintMode)
+  of "tlsemulation": result = contains(gGlobalOptions, optTlsEmulation)
   else: InvalidCmdLineOption(passCmd1, switch, info)
   
 proc processPath(path: string): string = 
@@ -314,6 +315,7 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
   of "assertions", "a": ProcessOnOffSwitch({optAssert}, arg, pass, info)
   of "deadcodeelim": ProcessOnOffSwitchG({optDeadCodeElim}, arg, pass, info)
   of "threads": ProcessOnOffSwitchG({optThreads}, arg, pass, info)
+  of "tlsemulation": ProcessOnOffSwitchG({optTlsEmulation}, arg, pass, info)
   of "taintmode": ProcessOnOffSwitchG({optTaintMode}, arg, pass, info)
   of "opt":
     expectArg(switch, arg, pass, info)
@@ -438,7 +440,6 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
 proc ProcessCommand(switch: string, pass: TCmdLinePass) = 
   var
     cmd, arg: string
-    info: TLineInfo
-  info = newLineInfo("command line", 1, 1)
+  var info = newLineInfo("command line", 1, 1)
   splitSwitch(switch, cmd, arg, pass, info)
   ProcessSwitch(cmd, arg, pass, info)
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim
index b37b754f0..376134180 100755
--- a/compiler/condsyms.nim
+++ b/compiler/condsyms.nim
@@ -88,4 +88,7 @@ proc InitDefines*() =
   DefineSymbol(normalize(endianToStr[cpu[targetCPU].endian]))
   DefineSymbol(cpu[targetCPU].name)
   DefineSymbol(platform.os[targetOS].name)
+  if platform.OS[targetOS].props.contains(ospLacksThreadVars):
+    DefineSymbol("emulatedthreadvars")
+
 
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 65b7f9049..9049fdb22 100755
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -59,7 +59,8 @@ type
     errCannotInstantiateX, errExprHasNoAddress, errXStackEscape,
     errVarForOutParamNeeded, 
     errPureTypeMismatch, errTypeMismatch, errButExpected, errButExpectedX, 
-    errAmbiguousCallXYZ, errWrongNumberOfArguments, errXCannotBePassedToProcVar, 
+    errAmbiguousCallXYZ, errWrongNumberOfArguments, 
+    errXCannotBePassedToProcVar, 
     errXCannotBeInParamDecl, errPragmaOnlyInHeaderOfProc, errImplOfXNotAllowed, 
     errImplOfXexpected, errNoSymbolToBorrowFromFound, errDiscardValue, 
     errInvalidDiscard, errIllegalConvFromXtoY, errCannotBindXTwice, 
@@ -94,7 +95,7 @@ type
     errUser,
     warnCannotOpenFile, 
     warnOctalEscape, warnXIsNeverRead, warnXmightNotBeenInit, 
-    warnCannotWriteMO2, warnCannotReadMO2, warnDeprecated, 
+    warnDeprecated, 
     warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, 
     warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, 
     warnXisPassedToProcVar, warnDerefDeprecated, warnAnalysisLoophole,
@@ -323,8 +324,6 @@ const
     warnOctalEscape: "octal escape sequences do not exist; leading zero is ignored [OctalEscape]", 
     warnXIsNeverRead: "\'$1\' is never read [XIsNeverRead]", 
     warnXmightNotBeenInit: "\'$1\' might not have been initialized [XmightNotBeenInit]", 
-    warnCannotWriteMO2: "cannot write file \'$1\' [CannotWriteMO2]", 
-    warnCannotReadMO2: "cannot read file \'$1\' [CannotReadMO2]", 
     warnDeprecated: "\'$1\' is deprecated [Deprecated]", 
     warnSmallLshouldNotBeUsed: "\'l\' should not be used as an identifier; may look like \'1\' (one) [SmallLshouldNotBeUsed]", 
     warnUnknownMagic: "unknown magic \'$1\' might crash the compiler [UnknownMagic]", 
@@ -354,8 +353,8 @@ const
     hintUser: "$1 [User]"]
 
 const
-  WarningsToStr*: array[0..18, string] = ["CannotOpenFile", "OctalEscape", 
-    "XIsNeverRead", "XmightNotBeenInit", "CannotWriteMO2", "CannotReadMO2", 
+  WarningsToStr*: array[0..16, string] = ["CannotOpenFile", "OctalEscape", 
+    "XIsNeverRead", "XmightNotBeenInit",
     "Deprecated", "SmallLshouldNotBeUsed", "UnknownMagic", 
     "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", 
     "CommentXIgnored", "XisPassedToProcVar", "DerefDeprecated",
diff --git a/compiler/options.nim b/compiler/options.nim
index 891fca8ae..a4188d81d 100755
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -47,7 +47,8 @@ type                          # please make sure we have under 32 options
     optContext,               # ideTools: 'context'
     optDef,                   # ideTools: 'def'
     optThreadAnalysis,        # thread analysis pass
-    optTaintMode              # taint mode turned on
+    optTaintMode,             # taint mode turned on
+    optTlsEmulation           # thread var emulation turned on
 
   TGlobalOptions* = set[TGlobalOption]
   TCommands* = enum           # Nimrod's commands
diff --git a/compiler/platform.nim b/compiler/platform.nim
index e5bf75c13..2a17bf9ba 100755
--- a/compiler/platform.nim
+++ b/compiler/platform.nim
@@ -151,24 +151,24 @@ type
 type 
   TEndian* = enum 
     littleEndian, bigEndian
-  TInfoCPU* = tuple[name: string, intSize: int, endian: TEndian, floatSize: int, 
-                    bit: int]
+  TInfoCPU* = tuple[name: string, intSize: int, endian: TEndian, 
+                    floatSize, bit: int]
 
-const 
+const
   EndianToStr*: array[TEndian, string] = ["littleEndian", "bigEndian"]
   CPU*: array[succ(low(TSystemCPU))..high(TSystemCPU), TInfoCPU] = [
     (name: "i386", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32), 
     (name: "m68k", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32), 
     (name: "alpha", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64), 
     (name: "powerpc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
-    (name: "powerpc64", intSize: 64, endian: bigEndian, floatSize: 64, bit: 64), 
+    (name: "powerpc64", intSize: 64, endian: bigEndian, floatSize: 64,bit: 64), 
     (name: "sparc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32), 
     (name: "vm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32), 
     (name: "ia64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64), 
     (name: "amd64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64), 
     (name: "mips", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32), 
     (name: "arm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32), 
-    (name: "ecmascript", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32), 
+    (name: "ecmascript", intSize: 32, endian: bigEndian,floatSize: 64,bit: 32), 
     (name: "nimrodvm", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32)]
 
 var 
diff --git a/doc/advopt.txt b/doc/advopt.txt
index 46ac7a07a..ed05ba108 100755
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -40,6 +40,7 @@ Advanced options:
                             (Nimrod, mangled) identifier pairs
   --lineDir:on|off          generation of #line directive on|off
   --threadanalysis:on|off   turn thread analysis on|off
+  --tlsEmulation:on|off     turn thread local storage emulation on|off
   --taintMode:on|off        turn taint mode on|off
   --symbolFiles:on|off      turn symbol files on|off (experimental)
   --skipCfg                 do not read the general configuration file
diff --git a/lib/system/threads.nim b/lib/system/threads.nim
index 9fbea2e1a..00ee11aa3 100755
--- a/lib/system/threads.nim
+++ b/lib/system/threads.nim
@@ -151,7 +151,7 @@ else:
       importc: "pthread_attr_setstack", header: "<pthread.h>".}
 
 const
-  emulatedThreadVars = true
+  emulatedThreadVars = compileOption("tlsEmulation")
 
 when emulatedThreadVars:
   # the compiler generates this proc for us, so that we can get the size of
diff --git a/todo.txt b/todo.txt
index 84543fae9..8419e1d09 100755
--- a/todo.txt
+++ b/todo.txt
@@ -18,10 +18,6 @@ incremental compilation
 
 - the loading has to be MUCH more lazy! --> next version: We should re-load
   symbol.ast lazily
-- adapt thread var implementation to care about the new merge operation
-- write test cases: needs test script support
-  - test thread var
-
 - automate tests:
   - test basic recompilation scheme
   - test type converters
@@ -77,6 +73,7 @@ version 0.9.XX
 - implicit ref/ptr->var conversion; the compiler may store an object
   implicitly on the heap for write barrier efficiency; better: 
   proc specialization in the code gen
+- adapt thread var emulation to care about the new merge operation
 - EcmaScript needs a new and better code gen: simply adapt the C code gen to it
 - tlastmod returns wrong results on BSD (Linux, MacOS X: works)
 - nested tuple unpacking
diff --git a/web/news.txt b/web/news.txt
index ad15920a9..84e3ee586 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -75,6 +75,8 @@ Compiler Additions
   and Objective C somewhat easier.
 - Added a ``--nimcache:PATH`` configuration option for control over the output
   directory for generated code.
+- Added a ``--tlsEmulation:on|off`` switch for control over thread local
+  storage emulation.
 - The compiler and standard library now support a *taint mode*. Input strings
   are declared with the ``TaintedString`` string type. If the taint
   mode is turned on it is a distinct string type which helps to detect input