Skip to content
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

How to compile simple program in AOT mode? #1119

Open
ArtemkaKun opened this issue Jun 3, 2024 · 6 comments
Open

How to compile simple program in AOT mode? #1119

ArtemkaKun opened this issue Jun 3, 2024 · 6 comments

Comments

@ArtemkaKun
Copy link

ArtemkaKun commented Jun 3, 2024

Hi, I have the following code in fibI.das file

def fibI(n)
    var last = 1
    var cur = 0
    for i in range(n)
        let tmp = cur
        cur += last
        last = tmp
    return cur

[export]
def main
    print("{fibI(6511134)}")

I call das -aot fibI.das fibI.cpp which creates fibI.cpp file

#include "daScript/misc/platform.h"

#include "daScript/simulate/simulate.h"
#include "daScript/simulate/aot.h"
#include "daScript/simulate/aot_library.h"

 // require builtin

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4100)   // unreferenced formal parameter
#pragma warning(disable:4189)   // local variable is initialized but not referenced
#pragma warning(disable:4244)   // conversion from 'int32_t' to 'float', possible loss of data
#pragma warning(disable:4114)   // same qualifier more than once
#pragma warning(disable:4623)   // default constructor was implicitly defined as deleted
#pragma warning(disable:4946)   // reinterpret_cast used between related classes
#pragma warning(disable:4269)   // 'const' automatic data initialized with compiler generated default constructor produces unreliable results
#pragma warning(disable:4555)   // result of expression not used
#endif
#if defined(__EDG__)
#pragma diag_suppress 826
#elif defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wreturn-local-addr"
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
#endif
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wwritable-strings"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#pragma clang diagnostic ignored "-Wunsequenced"
#pragma clang diagnostic ignored "-Wunused-function"
#endif

namespace das {
namespace _anon_15797834376470220468 {



static void resolveTypeInfoAnnotations()
{
}


inline void main_2f7179f6f3814808 ( Context * __context__ );

void __init_script ( Context * __context__, bool __init_shared )
{
}

inline void main_2f7179f6f3814808 ( Context * __context__ )
{
	builtin_print(((char *) "1781508648"),__context__,((LineInfoArg *)(&LineInfo::g_LineInfoNULL)));
}

static void registerAotFunctions ( AotLibrary & aotLib ) {
	// main_2f7179f6f3814808
	aotLib[0xb1c421b06a36eb6e] = [&](Context & ctx){
		return ctx.code->makeNode<SimNode_Aot<void (*) ( Context * __context__ ),&main_2f7179f6f3814808>>();
	};
	resolveTypeInfoAnnotations();
};

AotListBase impl(registerAotFunctions);
}
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if defined(__EDG__)
#pragma diag_default 826
#elif defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

when I'm trying to build executable with the command clang++ -O3 -I../include fibI.cpp -o fib_das, I have an error

/usr/bin/ld: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/usr/bin/ld: /tmp/fibI-3c0619.o: in function `std::_Function_handler<das::SimNode* (das::Context&), das::_anon_15797834376470220468::registerAotFunctions(std::unordered_map<unsigned long, std::function<das::SimNode* (das::Context&)>, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<std::pair<unsigned long const, std::function<das::SimNode* (das::Context&)> > > >&)::$_0>::_M_invoke(std::_Any_data const&,das::Context&)':
fibI.cpp:(.text+0xc6): undefined reference to `das::LinearChunkAllocator::allocate(unsigned int)'
/usr/bin/ld: /tmp/fibI-3c0619.o: in function `das::_anon_15797834376470220468::main_2f7179f6f3814808(das::Context*)':
fibI.cpp:(.text._ZN3das26_anon_1579783437647022046821main_2f7179f6f3814808EPNS_7ContextE[_ZN3das26_anon_1579783437647022046821main_2f7179f6f3814808EPNS_7ContextE]+0xd): undefined reference to `das::LineInfo::g_LineInfoNULL'
/usr/bin/ld: fibI.cpp:(.text._ZN3das26_anon_1579783437647022046821main_2f7179f6f3814808EPNS_7ContextE[_ZN3das26_anon_1579783437647022046821main_2f7179f6f3814808EPNS_7ContextE]+0x12): undefined reference to `das::builtin_print(char*, das::Context*, das::LineInfoArg*)'
/usr/bin/ld: /tmp/fibI-3c0619.o: in function `das::SimNode_Aot<void (*)(das::Context*), &das::_anon_15797834376470220468::main_2f7179f6f3814808>::eval(das::Context&)@@16':
fibI.cpp:(.text._ZN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEE4evalERS1_@@16[_ZN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEE4evalERS1_]+0x38): undefined reference to `das::LineInfo::g_LineInfoNULL'
/usr/bin/ld: fibI.cpp:(.text._ZN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEE4evalERS1_@@16[_ZN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEE4evalERS1_]+0x40): undefined reference to `das::builtin_print(char*, das::Context*, das::LineInfoArg*)'
/usr/bin/ld: /tmp/fibI-3c0619.o: in function `_GLOBAL__sub_I_fibI.cpp':
fibI.cpp:(.text.startup+0xf): undefined reference to `das::AotListBase::AotListBase(void (*)(std::unordered_map<unsigned long, std::function<das::SimNode* (das::Context&)>, std::hash<unsigned long>, std::equal_to<unsigned long>, std::allocator<std::pair<unsigned long const, std::function<das::SimNode* (das::Context&)> > > >&))'
/usr/bin/ld: /tmp/fibI-3c0619.o:(.data.rel.ro._ZTVN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE[_ZTVN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE]+0x10): undefined reference to `das::SimNode_CallBase::copyNode(das::Context&, das::NodeAllocator*)'
/usr/bin/ld: /tmp/fibI-3c0619.o:(.data.rel.ro._ZTVN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE[_ZTVN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE]+0x20): undefined reference to `das::SimNode::visit(das::SimVisitor&)'
/usr/bin/ld: /tmp/fibI-3c0619.o:(.data.rel.ro._ZTIN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE[_ZTIN3das11SimNode_AotIPFvPNS_7ContextEEXadL_ZNS_26_anon_1579783437647022046821main_2f7179f6f3814808ES2_EEEE]+0x10): undefined reference to `typeinfo for das::SimNode_CallBase'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

What I'm doing incorrectly? Unfortunately, I haven't found instruction in the documentation, and I don't understand tutorial02 thing and how I can apply it to my case?

I'm on Arch Linux, with lastest GCC and Clang and dev tools

@ArtemkaKun
Copy link
Author

After adding libraries to link clang++ -O3 -I../include fibI.cpp -o fib_das -L../build -llibDaScript, I have just

/usr/bin/ld: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

@borisbat
Copy link
Collaborator

borisbat commented Jun 3, 2024

tutorial02aot is example on how to hook up aot to the application

@ArtemkaKun
Copy link
Author

ArtemkaKun commented Jun 4, 2024

Thanks for the response. Unfortunately, I neither understand the example (without additional comments or documentation) nor make script (and I'm not sure that I want to learn how to use it).

Would you like to help me with a simple command I can run from the console on the Linux system? The project is very easy and doesn't need any additional hacks (in my opinion at least), so maybe I just need a couple of commands to make it run.

@borisbat
Copy link
Collaborator

borisbat commented Jun 4, 2024

ok. short version. compile daScriptProfile.exe. run it like this daScriptProfile -test fib_loop.
slightly longer version. AOT needs to be compiled into the executable, which runs interpreted code; aot flag enabled allows code to be picked up

@ArtemkaKun
Copy link
Author

Ok, I will try 👍

@MaxwellGengYF
Copy link
Contributor

I would like to use scripts in c++ build-system: https://github.com/MaxwellGengYF/daScript/blob/master/xmake/xmake_func.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants