mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 20:44:53 +01:00
For now, a builtin function is defined by specifying a string literal initializer in a function declaration: ```carbon fn MyBuiltin(a: i32) -> i32 = "builtin.name"; ``` End-to-end support is included for a sample `"int.add"` builtin performing integer addition, covering constant evaluation and code generation. The implementation here needs substantial refactoring before we'll be ready to start adding more builtins. That refactoring work will be coming next. This change is aiming to checkpoint some incremental progress.
25 lines
925 B
Plaintext
25 lines
925 B
Plaintext
// 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
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
fn AddNonmethod(a: i32, b: i32) -> i32 = "int.add";
|
|
fn AddMethod[self: i32](b: i32) -> i32 = "int.add";
|
|
|
|
fn TestAddNonmethod(a: i32, b: i32) -> i32 { return AddNonmethod(a, b); }
|
|
fn TestAddMethod(a: i32, b: i32) -> i32 { return a.(AddMethod)(b); }
|
|
|
|
// CHECK:STDOUT: ; ModuleID = 'method_vs_nonmethod.carbon'
|
|
// CHECK:STDOUT: source_filename = "method_vs_nonmethod.carbon"
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @TestAddNonmethod(i32 %a, i32 %b) {
|
|
// CHECK:STDOUT: %add = add i32 %a, %b
|
|
// CHECK:STDOUT: ret i32 %add
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: define i32 @TestAddMethod(i32 %a, i32 %b) {
|
|
// CHECK:STDOUT: %add = add i32 %a, %b
|
|
// CHECK:STDOUT: ret i32 %add
|
|
// CHECK:STDOUT: }
|