Module: Stone::LibC

Defined in:
lib/stone/libc.rb

Overview

Module for declaring C standard library functions in LLVM

Class Method Summary collapse

Class Method Details

.get_or_declare_strcmp(mod) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/stone/libc.rb', line 10

def get_or_declare_strcmp(mod)
  return mod.functions["strcmp"] if mod.functions["strcmp"]

  # Declare strcmp: i32 strcmp(i8*, i8*)
  strcmp_type = LLVM::Type.function([LLVM::Type.pointer(LLVM::Int8), LLVM::Type.pointer(LLVM::Int8)], LLVM::Int32)
  mod.functions.add("strcmp", strcmp_type)
end

.get_or_declare_strlen(mod) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/stone/libc.rb', line 18

def get_or_declare_strlen(mod)
  return mod.functions["strlen"] if mod.functions["strlen"]

  # Declare strlen: i64 strlen(i8*)
  strlen_type = LLVM::Type.function([LLVM::Type.pointer(LLVM::Int8)], LLVM::Int64)
  mod.functions.add("strlen", strlen_type)
end