How to clear output buffer using LLVM javacpp? How to execute fflush using LLVM javacpp?












0















I am using this javacpp to build a compiler with LLVM in Java.
I was able to generate code for input and output.



INPUT: First I have a LLVMValueRef which is the symbol, say the target variable that will receive the input. Then I have a LLVMValueRef that is the scanf function. I set the arguments and build the function call passing then. It works just fine.



    LLVMValueRef valueRef = symbol.getLlvmValueRef();
LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf");
LLVMValueRef scanfArgs = { str, valueRef };
LLVMBuildCall(builderRef, scanfFunction, new PointerPointer(scanfArgs), 2, "scanf");


OUTPUT: Similarly I am able to print out whatever the string I want. I have printt, which I can get with LLVMGetNamedFunction, and after that I build the fuction call passing all the arguments that composes the string to be printed.



    LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf");
LLVMBuildCall(builderRef, printFunction, new PointerPointer(args), printArgs.size(), "printf");


MY PROBLEM:



If I have a printf before a scanf, the scanf always comes first.
I think it has something with the buffer, similar to this problem:
C/C++ printf() before scanf() issue



So I tried to fflush it after build every printf call. Like this:



    LLVMValueRef fflushArgs = { LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)) };
LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");
LLVMBuildCall(builderRef, fflushFunction, new PointerPointer(fflushArgs), 1, "fflush");


My intention is to call fflush(null).



However, I get this error:



LLVM ERROR: Tried to execute an unknown external function: fflush



So, I have access to printf and scanf, but I can not use fflush



How can I be able to use FFLUSH?
Is there another way to clear this buffer?
What can I do to have printf and scanf happening in the correct order?
Thanks for all your help.










share|improve this question























  • Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

    – sepp2k
    Nov 24 '18 at 14:20











  • No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

    – MariaH
    Nov 24 '18 at 23:53













  • Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

    – sepp2k
    Nov 25 '18 at 3:24
















0















I am using this javacpp to build a compiler with LLVM in Java.
I was able to generate code for input and output.



INPUT: First I have a LLVMValueRef which is the symbol, say the target variable that will receive the input. Then I have a LLVMValueRef that is the scanf function. I set the arguments and build the function call passing then. It works just fine.



    LLVMValueRef valueRef = symbol.getLlvmValueRef();
LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf");
LLVMValueRef scanfArgs = { str, valueRef };
LLVMBuildCall(builderRef, scanfFunction, new PointerPointer(scanfArgs), 2, "scanf");


OUTPUT: Similarly I am able to print out whatever the string I want. I have printt, which I can get with LLVMGetNamedFunction, and after that I build the fuction call passing all the arguments that composes the string to be printed.



    LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf");
LLVMBuildCall(builderRef, printFunction, new PointerPointer(args), printArgs.size(), "printf");


MY PROBLEM:



If I have a printf before a scanf, the scanf always comes first.
I think it has something with the buffer, similar to this problem:
C/C++ printf() before scanf() issue



So I tried to fflush it after build every printf call. Like this:



    LLVMValueRef fflushArgs = { LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)) };
LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");
LLVMBuildCall(builderRef, fflushFunction, new PointerPointer(fflushArgs), 1, "fflush");


My intention is to call fflush(null).



However, I get this error:



LLVM ERROR: Tried to execute an unknown external function: fflush



So, I have access to printf and scanf, but I can not use fflush



How can I be able to use FFLUSH?
Is there another way to clear this buffer?
What can I do to have printf and scanf happening in the correct order?
Thanks for all your help.










share|improve this question























  • Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

    – sepp2k
    Nov 24 '18 at 14:20











  • No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

    – MariaH
    Nov 24 '18 at 23:53













  • Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

    – sepp2k
    Nov 25 '18 at 3:24














0












0








0








I am using this javacpp to build a compiler with LLVM in Java.
I was able to generate code for input and output.



INPUT: First I have a LLVMValueRef which is the symbol, say the target variable that will receive the input. Then I have a LLVMValueRef that is the scanf function. I set the arguments and build the function call passing then. It works just fine.



    LLVMValueRef valueRef = symbol.getLlvmValueRef();
LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf");
LLVMValueRef scanfArgs = { str, valueRef };
LLVMBuildCall(builderRef, scanfFunction, new PointerPointer(scanfArgs), 2, "scanf");


OUTPUT: Similarly I am able to print out whatever the string I want. I have printt, which I can get with LLVMGetNamedFunction, and after that I build the fuction call passing all the arguments that composes the string to be printed.



    LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf");
LLVMBuildCall(builderRef, printFunction, new PointerPointer(args), printArgs.size(), "printf");


MY PROBLEM:



If I have a printf before a scanf, the scanf always comes first.
I think it has something with the buffer, similar to this problem:
C/C++ printf() before scanf() issue



So I tried to fflush it after build every printf call. Like this:



    LLVMValueRef fflushArgs = { LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)) };
LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");
LLVMBuildCall(builderRef, fflushFunction, new PointerPointer(fflushArgs), 1, "fflush");


My intention is to call fflush(null).



However, I get this error:



LLVM ERROR: Tried to execute an unknown external function: fflush



So, I have access to printf and scanf, but I can not use fflush



How can I be able to use FFLUSH?
Is there another way to clear this buffer?
What can I do to have printf and scanf happening in the correct order?
Thanks for all your help.










share|improve this question














I am using this javacpp to build a compiler with LLVM in Java.
I was able to generate code for input and output.



INPUT: First I have a LLVMValueRef which is the symbol, say the target variable that will receive the input. Then I have a LLVMValueRef that is the scanf function. I set the arguments and build the function call passing then. It works just fine.



    LLVMValueRef valueRef = symbol.getLlvmValueRef();
LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf");
LLVMValueRef scanfArgs = { str, valueRef };
LLVMBuildCall(builderRef, scanfFunction, new PointerPointer(scanfArgs), 2, "scanf");


OUTPUT: Similarly I am able to print out whatever the string I want. I have printt, which I can get with LLVMGetNamedFunction, and after that I build the fuction call passing all the arguments that composes the string to be printed.



    LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf");
LLVMBuildCall(builderRef, printFunction, new PointerPointer(args), printArgs.size(), "printf");


MY PROBLEM:



If I have a printf before a scanf, the scanf always comes first.
I think it has something with the buffer, similar to this problem:
C/C++ printf() before scanf() issue



So I tried to fflush it after build every printf call. Like this:



    LLVMValueRef fflushArgs = { LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)) };
LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");
LLVMBuildCall(builderRef, fflushFunction, new PointerPointer(fflushArgs), 1, "fflush");


My intention is to call fflush(null).



However, I get this error:



LLVM ERROR: Tried to execute an unknown external function: fflush



So, I have access to printf and scanf, but I can not use fflush



How can I be able to use FFLUSH?
Is there another way to clear this buffer?
What can I do to have printf and scanf happening in the correct order?
Thanks for all your help.







buffer llvm fflush javacpp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 4:25









MariaHMariaH

1411415




1411415













  • Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

    – sepp2k
    Nov 24 '18 at 14:20











  • No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

    – MariaH
    Nov 24 '18 at 23:53













  • Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

    – sepp2k
    Nov 25 '18 at 3:24



















  • Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

    – sepp2k
    Nov 24 '18 at 14:20











  • No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

    – MariaH
    Nov 24 '18 at 23:53













  • Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

    – sepp2k
    Nov 25 '18 at 3:24

















Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

– sepp2k
Nov 24 '18 at 14:20





Did you declare printf and scanf before you used them? If so, you should do the same for fflush.

– sepp2k
Nov 24 '18 at 14:20













No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

– MariaH
Nov 24 '18 at 23:53







No, I just use them. I just do this: LLVMValueRef printFunction = LLVMGetNamedFunction(moduleRef, "printf"); LLVMValueRef scanfFunction = LLVMGetNamedFunction(moduleRef, "scanf"); and it works for them, but not for fflush when I do (similarly): LLVMValueRef fflushFunction = LLVMGetNamedFunction(moduleRef, "fflush");

– MariaH
Nov 24 '18 at 23:53















Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

– sepp2k
Nov 25 '18 at 3:24





Oh, on second look this looks like an error message you'd get out of lli. Does that mean that generating the LLVM works fine and you only get the error when running it? If so, does it work if you compile it instead of using lli? Or if you're not using lli, how are you running it? Have you looked at this: groups.google.com/forum/#!topic/llvm-dev/hhQv8U9aQLI

– sepp2k
Nov 25 '18 at 3:24












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455123%2fhow-to-clear-output-buffer-using-llvm-javacpp-how-to-execute-fflush-using-llvm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455123%2fhow-to-clear-output-buffer-using-llvm-javacpp-how-to-execute-fflush-using-llvm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen