Skip to content

Instantly share code, notes, and snippets.

@elliottslaughter
Created July 24, 2019 16:45
Show Gist options
  • Save elliottslaughter/321fd0969aaabb5e47f8434e0a533525 to your computer and use it in GitHub Desktop.
Save elliottslaughter/321fd0969aaabb5e47f8434e0a533525 to your computer and use it in GitHub Desktop.
local C = terralib.includec("stdio.h")
local SCHEMA = terralib.includecstring
[[
#ifndef __CONFIG_SCHEMA_H__
#define __CONFIG_SCHEMA_H__
#include <stdbool.h>
#include <stdint.h>
typedef int TempProfile;
#define TempProfile_File 0
typedef int InflowProfile;
#define InflowProfile_File 0
#define InflowProfile_SuctionAndBlowing 1
struct Config {
struct {
struct {
int32_t type;
union {
struct {
int8_t FileDir[256];
} File;
} u;
} xBCLeftHeat;
struct {
int32_t type;
union {
struct {
double addedVelocity;
int8_t FileDir[256];
} File;
struct {
double sigma;
struct {
uint32_t length;
double values[10];
} beta;
double Zw;
struct {
uint32_t length;
double values[10];
} A;
struct {
uint32_t length;
double values[10];
} omega;
} SuctionAndBlowing;
} u;
} yBCLeftInflowProfile;
struct {
int32_t type;
union {
struct {
double addedVelocity;
int8_t FileDir[256];
} File;
struct {
double sigma;
struct {
uint32_t length;
double values[10];
} beta;
double Zw;
struct {
uint32_t length;
double values[10];
} A;
struct {
uint32_t length;
double values[10];
} omega;
} SuctionAndBlowing;
} u;
} xBCLeftInflowProfile;
} BC;
};
#endif // __CONFIG_SCHEMA_H__
]]
local Config = SCHEMA.Config
terra out(config : Config)
C.printf("\nInside Terra function:\n")
C.printf("%s\n", config.BC.xBCLeftInflowProfile.u.File.FileDir)
C.printf("%s\n", config.BC.xBCLeftHeat.u.File.FileDir)
C.printf("\n")
end
terra main()
var config : Config
C.snprintf(&(config.BC.xBCLeftInflowProfile.u.File.FileDir[0]), 256, "%s", "String1111111111111111111111111111111111111111")
C.snprintf(&(config.BC.xBCLeftHeat.u.File.FileDir[0]), 256, "%s", "String2222222222222222222222222222222222222222")
C.printf("Expect this ouput:\n")
C.printf("%s\n", config.BC.xBCLeftInflowProfile.u.File.FileDir)
C.printf("%s\n", config.BC.xBCLeftHeat.u.File.FileDir)
C.printf("\n")
out(config)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment