diff --git a/msvc/Makefile b/msvc/Makefile index a4b4420a..eab0592f 100755 --- a/msvc/Makefile +++ b/msvc/Makefile @@ -6,7 +6,7 @@ # all paths must be ABSOLUTE LLVM_DIR=C:\Users\zdevito\LLVM -LUAJIT_DIR=C:\Users\zdevito\LuaJIT-2.0.3 +LUAJIT_DIR=C:\Users\zdevito\LuaJIT-2.0.4 TERRA_DIR=C:\Users\zdevito\terra CUDA_DIR=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5 @@ -49,7 +49,7 @@ LIBPATHS = /LIBPATH:"$(LLVM_DIR)\lib" CLANG_RESOURCE_DIRECTORY=$(LLVM_DIR)\lib\clang\3.5.0 -TERRALIB_SRC = $(SRC)\lctype.cpp $(SRC)\llex.cpp $(SRC)\lobject.cpp $(SRC)\lparser.cpp $(SRC)\lstring.cpp $(SRC)\lzio.cpp $(SRC)\tcompiler.cpp $(SRC)\tcuda.cpp $(SRC)\tcwrapper.cpp $(SRC)\tdebug.cpp $(SRC)\terra.cpp $(SRC)\tinline.cpp $(SRC)\tkind.cpp $(SRC)\tllvmutil.cpp $(SRC)\treadnumber.c +TERRALIB_SRC = $(SRC)\lctype.cpp $(SRC)\llex.cpp $(SRC)\lobject.cpp $(SRC)\lparser.cpp $(SRC)\lstring.cpp $(SRC)\lzio.cpp $(SRC)\tcompiler.cpp $(SRC)\tcuda.cpp $(SRC)\tcwrapper.cpp $(SRC)\tdebug.cpp $(SRC)\terra.cpp $(SRC)\tinline.cpp $(SRC)\tkind.cpp $(SRC)\tllvmutil.cpp $(SRC)\tinternalizedfiles.cpp $(SRC)\treadnumber.c CPP=cl LINK=link @@ -57,19 +57,19 @@ LINK=link LUAJIT = $(LUAJIT_DIR)\src\luajit.exe CPPFLAGS = /MP8 /nologo /EHsc /w /MD /Zi /D_CRT_SECURE_NO_DEPRECATE /DNOMINMAX /DTERRA_LLVM_HEADERS_HAVE_NDEBUG \ - /I$(LUAJIT_DIR)\src /I$(SRC) /I$(BUILD) /I$(TERRA_DIR)\release\include /I$(LLVM_DIR)\include /I$(TERRA_DIR)\msvc \ + /I$(LUAJIT_DIR)\src /I$(SRC) /I$(BUILD) /I$(TERRA_DIR)\release\include\terra /I$(LLVM_DIR)\include /I$(TERRA_DIR)\msvc \ /DLLVM_VERSION=35 \ /DTERRA_ENABLE_CUDA /I"$(CUDA_DIR)\include" /I"$(CUDA_DIR)\nvvm\include" -all: $(TERRA_DIR)\release\terra.exe +all: $(TERRA_DIR)\release\bin\terra.exe $(LUAJIT) $(TERRA_DIR)\release\include\lua.h: $(LUAJIT_DIR)\src\luajit.c cd $(LUAJIT_DIR)\src msvcbuild.bat - copy lua.h $(TERRA_DIR)\release\include - copy lualib.h $(TERRA_DIR)\release\include - copy lauxlib.h $(TERRA_DIR)\release\include - copy luaconf.h $(TERRA_DIR)\release\include + copy lua.h $(TERRA_DIR)\release\include\terra + copy lualib.h $(TERRA_DIR)\release\include\terra + copy lauxlib.h $(TERRA_DIR)\release\include\terra + copy luaconf.h $(TERRA_DIR)\release\include\terra $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h: $(SRC)\terralib.lua $(SRC)\strict.lua $(SRC)\cudalib.lua $(LUAJIT) set LUA_PATH=$(LUAJIT_DIR)\src\?.lua @@ -81,29 +81,34 @@ $(BUILD)\clangpaths.h: $(LUAJIT) $(SRC)\genclangpaths.lua cd $(TERRA_DIR) $(LUAJIT) src\genclangpaths.lua build\clangpaths.h $(LLVM_DIR)\bin\clang -I "$(CUDA_DIR:\=/)/include" +$(BUILD)\internalizedfiles.h: $(LUAJIT) $(SRC)\geninternalizedfiles.lua + cd $(TERRA_DIR) + $(LUAJIT) src\geninternalizedfiles.lua build\internalizedfiles.h $(CLANG_RESOURCE_DIRECTORY) "%.h$$" $(CLANG_RESOURCE_DIRECTORY) "%.modulemap$$" $(TERRA_DIR)\lib "%.t$$" + EXPORTS = /EXPORT:terra_init /EXPORT:terra_initwithoptions /EXPORT:terra_load /EXPORT:terra_loadfile /EXPORT:terra_loadbuffer /EXPORT:terra_loadstring /EXPORT:terra_llvmshutdown -$(BUILD)\terra.obj: $(BUILD)\clangpaths.h $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h $(TERRALIB_SRC) +$(BUILD)\terra.obj: $(BUILD)\clangpaths.h $(BUILD)\internalizedfiles.h $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h $(TERRALIB_SRC) cd $(BUILD) $(CPP) $(CPPFLAGS) /c $(TERRALIB_SRC) -$(TERRA_DIR)\release\terra.dll: $(BUILD)\terra.obj - cd $(TERRA_DIR)\release +$(TERRA_DIR)\release\bin\terra.dll: $(BUILD)\terra.obj + if not exist $(TERRA_DIR)\release\bin mkdir $(TERRA_DIR)\release\bin + if not exist $(TERRA_DIR)\release\lib mkdir $(TERRA_DIR)\release\lib + cd $(TERRA_DIR)\release\bin $(LINK) /nologo /MACHINE:X64 /DLL /DEBUG /PDB:terralib.pdb /out:terra.dll /IMPLIB:terra.lib $(BUILD)/*.obj $(LIBS) $(LIBPATHS) $(EXPORTS) + move terra.lib ..\lib\terra.lib REDIST=$(VCINSTALLDIR)redist\x64\Microsoft.VC120.CRT -$(TERRA_DIR)\release\terra.exe: $(TERRA_DIR)\release\terra.dll $(SRC)\main.cpp +$(TERRA_DIR)\release\bin\terra.exe: $(TERRA_DIR)\release\bin\terra.dll $(SRC)\main.cpp cd $(TERRA_DIR) - copy $(LUAJIT_DIR)\src\lua51.dll release - copy $(LUAJIT_DIR)\src\lua51.lib release - copy "$(REDIST)\msvcp120.dll" release - copy "$(REDIST)\msvcr120.dll" release - xcopy /E /I /Q /Y $(CLANG_RESOURCE_DIRECTORY) release\include\clang_resource - $(CPP) $(CPPFLAGS) /Fe:$@ $(SRC)\main.cpp $(TERRA_DIR)\msvc\ext\getopt.c $(TERRA_DIR)\msvc\ext\getopt_long.c $(TERRA_DIR)\release\terra.lib $(LUAJIT_DIR)\src\lua51.lib + copy $(LUAJIT_DIR)\src\lua51.dll release\bin + copy $(LUAJIT_DIR)\src\lua51.lib release\lib + copy "$(REDIST)\msvcp120.dll" release\bin + copy "$(REDIST)\msvcr120.dll" release\bin + $(CPP) $(CPPFLAGS) /Fe:$@ $(SRC)\main.cpp $(TERRA_DIR)\msvc\ext\getopt.c $(TERRA_DIR)\msvc\ext\getopt_long.c $(TERRA_DIR)\release\lib\terra.lib $(LUAJIT_DIR)\src\lua51.lib clean: - del ..\build\*.obj ..\build\*.h ..\build\terra.lib ..\release\terra.exe ..\release\clang.exe - rmdir /s ..\release\include\clang_resource + del ..\build\*.obj ..\build\*.h ..\build\terra.lib ..\release\bin\terra.dll ..\release\lib\terra.lib ..\release\bin\terra.exe .SUFFIXES: \ No newline at end of file diff --git a/src/geninternalizedfiles.lua b/src/geninternalizedfiles.lua index e4a8e5c0..9a17df52 100644 --- a/src/geninternalizedfiles.lua +++ b/src/geninternalizedfiles.lua @@ -1,9 +1,13 @@ local outputfilename = arg[1] +local ffi = require("ffi") +local findcmd = ffi.os == "Windows" and "cmd /c dir /b /s \"%s\"" or "find %q" + local listoffiles = {} for i = 2,#arg,2 do local path,pattern = arg[i],arg[i+1] - local p = assert(io.popen(("find %q"):format(path))) + local p = assert(io.popen(findcmd:format(path))) + print(findcmd:format(path)) for l in p:lines() do if l:match(pattern) then table.insert(listoffiles,{ name = l:sub(#path+1), path = l }) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 2060f2d2..7b756f39 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -317,13 +317,15 @@ int terra_initcompilationunit(lua_State * L) { static void InitializeJIT(TerraCompilationUnit * CU) { if(CU->ee) return; //already initialized + Module * topeemodule = (CU->T->options.usemcjit) ? new Module("terra",*CU->T->C->ctx) : CU->M; #ifdef _WIN32 std::string MCJITTriple = CU->Triple; MCJITTriple.append("-elf"); //on windows we need to use an elf container because coff is not supported yet topeemodule->setTargetTriple(MCJITTriple); -#endif - Module * topeemodule = (CU->T->options.usemcjit) ? new Module("terra",*CU->T->C->ctx) : CU->M; +#else topeemodule->setTargetTriple(CU->Triple); +#endif + std::string err; EngineBuilder eb(UNIQUEIFY(Module,topeemodule)); eb.setErrorStr(&err) diff --git a/src/terra.cpp b/src/terra.cpp index 7be86d2e..f7386662 100644 --- a/src/terra.cpp +++ b/src/terra.cpp @@ -201,6 +201,7 @@ static bool pushterrahome(lua_State * L) { VirtualQuery((void *)terra_init, &mbi, sizeof(mbi)); GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH); PathRemoveFileSpecA(path); + PathRemoveFileSpecA(path); lua_pushstring(L, path); return true; } diff --git a/src/terralib.lua b/src/terralib.lua index 58a0c396..5c3ec327 100644 --- a/src/terralib.lua +++ b/src/terralib.lua @@ -3587,14 +3587,18 @@ end terra.includepath = os.getenv("INCLUDE_PATH") or "." local internalizedfiles = {} +local function fileparts(path) + local fileseparators = ffi.os == "Windows" and "\\/" or "/" + local pattern = "[%s]([^%s]*)" + return path:gmatch(pattern:format(fileseparators,fileseparators)) +end function terra.registerinternalizedfiles(names,contents,sizes) names,contents,sizes = ffi.cast("const char **",names),ffi.cast("uint8_t **",contents),ffi.cast("int*",sizes) for i = 0,math.huge do if names[i] == nil then break end local name,content,size = ffi.string(names[i]),contents[i],sizes[i] - --print(name,size) local cur = internalizedfiles - for segment in name:gmatch("/([^/]*)") do + for segment in fileparts(name) do cur.children = cur.children or {} cur.kind = "directory" if not cur.children[segment] then @@ -3605,9 +3609,10 @@ function terra.registerinternalizedfiles(names,contents,sizes) cur.contents,cur.size,cur.kind = terra.pointertolightuserdata(content), size, "file" end end + local function getinternalizedfile(path) local cur = internalizedfiles - for segment in path:gmatch("/([^/]*)") do + for segment in fileparts(path) do if cur.children and cur.children[segment] then cur = cur.children[segment] else return end @@ -3626,7 +3631,7 @@ end function terra.includecstring(code,cargs,targetoptions) local args = terra.newlist {"-O3","-Wno-deprecated","-resource-dir",clangresourcedirectory} - if ffi.os == "Linux" or (targetoptions and targetoptions.Triple and targetoptions.Triple:match("linux")) then + if ffi.os == "Linux" or ffi.os == "Windows" or (targetoptions and targetoptions.Triple and targetoptions.Triple:match("linux")) then args:insert("-internal-isystem") args:insert(clangresourcedirectory.."/include") end diff --git a/tests/classifyfloatstructs.t b/tests/classifyfloatstructs.t index 463fb270..e9c4d66b 100644 --- a/tests/classifyfloatstructs.t +++ b/tests/classifyfloatstructs.t @@ -81,7 +81,7 @@ add4_val_val:disas() -- add4_ref_ref_tempvar:disas() -if terralib.lookupsymbol then +if terralib.lookupsymbol and require("ffi").os ~= "Windows" then terra sizecheck() var si : terralib.SymbolInfo terralib.lookupsymbol(add4_val_val,&si) diff --git a/tests/cudaoffline.t b/tests/cudaoffline.t index 4ca88411..0d83fc68 100644 --- a/tests/cudaoffline.t +++ b/tests/cudaoffline.t @@ -59,6 +59,6 @@ path = terralib.cudahome..path local args = ffi.os == "Windows" and {path.."\\cuda.lib", path.."\\cudart.lib"} or {"-L"..path, "-Wl,-rpath,"..path, "-lcuda", "-lcudart"} -terralib.saveobj("cudaoffline",{ main = main },args) -local exe = ffi.os == "Windows" and ".\\cudaoffline" or "./cudaoffline" -assert(os.execute(exe) == 0) +local name = ffi.os == "Windows" and ".\\cudaoffline.exe" or "./cudaoffline" +terralib.saveobj(name,{ main = main },args) +assert(os.execute(name) == 0) diff --git a/tests/dynlib.t b/tests/dynlib.t index 60127c3e..2d67bbab 100644 --- a/tests/dynlib.t +++ b/tests/dynlib.t @@ -40,8 +40,8 @@ if ffi.os ~= "Windows" then else local putenv = terralib.externfunction("_putenv", rawstring -> int) - local flags = {libpath.."\\terra_dynamic.lib",libpath.."\\lua51.lib"} + local flags = {libpath.."\\terra.lib",libpath.."\\lua51.lib"} terralib.saveobj("dynlib.exe",{main = main},flags) - putenv("Path="..os.getenv("Path")..";"..terralib.terrahome.."\\lib") --make dll search happy + putenv("Path="..os.getenv("Path")..";"..terralib.terrahome.."\\bin") --make dll search happy assert(0 == os.execute(".\\dynlib.exe")) end \ No newline at end of file diff --git a/tests/run b/tests/run index 1e61811c..a620bcc8 100755 --- a/tests/run +++ b/tests/run @@ -12,7 +12,7 @@ local function getcommand(file) local prefix = terralib and terralib.terrahome and terralib.terrahome .."/bin/terra" or "../terra" if ffi.os == "Windows" then - prefix = "cmd /c " .. prefix:gsub("/","\\\\") + prefix = "cmd /c " .. prefix:gsub("[/\\]","\\\\") end return prefix end