Displaying 5 results from an estimated 5 matches for "int_spec".
2007 Nov 26
0
[LLVMdev] How to declare and use sprintf
On Nov 25, 2007, at 18:53, Jon Harrop wrote:
> So my Fib program is segfaulting and I'm not sure why. I think it
> might be because my declaration and use of sprintf is wrong.
>
> I notice llvm-gcc produces declarations containing "..." like:
>
> declare int %printf(sbyte*, ...)
>
> What is the correct way to do this?
The type you want is:
let sp =
2007 Nov 25
2
[LLVMdev] How to declare and use sprintf
So my Fib program is segfaulting and I'm not sure why. I think it might be
because my declaration and use of sprintf is wrong.
I notice llvm-gcc produces declarations containing "..." like:
declare int %printf(sbyte*, ...)
but I'm not sure how to do this so I've used:
let sprintf =
declare_function "sprintf"
(function_type (pointer_type
2007 Nov 26
1
[LLVMdev] How to declare and use sprintf
...declare_function "printf" (var_arg_function_type i32_type [|string|]) m
in
let main =
define_function "main" (function_type i32_type [| |]) m
|> entry_block
|> builder_at_end in
let str s = define_global "buf" (const_stringz s) m in
let int_spec = build_gep (str "%d\n") [| int 0; int 0 |] "int_spec" main in
let n = build_call (build_fib m) [| const_int i32_type 40 |] "" main in
let _ = build_call printf [| int_spec; n |] "" main in
build_ret (const_null i32_type) main |> ignore;
if...
2007 Nov 26
0
[LLVMdev] Fibonacci example in OCaml
..._function "printf" (var_arg_function_type i32_type [|string|]) m in
let main = define_function "main" (function_type i32_type [| |]) m in
let blk = entry_block main in
let bb = builder_at_end blk in
let str s = define_global "buf" (const_stringz s) m in
let int_spec = build_gep (str "%d\n") [| int 0; int 0 |] "int_spec" bb in
let vars = List.fold_left (defn m) [] program in
let n, _ = expr { fn = main; blk = blk; vars = vars } run in
build_call print [| int_spec; n |] "" bb |> ignore;
build_ret (int 0) bb |> ignor...
2007 Nov 25
2
[LLVMdev] Fibonacci example in OCaml
Here's my translation of the Fibonacci example into OCaml:
open Printf
open Llvm
let build_fib m =
let fibf =
define_function "fib" (function_type i32_type [| i32_type |]) m in
let bb = builder_at_end (entry_block fibf) in
let one = const_int i32_type 1 and two = const_int i32_type 2 in
let argx = param fibf 0 in
set_value_name "AnArg" argx;
let