Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hammer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Denley Lam
hammer
Commits
e30a251f
Commit
e30a251f
authored
8 years ago
by
Andrea Shepard
Browse files
Options
Downloads
Patches
Plain Diff
Split h_llvm_make_tt_suint() out into new file
parent
aeeb7ef9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/SConscript
+1
-1
1 addition, 1 deletion
src/SConscript
src/backends/llvm/llvm.c
+0
-78
0 additions, 78 deletions
src/backends/llvm/llvm.c
src/backends/llvm/llvm_suint.c
+90
-0
90 additions, 0 deletions
src/backends/llvm/llvm_suint.c
with
91 additions
and
79 deletions
src/SConscript
+
1
−
1
View file @
e30a251f
...
@@ -70,7 +70,7 @@ backends = ['backends/%s.c' % s for s in
...
@@ -70,7 +70,7 @@ backends = ['backends/%s.c' % s for s in
# Add LLVM backend if enabled
# Add LLVM backend if enabled
if
GetOption
(
"
use_llvm
"
):
if
GetOption
(
"
use_llvm
"
):
llvm_backend_files
=
[
'
llvm.c
'
,
'
llvm_charset.c
'
]
llvm_backend_files
=
[
'
llvm.c
'
,
'
llvm_charset.c
'
,
'
llvm_suint.c
'
]
backends
=
backends
+
[
'
backends/llvm/%s
'
%
s
for
s
in
llvm_backend_files
]
backends
=
backends
+
[
'
backends/llvm/%s
'
%
s
for
s
in
llvm_backend_files
]
misc_hammer_parts
=
[
misc_hammer_parts
=
[
...
...
This diff is collapsed.
Click to expand it.
src/backends/llvm/llvm.c
+
0
−
78
View file @
e30a251f
...
@@ -179,84 +179,6 @@ void h_llvm_free(HParser *parser) {
...
@@ -179,84 +179,6 @@ void h_llvm_free(HParser *parser) {
llvm_parser
->
mod
=
NULL
;
llvm_parser
->
mod
=
NULL
;
}
}
/*
* Construct LLVM IR to allocate a token of type TT_SINT or TT_UINT
*
* Parameters:
* - mod [in]: an LLVMModuleRef
* - builder [in]: an LLVMBuilderRef, positioned appropriately
* - stream [in]: a value ref to an llvm_inputstreamptr, for the input stream
* - arena [in]: a value ref to an llvm_arenaptr to be used for the malloc
* - r [in]: a value ref to the value to be used to this token
* - mr_out [out]: the return value from make_result()
*
* TODO actually support TT_SINT, inputs other than 8 bit
*/
void
h_llvm_make_tt_suint
(
HLLVMParserCompileContext
*
ctxt
,
LLVMValueRef
r
,
LLVMValueRef
*
mr_out
)
{
/* Set up call to h_arena_malloc() for a new HParsedToken */
LLVMValueRef
tok_size
=
LLVMConstInt
(
LLVMInt32Type
(),
sizeof
(
HParsedToken
),
0
);
LLVMValueRef
amalloc_args
[]
=
{
ctxt
->
arena
,
tok_size
};
/* %h_arena_malloc = call void* @h_arena_malloc(%struct.HArena_.1* %1, i32 48) */
LLVMValueRef
amalloc
=
LLVMBuildCall
(
ctxt
->
builder
,
LLVMGetNamedFunction
(
ctxt
->
mod
,
"h_arena_malloc"
),
amalloc_args
,
2
,
"h_arena_malloc"
);
/* %tok = bitcast void* %h_arena_malloc to %struct.HParsedToken_.2* */
LLVMValueRef
tok
=
LLVMBuildBitCast
(
ctxt
->
builder
,
amalloc
,
ctxt
->
llvm_parsedtokenptr
,
"tok"
);
/*
* tok->token_type = TT_UINT;
*
* %token_type = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 0
*
* TODO if we handle TT_SINT too, adjust here and the zero-ext below
*/
LLVMValueRef
toktype
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
0
,
"token_type"
);
/* store i32 8, i32* %token_type */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt32Type
(),
8
,
0
),
toktype
);
/*
* tok->uint = r;
*
* %token_data = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 1
*/
LLVMValueRef
tokdata
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
1
,
"token_data"
);
/*
* TODO
*
* This is where we'll need to adjust to handle other types (sign vs. zero extend, omit extend if
* r is 64-bit already
*/
LLVMBuildStore
(
ctxt
->
builder
,
LLVMBuildZExt
(
ctxt
->
builder
,
r
,
LLVMInt64Type
(),
"r"
),
tokdata
);
/*
* Store the index from the stream into the token
*/
/* %t_index = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 2 */
LLVMValueRef
tokindex
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
2
,
"t_index"
);
/* %s_index = getelementptr inbounds %struct.HInputStream_.0, %struct.HInputStream_.0* %0, i32 0, i32 2 */
LLVMValueRef
streamindex
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
ctxt
->
stream
,
2
,
"s_index"
);
/* %4 = load i64, i64* %s_index */
/* store i64 %4, i64* %t_index */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMBuildLoad
(
ctxt
->
builder
,
streamindex
,
""
),
tokindex
);
/* Store the bit length into the token */
LLVMValueRef
tokbitlen
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
3
,
"bit_length"
);
/* TODO handle multiple bit lengths */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt64Type
(),
8
,
0
),
tokbitlen
);
/*
* Now call make_result()
*
* %make_result = call %struct.HParseResult_.3* @make_result(%struct.HArena_.1* %1, %struct.HParsedToken_.2* %3)
*/
LLVMValueRef
result_args
[]
=
{
ctxt
->
arena
,
tok
};
LLVMValueRef
mr
=
LLVMBuildCall
(
ctxt
->
builder
,
LLVMGetNamedFunction
(
ctxt
->
mod
,
"make_result"
),
result_args
,
2
,
"make_result"
);
*
mr_out
=
mr
;
}
HParseResult
*
h_llvm_parse
(
HAllocator
*
mm__
,
const
HParser
*
parser
,
HInputStream
*
input_stream
)
{
HParseResult
*
h_llvm_parse
(
HAllocator
*
mm__
,
const
HParser
*
parser
,
HInputStream
*
input_stream
)
{
const
HLLVMParser
*
llvm_parser
=
parser
->
backend_data
;
const
HLLVMParser
*
llvm_parser
=
parser
->
backend_data
;
HArena
*
arena
=
h_new_arena
(
mm__
,
0
);
HArena
*
arena
=
h_new_arena
(
mm__
,
0
);
...
...
This diff is collapsed.
Click to expand it.
src/backends/llvm/llvm_suint.c
0 → 100644
+
90
−
0
View file @
e30a251f
#ifdef HAMMER_LLVM_BACKEND
#include
<llvm-c/Analysis.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include
<llvm-c/Core.h>
#pragma GCC diagnostic pop
#include
<llvm-c/ExecutionEngine.h>
#include
"../../internal.h"
#include
"llvm.h"
/*
* Construct LLVM IR to allocate a token of type TT_SINT or TT_UINT
*
* Parameters:
* - mod [in]: an LLVMModuleRef
* - builder [in]: an LLVMBuilderRef, positioned appropriately
* - stream [in]: a value ref to an llvm_inputstreamptr, for the input stream
* - arena [in]: a value ref to an llvm_arenaptr to be used for the malloc
* - r [in]: a value ref to the value to be used to this token
* - mr_out [out]: the return value from make_result()
*
* TODO actually support TT_SINT, inputs other than 8 bit
*/
void
h_llvm_make_tt_suint
(
HLLVMParserCompileContext
*
ctxt
,
LLVMValueRef
r
,
LLVMValueRef
*
mr_out
)
{
/* Set up call to h_arena_malloc() for a new HParsedToken */
LLVMValueRef
tok_size
=
LLVMConstInt
(
LLVMInt32Type
(),
sizeof
(
HParsedToken
),
0
);
LLVMValueRef
amalloc_args
[]
=
{
ctxt
->
arena
,
tok_size
};
/* %h_arena_malloc = call void* @h_arena_malloc(%struct.HArena_.1* %1, i32 48) */
LLVMValueRef
amalloc
=
LLVMBuildCall
(
ctxt
->
builder
,
LLVMGetNamedFunction
(
ctxt
->
mod
,
"h_arena_malloc"
),
amalloc_args
,
2
,
"h_arena_malloc"
);
/* %tok = bitcast void* %h_arena_malloc to %struct.HParsedToken_.2* */
LLVMValueRef
tok
=
LLVMBuildBitCast
(
ctxt
->
builder
,
amalloc
,
ctxt
->
llvm_parsedtokenptr
,
"tok"
);
/*
* tok->token_type = TT_UINT;
*
* %token_type = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 0
*
* TODO if we handle TT_SINT too, adjust here and the zero-ext below
*/
LLVMValueRef
toktype
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
0
,
"token_type"
);
/* store i32 8, i32* %token_type */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt32Type
(),
8
,
0
),
toktype
);
/*
* tok->uint = r;
*
* %token_data = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 1
*/
LLVMValueRef
tokdata
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
1
,
"token_data"
);
/*
* TODO
*
* This is where we'll need to adjust to handle other types (sign vs. zero extend, omit extend if
* r is 64-bit already
*/
LLVMBuildStore
(
ctxt
->
builder
,
LLVMBuildZExt
(
ctxt
->
builder
,
r
,
LLVMInt64Type
(),
"r"
),
tokdata
);
/*
* Store the index from the stream into the token
*/
/* %t_index = getelementptr inbounds %struct.HParsedToken_.2, %struct.HParsedToken_.2* %3, i32 0, i32 2 */
LLVMValueRef
tokindex
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
2
,
"t_index"
);
/* %s_index = getelementptr inbounds %struct.HInputStream_.0, %struct.HInputStream_.0* %0, i32 0, i32 2 */
LLVMValueRef
streamindex
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
ctxt
->
stream
,
2
,
"s_index"
);
/* %4 = load i64, i64* %s_index */
/* store i64 %4, i64* %t_index */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMBuildLoad
(
ctxt
->
builder
,
streamindex
,
""
),
tokindex
);
/* Store the bit length into the token */
LLVMValueRef
tokbitlen
=
LLVMBuildStructGEP
(
ctxt
->
builder
,
tok
,
3
,
"bit_length"
);
/* TODO handle multiple bit lengths */
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt64Type
(),
8
,
0
),
tokbitlen
);
/*
* Now call make_result()
*
* %make_result = call %struct.HParseResult_.3* @make_result(%struct.HArena_.1* %1, %struct.HParsedToken_.2* %3)
*/
LLVMValueRef
result_args
[]
=
{
ctxt
->
arena
,
tok
};
LLVMValueRef
mr
=
LLVMBuildCall
(
ctxt
->
builder
,
LLVMGetNamedFunction
(
ctxt
->
mod
,
"make_result"
),
result_args
,
2
,
"make_result"
);
*
mr_out
=
mr
;
}
#endif
/* defined(HAMMER_LLVM_BACKEND) */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment