Skip to content

Commit

Permalink
Update clang generators (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst authored Nov 23, 2022
1 parent 1d43e1b commit ce86c04
Show file tree
Hide file tree
Showing 11 changed files with 1,771 additions and 229 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.11
current_version = 0.3.12
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Libxc"
uuid = "66e17ffc-8502-11e9-23b5-c9248d0eb96d"
authors = ["Jason Eu <[email protected]>", "Michael F. Herbst <[email protected]>"]
version = "0.3.11"
version = "0.3.12"

[deps]
Libxc_jll = "a56a6d9d-ad03-58af-ab61-878bf78270d6"
Expand Down
21 changes: 21 additions & 0 deletions gen/generator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Clang.Generators
using Libxc_jll

cd(@__DIR__)
include_dir = normpath(Libxc_jll.artifact_dir, "include")
options = load_options(joinpath(@__DIR__, "generator.toml"))

# add compiler flags, e.g. "-DXXXXXXXXX"
args = get_default_args()
push!(args, "-I$include_dir")

headers = [joinpath(include_dir, header)
for header in ("xc.h", )]

ctx = create_context(headers, args, options)
build!(ctx);

targetdir = joinpath(@__DIR__, "..", "src", "gen")
for file in ("api.jl", "common.jl")
mv(file, joinpath(targetdir, file), force=true)
end
7 changes: 7 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[general]
output_api_file_path = "api.jl"
output_common_file_path = "common.jl"
output_file_path = "Libxc.jl"
library_name = "libxc"
module_name = "Libxc"
jll_pkg_name = "Libxc_jll"
38 changes: 0 additions & 38 deletions scripts/generate_api.jl

This file was deleted.

3 changes: 2 additions & 1 deletion src/Functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function extract_references(info::Ptr{xc_func_info_type})
ref_ptr = xc_func_info_get_references(info, iref)
(reference=unsafe_string(xc_func_reference_get_ref(ref_ptr)),
doi=unsafe_string(xc_func_reference_get_doi(ref_ptr)),
bibtex=unsafe_string(xc_func_reference_get_bibtex(ref_ptr)))
bibtex=unsafe_string(xc_func_reference_get_bibtex(ref_ptr)),
key=unsafe_string(xc_func_reference_get_key(ref_ptr)))
end
end
10 changes: 3 additions & 7 deletions src/Libxc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ module Libxc
using Libxc_jll
const libxc = Libxc_jll.libxc

include("gen/libxc_common.jl")
include("gen/libxc.jl")
include("gen/common.jl")
include("gen/api.jl")
include("Functional.jl")
include("evaluate.jl")

const libxc_version = begin
varray = zeros(Cint, 3)
xc_version(pointer(varray, 1), pointer(varray, 2), pointer(varray, 3))
VersionNumber(varray[1], varray[2], varray[3])
end
const libxc_version = VersionNumber(XC_VERSION)
const libxc_doi = unsafe_string(Libxc.xc_reference_doi())

"""Return the list of available libxc functionals as strings"""
Expand Down
2 changes: 1 addition & 1 deletion src/gen/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
These files are automatically generated from the libxc C source
using Clang.jl with the script Libxc.jl/scripts/generate_api.jl.
using Clang.jl with the script Libxc.jl/gen/generate.jl.
Do not update them manually.
55 changes: 42 additions & 13 deletions src/gen/libxc.jl → src/gen/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,39 @@


function xc_reference()
ccall((:xc_reference, libxc), Cstring, ())
ccall((:xc_reference, libxc), Ptr{Cchar}, ())
end

function xc_reference_doi()
ccall((:xc_reference_doi, libxc), Cstring, ())
ccall((:xc_reference_doi, libxc), Ptr{Cchar}, ())
end

function xc_reference_key()
ccall((:xc_reference_key, libxc), Ptr{Cchar}, ())
end

function xc_version(major, minor, micro)
ccall((:xc_version, libxc), Cvoid, (Ptr{Cint}, Ptr{Cint}, Ptr{Cint}), major, minor, micro)
end

function xc_version_string()
ccall((:xc_version_string, libxc), Cstring, ())
ccall((:xc_version_string, libxc), Ptr{Cchar}, ())
end

function xc_func_reference_get_ref(reference)
ccall((:xc_func_reference_get_ref, libxc), Cstring, (Ptr{func_reference_type},), reference)
ccall((:xc_func_reference_get_ref, libxc), Ptr{Cchar}, (Ptr{func_reference_type},), reference)
end

function xc_func_reference_get_doi(reference)
ccall((:xc_func_reference_get_doi, libxc), Cstring, (Ptr{func_reference_type},), reference)
ccall((:xc_func_reference_get_doi, libxc), Ptr{Cchar}, (Ptr{func_reference_type},), reference)
end

function xc_func_reference_get_bibtex(reference)
ccall((:xc_func_reference_get_bibtex, libxc), Cstring, (Ptr{func_reference_type},), reference)
ccall((:xc_func_reference_get_bibtex, libxc), Ptr{Cchar}, (Ptr{func_reference_type},), reference)
end

function xc_func_reference_get_key(reference)
ccall((:xc_func_reference_get_key, libxc), Ptr{Cchar}, (Ptr{func_reference_type},), reference)
end

function xc_func_info_get_number(info)
Expand All @@ -39,7 +47,7 @@ function xc_func_info_get_kind(info)
end

function xc_func_info_get_name(info)
ccall((:xc_func_info_get_name, libxc), Cstring, (Ptr{xc_func_info_type},), info)
ccall((:xc_func_info_get_name, libxc), Ptr{Cchar}, (Ptr{xc_func_info_type},), info)
end

function xc_func_info_get_family(info)
Expand All @@ -59,23 +67,23 @@ function xc_func_info_get_n_ext_params(info)
end

function xc_func_info_get_ext_params_name(p, number)
ccall((:xc_func_info_get_ext_params_name, libxc), Cstring, (Ptr{xc_func_info_type}, Cint), p, number)
ccall((:xc_func_info_get_ext_params_name, libxc), Ptr{Cchar}, (Ptr{xc_func_info_type}, Cint), p, number)
end

function xc_func_info_get_ext_params_description(info, number)
ccall((:xc_func_info_get_ext_params_description, libxc), Cstring, (Ptr{xc_func_info_type}, Cint), info, number)
ccall((:xc_func_info_get_ext_params_description, libxc), Ptr{Cchar}, (Ptr{xc_func_info_type}, Cint), info, number)
end

function xc_func_info_get_ext_params_default_value(info, number)
ccall((:xc_func_info_get_ext_params_default_value, libxc), Cdouble, (Ptr{xc_func_info_type}, Cint), info, number)
end

function xc_functional_get_number(name)
ccall((:xc_functional_get_number, libxc), Cint, (Cstring,), name)
ccall((:xc_functional_get_number, libxc), Cint, (Ptr{Cchar},), name)
end

function xc_functional_get_name(number)
ccall((:xc_functional_get_name, libxc), Cstring, (Cint,), number)
ccall((:xc_functional_get_name, libxc), Ptr{Cchar}, (Cint,), number)
end

function xc_family_from_id(id, family, number)
Expand All @@ -99,7 +107,7 @@ function xc_available_functional_numbers_by_name(list)
end

function xc_available_functional_names(list)
ccall((:xc_available_functional_names, libxc), Cvoid, (Ptr{Cstring},), list)
ccall((:xc_available_functional_names, libxc), Cvoid, (Ptr{Ptr{Cchar}},), list)
end

function xc_func_alloc()
Expand Down Expand Up @@ -143,7 +151,15 @@ function xc_func_set_ext_params(p, ext_params)
end

function xc_func_set_ext_params_name(p, name, par)
ccall((:xc_func_set_ext_params_name, libxc), Cvoid, (Ptr{xc_func_type}, Cstring, Cdouble), p, name, par)
ccall((:xc_func_set_ext_params_name, libxc), Cvoid, (Ptr{xc_func_type}, Ptr{Cchar}, Cdouble), p, name, par)
end

function xc_lda_new(p, order, np, rho, out)
ccall((:xc_lda_new, libxc), Cvoid, (Ptr{xc_func_type}, Cint, Csize_t, Ptr{Cdouble}, Ptr{xc_lda_out_params}), p, order, np, rho, out)
end

function xc_gga_new(p, order, np, rho, sigma, out)
ccall((:xc_gga_new, libxc), Cvoid, (Ptr{xc_func_type}, Cint, Csize_t, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{xc_gga_out_params}), p, order, np, rho, sigma, out)
end

function xc_lda(p, np, rho, zk, vrho, v2rho2, v3rho3, v4rho4)
Expand Down Expand Up @@ -297,3 +313,16 @@ end
function xc_nlc_coef(p, nlc_b, nlc_C)
ccall((:xc_nlc_coef, libxc), Cvoid, (Ptr{xc_func_type}, Ptr{Cdouble}, Ptr{Cdouble}), p, nlc_b, nlc_C)
end

function xc_num_aux_funcs(p)
ccall((:xc_num_aux_funcs, libxc), Cint, (Ptr{xc_func_type},), p)
end

function xc_aux_func_ids(p, ids)
ccall((:xc_aux_func_ids, libxc), Cvoid, (Ptr{xc_func_type}, Ptr{Cint}), p, ids)
end

function xc_aux_func_weights(p, weights)
ccall((:xc_aux_func_weights, libxc), Cvoid, (Ptr{xc_func_type}, Ptr{Cdouble}), p, weights)
end

Loading

2 comments on commit ce86c04

@mfherbst
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72746

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.12 -m "<description of version>" ce86c043e15185ae81ee78885627406992c6132a
git push origin v0.3.12

Please sign in to comment.