-
Notifications
You must be signed in to change notification settings - Fork 104
Add methods for LLVMTargetDataRef #141
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dea9131
add methods for LLVMTargetDataRef
yowl 3ff9586
attempt to fix data layout so that it passes on x86
yowl 212633f
add headers, mv file to tests from Tests
yowl 8085b40
add header
yowl 6f9bc5f
address feedback, create StructLayout class to provide struct offset …
yowl d6200c1
Match c++ name
yowl 04c5014
Match c++ name
yowl 2de04f0
line up method names with DataLayout.h
yowl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add methods for LLVMTargetDataRef
- Loading branch information
commit dea91316c51b13adaa88246c650dbf7b0dfa23ec
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using LLVMSharp.Interop; | ||
tannergooding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using NUnit.Framework; | ||
|
|
||
| namespace LLVMSharp.UnitTests | ||
| { | ||
| class TargetData | ||
| { | ||
| [Test] | ||
| public void OffsetTest() | ||
| { | ||
| LLVMModuleRef m = LLVMModuleRef.CreateWithName("netscripten"); | ||
| LLVMExecutionEngineRef engineRef = m.CreateExecutionEngine(); | ||
| LLVMTargetDataRef target = engineRef.TargetData; | ||
| LLVMTypeRef testStruct = LLVMTypeRef.CreateStruct( | ||
| new[] | ||
| { | ||
| LLVMTypeRef.Int16, | ||
| LLVMTypeRef.Int32 | ||
| }, true); | ||
|
|
||
| Assert.AreEqual(0, target.OffsetOfElement(testStruct, 0)); | ||
| Assert.AreEqual(2, target.OffsetOfElement(testStruct, 1)); | ||
|
|
||
| Assert.AreEqual(target.ElementAtOffset(testStruct, 0), 0); | ||
| Assert.AreEqual(target.ElementAtOffset(testStruct, 2), 1); | ||
| } | ||
|
|
||
| [Test] | ||
| public void SizeTest() | ||
| { | ||
| LLVMModuleRef m = LLVMModuleRef.CreateWithName("netscripten"); | ||
| LLVMExecutionEngineRef engineRef = m.CreateExecutionEngine(); | ||
| LLVMTargetDataRef target = engineRef.TargetData; | ||
| LLVMTypeRef testStruct = LLVMTypeRef.CreateStruct( | ||
| new[] | ||
| { | ||
| LLVMTypeRef.Int16, | ||
| LLVMTypeRef.Int32 | ||
| }, true); | ||
|
|
||
| Assert.AreEqual(48, target.SizeOfTypeInBits(testStruct)); | ||
| Assert.AreEqual(6, target.StoreSizeOfType(testStruct)); | ||
| Assert.AreEqual(6, target.ABISizeOfType(testStruct)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void AlignmentTest() | ||
| { | ||
| LLVMModuleRef m = LLVMModuleRef.CreateWithName("netscripten"); | ||
| LLVMExecutionEngineRef engineRef = m.CreateExecutionEngine(); | ||
| LLVMTargetDataRef target = engineRef.TargetData; | ||
| LLVMTypeRef testStruct = LLVMTypeRef.CreateStruct( | ||
| new[] | ||
| { | ||
| LLVMTypeRef.Int16, | ||
| LLVMTypeRef.Int32 | ||
| }, true); | ||
|
|
||
| Assert.AreEqual(1, target.ABIAlignmentOfType(testStruct)); | ||
| Assert.AreEqual(1, target.CallFrameAlignmentOfType(testStruct)); | ||
| Assert.AreEqual(8, target.PreferredAlignmentOfType(testStruct)); | ||
|
|
||
| LLVMValueRef global = m.AddGlobal(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), "someGlobal"); | ||
| Assert.AreEqual(8, target.PreferredAlignmentOfGlobal(global)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using LLVMSharp.Interop; | ||
tannergooding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace LLVMSharp | ||
| { | ||
| public class LLVMTargetData | ||
tannergooding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| private readonly LLVMTargetDataRef _llvmTargetDataRef; | ||
|
|
||
| public LLVMTargetData(LLVMTargetDataRef llvmTargetDataRef) | ||
| { | ||
| _llvmTargetDataRef = llvmTargetDataRef; | ||
| } | ||
|
|
||
| public ulong OffsetOfElement(LLVMTypeRef type, uint element) | ||
| { | ||
| return _llvmTargetDataRef.OffsetOfElement(type, element); | ||
| } | ||
|
|
||
| public ulong ElementAtOffset(LLVMTypeRef type, ulong offset) | ||
| { | ||
| return _llvmTargetDataRef.ElementAtOffset(type, offset); | ||
| } | ||
|
|
||
| public ulong SizeOfTypeInBits(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.SizeOfTypeInBits(type); | ||
| } | ||
|
|
||
| public ulong StoreSizeOfType(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.StoreSizeOfType(type); | ||
| } | ||
|
|
||
| public ulong ABISizeOfType(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.ABISizeOfType(type); | ||
| } | ||
|
|
||
| public uint ABIAlignmentOfType(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.ABIAlignmentOfType(type); | ||
| } | ||
|
|
||
| public uint CallFrameAlignmentOfType(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.CallFrameAlignmentOfType(type); | ||
| } | ||
|
|
||
| public uint PreferredAlignmentOfType(LLVMTypeRef type) | ||
| { | ||
| return _llvmTargetDataRef.PreferredAlignmentOfType(type); | ||
| } | ||
|
|
||
| public uint PreferredAlignmentOfGlobal(LLVMValueRef globalVar) | ||
| { | ||
| return _llvmTargetDataRef.PreferredAlignmentOfGlobal(globalVar); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.