Skip to content

Instantly share code, notes, and snippets.

@sergio2540
Last active December 21, 2015 00:39
Show Gist options
  • Save sergio2540/b5b45f9e13e533ea056d to your computer and use it in GitHub Desktop.
Save sergio2540/b5b45f9e13e533ea056d to your computer and use it in GitHub Desktop.
Explain crowprocess/pre/data/

####1. In crowdprocess/pre/data.json: ######Example: FireSim-Emscripten/crowdprocess/pre/data.json:

{
  "input": {
    "argv": [
      {
        "arg": "argument_value1",
        "pos": "position of  argument_value1"
      },
      {
        "arg": "argument_value2",
        "pos": "position of  argument_value2"
      }
    ]
  }
}

####2. In generated code:

// var data is equal to read and parse ./data.json 

Module['arguments'] = []

//Fixed arguments

if((data.input) && (data.input.argv)){
	var argv = data.input.argv;
	argv.forEach(function(arg){
		Module['arguments'][arg.pos] = arg.arg;
	});
}

Module.callMain(Module['arguments']);

####1. In crowdprocess/pre/data.json: ######Example: FireSim-Emscripten/crowdprocess/pre/data_input.json:

{
  "input": {
    "files": [
      {
        "name": "/random.txt",
        "content": "../../random/random.txt"
      }
    ]
  }
}

####2. In crowdprocess/

cat ./pre/data/data.json | gencpd --compress compressFunction.js > ./data/data.json

gencpd replace the local path ../../random/random.txt with the content of the file and add the property compress if you specify a compress function with --compress option.

####3. In generated code:

// var data is equal to  read and parse ./data.json 


//Fixed files

if((data.input) && (data.input.files)){ 
    var files = data.input.files;
	files.forEach(function(file) {
 
		var dirname = Module['dirname'](file.name);
		var basename = Module['basename'](file.name);
		
	
		var content = ((file.decompress) || (file.compress)) ? Module['decompress'](file.content) : file.content;
		

		Module['FS_createDataFile'](dirname,basename,content,true,true); 
	}); 

}

####1. In crowdprocess/pre/data.json ######Example: FireSim-Emscripten/crowdprocess/pre/data_output.json:

{
  "output": {
    "files": [
      {
        "name": "/random.txt"
      }
    ]
  }
}

####2. In generated code:

//Fixed output

if((data.output) && (data.output.files)){
    var files = data.output.files;
	files.forEach(function(file) {
   
		var dirname = Module['dirname'](file.name);
	
		var basename = Module['basename'](file.name);

                //Attention: always get content from root '/' !!!!!!
		
                var content = intArrayToString(FS.root.contents[basename].contents);
		content = ((file.compress) || (file.decompress)) ? Module['compress'](content) : content;

		Module['return']['output']['files'][dirname + basename] =  content;
    


	}); 

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment