mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 17:41:08 +01:00
Only supports classes with a single (non copy non move) constructor (without default values), until overloading is supported. Based on #5878. C++ Interop Demo: ```c++ // hello_world.h #include <cstdio> class C { public: C(int x, int y) : x_(x), y_(y) {} int x() const { return x_;} int y() const { return y_;} private: int x_; int y_; }; void hello_world(C* _Nonnull c); ``` ```c++ // hello_world.cpp #include "hello_world.h" #include <cstdio> void hello_world(C* _Nonnull c) { printf("C.x = %d. C.y = %d\n", c->x(), c->y()); } ``` ```carbon // main.carbon library "Main"; import Cpp library "hello_world.h"; fn Run() -> i32 { var c : Cpp.C = Cpp.C.C(1, 2); Cpp.hello_world(&c); return 0; } ``` ```shell $ clang -c hello_world.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_world.o main.o --output=demo $ ./demo C.x = 1. C.y = 2 ``` Part of #5880.
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
load("//bazel/cc_rules:defs.bzl", "cc_library")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
filegroup(
|
|
name = "testdata",
|
|
srcs = glob(["testdata/**/*.carbon"]),
|
|
)
|
|
|
|
cc_library(
|
|
name = "lower",
|
|
srcs = ["lower.cpp"],
|
|
hdrs = ["lower.h"],
|
|
deps = [
|
|
":context",
|
|
"//common:vlog",
|
|
"//toolchain/parse:tree",
|
|
"//toolchain/sem_ir:file",
|
|
"//toolchain/sem_ir:inst_namer",
|
|
"@llvm-project//llvm:Core",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "context",
|
|
srcs = [
|
|
"clang_global_decl.cpp",
|
|
"clang_global_decl.h",
|
|
"constant.cpp",
|
|
"constant.h",
|
|
"context.cpp",
|
|
"file_context.cpp",
|
|
"function_context.cpp",
|
|
"mangler.cpp",
|
|
"mangler.h",
|
|
"specific_coalescer.cpp",
|
|
] +
|
|
# Glob handler files to avoid missing any.
|
|
glob([
|
|
"handle*.cpp",
|
|
]),
|
|
hdrs = [
|
|
"context.h",
|
|
"file_context.h",
|
|
"function_context.h",
|
|
"specific_coalescer.h",
|
|
],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:growing_range",
|
|
"//common:map",
|
|
"//common:pretty_stack_trace_function",
|
|
"//common:raw_string_ostream",
|
|
"//common:vlog",
|
|
"//toolchain/base:fixed_size_value_store",
|
|
"//toolchain/base:kind_switch",
|
|
"//toolchain/parse:tree",
|
|
"//toolchain/sem_ir:absolute_node_id",
|
|
"//toolchain/sem_ir:diagnostic_loc_converter",
|
|
"//toolchain/sem_ir:entry_point",
|
|
"//toolchain/sem_ir:expr_info",
|
|
"//toolchain/sem_ir:file",
|
|
"//toolchain/sem_ir:inst_namer",
|
|
"//toolchain/sem_ir:stringify",
|
|
"//toolchain/sem_ir:typed_insts",
|
|
"@llvm-project//clang:ast",
|
|
"@llvm-project//clang:basic",
|
|
"@llvm-project//clang:codegen",
|
|
"@llvm-project//clang:lex",
|
|
"@llvm-project//llvm:Core",
|
|
"@llvm-project//llvm:Linker",
|
|
"@llvm-project//llvm:Support",
|
|
"@llvm-project//llvm:TransformUtils",
|
|
],
|
|
)
|