Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local C = terralib.includecstring [[
#include "stdio.h"
#include "stdlib.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;
};
]]
local Config = C.Config
terra out(input : &Config)
var config : Config = terralib.attrload(input, { align = 1 })
C.printf("\nInside the task:\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")
var buffer = [&Config](C.malloc(terralib.sizeof(Config)))
if buffer == nil then C.abort() end
terralib.attrstore(buffer, config, { align = 1 })
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(buffer)
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.