search for: const_stringz

Displaying 14 results from an estimated 14 matches for "const_stringz".

Did you mean: const_string
2010 Mar 05
3
[LLVMdev] Pointer to String Constant
I'm writing a C compiler in OCaml and I've run into a small problem. I wrote the following piece of code to generate a pointer to a string constant, so I could compile C expressions of the form "const char* p = "test\n";" : let strval = const_stringz codecontext v in dump_value strval; dump_value i32_zero; const_gep strval [| i32_zero; i32_zero |] The dump statements I put confirm that the string array and the index values have the types I would expect: [6 x i8] c"test\0A\00" i32 0 However, the code still seems to break an assertio...
2008 May 10
0
[LLVMdev] Python bindings available.
...s, packed) -- a struct, consts is a list of > other constants, packed is boolean I did this in Ocaml initially, but found the boolean constants pretty confusing to read in code. I kept asking “What's that random true doing there?” Therefore, the bindings expose these as const_string/ const_stringz and const_struct/const_packed_struct respectively. I figure the user can always write her own in the (very) rare cases that it is necessary to conditionalize such things: let const_string_maybez nullterm = if nullterm then const_stringz else const_string > Memory Buffer and Typ...
2008 May 10
4
[LLVMdev] Python bindings available.
Hi all, I'd like to announce the availability of Python bindings for LLVM. It is built over llvm-c, and currently exposes enough APIs to build an in-memory IR (and dump it!). It needs LLVM 2.3 latest and Python 2.5 (2.4 should be sufficient, but I haven't tested). Tested only on Linux/i386. Would love to hear your comments. [Needless to say, it's all work in progress, but mostly it
2007 Nov 25
1
[LLVMdev] OCaml bindings
...rgs function types, among others, but weren't self-documenting, so I introduced variant names instead. For instance: > Also, I think const_string maybe should null terminate the given > string so I changed your example to pass it a null terminated string > instead (nasty hack). const_stringz null-terminates the string. But adding \000 in the literal as you did is equivalent. > My code is: > > [...] > > To use it I just do: > > $ ocamlopt -dtypes -cc g++ -I /usr/local/lib/ocaml/ llvm.cmxa > llvm_bitwriter.cmxa hellow.ml -o hellow > $ ./hellow run.bc >...
2010 Mar 05
0
[LLVMdev] Pointer to String Constant
...: > > I'm writing a C compiler in OCaml and I've run into a small problem. I wrote > the following piece of code to generate a pointer to a string constant, so I > could compile C expressions of the form "const char* p = "test\n";" : > > let strval = const_stringz codecontext v in > dump_value strval; > dump_value i32_zero; > const_gep strval [| i32_zero; i32_zero |] > > The dump statements I put confirm that the string array and the index values > have the types I would expect: > > [6 x i8] c"test\0A\00" > i32 0 >...
2007 Dec 23
0
[LLVMdev] Ocaml JIT example
...; (* Tear down the JIT. *) ExecutionEngine.run_static_dtors jit; ExecutionEngine.dispose jit let build_module = let m = create_module "jithelloworld" in (* @greeting = global [14 x i8] c"Hello, world!\00" *) let greeting = define_global "greeting" (const_stringz "Hello, world!") m in (* declare i32 @puts(i8* ) *) let puts = declare_function "puts" (function_type i32_type [| pointer_type i8_type |]) m in (* define i32 @main() { entry: *) let main = define_function "main" (funct...
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
...ype in let printf = 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) m...
2008 May 11
2
[LLVMdev] Python bindings available.
...ist of > > other constants, packed is boolean > > I did this in Ocaml initially, but found the boolean constants pretty > confusing to read in code. I kept asking "What's that random true > doing there?" Therefore, the bindings expose these as const_string/ > const_stringz and const_struct/const_packed_struct respectively. I OK, will do. > :) Type handles in particular are very important. You can't form a > recursive type without using them, so you can't build any sort of data > structure. On it already. BTW, where can I find a good example of...
2007 Nov 25
0
[LLVMdev] OCaml bindings
...thers, but weren't > > self-documenting, so I introduced variant names instead. For instance: > > Also, I think const_string maybe should null terminate the given > > string so I changed your example to pass it a null terminated string > > instead (nasty hack). > > const_stringz null-terminates the string. But adding \000 in the > literal as you did is equivalent. Great. > > My code is: > > > > [...] > > > > To use it I just do: > > > > $ ocamlopt -dtypes -cc g++ -I /usr/local/lib/ocaml/ llvm.cmxa > > llvm_bitwriter.cmxa...
2007 Nov 26
0
[LLVMdev] Fibonacci example in OCaml
...n let print = declare_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...
2007 Nov 25
5
[LLVMdev] OCaml
On Sunday 25 November 2007 12:23, Gordon Henriksen wrote: > On 2007-11-24, at 21:58, Jon Harrop wrote: > > - Garbage collection tuned for functional programming > > http://llvm.org/docs/GarbageCollection.html > > I've been doing some interesting work on this front. Getting Lattner- > cycles to have it reviewed and integrated is probably the biggest > challenge; LLVM
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