Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.57 KB | None | 0 0
  1. ----------------------------hello.c-------------------------
  2.  
  3.  
  4. #include <stdio.h>
  5.  
  6. int main() {
  7. printf("hello world\n");
  8. return 0;
  9. }
  10.  
  11. int testa() {
  12. int a = 2 ;
  13. return a;
  14. }
  15.  
  16. int test() {
  17. int a = 0;
  18. a = testa;
  19. return a;
  20. }
  21.  
  22. int testb() {
  23. return testa;
  24. }
  25.  
  26.  
  27. --------------------------
  28. llvm-gcc-4.2 -O3 -emit-llvm hello.c -c -o hello.bc
  29. llvm-dis < hello.bc > hello.bc.through_llvm-dis
  30. -----------------------hello.bc
  31. ; ModuleID = '<stdin>'
  32. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
  33. target triple = "i386-linux-gnu"
  34.  
  35. @.str = private constant [12 x i8] c"hello world\00", align 1
  36.  
  37. define i32 @testa() nounwind readnone {
  38. entry:
  39. ret i32 2
  40. }
  41.  
  42. define i32 @test() nounwind readnone {
  43. entry:
  44. ret i32 ptrtoint (i32 ()* @testa to i32)
  45. }
  46.  
  47. define i32 @testb() nounwind readnone {
  48. entry:
  49. ret i32 ptrtoint (i32 ()* @testa to i32)
  50. }
  51.  
  52. define i32 @main() nounwind {
  53. entry:
  54. %0 = tail call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i32 0, i32 0)) nounwind
  55. ret i32 0
  56. }
  57.  
  58. declare i32 @puts(i8* nocapture) nounwind
  59.  
  60.  
  61. -------------------------------------------------
  62. llc hello.bc -march=c -o hello-llc.c
  63. --------------------------------------hello-llc.c
  64. /* Provide Declarations */
  65. #include <stdarg.h>
  66. #include <setjmp.h>
  67.  
  68. #ifndef __GNUC__ /* Can only support "linkonce" vars with GCC */
  69. #define __attribute__(X)
  70. #endif
  71.  
  72. #if defined(__GNUC__) && defined(__APPLE_CC__)
  73. #define __EXTERNAL_WEAK__ __attribute__((weak_import))
  74. #elif defined(__GNUC__)
  75. #define __EXTERNAL_WEAK__ __attribute__((weak))
  76. #else
  77. #define __EXTERNAL_WEAK__
  78. #endif
  79.  
  80. #if defined(__GNUC__) && defined(__APPLE_CC__)
  81. #define __ATTRIBUTE_WEAK__
  82. #elif defined(__GNUC__)
  83. #define __ATTRIBUTE_WEAK__ __attribute__((weak))
  84. #else
  85. #define __ATTRIBUTE_WEAK__
  86. #endif
  87.  
  88. #if defined(__GNUC__)
  89. #define __HIDDEN__ __attribute__((visibility("hidden")))
  90. #endif
  91.  
  92. #ifdef __GNUC__
  93. #define LLVM_NAN(NanStr) __builtin_nan(NanStr) /* Double */
  94. #define LLVM_NANF(NanStr) __builtin_nanf(NanStr) /* Float */
  95. #define LLVM_NANS(NanStr) __builtin_nans(NanStr) /* Double */
  96. #define LLVM_NANSF(NanStr) __builtin_nansf(NanStr) /* Float */
  97. #define LLVM_INF __builtin_inf() /* Double */
  98. #define LLVM_INFF __builtin_inff() /* Float */
  99. #define LLVM_PREFETCH(addr,rw,locality) __builtin_prefetch(addr,rw,locality)
  100. #define __ATTRIBUTE_CTOR__ __attribute__((constructor))
  101. #define __ATTRIBUTE_DTOR__ __attribute__((destructor))
  102. #define LLVM_ASM __asm__
  103. #else
  104. #define LLVM_NAN(NanStr) ((double)0.0) /* Double */
  105. #define LLVM_NANF(NanStr) 0.0F /* Float */
  106. #define LLVM_NANS(NanStr) ((double)0.0) /* Double */
  107. #define LLVM_NANSF(NanStr) 0.0F /* Float */
  108. #define LLVM_INF ((double)0.0) /* Double */
  109. #define LLVM_INFF 0.0F /* Float */
  110. #define LLVM_PREFETCH(addr,rw,locality) /* PREFETCH */
  111. #define __ATTRIBUTE_CTOR__
  112. #define __ATTRIBUTE_DTOR__
  113. #define LLVM_ASM(X)
  114. #endif
  115.  
  116. #if __GNUC__ < 4 /* Old GCC's, or compilers not GCC */
  117. #define __builtin_stack_save() 0 /* not implemented */
  118. #define __builtin_stack_restore(X) /* noop */
  119. #endif
  120.  
  121. #if __GNUC__ && __LP64__ /* 128-bit integer types */
  122. typedef int __attribute__((mode(TI))) llvmInt128;
  123. typedef unsigned __attribute__((mode(TI))) llvmUInt128;
  124. #endif
  125.  
  126. #define CODE_FOR_MAIN() /* Any target-specific code for main()*/
  127.  
  128. #ifndef __cplusplus
  129. typedef unsigned char bool;
  130. #endif
  131.  
  132.  
  133. /* Support for floating point constants */
  134. typedef unsigned long long ConstantDoubleTy;
  135. typedef unsigned int ConstantFloatTy;
  136. typedef struct { unsigned long long f1; unsigned short f2; unsigned short pad[3]; } ConstantFP80Ty;
  137. typedef struct { unsigned long long f1; unsigned long long f2; } ConstantFP128Ty;
  138.  
  139.  
  140. /* Global Declarations */
  141. /* Helper union for bitcasts */
  142. typedef union {
  143. unsigned int Int32;
  144. unsigned long long Int64;
  145. float Float;
  146. double Double;
  147. } llvmBitCastUnion;
  148. /* Structure forward decls */
  149. struct l_unnamed0;
  150.  
  151. /* Typedefs */
  152. typedef struct l_unnamed0 l_unnamed0;
  153.  
  154. /* Structure contents */
  155. struct l_unnamed0 { unsigned char array[12]; };
  156.  
  157.  
  158. /* External Global Variable Declarations */
  159.  
  160. /* Function Declarations */
  161. unsigned int testa(void);
  162. unsigned int test(void);
  163. unsigned int testb(void);
  164. unsigned int main(void);
  165. //unsigned int puts(unsigned char *);
  166. void abort(void);
  167.  
  168.  
  169. /* Global Variable Declarations */
  170. static struct l_unnamed0 _OC_str;
  171.  
  172.  
  173. /* Global Variable Definitions and Initialization */
  174. static struct l_unnamed0 _OC_str = { "hello world" };
  175.  
  176.  
  177. /* Function Bodies */
  178.  
  179. unsigned int testa(void) {
  180. return 2u;
  181. }
  182.  
  183.  
  184. unsigned int test(void) {
  185. return ((unsigned int )(unsigned long)testa);
  186. }
  187.  
  188.  
  189. unsigned int testb(void) {
  190. return ((unsigned int )(unsigned long)testa);
  191. }
  192.  
  193. unsigned int main(void) {
  194. unsigned int llvm_cbe_tmp__1;
  195.  
  196. CODE_FOR_MAIN();
  197. //llvm_cbe_tmp__1 = /*tail*/ puts(((&_OC_str.array[((signed int )0u)])));
  198. return 0u;
  199. }
  200. -------------------------------------------------------
  201. sdcc -p18f4455 -L /home/j/local/sdcc/share/sdcc/non-free/lib/pic16/ hello-llc.c
  202. ---------------------------------------------hello-llc.lst
  203. gplink-0.13.7 beta
  204. Copyright (c) 1998-2005 gputils project
  205. Listing File Generated: 2-13-2011 05:38:58
  206.  
  207.  
  208. Address Value Disassembly Source
  209. ------- ----- ----------- ------
  210. ;--------------------------------------------------------
  211. ; File Created by SDCC : free open source ANSI-C Compiler
  212. ; Version 3.0.1 #6214 (Feb 7 2011) (Linux)
  213. ; This file was generated Sun Feb 13 05:38:58 2011
  214. ;--------------------------------------------------------
  215. ; PIC16 port for the Microchip 16-bit core micros
  216. ;--------------------------------------------------------
  217. list p=18f4455
  218.  
  219. radix dec
  220.  
  221. ;--------------------------------------------------------
  222. ; public variables in this module
  223. ;--------------------------------------------------------
  224. global _testa
  225. global _test
  226. global _testb
  227. global _main
  228. ;--------------------------------------------------------
  229. ; Equates to used internal registers
  230. ;--------------------------------------------------------
  231. WREG equ 0xfe8
  232. FSR1L equ 0xfe1
  233. FSR2L equ 0xfd9
  234. POSTDEC1 equ 0xfe5
  235. PREINC1 equ 0xfe4
  236. PRODL equ 0xff3
  237.  
  238.  
  239. idata
  240. __OC_str db 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00
  241.  
  242.  
  243. ; Internal registers
  244. .registers udata_ovr 0x0000
  245. r0x00 res 1
  246. r0x01 res 1
  247. r0x02 res 1
  248. r0x03 res 1
  249.  
  250. ;--------------------------------------------------------
  251. ; interrupt vector
  252. ;--------------------------------------------------------
  253.  
  254. ;--------------------------------------------------------
  255. ; global & static initialisations
  256. ;--------------------------------------------------------
  257. ; I code from now on!
  258. ; ; Starting pCode block
  259. S_hello_llc__main code
  260. _main:
  261. ; .line 136; hello-llc.c return 0u;
  262. 000166 6af3 clrf 0xf3, 0 CLRF PRODL
  263. 000168 6ae8 clrf 0xe8, 0 CLRF WREG
  264. 00016a 0012 return 0 RETURN
  265.  
  266. ; ; Starting pCode block
  267. S_hello_llc__testb code
  268. _testb:
  269. ; .line 126; hello-llc.c unsigned int testb(void) {
  270. 00009c cfd9 movff 0xfd9, 0xfe5 MOVFF FSR2L, POSTDEC1
  271. 00009e ffe5
  272. 0000a0 cfe1 movff 0xfe1, 0xfd9 MOVFF FSR1L, FSR2L
  273. 0000a2 ffd9
  274. 0000a4 c000 movff 0, 0xfe5 MOVFF r0x00, POSTDEC1
  275. 0000a6 ffe5
  276. 0000a8 c001 movff 0x1, 0xfe5 MOVFF r0x01, POSTDEC1
  277. 0000aa ffe5
  278. 0000ac c002 movff 0x2, 0xfe5 MOVFF r0x02, POSTDEC1
  279. 0000ae ffe5
  280. 0000b0 c003 movff 0x3, 0xfe5 MOVFF r0x03, POSTDEC1
  281. 0000b2 ffe5
  282. ; .line 127; hello-llc.c return ((unsigned int )(unsigned long)testa);
  283. 0000b4 0e38 movlw 0x38 MOVLW LOW(_testa)
  284. 0000b6 6e00 movwf 0, 0 MOVWF r0x00
  285. 0000b8 0e01 movlw 0x1 MOVLW HIGH(_testa)
  286. 0000ba 6e01 movwf 0x1, 0 MOVWF r0x01
  287. 0000bc 0e00 movlw 0 MOVLW UPPER(_testa)
  288. 0000be 6e02 movwf 0x2, 0 MOVWF r0x02
  289. 0000c0 6a03 clrf 0x3, 0 CLRF r0x03
  290. 0000c2 c001 movff 0x1, 0xff3 MOVFF r0x01, PRODL
  291. 0000c4 fff3
  292. 0000c6 5000 movf 0, 0, 0 MOVF r0x00, W
  293. 0000c8 cfe4 movff 0xfe4, 0x3 MOVFF PREINC1, r0x03
  294. 0000ca f003
  295. 0000cc cfe4 movff 0xfe4, 0x2 MOVFF PREINC1, r0x02
  296. 0000ce f002
  297. 0000d0 cfe4 movff 0xfe4, 0x1 MOVFF PREINC1, r0x01
  298. 0000d2 f001
  299. 0000d4 cfe4 movff 0xfe4, 0 MOVFF PREINC1, r0x00
  300. 0000d6 f000
  301. 0000d8 cfe4 movff 0xfe4, 0xfd9 MOVFF PREINC1, FSR2L
  302. 0000da ffd9
  303. 0000dc 0012 return 0 RETURN
  304.  
  305. ; ; Starting pCode block
  306. S_hello_llc__test code
  307. _test:
  308. ; .line 121; hello-llc.c unsigned int test(void) {
  309. 0000de cfd9 movff 0xfd9, 0xfe5 MOVFF FSR2L, POSTDEC1
  310. 0000e0 ffe5
  311. 0000e2 cfe1 movff 0xfe1, 0xfd9 MOVFF FSR1L, FSR2L
  312. 0000e4 ffd9
  313. 0000e6 c000 movff 0, 0xfe5 MOVFF r0x00, POSTDEC1
  314. 0000e8 ffe5
  315. 0000ea c001 movff 0x1, 0xfe5 MOVFF r0x01, POSTDEC1
  316. 0000ec ffe5
  317. 0000ee c002 movff 0x2, 0xfe5 MOVFF r0x02, POSTDEC1
  318. 0000f0 ffe5
  319. 0000f2 c003 movff 0x3, 0xfe5 MOVFF r0x03, POSTDEC1
  320. 0000f4 ffe5
  321. ; .line 122; hello-llc.c return ((unsigned int )(unsigned long)testa);
  322. 0000f6 0e38 movlw 0x38 MOVLW LOW(_testa)
  323. 0000f8 6e00 movwf 0, 0 MOVWF r0x00
  324. 0000fa 0e01 movlw 0x1 MOVLW HIGH(_testa)
  325. 0000fc 6e01 movwf 0x1, 0 MOVWF r0x01
  326. 0000fe 0e00 movlw 0 MOVLW UPPER(_testa)
  327. 000100 6e02 movwf 0x2, 0 MOVWF r0x02
  328. 000102 6a03 clrf 0x3, 0 CLRF r0x03
  329. 000104 c001 movff 0x1, 0xff3 MOVFF r0x01, PRODL
  330. 000106 fff3
  331. 000108 5000 movf 0, 0, 0 MOVF r0x00, W
  332. 00010a cfe4 movff 0xfe4, 0x3 MOVFF PREINC1, r0x03
  333. 00010c f003
  334. 00010e cfe4 movff 0xfe4, 0x2 MOVFF PREINC1, r0x02
  335. 000110 f002
  336. 000112 cfe4 movff 0xfe4, 0x1 MOVFF PREINC1, r0x01
  337. 000114 f001
  338. 000116 cfe4 movff 0xfe4, 0 MOVFF PREINC1, r0x00
  339. 000118 f000
  340. 00011a cfe4 movff 0xfe4, 0xfd9 MOVFF PREINC1, FSR2L
  341. 00011c ffd9
  342. 00011e 0012 return 0 RETURN
  343.  
  344. ; ; Starting pCode block
  345. S_hello_llc__testa code
  346. _testa:
  347. ; .line 116; hello-llc.c unsigned int testa(void) {
  348. 000138 cfd9 movff 0xfd9, 0xfe5 MOVFF FSR2L, POSTDEC1
  349. 00013a ffe5
  350. 00013c cfe1 movff 0xfe1, 0xfd9 MOVFF FSR1L, FSR2L
  351. 00013e ffd9
  352. ; .line 117; hello-llc.c return 2u;
  353. 000140 6af3 clrf 0xf3, 0 CLRF PRODL
  354. 000142 0e02 movlw 0x2 MOVLW 0x02
  355. 000144 cfe4 movff 0xfe4, 0xfd9 MOVFF PREINC1, FSR2L
  356. 000146 ffd9
  357. 000148 0012 return 0 RETURN
  358.  
  359.  
  360.  
  361. ; Statistics:
  362. ; code size: 156 (0x009c) bytes ( 0.12%)
  363. ; 78 (0x004e) words
  364. ; udata size: 0 (0x0000) bytes ( 0.00%)
  365. ; access size: 4 (0x0004) bytes
  366.  
  367.  
  368. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement