-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
irutil: add stdlib package for C standard library declarations #188
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Lets keep all issues in one tracker for now (in
We can add two packages, |
I have implemented some of the most used |
Definitely helpful. I think we can evaluate a few different approaches before settling on the one to use. I would wish for us also to consider maintenance of the Cheers, |
Can clang produce LLVM from headers? |
At least using a tiny dummy C file including the headers. Input (dummy) C file: #include <stdio.h>
#include <string.h>
void *foo1 = printf;
void *foo2 = memcpy; Run: clang -S -emit-llvm -o a.ll a.c Output LLVM IR: ; ModuleID = 'a.c'
source_filename = "a.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@foo1 = dso_local global i8* bitcast (i32 (i8*, ...)* @printf to i8*), align 8
@foo2 = dso_local global i8* bitcast (i8* (i8*, i8*, i64)* @memcpy to i8*), align 8
declare i32 @printf(i8*, ...) #0
; Function Attrs: nounwind
declare i8* @memcpy(i8*, i8*, i64) #1
attributes #0 = { "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!"clang version 12.0.1"} The output LLVM IR contains the function declarations for |
Perhaps by getting a list of stdlib functions and then doing this for the stdlib we could get a list of function declarations, and we could parse them using this library and get the output But how would the API look? A map of function name to function? A bunch of global variables with the functions? A function to get a stdlib fn by name? |
Good question. I'm not quite sure that the best API would. How would you envision yourself wishing to use it @Nv7-GitHub? Perhaps that could help guide API design. Cheers, |
I'm pretty sure A map of name to function would be the best, we simply modify |
As suggested in #187 (comment):
Add a new
irutil/stdlib
package containing function (and global variable) declarations for interacting with the C standard library.We should consider automatically doing this, perhaps using the LLVM compiler to parse the C standard library headers and generating LLVM IR function (and global variable) declarations.
Then, we could parse the LLVM IR output using
llir/llvm/asm
to get thellir/llvm/ir
representation to interact with.Will require some experimentation to find what approach works well, and is easy to work with.
Edit: related issues #22, #178, #180.
The text was updated successfully, but these errors were encountered: