Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
659856ce
Commit
659856ce
authored
Feb 07, 2015
by
David Malcolm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new files erroneously omitted from r220494.
From-SVN: r220496
parent
a82289f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
0 deletions
+142
-0
gcc/testsuite/jit.dg/create-code-for-hello-world-executable.h
+101
-0
gcc/testsuite/jit.dg/verify-dynamic-library.c
+41
-0
No files found.
gcc/testsuite/jit.dg/create-code-for-hello-world-executable.h
0 → 100644
View file @
659856ce
/* This code is shared by various test-compile-to-*.c test cases
that ultimately generate a standalone executable
(all of them apart from test-compile-to-dynamic-library.c). */
void
create_code
(
gcc_jit_context
*
ctxt
,
void
*
user_data
)
{
/* Let's try to inject the equivalent of:
static void
hello_world (const char *name)
{
// a test comment
printf ("hello from %s\n", name);
}
extern int
main (int argc, char **argv)
{
hello_world (argv[0]);
return 0;
}
*/
gcc_jit_type
*
void_type
=
gcc_jit_context_get_type
(
ctxt
,
GCC_JIT_TYPE_VOID
);
gcc_jit_type
*
const_char_ptr_type
=
gcc_jit_context_get_type
(
ctxt
,
GCC_JIT_TYPE_CONST_CHAR_PTR
);
gcc_jit_param
*
param_name
=
gcc_jit_context_new_param
(
ctxt
,
NULL
,
const_char_ptr_type
,
"name"
);
gcc_jit_function
*
func
=
gcc_jit_context_new_function
(
ctxt
,
NULL
,
GCC_JIT_FUNCTION_INTERNAL
,
void_type
,
"hello_world"
,
1
,
&
param_name
,
0
);
gcc_jit_param
*
param_format
=
gcc_jit_context_new_param
(
ctxt
,
NULL
,
const_char_ptr_type
,
"format"
);
gcc_jit_function
*
printf_func
=
gcc_jit_context_new_function
(
ctxt
,
NULL
,
GCC_JIT_FUNCTION_IMPORTED
,
gcc_jit_context_get_type
(
ctxt
,
GCC_JIT_TYPE_INT
),
"printf"
,
1
,
&
param_format
,
1
);
gcc_jit_rvalue
*
args
[
2
];
args
[
0
]
=
gcc_jit_context_new_string_literal
(
ctxt
,
"hello from %s
\n
"
);
args
[
1
]
=
gcc_jit_param_as_rvalue
(
param_name
);
gcc_jit_block
*
block
=
gcc_jit_function_new_block
(
func
,
NULL
);
gcc_jit_block_add_comment
(
block
,
NULL
,
"a test comment"
);
gcc_jit_block_add_eval
(
block
,
NULL
,
gcc_jit_context_new_call
(
ctxt
,
NULL
,
printf_func
,
2
,
args
));
gcc_jit_block_end_with_void_return
(
block
,
NULL
);
gcc_jit_type
*
int_type
=
gcc_jit_context_get_type
(
ctxt
,
GCC_JIT_TYPE_INT
);
gcc_jit_param
*
param_argc
=
gcc_jit_context_new_param
(
ctxt
,
NULL
,
int_type
,
"argc"
);
gcc_jit_type
*
char_ptr_ptr_type
=
gcc_jit_type_get_pointer
(
gcc_jit_type_get_pointer
(
gcc_jit_context_get_type
(
ctxt
,
GCC_JIT_TYPE_CHAR
)));
gcc_jit_param
*
param_argv
=
gcc_jit_context_new_param
(
ctxt
,
NULL
,
char_ptr_ptr_type
,
"argv"
);
gcc_jit_param
*
params
[
2
]
=
{
param_argc
,
param_argv
};
gcc_jit_function
*
func_main
=
gcc_jit_context_new_function
(
ctxt
,
NULL
,
GCC_JIT_FUNCTION_EXPORTED
,
int_type
,
"main"
,
2
,
params
,
0
);
block
=
gcc_jit_function_new_block
(
func_main
,
NULL
);
gcc_jit_rvalue
*
zero
=
gcc_jit_context_zero
(
ctxt
,
int_type
);
args
[
0
]
=
gcc_jit_context_new_cast
(
ctxt
,
NULL
,
gcc_jit_lvalue_as_rvalue
(
gcc_jit_context_new_array_access
(
ctxt
,
NULL
,
gcc_jit_param_as_rvalue
(
param_argv
),
zero
)),
const_char_ptr_type
);
gcc_jit_block_add_eval
(
block
,
NULL
,
gcc_jit_context_new_call
(
ctxt
,
NULL
,
func
,
1
,
args
));
gcc_jit_block_end_with_return
(
block
,
NULL
,
zero
);
}
gcc/testsuite/jit.dg/verify-dynamic-library.c
0 → 100644
View file @
659856ce
/* For use by jit-verify-dynamic-library, used by
test-compile-to-dynamic-library.c. */
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int
main
(
int
argc
,
char
**
argv
)
{
void
*
handle
;
void
(
*
hello_world
)
(
const
char
*
name
);
char
*
error
;
handle
=
dlopen
(
"./output-of-test-compile-to-dynamic-library.c.so"
,
RTLD_NOW
|
RTLD_LOCAL
);
if
(
!
handle
)
{
fprintf
(
stderr
,
"dlopen failed: %s
\n
"
,
dlerror
());
exit
(
1
);
}
/* Clear any existing error */
dlerror
();
/* This symbol is from the DSO built by
test-compile-to-dynamic-library.c. */
*
(
void
**
)
(
&
hello_world
)
=
dlsym
(
handle
,
"hello_world"
);
if
((
error
=
dlerror
())
!=
NULL
)
{
fprintf
(
stderr
,
"dlsym failed: %s
\n
"
,
error
);
exit
(
2
);
}
/* Call the function from the generated DSO. */
hello_world
(
argv
[
0
]);
dlclose
(
handle
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment