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
b1c26eb7
Commit
b1c26eb7
authored
8 years ago
by
Andrea Shepard
Browse files
Options
Downloads
Patches
Plain Diff
Make h_llvm_make_tt_suint support variable bit lengths and signed/unsigned distinction
parent
e30a251f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/backends/llvm/llvm.h
+1
-0
1 addition, 0 deletions
src/backends/llvm/llvm.h
src/backends/llvm/llvm_suint.c
+18
-11
18 additions, 11 deletions
src/backends/llvm/llvm_suint.c
src/parsers/ch.c
+1
-1
1 addition, 1 deletion
src/parsers/ch.c
src/parsers/charset.c
+1
-1
1 addition, 1 deletion
src/parsers/charset.c
with
21 additions
and
13 deletions
src/backends/llvm/llvm.h
+
1
−
0
View file @
b1c26eb7
...
...
@@ -37,6 +37,7 @@ bool h_llvm_make_charset_membership_test(HLLVMParserCompileContext *ctxt,
LLVMValueRef
r
,
HCharset
cs
,
LLVMBasicBlockRef
yes
,
LLVMBasicBlockRef
no
);
void
h_llvm_make_tt_suint
(
HLLVMParserCompileContext
*
ctxt
,
uint8_t
length
,
uint8_t
signedp
,
LLVMValueRef
r
,
LLVMValueRef
*
mr_out
);
#endif // #ifndef HAMMER_LLVM__H
...
...
This diff is collapsed.
Click to expand it.
src/backends/llvm/llvm_suint.c
+
18
−
11
View file @
b1c26eb7
...
...
@@ -24,6 +24,7 @@
*/
void
h_llvm_make_tt_suint
(
HLLVMParserCompileContext
*
ctxt
,
uint8_t
length
,
uint8_t
signedp
,
LLVMValueRef
r
,
LLVMValueRef
*
mr_out
)
{
/* Set up call to h_arena_malloc() for a new HParsedToken */
LLVMValueRef
tok_size
=
LLVMConstInt
(
LLVMInt32Type
(),
sizeof
(
HParsedToken
),
0
);
...
...
@@ -36,29 +37,36 @@ void h_llvm_make_tt_suint(HLLVMParserCompileContext *ctxt,
LLVMValueRef
tok
=
LLVMBuildBitCast
(
ctxt
->
builder
,
amalloc
,
ctxt
->
llvm_parsedtokenptr
,
"tok"
);
/*
* tok->token_type = TT_UINT;
* tok->token_type =
signedp ? TT_SINT :
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
);
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt32Type
(),
signedp
?
TT_SINT
:
TT_UINT
,
0
),
toktype
);
/*
* tok->sint = r;
* or
* 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
* the token_data field is a union, but either an int64_t or a uint64_t in the
* cases we can be called for.
*/
LLVMBuildStore
(
ctxt
->
builder
,
LLVMBuildZExt
(
ctxt
->
builder
,
r
,
LLVMInt64Type
(),
"r"
),
tokdata
);
if
(
length
<
64
)
{
/* Extend needed */
LLVMValueRef
r_ext
;
if
(
signedp
)
r_ext
=
LLVMBuildSExt
(
ctxt
->
builder
,
r
,
LLVMInt64Type
(),
"r_sext"
);
else
r_ext
=
LLVMBuildZExt
(
ctxt
->
builder
,
r
,
LLVMInt64Type
(),
"r_zext"
);
LLVMBuildStore
(
ctxt
->
builder
,
r_ext
,
tokdata
);
}
else
{
LLVMBuildStore
(
ctxt
->
builder
,
r
,
tokdata
);
}
/*
* Store the index from the stream into the token
*/
...
...
@@ -71,8 +79,7 @@ void h_llvm_make_tt_suint(HLLVMParserCompileContext *ctxt,
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
);
LLVMBuildStore
(
ctxt
->
builder
,
LLVMConstInt
(
LLVMInt64Type
(),
length
,
0
),
tokbitlen
);
/*
* Now call make_result()
...
...
This diff is collapsed.
Click to expand it.
src/parsers/ch.c
+
1
−
1
View file @
b1c26eb7
...
...
@@ -91,7 +91,7 @@ static bool ch_llvm(HLLVMParserCompileContext *ctxt, void* env) {
/* Make a token */
LLVMValueRef
mr
;
h_llvm_make_tt_suint
(
ctxt
,
r
,
&
mr
);
h_llvm_make_tt_suint
(
ctxt
,
8
,
0
,
r
,
&
mr
);
// br label %ch_end
LLVMBuildBr
(
ctxt
->
builder
,
end
);
...
...
This diff is collapsed.
Click to expand it.
src/parsers/charset.c
+
1
−
1
View file @
b1c26eb7
...
...
@@ -116,7 +116,7 @@ static bool cs_llvm(HLLVMParserCompileContext *ctxt, void* env) {
LLVMPositionBuilderAtEnd
(
ctxt
->
builder
,
success
);
LLVMValueRef
mr
;
h_llvm_make_tt_suint
(
ctxt
,
r
,
&
mr
);
h_llvm_make_tt_suint
(
ctxt
,
8
,
0
,
r
,
&
mr
);
/* br label %ch_end */
LLVMBuildBr
(
ctxt
->
builder
,
end
);
...
...
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