예제 #1
0
파일: main.cpp 프로젝트: dinogun/omr
int main(int argc, char const * const * const argv) {
    assert(argc == 2);
    assert(initializeJit());

    // parse the input Tril file
    FILE* inputFile = fopen(argv[1], "r");
    assert(inputFile != NULL);
    ASTNode* trees = parseFile(inputFile);
    fclose(inputFile);

    printf("parsed trees:\n");
    printTrees(stdout, trees, 0);

    // assume that the file contians a single method and compile it
    Tril::DefaultCompiler incordecCompiler{trees};
    assert(incordecCompiler.compile() == 0);
    auto incordec = incordecCompiler.getEntryPoint<IncOrDecFunction*>();

    int32_t value = 1;
    printf("%d -> %d\n", value, incordec(&value));
    value = 2;
    printf("%d -> %d\n", value, incordec(&value));
    value = -1;
    printf("%d -> %d\n", value, incordec(&value));
    value = -2;
    printf("%d -> %d\n", value, incordec(&value));

    shutdownJit();
    return 0;
}
예제 #2
0
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define type dictionaries\n");
   StructTypeDictionary structTypes;
   UnionTypeDictionary unionTypes;

   printf("Step 3: compile getStructFieldAddress builder\n");
   GetStructFieldAddressBuilder getStructFieldAddressBuilder(&structTypes);
   uint8_t *getStructFieldAddressEntry;
   int32_t rc = compileMethodBuilder(&getStructFieldAddressBuilder, &getStructFieldAddressEntry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: invoke compiled code for getStructFieldAddress and verify results\n");
   Struct s;
   s.f1 = 1;
   s.f2 = 2;
   auto getStructFieldAddress = (GetStructFieldAddressFunction *) getStructFieldAddressEntry;
   auto structFieldAddress = getStructFieldAddress(&s);
   assert(&(s.f2) == structFieldAddress);

   printf("Step 5: compile getUnionFieldAddress builder\n");
   GetUnionFieldAddressBuilder getUnionFieldAddressBuilder(&unionTypes);
   uint8_t *getUnionFieldAddressEntry;
   rc = compileMethodBuilder(&getUnionFieldAddressBuilder, &getUnionFieldAddressEntry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 6: invoke compiled code for getUnionFieldAddress and verify results\n");
   Union u;
   u.f2 = 2;
   auto getUnionFieldAddress = (GetUnionFieldAddressFunction  *) getUnionFieldAddressEntry;
   auto unionFieldAddress = getUnionFieldAddress(&u);
   assert(&(u.f2) == unionFieldAddress);

   printf ("Step 7: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
예제 #3
0
파일: DotProduct.cpp 프로젝트: lmaisons/omr
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define type dictionary\n");
   TR::TypeDictionary types;

   printf("Step 3: compile method builder\n");
   DotProduct method(&types);
   uint8_t *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: define values\n");
   double result[10] = { 0 };
   double values1[10] = { 1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5 };
   double values2[10] = { 10.5,9.5,8.5,7.5,6.5,5.5,4.5,3.5,2.5,1.5 };

   printf("Step 5: invoke compiled code and verify results\n");
   DotProductFunctionType *test = (DotProductFunctionType *)entry;
   test(result, values1, values2, 10);

   printf("result = [\n");
   for (int32_t i=0;i < 10;i++)
      printf("           %lf\n", result[i]);
   printf("         ]\n\n");

   printf ("Step 6: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
예제 #4
0
int
main(int argc, char *argv[])
   {
   int32_t inliningDepth = 1;   // by default, inline one level of calls
   if (argc == 2)
      inliningDepth = atoi(argv[1]);

   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define relevant types\n");
   TR::TypeDictionary types;

   printf("Step 3: compile method builder, inlining one level\n");
   InliningRecursiveFibonacciMethod method(&types, inliningDepth);
   uint8_t *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: invoke compiled code\n");
   RecursiveFibFunctionType *fib = (RecursiveFibFunctionType *)entry;
   for (int32_t n=0;n < 20;n++)
      printf("fib(%2d) = %d\n", n, fib(n));

   printf ("Step 5: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
예제 #5
0
파일: Union.cpp 프로젝트: bjornvar/omr
int
main()
   {
   std::cout << "Step 1: initialize JIT\n";
   assert(initializeJit());

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   {
   std::cout << "Step 2: create UnionTypeDictionary\n";
   UnionTypeDictionary typeDictionary;

   std::cout << "Step 3: assert that the size of each union is the size of its largest member\n";
   assert(sizeof(char*) == typeDictionary.LookupUnion("TestUnionInt8pChar")->getSize());
   assert(sizeof(uint32_t) == typeDictionary.LookupUnion("TestUnionInt32Int32")->getSize());
   assert(sizeof(double) == typeDictionary.LookupUnion("TestUnionInt16Double")->getSize());
   }

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   {
   UnionTypeDictionary setUnionByteTypes;
   UnionTypeDictionary getUnionByteTypes;
   TestUnionInt8pChar testUnion;
   const uint8_t constval = 3;

   std::cout << "Step 4: compile setUnionByte\n";
   SetUnionByteBuilder setUnionByte(&setUnionByteTypes);
   auto setByte = assert_compile<SetUnionByteFunction>(&setUnionByte);

   std::cout << "Step 5: invoke setUnionByte\n";
   setByte(&testUnion, constval);
   assert(constval == testUnion.v_uint8);

   std::cout << "Step 6: compile getUnionByte\n";
   GetUnionByteBuilder getUnionByte(&getUnionByteTypes);
   auto getByte = assert_compile<GetUnionByteFunction>(&getUnionByte);

   std::cout << "Step 7: invoke getUnionByte\n";
   auto expectedByte = testUnion.v_uint8;
   assert(expectedByte == getByte(&testUnion));
   }

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   {
   UnionTypeDictionary setUnionStrTypes;
   UnionTypeDictionary getUnionStrTypes;
   TestUnionInt8pChar testUnion;
   const char* msg = "Hello World!\n";

   std::cout << "Step 8: compile setUnionStr\n";
   SetUnionStrBuilder setUnionStr(&setUnionStrTypes);
   auto setStr = assert_compile<SetUnionStrFunction>(&setUnionStr);

   std::cout << "Step 9: invoke setUnionStr\n";
   setStr(&testUnion, msg);
   assert(msg == testUnion.v_pchar);

   std::cout << "Step 10: compile getUnionStr\n";
   GetUnionStrBuilder getUnionStr(&getUnionStrTypes);
   auto getStr = assert_compile<GetUnionStrFunction>(&getUnionStr);

   std::cout << "Step 11: invoke getUnionStr\n";
   auto expectedStr = testUnion.v_pchar;
   assert(expectedStr == getStr(&testUnion));
   }

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   {
   UnionTypeDictionary typeDictionary;
   TestUnionInt32Int32 testUnion;
   const uint32_t v1 = 5;
   const uint32_t v2 = 10;

   std::cout << "Step 12: compile typePunInt32Int32\n";
   TypePunInt32Int32Builder builder(&typeDictionary);
   auto typePunInt32Int32 = assert_compile<TypePunInt32Int32Function>(&builder);

   std::cout << "Step 13: invoke typePunInt32Int32\n";
   assert(v2 == typePunInt32Int32(&testUnion, v1, v2));
   }

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   {
   UnionTypeDictionary typeDictionary;
   TestUnionInt16Double testUnion;
   const uint16_t v1 = 0xFFFF;
   const double v2 = +0.0;

   std::cout << "Step 14: compile typePunInt16Double\n";
   TypePunInt16DoubleBuilder builder(&typeDictionary);
   auto typePunInt16Dboule = assert_compile<TypePunInt16DoubleFunction>(&builder);

   std::cout << "Step 15: invoke typePunInt16Double\n";
   assert(static_cast<uint16_t>(v2) == typePunInt16Dboule(&testUnion, v1, v2));
   }

   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   std::cout << "Step 16: shutdown JIT\n";
   shutdownJit();
   }
예제 #6
0
파일: main.cpp 프로젝트: jduimovich/omr
int main(int argc, char const * const * const argv) {
    assert(argc == 2);
    assert(initializeJit());

    // parse the input Tril file
    FILE* inputFile = fopen(argv[1], "r");
    assert(inputFile != NULL);
    ASTNode* trees = parseFile(inputFile);
    fclose(inputFile);

    printf("parsed trees:\n");
    printTrees(stdout, trees, 0);

    // assume that the file contians a single method and compile it
    Tril::DefaultCompiler mandelbrotCompiler{trees};
    assert(mandelbrotCompiler.compile() == 0);
    auto mandelbrot = mandelbrotCompiler.getEntryPoint<MandelbrotFunction*>();

    const auto size = 80;                   // number of rows/columns in the output table
    const auto iterations = 1000;           // number of iterations to be performed
    int32_t table[size][size] = {{0}};          // the output table

    mandelbrot(iterations, size, &table[0][0]);

    // iterate over each cell in the table and print a corresponding character
    for (auto y = 0; y < size; ++y) {
        for (auto x = 0; x < size; ++x) {

#if defined(FULL_COLOUR)
            // if the current cell is *outside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] < iterations ? '#' : ' ';

            // map the modulus of the cell's value to a terminal color
            int colors[] = {1, 1, 5, 4, 6, 2, 3, 3, 3, 3};
            auto color = colors[table[y][x] % 10];

            // print the selected character in the calculated color
            // using ANSI escape codes
            printf(" \e[0;3%dm%c\e[0m ", color, c);
#elif defined(SIMPLE_COLOUR)
            // if the current cell is *inside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] >= 1000 ? '#' : ' ';

            // map the cell's x-coordinate to a color
            int colors[] = {0, 1, 3, 2, 6, 4, 5, 5, 5};
            auto color = colors[x / 10];

            // print the selected character in the calculated color
            // using ANSI escape codes
            printf(" \e[0;3%dm%c\e[0m ", color , c);
#else
            // if the current cell is *inside* the Mandelbrot set, print a '#',
            // other wise print ' ' (blank space)
            auto c = table[y][x] >= 1000 ? '#' : ' ';

            // print the selected character
            printf(" %c ", c );
#endif

        }
        printf("\n");
    }

   shutdownJit();
   return 0;
}
예제 #7
0
파일: MatMult.cpp 프로젝트: LinHu2016/omr
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define matrices\n");
   const int32_t N=4;
   double A[N*N];
   double B[N*N];
   double C[N*N];
   double D[N*N];
   for (int32_t i=0;i < N;i++)
      {
      for (int32_t j=0;j < N;j++)
         {
         A[i*N+j] = 1.0;
         B[i*N+j] = (double)i+(double)j;
         C[i*N+j] = 0.0;
         D[i*N+j] = 0.0;
         }
      }
   printMatrix(A, N, "A");
   printMatrix(B, N, "B");

   printf("Step 3: define type dictionaries\n");
   OMR::JitBuilder::TypeDictionary types;
   OMR::JitBuilder::TypeDictionary vectypes;

   printf("Step 4: compile MatMult method builder\n");
   MatMult method(&types);
   void *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 5: invoke MatMult compiled code\n");
   MatMultFunctionType *test = (MatMultFunctionType *)entry;
   test(C, A, B, N);
   printMatrix(C, N, "C");

   printf("Step 6: compile VectorMatMult method builder\n");
   VectorMatMult vecmethod(&vectypes);
   void *vecentry=0;
   rc = compileMethodBuilder(&vecmethod, &vecentry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 7: invoke MatMult compiled code\n");
   MatMultFunctionType *vectest = (MatMultFunctionType *)vecentry;
   vectest(D, A, B, N);
   printMatrix(D, N, "D");

   printf ("Step 8: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }