Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Fix source build(macOS), REPL mode and misc. upgrading oversights #400

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
.DS_Store
docs/build
docs/site
deps/build.log
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ julia> using Cxx
julia> const path_to_lib = pwd()
julia> addHeaderDir(path_to_lib, kind=C_System)
julia> Libdl.dlopen(path_to_lib * "/libArrayMaker.so", Libdl.RTLD_GLOBAL)
Ptr{Void} @0x000000000728e6d0
Ptr{Cvoid} @0x000000000728e6d0
julia> cxxinclude("ArrayMaker.h")

# Creating class object
julia> maker = @cxxnew ArrayMaker(5, 2.0)
Got arguments: 5, and 2
Cxx.CppPtr{Cxx.CppValue{Cxx.CppBaseType{:ArrayMaker},(false,false,false)},(false,false,false)}(Ptr{Void} @0x00000000060ab570)
Cxx.CppPtr{Cxx.CppValue{Cxx.CppBaseType{:ArrayMaker},(false,false,false)},(false,false,false)}(Ptr{Cvoid} @0x00000000060ab570)

julia> arr = @cxx maker->fillArr()
Filling the array
Expand Down
4 changes: 2 additions & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ close(f)
println("Tuning for julia installation at $BASE_JULIA_BIN with sources possibly at $BASE_JULIA_SRC")

# Try to autodetect C++ ABI in use
llvm_path = (Sys.isapple() && VersionNumber(Base.libllvm_version) >= v"3.8") ? "libLLVM" : "libLLVM-$(Base.libllvm_version)"
llvm_path = (Sys.isapple() && Base.libllvm_version >= v"3.8") ? "libLLVM" : "libLLVM-$(Base.libllvm_version)"

llvm_lib_path = Libdl.dlpath(llvm_path)
old_cxx_abi = findfirst("_ZN4llvm3sys16getProcessTripleEv", String(open(read, llvm_lib_path))) !== nothing
Expand All @@ -47,7 +47,7 @@ else
@info "Building julia binary build"
ENV["LLVM_VER"] = Base.libllvm_version
ENV["JULIA_BINARY_BUILD"] = "1"
ENV["PATH"] = string(JULIA_HOME,":",ENV["PATH"])
ENV["PATH"] = string(BASE_JULIA_BIN,":",ENV["PATH"])
end

make = Sys.isbsd() && !Sys.isapple() ? `gmake` : `make`
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ John
```julia-repl
julia> cxx"""
void test_print() {
$:(println("\nTo end this test, press any key")::Void);
$:(println("\nTo end this test, press any key")::Cvoid);
}
"""
true
Expand Down Expand Up @@ -200,7 +200,7 @@ julia> const path_to_lib = pwd();
julia> addHeaderDir(path_to_lib, kind=C_System)

julia> Libdl.dlopen(joinpath(path_to_lib, "libarraymaker.so"), Libdl.RTLD_GLOBAL)
Ptr{Void} @0x00007f9dd4556d60
Ptr{Cvoid} @0x00007f9dd4556d60

julia> cxxinclude("ArrayMaker.h")

Expand Down
2 changes: 1 addition & 1 deletion docs/src/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unboxing `x` and `y` if necessary). Afterwards, the resulting call instruction
is inlined.

In this package, however, we use the second form of `llvmcall`, which differs
from the first in that the IR argument is not a string, but a `Ptr{Void}`. In
from the first in that the IR argument is not a string, but a `Ptr{Cvoid}`. In
this case, Julia will skip the wrapping and proceed straight to argument
translation and inlining.

Expand Down
2 changes: 1 addition & 1 deletion src/Cxx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
# is inlined.
#
# In this package, however, we use the second form of llvmcall, which differs
# from the first inthat the IR argument is not a string, but a Ptr{Void}. In
# from the first inthat the IR argument is not a string, but a Ptr{Cvoid}. In
# this case, julia will skip the wrapping and proceed straight to argument
# translation and inlining.
#
Expand Down
58 changes: 31 additions & 27 deletions src/CxxREPL/replpane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module CxxREPL
using REPL
using REPL.LineEdit
using ..Cxx
import Cxx: CxxCore

# Some of this code is derived from cling.
# Copyright (c) 2007-2014 by the Authors.
Expand Down Expand Up @@ -85,7 +86,7 @@ module CxxREPL
icxx"""
const char *BufferStart = $(pointer(data));
const char *BufferEnd = BufferStart+$(lastindex(data))-1;
clang::Lexer L(clang::SourceLocation(),$(Cxx.compiler(C))->getLangOpts(),
clang::Lexer L(clang::SourceLocation(),$(CxxCore.compiler(C))->getLangOpts(),
BufferStart, BufferStart, BufferEnd);
clang::Token Tok;
L.LexFromRawLexer(Tok);
Expand All @@ -98,30 +99,33 @@ module CxxREPL
if occursin(":=", data)
return false
end
x = [Cxx.instance(C)]
return isPPDirective(C,data) || icxx"""
clang::Parser *P = $(Cxx.parser(C));
clang::Preprocessor *PP = &P->getPreprocessor();
clang::Parser::TentativeParsingAction TA(*P);
EnterSourceFile((CxxInstance*)$(convert(Ptr{Cvoid},pointer(x))),
$(pointer(data)),$(sizeof(data))-1);
clang::PreprocessorLexer *L = PP->getCurrentLexer();
P->ConsumeToken();
bool result = P->getCurToken().is(clang::tok::kw_template) ||
P->isCXXDeclarationStatement();
TA.Revert();
// Consume all cached tokens, so we don't accidentally
// Lex them later after we abort this buffer
while (PP->InCachingLexMode() || PP->getCurrentLexer() == nullptr)
{
clang::Token Tok;
PP->Lex(Tok);
}
// Exit the lexer for this buffer
if (L == PP->getCurrentLexer())
PP->RemoveTopOfLexerStack();
return result;
"""
x = [CxxCore.instance(C)]
GC.@preserve x begin
ret = isPPDirective(C,data) || icxx"""
clang::Parser *P = $(CxxCore.parser(C));
clang::Preprocessor *PP = &P->getPreprocessor();
clang::Parser::TentativeParsingAction TA(*P);
EnterSourceFile((CxxInstance*)$(convert(Ptr{Cvoid},pointer(x))),
$(pointer(data)),$(sizeof(data))-1);
clang::PreprocessorLexer *L = PP->getCurrentLexer();
P->ConsumeToken();
bool result = P->getCurToken().is(clang::tok::kw_template) ||
P->isCXXDeclarationStatement();
TA.Revert();
// Consume all cached tokens, so we don't accidentally
// Lex them later after we abort this buffer
while (PP->InCachingLexMode() || PP->getCurrentLexer() == nullptr)
{
clang::Token Tok;
PP->Lex(Tok);
}
// Exit the lexer for this buffer
if (L == PP->getCurrentLexer())
PP->RemoveTopOfLexerStack();
return result;
"""
end
return ret;
end

# Inspired by cling's InputValidator.cpp
Expand All @@ -130,7 +134,7 @@ module CxxREPL
icxx"""
const char *BufferStart = $(pointer(data));
const char *BufferEnd = BufferStart+$(lastindex(data))-1;
clang::Lexer L(clang::SourceLocation(),$(Cxx.compiler(C))->getLangOpts(),
clang::Lexer L(clang::SourceLocation(),$(CxxCore.compiler(C))->getLangOpts(),
BufferStart, BufferStart, BufferEnd);
clang::Token Tok;
std::deque<int> parenStack;
Expand Down Expand Up @@ -175,7 +179,7 @@ module CxxREPL
end
# Strip trailing semicolon (since we add one on the next line) to avoid unused result warning
line = line[end] == ';' ? line[1:end-1] : line
ret = CxxCore.process_cxx_string(string(line,"\n;"), isToplevel, false, CxxCore.FakeLineNumberNode(:REPL, 1), "p";
ret = CxxCore.process_cxx_string(string(line,"\n;"), isToplevel, false, LineNumberNode(1, :REPL), "p";
compiler = C)
if isAssignment
ret = :($var = $ret)
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ static Function *CloneFunctionAndAdjust(C, Function *F, FunctionType *FTy,
T_size = T_int64;
else
T_size = T_int32;

if (needsbox) {
cppcall_state_t *state = (cppcall_state_t *)setup_cpp_env(Cxx,NewF);
// Julia 0.7 Implementation
Expand Down Expand Up @@ -912,7 +912,7 @@ JL_DLLEXPORT void ReplaceFunctionForDecl(C,clang::FunctionDecl *D, llvm::Functio
# endif
true);
} else {
I->dump();
I->print(llvm::errs(), false);
jl_error("Tried to do something other than calling it to a julia expression");
}
}
Expand Down Expand Up @@ -2284,12 +2284,12 @@ JL_DLLEXPORT void typedump(void *t)

JL_DLLEXPORT void llvmdump(void *t)
{
((llvm::Value*) t)->dump();
((llvm::Value*) t)->print(llvm::errs(), false);
}

JL_DLLEXPORT void llvmtdump(void *t)
{
((llvm::Type*) t)->dump();
((llvm::Type*) t)->print(llvm::errs(), false);
}

JL_DLLEXPORT void *createLoad(CxxIRBuilder *builder, llvm::Value *val)
Expand Down
3 changes: 1 addition & 2 deletions src/cxxstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function adjust_source(C, source)
source
end

function process_cxx_string(str,global_scope = true,type_name = false,__source__=FakeLineNumberNode(),
function process_cxx_string(str,global_scope = true,type_name = false,__source__=LineNumberNode(1, :none),
annotations = "";
compiler = :__current_compiler__, tojuliatype = true)
disable_ac = 'p' in annotations
Expand Down Expand Up @@ -714,7 +714,6 @@ end
dne = CreateDeclRefExpr(C,FD)
argt = tuple(llvmargs...)
expr = CallDNE(C,dne,argt; argidxs = argidxs, symargs = symargs)
expr
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ nostdcxx = haskey(ENV,"CXXJL_NOSTDCXX")
# On OS X, we just use the libc++ headers that ship with XCode
@static if isapple() function collectStdHeaders!(headers)
xcode_path = strip(read(`xcode-select --print-path`, String))
contains(xcode_path, "Xcode.app") && (xcode_path *= "/Toolchains/XcodeDefault.xctoolchain")
occursin("Xcode.app", xcode_path) && (xcode_path *= "/Toolchains/XcodeDefault.xctoolchain")
xcode_path *= "/"

didfind = false
Expand Down
6 changes: 3 additions & 3 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
QT = try
cpptype(C,x)
catch err
(isa(err, ErrorException) && contains(err.msg, "Could not find")) || rethrow(err)
(isa(err, ErrorException) && occursin("Could not find", err.msg)) || rethrow(err)
return :( Base.show_datatype(io, typeof(x)); println(io,"(<not found in compilation unit>)") )
end
name = typename(QT)
Expand Down Expand Up @@ -47,8 +47,8 @@ end
cpptype(C,x)
catch err
(isa(err, ErrorException) && contains(err.msg, "Could not find")) || rethrow(err)
return :( Base.show_datatype(io, typeof(x)); println(io," @0x", hex(convert(UInt,convert(Ptr{Void},x)),Sys.WORD_SIZE>>2)) )
return :( Base.show_datatype(io, typeof(x)); println(io," @0x", string(convert(UInt,convert(Ptr{Cvoid},x)),Sys.WORD_SIZE>>2)) )
end
name = typename(QT)
:( println(io,"(",$name,") @0x", hex(convert(UInt,convert(Ptr{Void},x)),Sys.WORD_SIZE>>2) ))
:( println(io,"(",$name,") @0x", string(convert(UInt,convert(Ptr{Cvoid},x)),Sys.WORD_SIZE>>2) ))
end
10 changes: 5 additions & 5 deletions test/clangutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace llvm;

function dumpLayout(d)
ctx = pcpp"clang::ASTContext"(
ccall((:getASTContext,libcxxffi),Ptr{Void},()))
ccall((:getASTContext,libcxxffi),Ptr{Cvoid},()))
icxx"""
raw_os_ostream OS(std::cout);
$ctx->DumpRecordLayout(
Expand All @@ -23,16 +23,16 @@ function dumpLayout(d)
end

clangmod = pcpp"llvm::Module"(unsafe_load(cglobal(
(:clang_shadow_module,libcxxffi),Ptr{Void})))
(:clang_shadow_module,libcxxffi),Ptr{Cvoid})))

EE = pcpp"llvm::ExecutionEngine"(unsafe_load(cglobal(
:jl_ExecutionEngine,Ptr{Void})))
:jl_ExecutionEngine,Ptr{Cvoid})))

mcjmm = pcpp"llvm::RTDyldMemoryManager"(unsafe_load(cglobal(
:jl_mcjmm,Ptr{Void})))
:jl_mcjmm,Ptr{Cvoid})))

cc = pcpp"clang::CompilerInstance"(unsafe_load(cglobal(
(:clang_compiler,libcxxffi),Ptr{Void})))
(:clang_compiler,libcxxffi),Ptr{Cvoid})))

pass_llvm_command_line(str) =
@cxx llvm::cl::ParseCommandLineOptions(1+length(str),pointer([pointer("julia"),[pointer(s) for s in str],convert(Ptr{UInt8},C_NULL)]))
Expand Down
2 changes: 1 addition & 1 deletion test/cxxstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test = @cxxnew PrintTest()
cxx"""
void printfoo() {
for (int i = 0; i <= 10; ++i)
$:(println("foo")::Void);
$:(println("foo")::Cvoid);
}
"""

Expand Down
2 changes: 1 addition & 1 deletion test/llvmgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ vertex_index(v,g) = reinterpret(UInt64, v.ptr)

buf = IOBuffer()

code_llvmf(f,t::Tuple{Vararg{Type}}) = pcpp"llvm::Function"(ccall(:jl_get_llvmf, Ptr{Void}, (Any,Bool,Bool), Tuple{t...}, false, false))
code_llvmf(f,t::Tuple{Vararg{Type}}) = pcpp"llvm::Function"(ccall(:jl_get_llvmf, Ptr{Cvoid}, (Any,Bool,Bool), Tuple{t...}, false, false))
function code_graph(f,args)
v = @cxx std::string()
os = @cxx llvm::raw_string_ostream(v)
Expand Down
2 changes: 1 addition & 1 deletion test/llvmincludes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(joinpath(dirname(@__FILE__), "..", "deps", "path.jl")
const basever = Base.libllvm_version
function addLLVMIncludes(C, clangheaders = true, juliainclude = joinpath(BASE_JULIA_BIN,"..","include"),
llvmdir = joinpath(Cxx.depspath,contains(basever,"svn") ? "llvm-svn" : "llvm-$ver"), ver = VersionNumber(basever))
llvmdir = joinpath(Cxx.depspath,occursin("svn", basever) ? "llvm-svn" : "llvm-$ver"), ver = VersionNumber(basever))

# LLVM Headers

Expand Down
14 changes: 7 additions & 7 deletions test/llvmtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ using Cxx
include("llvmincludes.jl")

RequireCompleteType(C,d::cpcpp"clang::Type") =
ccall((:RequireCompleteType,Cxx.libcxxffi),Cint,(Ptr{Cxx.ClangCompiler},Ptr{Void}),&C,d.ptr) > 0
ccall((:RequireCompleteType,Cxx.libcxxffi),Cint,(Ptr{Cxx.ClangCompiler},Ptr{Cvoid}),&C,d.ptr) > 0

function cxxsizeof(d::pcpp"clang::CXXRecordDecl")
executionEngine = pcpp"llvm::ExecutionEngine"(ccall((:jl_get_llvm_ee,Cxx.libcxxffi),Ptr{Void},()))
executionEngine = pcpp"llvm::ExecutionEngine"(ccall((:jl_get_llvm_ee,Cxx.libcxxffi),Ptr{Cvoid},()))
C = Cxx.instance(__current_compiler__)
cgt = pcpp"clang::CodeGen::CodeGenTypes"(ccall((:clang_get_cgt,Cxx.libcxxffi),Ptr{Void},
cgt = pcpp"clang::CodeGen::CodeGenTypes"(ccall((:clang_get_cgt,Cxx.libcxxffi),Ptr{Cvoid},
(Ptr{Cxx.ClangCompiler},),&C))
dl = @cxx executionEngine->getDataLayout()
RequireCompleteType(C,@cxx d->getTypeForDecl())
Expand All @@ -20,7 +20,7 @@ size = cxxsizeof(pcpp"clang::CXXRecordDecl"(Cxx.lookup_name(Cxx.instance(__curre
["llvm","ExecutionEngine"]).ptr))
@assert size >= 144

code_llvmf(f,t::Tuple{Vararg{Type}}) = pcpp"llvm::Function"(ccall(:jl_get_llvmf, Ptr{Void}, (Any,Bool,Bool), Tuple{t...}, false, false))
code_llvmf(f,t::Tuple{Vararg{Type}}) = pcpp"llvm::Function"(ccall(:jl_get_llvmf, Ptr{Cvoid}, (Any,Bool,Bool), Tuple{t...}, false, false))
function code_graph(f,args)
v = @cxx std::string()
os = @cxx llvm::raw_string_ostream(v)
Expand All @@ -38,12 +38,12 @@ cxx"""
void f() {}
"""
C = Cxx.instance(__current_compiler__)
clangmod = pcpp"llvm::Module"(ccall(:clang_shadow_module,Ptr{Void},
clangmod = pcpp"llvm::Module"(ccall(:clang_shadow_module,Ptr{Cvoid},
(Ptr{Cxx.ClangCompiler},),&C))
ptr = @cxx clangmod->getFunction(pointer("_Z1fv"))
@assert ptr != C_NULL

jns = cglobal((:julia_namespace,Cxx.libcxxffi),Ptr{Void})
jns = cglobal((:julia_namespace,Cxx.libcxxffi),Ptr{Cvoid})
ns = Cxx.createNamespace(C,"julia")

# This is basically the manual expansion of the cxx_str macro
Expand All @@ -62,7 +62,7 @@ uint64_t foo() {
""")
unsafe_store!(jns,C_NULL)
#GV = @cxx dyn_cast{llvm::GlobalVariable}(@cxx (@cxx clang_shadow_module)->getNamedValue(pointer("_ZN5julia4var1E")))
GV = pcpp"llvm::GlobalVariable"((@cxx (@cxx clang_shadow_module(convert(Ptr{Void},pointer([C]))))->getNamedValue(pointer("_ZN5julia5xvar1E"))).ptr)
GV = pcpp"llvm::GlobalVariable"((@cxx (@cxx clang_shadow_module(convert(Ptr{Cvoid},pointer([C]))))->getNamedValue(pointer("_ZN5julia5xvar1E"))).ptr)
@assert GV != C_NULL
@cxx (@cxx GV->getType())->dump()
@cxx GV->setInitializer(@cxx llvm::ConstantInt::get((@cxx llvm::Type::getInt64Ty(*(@cxx &jl_LLVMContext))),UInt64(0)))
Expand Down
2 changes: 1 addition & 1 deletion test/qttest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mb = @cxxnew QMessageBox(@cxx(QMessageBox::Information),
hibtn = @cxxnew QPushButton(pointer("Say Hi!"))
@cxx mb->addButton(hibtn, @cxx(QMessageBox::ApplyRole))

say_hi() = println("Hi!")::Void
say_hi() = println("Hi!")::Cvoid
cxx"""
#include <iostream>
void handle_hi()
Expand Down