how to define metadata for #llvm.dbg.declare? - compilation

I am trying to use #llvm.dbg.declare to get information about a variable inside llvm code
I use the following code:
define i32 #main() nounwind ssp {
%1 = alloca i32, align 4
%tsi = alloca %struct.timespec, align 8
%tsf = alloca %struct.timespec, align 8
%elaps_s = alloca double, align 8
%elaps_ns = alloca i64, align 8
%N = alloca i32, align 4
call void #llvm.dbg.declare(metadata !{i32* %N }, metadata !11, metadata !13)
...
}
!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !4, globals: !5, imports: !6)
!1 = !DIFile(filename: "mmul.ll", directory: "/home/clereco/LLFI-master/test_programs/mmul-10x10-v3")
!2 = !{}
!3 = !{!4}
!4 = !DISubprogram(name: "main", scope: !1, file: !1, line: 18, type: !5, isLocal: false, isDefinition: true, scopeLine: 18, isOptimized: false, function: i32 ()* #main, variables: !2)
!5 = !DISubroutineType(types: !6)
!6 = !{null}
!7 = !{i32 2, !"Dwarf Version", i32 2}
!8 = !{i32 2, !"Debug Info Version", i32 3}
!9 = !{i32 1, !"PIC Level", i32 2}
!10 = !{!"clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)"}
!11 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "N", scope: !4, file: !1, line: 6, type: !12)
!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!13 = !DIExpression()
When I compile using llc file.ll I getthe following error:
llc: mmul.ll:290:6: error: expected type
!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, flags: "-O2", runtimeVersion: 2, splitDebugFilename: "abc.debug", emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !4, globals: !5, imports: !6)
^
I can not understand if it is a problem in the definition of the metadata inside the llvm code or I should specify some parameters when compiling?
Thanks for your help

Related

How can replace all case in value of column using linq.js?

I using linq.js and i want replace single quotes when searching data.
This my code.
var list = [
{ a: "50", b: 4, c: 1 },
{ a: "60", b: 3, c: 7 },
{ a: "'540'", b: 3, c: 3 }
];
var val = "'540'";
val = val.replace(/'/g, "'");
var res = Enumerable.From(list).Where("($.a).replace(\"'\",\"'\")=='" + val + "'").ToArray();
If there is only 1 single quote in the data, it works.
But if there are 2 single quote in it, it can't search.
Oh, linq.js the same code in javascript.
I have to use regex to replace:
It is ok , if i change to :
var res = Enumerable.From(list).Where("($.a).replace(\/'\/g,\"'\")=='" + val + "'").ToArray();

Bad instruction error Swift 3 and XCode 8

I've been learning Swift 3 syntax lately and I thought that a good first project would be a Vigenère Cipher. So I've begun to create a script for it in Playground.
The issue is that I keep getting an error when I call the method and I know what the mistake is, it has to do with how I am calling my Dictionary value and the fact that I am unwrapping it, But I don't know what else to do about it. Any ideas?
import Foundation
let alphabet: [String: Int] = ["a": 0, "b": 1, "c": 2, "d": 3, "e": 4, "f": 5, "g": 6, "h": 7, "i": 8,
"j": 9, "k": 10, "l": 11, "m": 12, "n": 13, "o": 14, "p": 15, "q": 16,
"r": 17, "s": 18,"t": 19, "u": 20, "v": 21, "w": 22, "x": 23, "y": 24, "z": 25]
let alphabet2: [Int: String] = [0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g", 7: "h", 8: "i",
9: "j", 10: "k", 11: "l", 12: "m", 13: "n", 14: "o", 15: "p", 16: "q",
17: "r", 18: "s", 19: "t", 20: "u", 21: "v", 22: "w", 23: "x", 24: "y", 25: "z"]
var mess = "I once saw a big mosquito"
var key = "pass"
func cipher(message: String, key: String) -> String{
var code: [Int] = [] // will hold the encripted code
// removes whietspace from message and key
let trimmedMessage = message.trimmingCharacters(in: NSCharacterSet.whitespaces)
let trimmedKey = key.trimmingCharacters(in: NSCharacterSet.whitespaces)
// Sets the key the same size as the message
let paddedTrimmedKey = trimmedKey.padding(toLength: message.characters.count, withPad: trimmedKey, startingAt: 0)
// separates the message and key into individual characters
let charTrimmedMessage = Array(trimmedMessage.characters)
let charPaddedTrimmedKey = Array(paddedTrimmedKey.characters)
// Compare the values in the key to the message and scrambles the message.
var i = 0
for chr in charTrimmedMessage{
code.append((alphabet[String(chr)]! + alphabet[String(charPaddedTrimmedKey[i])]!) % 26) // <- I think the error comes from this line. Maybe the exclamation marks?
i += 1
}
var cyphr: String = "" // this will hold the return String
// I think I could have used some sort of "join" function here.
for number in code{
cyphr = cyphr + alphabet2[number + 1]!
}
return cyphr
}
cipher(message: mess, key: key) // <--- this returns an error, no clue why. The code works and compiles great.
I get this error:
If you could let me know any pointer on how to improve my code to avoid things like this even better.
Your alphabet dictionary does not have lookup values for the letters "I", " " which are contained in your plain text. The cipher function fails because of this (since it is force unwrapping an optional which is nil)
If you initialize the mess variable, you will get the cipher to work
var mess = "ioncesawabigmosquito"
cipher(...) -> "ypgvuttpqcbzcpljkjmh"
Either
update the alphabet lookup dictionary. E.g. add ' ' as a valid input, update alphabet2 to provide reverse lookup, and change the mod factor from 26 to 27 (to account for new ' ' character)
OR
validate your input beforehand. (trim spaces, replace spaces, convert uppercase to lowercase / strip characters not in valid range)
To trim your input to only include valid letters in the alphabet, you could try:
let validSet = CharacterSet.init(charactersIn: alphabet.keys.joined())
var messTrimmed = mess.trimmingCharacters(in: validSet.inverted)
Note that doing this mean losing information from the original message
Another bug:
The line cyphr = cyphr + alphabet2[number+1]! should be cyphr = cyphr + alphabet2[number]!.
It's not correct to add 1 to number since the values in the code array are computed mod 26, and the max key value in alphabet is 25. It will cause an exception when force unwrapping to a non-existent key.
E.g. try cipher(message: "ypgvuttpqcbzcpljkjmh", key: "pass") to make it fail.
Footnote
As a complete aside, here's a variant of the cipher function (I have not sanitized the inputs; just showing how the code could be written in a functional way)
func cipher2(message: String, key: String) -> String {
return
message
.characters
.enumerated()
.map { ($0, String($1)) }
.map {
(
alphabet[$1]!
+ alphabet[String(key[key.index(key.startIndex, offsetBy: ($0 % key.characters.count))])]!
) % 26
}
.map { alphabet2[$0]! }
.joined()
}

EXEC_BAD_INSTRUCTION (code=1, address=0xe) with MusicSequenceBarBeatTimeToBeats in Swift 2

I have problem when using Apples MusicSequence C API in Swift 2. I can't figure out how to get rid of EXEC_BAD_INSTRUCTION when calling MusicSequenceBarBeatTimeToBeats.
I have tried a lot of different solutions found on internet, but nothing seems to work.
My first try that didn't result an compile error was:
import Cocoa
import AudioToolbox
var musicSequence = MusicSequence()
NewMusicSequence(&musicSequence)
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, &musicTimeStamp)
The result is: EXEC_BAD_INSTRUCTION (code=1, address=0xe) at the MusicSequenceBarBeatTimeToBeats code row
Then I tried with this, but with same result:
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp = UnsafeMutablePointer<MusicTimeStamp>.alloc(sizeof(MusicTimeStamp))
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, musicTimeStamp)
musicTimeStamp.dealloc(sizeof(MusicTimeStamp))
I have tried the withUnsafeutablePointer function, but with same runtime error:
var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0
withUnsafeMutablePointer(&musicTimeStamp,
{
MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, UnsafeMutablePointer($0))
})
If I pass nil in the third parameter it doesn't crash, but this is useless because the output is missing. So it seem to be the UnsafeMutablePointer<MusicTimeStamp> output parameter that is the problem.
MusicSequenceBarBeatTimeToBeats(musicSequence, &caBarBeatTime, nil)
Any suggestions?

AuthorizationCreate in Swift (Xcode 6)

I've been looking for some help in creating authorization for my app to have it run a few shell scripts as root. I've looked through the Apple documentation (which is of course written in OBJ-C and quite vague) and I'm trying to use the code examples in Swift.
Immediately I'm running in an error with the AuthorizationCreate function:
var authRef: AuthorizationRef
let osStatus = AuthorizationCreate(nil, nil, kAuthorizationFlagDefaults, &authRef)
'Int' is not convertible to 'AuthorizationFlags'
I'm just trying to follow along with the code snippets in the docs from: https://developer.apple.com/library/mac/documentation/Security/Conceptual/authorization_concepts/03authtasks/authtasks.html#//apple_ref/doc/uid/TP30000995-CH206-TP9
And I found the constant for kAuthorizationFlagDefaults from here: https://developer.apple.com/library/mac/documentation/Security/Reference/authorization_ref/#//apple_ref/doc/constant_group/Authorization_Options
I'm running in 10.10.1 if that matters.
I've seen the solution for using AppleScript, but I really want to avoid this is possible.
kAuthorizationFlagDefaults is an Int and has to be converted to
AuthorizationFlags (which is a type alias for UInt32). Also authRef has to be initialized:
var authRef: AuthorizationRef = nil
let authFlags = AuthorizationFlags(kAuthorizationFlagDefaults)
let osStatus = AuthorizationCreate(nil, nil, authFlags, &authRef)
Extended example (untested!):
var myItems = [
AuthorizationItem(name: "com.myOrganization.myProduct.myRight1",
valueLength: 0, value: nil, flags: 0),
AuthorizationItem(name: "com.myOrganization.myProduct.myRight2",
valueLength: 0, value: nil, flags: 0)
]
var myRights = AuthorizationRights(count: UInt32(myItems.count), items: &myItems)
let myFlags = AuthorizationFlags(kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights)
var authRef: AuthorizationRef = nil
let authFlags = AuthorizationFlags(kAuthorizationFlagDefaults)
let osStatus = AuthorizationCreate(&myRights, nil, authFlags, &authRef)
Edit: Swift 3
var myItems = [
AuthorizationItem(name: "com.myOrganization.myProduct.myRight1",
valueLength: 0, value: nil, flags: 0),
AuthorizationItem(name: "com.myOrganization.myProduct.myRight2",
valueLength: 0, value: nil, flags: 0)
]
var myRights = AuthorizationRights(count: UInt32(myItems.count), items: &myItems)
let myFlags : AuthorizationFlags = [.interactionAllowed, .extendRights]
var authRef: AuthorizationRef?
let osStatus = AuthorizationCreate(&myRights, nil, myFlags, &authRef)

Need help with report expression - RDLC

I have a column type int and I want to check the value to display string instead of the number.
I added this expression
=IIf(Fields!Categ.Value = 1, "First", "")
=IIf(Fields!Categ.Value = 2, "Second", "")
=IIf(Fields!Categ.Value = 3, "Third", "")
=IIf(Fields!Categ.Value = 4, "Fourth", "")
=IIf(Fields!Categ.Value = 5, "Fifth", "")
but it is not working.
How can I do it?
Can you try this?
=Switch(
Fields!Categ.Value = 1, "First",
Fields!Categ.Value = 2, "Second",
Fields!Categ.Value = 3, "Third",
Fields!Categ.Value = 4, "Fourth",
Fields!Categ.Value = 5, "Fifth",
Fields!Categ.Value > 5, "",
Fields!Categ.Value < 1, "",
)
I believe the values returned by the .value condition are strings so you could either have to cast them or do a string comparison.
String Comparison
=IIf(Fields!Categ.Value == "1", "First", "")
Int Cast
=IIf(Int.Parse(Fields!Categ.Value) == 1, "First", "")
Its been awhile since I have worked with RDLC.
To add embedded code to a report, use the Code tab of the Report Properties dialog box. The code block you create can contain multiple methods. Methods in embedded code must be written in Microsoft Visual Basic and must be instance-based.
so for example:
public function getDescription(cat as integer) as string
dim sRet as string
select case cat
case 1: sRet = "first"
case 2: sRet = "second"
case else
sRet = "uh?"
end select
return sRet
end function
then use the expression:
=code.getDescription(fields!Categ.value)

Resources